Source code Security & compliance

JWT verify without algorithm check

Part of the AI-generated code risks check · fix arrives as a pull request

What it is

A JWT is verified without pinning the expected signing algorithm, so the algorithm is taken from the token's own header.

Why it matters

The token tells your verifier how to check the token. With alg: none, or by presenting an HMAC token to a verifier holding an RSA public key, an attacker can mint a valid-looking token for any user.

How to fix it

Pass the algorithm explicitly — jwt.verify(token, key, { algorithms: ['RS256'] }) — and reject anything else. Never let the header decide.

Run them all on your app

Connect your repo and your live services with read-only scopes. The first scan is free, and nothing changes without your approval.