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
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
}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)
}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.
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
- Pin the accepted algorithm explicitly and reject anything else, including none.
- Choose the verification key from server trust config, never from the token's own key hint.
- Reject asymmetric tokens presented for symmetric verification and the reverse.
- Add a test that feeds a none-alg token and an algorithm-swapped token and expects rejection.