Security rules
NGB059: JWT decoded without signature verification
Reports server-side code (SSR servers, API routes, BFFs) that decodes a JSON Web Token without verifying its signature — jsonwebtoken jwt.decode(), and jose decodeJwt() / jwt-decode in server files — when no verification call (jwt.verify, jwtVerify, verifyIdToken, …) exists in the same function.
| Property | Value |
|---|---|
| Rule ID | NGB059 |
| Category | Angular SSR security |
| Default severity | high |
| CWE | CWE-347, CWE-345, CWE-287 |
| Built-in presets | recommended: error, strict: error |
Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.
What it checks
Reports server-side code (SSR servers, API routes, BFFs) that decodes a JSON Web Token without verifying its signature — jsonwebtoken jwt.decode(), and jose decodeJwt() / jwt-decode in server files — when no verification call (jwt.verify, jwtVerify, verifyIdToken, …) exists in the same function. Also reports jwt.verify() configured to accept the none algorithm. Severity is high when the payload drives an authorization decision or becomes the request identity, medium otherwise.
Why it matters
Decoding is Base64: anyone can create a token with "role": "admin". Code that decodes a bearer token on the server and trusts its claims accepts forged identities. Decoding in the browser is fine (the client cannot be trusted anyway and the API verifies), which is why browser code is not reported.
Detection behavior and supported patterns
jwt.decode(token)(jsonwebtoken, any import style) — server-only package, reported anywheredecodeJwt(token)(jose) andjwtDecode(token)(jwt-decode) in server files (server.ts,*.server.ts, files importing Node / Express modules)- Not reported when the same function also calls a verification function (
verify,jwtVerify,compactVerify,verifyIdToken, …) — e.g. decoding the header to look up a key jwt.verify(token, key, { algorithms: ['none', …] })— high- High severity: claims such as
role,admin,scope,permissions,subused in conditions, or the payload assigned toreq.user/res.locals
Example
const claims = jwt.decode(req.headers.authorization!.slice(7)) as JwtPayload;if (claims.role === 'admin') return next();Safer alternative
const claims = jwt.verify(req.headers.authorization!.slice(7), publicKey, { algorithms: ['RS256'], audience: 'api' }) as JwtPayload;if (claims.role === 'admin') return next();Remediation
Verify the token with the issuer's key and an explicit algorithm list (jwt.verify(token, key, { algorithms: ['RS256'], audience, issuer }) or jose.jwtVerify) and use the claims from the verification result only. Never allow none.
False-positive considerations
- Handlers behind a verifying gateway / middleware that only read display claims are reported with medium severity; prefer reading the claims the middleware attached (
req.auth).
Known limitations
- Verification performed by middleware before the handler (e.g.
express-jwt) is not linked; such handlers are reported if they decode the token again themselves. - Custom JWT parsing (
JSON.parse(atob(token.split(".")[1]))) is not recognized.
References
Run it
ngbastion explain NGB059