Blog / A07:2021 Identification and Authentication Failures
A07:2021 · Identification and Authentication Failures

Let the Token Pick Its Own Verification

If your JWT check reads the algorithm and key hint out of the token before verifying it, the attacker sets both. none, or HS256 against your public key, whatever gets in.

client posts atokenverifier readstoken headeralg and key takenfrom headersignature checkweakenedforged tokenacceptedATTACKER INPUTIMPACTcheck absent
Attack path · client posts a token → verifier reads token header → alg and key taken from header → signature check weakened → forged token accepted

If your JWT check reads the algorithm and key hint out of the token before verifying it, the attacker sets both. none, or HS256 against your public key, whatever gets in.

What goes wrong

A JWT header is attacker-controlled input. It carries the algorithm and often a key hint, and both sit in the token before anyone has verified a thing. If your verification routine trusts those fields to decide how to check the signature, you have handed the attacker the rules of the check.

The classic outcomes stack up fast. An alg of none disables verification entirely. Switch RS256 to HS256 and a token can be signed with your public key as if it were an HMAC secret. A key hint can point verification at a key the attacker chose. Each path ends with a forged token passing.

Verification has to start from what the server already decided, before it reads the token. You pin the algorithm you expect and the key you trust. The token does not get a vote. If the header disagrees with your policy, that is a rejection, not a setting to honor.

The pattern

Vulnerable
function verify(token) {
  let header = decode(token.header)      // attacker-controlled
  let alg = header.alg
  let key = selectKey(header.kid)
  return check(token, alg, key)          // token chose alg and key
}
Hardened
const EXPECTED_ALG = 'RS256'
function verify(token) {
  let header = decode(token.header)
  if (header.alg != EXPECTED_ALG) reject()   // pin it
  let key = trustedKeyFor(issuer)            // server picks the key
  return check(token, EXPECTED_ALG, key)
}
How the pipeline adjudicated itHELD
ABCDEFGH

Grounding and reachability were confirmed. The exploit-path gate would not conclude without the calling code, so the finding was held and an evidence request was raised instead of being reported as fact.

Ed25519 · per-tenant signing key · gate ledger A–H · verify offline against the published payload hash

Why it matters to you

A token is usually your proof of who is calling. If it can be forged, every authorization decision built on it is void and the attacker gets to be anyone. This is one of the most reliable authentication bypasses in the wild, and it survives because 'verify this token' quietly became 'verify it however the token asks.' Pin the algorithm and the key on the server side and the whole class of attacks closes.

Check your own code