Why AI tools produce this: AI coding tools generate this anti-pattern by default, it appears in a large share of AI-written auth code.
Why this matters
It does NOT verify the signature. Trusting any claim returned by decode() (e.g. sub, role, scope) lets an attacker forge a token and bypass authentication entirely.
Use jwt.verify(token, secret, { algorithms: ['RS256'] }), which checks the signature before returning the payload. Only use decode() for non-security-sensitive inspection (e.g. reading kid before verifying).
import jwt from 'jsonwebtoken';import { decodeJwt } from 'jose';declare const token: string;// ok: auth.jwt.decode-without-verify -- verify() checks the signatureconst verified = jwt.verify(token, process.env.JWT_SECRET!, { algorithms: ['RS256'],});// ok: auth.jwt.decode-without-verify -- jose.decodeJwt is a different library, out of scopeconst joseClaims = decodeJwt(token);// ok: auth.jwt.decode-without-verify -- a custom decode() unrelated to jsonwebtokenfunction decode(value: string): string { return Buffer.from(value, 'base64').toString('utf8');}const custom = decode(token);export { verified, joseClaims, custom };
Suppressing this rule
If a finding is a genuine false positive, scope the suppression to the exact line and leave a reason, never disable the rule project-wide. Disable directives are line-scoped by design.