The Zyber Security home
AppSecJuly 14, 2026Updated November 15, 20268 min read

JWT Algorithm Confusion: How the Wrong `alg` Forges Any User

JWT algorithm confusion lets attackers sign forged tokens with your public key. Real CVE examples, 10-min self-test, library defaults, and the exact fix.

By Zyber Research

TL;DR — JWT algorithm confusion lets an attacker sign forged tokens with your public key. Pin the algorithm server-side; never let the token choose.

Algorithm confusion is when a JSON Web Token verifier can be tricked into accepting a token signed with the wrong algorithm. The classic case: a service that issues RS256 (asymmetric) tokens is handed an HS256 (symmetric) token, and it uses the public key as the HMAC secret. Because the public key is public, an attacker can forge a valid token for any user, in any tenant.

It maps to OWASP API2:2023 Broken Authentication, which lists accepting unsigned or weakly signed JWTs as a sign of the risk, and to CWE-347 Improper Verification of Cryptographic Signature. The fix is one line of intent: pin the algorithm server-side and never let the token choose.

Why is this JWT bug still alive in 2026?#

JWTs carry their own algorithm in the header — {"alg":"RS256"}. For years, libraries trusted that field. RFC 8725, the JWT best current practice, describes the two failure modes that fall straight out of that trust:

  1. alg: none. The token declares itself unsigned, and a permissive verifier accepts it with no signature. Drop the signature, rewrite the claims, and you are whoever you say you are.
  2. RS256 → HS256 confusion. The server expects an RS256 signature it checks with an RSA public key. The attacker re-signs the tampered token as HS256 — a symmetric HMAC — using that public key as the secret. A naive verify(token, publicKey) call feeds the same key into the HMAC path, and the signature matches.

The reason it survives modern stacks is mundane: the RSA public key is not a secret. PortSwigger notes that servers often publish it at /jwks.json or /.well-known/jwks.json, and it can also sit in a mobile app bundle or front-end. So the "secret" the attacker needs is already in their hands.

Which real CVEs show the pattern?#

  • CVE-2015-9235 (jsonwebtoken for Node, before 4.2.2) — NVD describes a token expected to be signed with an RS or ES key being accepted when signed with HS instead. The class was first made public in Tim McLean's March 2015 write-up on the Auth0 blog.
  • CVE-2018-0114 (Cisco node-jose, before 0.11.0) — key confusion via an embedded JWK: an attacker puts their own public key in the token header, and the library trusts it for verification.
  • CVE-2022-21449 (Oracle Java SE 17.0.2 and 18, ECDSA verification) — the "psychic signatures" bug, listed on NVD. It is a distinct bug, but the same family: the verifier trusts something it should check.
  • CVE-2022-23541 (jsonwebtoken 8.5.1 and earlier) — a poorly written key-lookup function could let a token signed for an asymmetric key be verified with HS256. Fixed in 9.0.0.

Every few years a new library or wrapper brings the same bug back.

Why won't a CVE scanner catch it?#

A CVE scanner looks for known-vulnerable versions. Algorithm confusion is usually not a library CVE — it is how your code calls the library. A verify(token, key) call with no algorithm allow-list can be up to date and still exploitable. It needs a human reading the auth path, not a version diff.

The same "trust nothing the client sends" rule applies to AI features; see our OWASP LLM Top 10 for founders.

How do we fix JWT algorithm confusion and prove it stays fixed?#

  • Pin the algorithm. Pass an explicit allow-list on every verify: verify(token, key, { algorithms: ["RS256"] }). RFC 8725 §3.1 says libraries must let the caller set the allowed algorithms and must not use any others.
  • Bind each key to one algorithm. The key you use to verify RS256 should never be reachable by an HMAC code path. RFC 8725 asks for each key to be used with exactly one algorithm.
  • Reject none at the edge. Treat an unsigned token as a malformed request, not an auth failure to log and continue. RFC 8725 §3.2 says none should only be used when the JWT is protected by other means, and libraries should not accept it unless the caller explicitly asks.
  • Prove it with a test. A one-line negative test — "an HS256 token signed with our public key is rejected" — turns a subtle assumption into a regression gate.

A good report hands you the forged token, the exact verify call at fault and a test that proves the fix. That is what we aim for in our web application penetration testing: a proof of concept, advice on the fix and a retest.

How do we test our own JWT verifier in 10 minutes?#

The self-test is short. Grab a valid JWT your app issued, then:

  1. Decode the token (base64url, no signature required — use jwt.io or a few lines of Python).
  2. Change a claim you care about (for example, role: admin) and re-encode it.
  3. Re-sign the tampered token as HS256 using your app's public key as the HMAC secret. pyjwt, jsonwebtoken or jwt.io can do this.
  4. Send the forged token to any authenticated endpoint.
  5. If the request succeeds, your verifier is vulnerable. If the endpoint rejects it with 401 or 400, your allow-list is pinned.

Do this against staging, not production. It gives you a clear yes or no.

Which JWT libraries got the defaults right?#

  • jsonwebtoken (Node) — version 9.0.0 (December 2022) removed default support for none in verify() (CVE-2022-23540) and added checks on asymmetric key types. Versions up to 8.5.1 were open to both problems when no algorithms were given.
  • PyJWT (Python) — version 2.0.0 (December 2020) requires an explicit algorithms list in jwt.decode() by default.
  • jose (JS) — lets you pass the allowed algorithms in the verify options; set them every time.
  • java-jwt (Auth0) — the verifier is built from a specific Algorithm object, which makes misuse harder.
  • nimbus-jose-jwt (Java) — uses a separate JWSVerifier per algorithm family.
  • Custom wrappers — the biggest risk. verifyToken(token, key) helpers often drop the algorithm parameter. Audit every one.

With a managed identity provider (Auth0, Okta, AWS Cognito, Microsoft Entra ID), the issuing side is usually safe. The verifying side — your gateways, microservices and workers — is where confusion lives.

To check your own auth path, start with a free Exposure Check. The standards behind this post: OWASP API2:2023, the OWASP JWT Cheat Sheet (hardcode the accepted algorithms), CWE-347, RFC 7519 and RFC 8725.

Frequently asked questions#

Is alg:none really still exploitable?#

On a correctly configured library, no. But defaults drift, wrappers get written, and one service in a fleet forgets the allow-list. We find it by testing the actual endpoints, not by trusting the framework's reputation.

Does rotating keys help?#

No. Rotation limits the damage of a leaked private key. Algorithm confusion never needs the private key — it abuses the public one — so rotation changes nothing here.

We use a managed identity provider. Are we safe?#

The provider's own side is usually fine. The risk moves to your services that check its tokens — gateways, microservices and background workers. Those are the code paths to test.

Does the JWT kid header create a similar risk?#

Yes, in the same family. A verifier that looks up the key from the kid value can be tricked through injection into using an attacker's key. RFC 8725 §3.10 says to sanitise kid; match it against a list of known key IDs.

Which JWT library versions had unsafe defaults?#

jsonwebtoken (Node) up to 8.5.1 and PyJWT before 2.0.0, plus many in-house wrappers. If you pin those old versions or wrap verify in a way that hides the algorithm list, treat it as a red flag.

Sources#

AuthenticationJWTOWASP API SecurityOWASP ASVSAppSecCWE-347
Put this into practice

Web Application Pen Testing

The flaws in your app that scanners miss.

Start here

Tell us what you need tested.

A 30-minute scoping call. A fixed scope and price within five business days. No obligation either way.

Day 0Scoping callWe learn your systems, deadlines and what “done” looks like.
Within 5 business daysFixed scope & priceA written engagement letter. No surprises later.
Within 2 weeksTesting startsCritical findings reach you within 24 hours of confirmation.