Do not use hardcoded secret with a JWT

Metadata

ID: typescript-node-security/jwt-hardcoded-secret

Language: TypeScript

Severity: Error

Category: Security

Description

Never hardcode secrets. Instead, use secrets from environment variables or a secret vault.

Non-Compliant Code Examples

import jwt from "jsonwebtoken";

const token = jwt.sign({ foo: "bar" }, "secret");

const token = jwt.sign({ foo: "bar" }, 'secret');

const token = jwt.sign({ foo: "bar" }, `secret`);

Compliant Code Examples

import jwt from "jsonwebtoken";

const token = jwt.sign({ foo: "bar" }, process.env.JWT_SECRET);