All vulnerabilities
CRITICALAppSecexploited in the wild

APPSEC-JWT-ALG-CONFUSION

API · JWT authentication (JSON Web Tokens)

Summary

JWT algorithm confusion is an authentication-bypass class affecting servers that trust the attacker-controlled 'alg' field in a token's header to choose how the signature is verified, mapping to OWASP API2:2023 Broken Authentication. When a library exposes a single algorithm-agnostic verify call, setting alg to 'none' makes it accept a token with an empty signature and skip verification entirely, as Tim McLean documented across multiple libraries in a 2015 Auth0-coordinated disclosure. In the RS256-to-HS256 variant, a server expecting asymmetric RS256 passes its RSA public key to verify, but an attacker flips the header to HS256 so the library reuses that same public key as the HMAC secret; because the public key is not secret, the attacker can forge and HMAC-sign an arbitrary admin payload that validates. CVE-2015-9235 (CVSS 9.8) captured exactly this in node jsonwebtoken before 4.2.2, where a token signed with an HS-family algorithm was accepted in place of one expected to use an RS/ES asymmetric key. PortSwigger's Web Security Academy documents both the 'none' and RS256/HS256 confusion techniques as practical authentication-bypass labs.

How to avoid it in your code

  • Pin the expected signing algorithm server-side and explicitly reject 'none' and any mismatched alg.
  • Verify with the correct key type only; never let an RSA public key be used as an HMAC secret.
  • Pass an allowlist of algorithms to the verify call rather than trusting the token's alg header.
  • Validate iss/aud/exp and bind the token to a server-side session.
  • Upgrade to patched libraries (jsonwebtoken >= 4.2.2) and prefer asymmetric-only verification paths.

References

Related vulnerabilities

All AppSec →