Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
Algorithm confusion is an attack in which a token tells the server which algorithm to verify it with. Switch RS256 to HS256 and the server’s public key becomes the signing secret.

What Is JWT Algorithm Confusion?
A JSON Web Token carries its own instructions. The header names the algorithm the verifier should use, and for years libraries did exactly as they were told. Algorithm confusion exploits that obedience: the attacker rewrites the header, the server switches verification method, and a token that should be unforgeable becomes trivial to produce.
The attack is a design flaw in how the standard was first implemented rather than a weakness in any algorithm. It persists because the vulnerable pattern — call verify(token, key) and let the library decide — still looks correct to a reviewer.
RFC 7519 defines none as a valid algorithm for unsecured tokens. An attacker changes the header to {"alg":"none"}, edits the claims to "role":"admin", removes the signature, and leaves the trailing full stop. A library that honours the header verifies nothing and returns success. This was disclosed across multiple implementations in 2015, including node-jsonwebtoken, and it still appears in bespoke verification code and in older forks.
The more interesting variant exploits the difference between asymmetric and symmetric verification. With RS256 the server verifies using the issuer’s public key, which is public by definition. With HS256 the server verifies using a shared secret — and the library takes whatever key material it was given.
So the attacker takes the public key, uses it as the HMAC secret, signs a forged payload with HS256, and sets the header accordingly. The server loads the same public key, sees alg: HS256, computes HMAC-SHA256 with it, and the signatures match. The attacker has produced a valid token for any identity, using only information that was published on purpose.
The attack needs the exact key bytes in the exact format the server uses, which is usually easy:
/.well-known/jwks.json, publishes it directly.Formatting matters to the attacker: PEM with or without a trailing newline, DER, or the JWK representation will produce different HMAC outputs, so exploitation involves trying each. Tooling such as Burp Suite’s JWT extensions and jwt_tool automates both the variants and the formats.
| Header | Abuse |
|---|---|
kid | Path traversal to a predictable file such as /dev/null, giving an empty key; or SQL injection where keys are looked up in a database |
jku | Point the verifier at a key set on a host the attacker controls, or at an internal URL for server-side request forgery |
x5u / x5c | Supply an attacker-generated certificate and sign with the matching private key |
jwk | Embed a public key in the token itself and sign with its private counterpart |
All four share one root cause with algorithm confusion: the verifier is taking key selection instructions from the thing it is supposed to be checking.
algorithms: ['RS256'] — and reject anything else before any cryptographic work happens. Every maintained library supports this, and most now require it.alg field of the JWK.jku, x5u, and jwk, unless you have a documented need and a strict host allowlist.kid as hostile input. Look it up in a fixed map of known identifiers; never interpolate it into a path or a query.iss, aud, exp, and nbf, and do not short-circuit any of them in a code path used by internal services.none outright and require an explicit algorithm list. Hand-rolled verification is where these flaws survive.Because a successful exploit yields authentication bypass and privilege escalation in one step, we test JOSE token handling on every API engagement within our web application security services, and it is still a finding often enough to be worth checking in your own code this week.
Take a valid token, change the header algorithm to none, strip the signature, and send it. Then fetch the public key from your JWKS endpoint, sign a modified payload with HS256 using that key as the secret, and send that. If either is accepted, the verifier is trusting the header. Tools such as jwt_tool automate both checks.
No. HMAC-SHA256 is a sound construction, and HS256 is appropriate when the issuer and verifier are the same service and share a strong random secret. The danger is accepting several algorithm families with one key loading path, and using a weak or guessable secret, which brute-force tools will recover from a captured token.
No. Algorithm confusion works with whatever the current public key is, so rotation changes nothing. The fix is to pin accepted algorithms, separate keys by purpose, and ignore key selection hints in the token header. Rotation remains good practice for other reasons, but it is not a mitigation here.
Not necessarily, though opaque session tokens validated against server-side state are simpler and revocable, and are a better fit for first-party web sessions. JWTs earn their place in distributed systems where stateless verification matters. If you keep them, keep lifetimes short, verify strictly, and have a revocation path for compromise.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.