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);
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis