JWT Algorithm Confusion Attack Explained
Understand the JWT algorithm confusion vulnerability: RS256 to HS256 switch, prevention, and secure library configuration.
Quick Answer
To JWT Algorithm Confusion Attack Explained, paste your token into our JWT Decoder, inspect the header and payload claims, then verify the signature with the JWT Validator. All processing runs locally in your browser.
The Attack
Server expects RS256 and uses public key for RSA verify. Attacker sets alg=HS256 and signs with public key as HMAC secret. If server switches verify mode based on header, attack succeeds.
Real-World Impact
CVE-class vulnerability in multiple libraries over the years. Always pinned algorithm lists.
Prevention
jwt.verify(token, getKey, { algorithms: ['RS256'] }); // never ['RS256','HS256'] from header
Related
Invalid Signature, Security Hub.
Understanding JWT Algorithm Confusion Attack Explained in Production
Developers search for JWT Algorithm Confusion Attack Explained when building API authentication with JSON Web Tokens. JWTs are used by OAuth 2.0, OpenID Connect, Auth0, Firebase, AWS Cognito, and Keycloak. Always validate exp, iss, and aud server-side — decoding alone proves nothing about authenticity.
JWT Structure Recap
Every JWT has three dot-separated segments: header (algorithm), payload (claims), signature (proof). Use JWT Decoder to inspect and JWT Validator to verify before trusting any claim value in production code.
Common Pitfalls
- Algorithm confusion (
noneattack) — whitelist allowed algorithms - Secrets in the payload — payload is only Base64-encoded, not encrypted
- Ignoring clock skew on
expandnbf - Weak HMAC secrets — use 256-bit random keys
- Skipping signature verification — always call verify(), not decode()
- Storing tokens in localStorage — XSS can steal them
Further Reading
Browse related resources: JWT Decoder, JWT Validator, JWT Basics, JWT Authentication, JWT Errors, Algorithms, Glossary, and Learning Path.
Try It Now
FAQ
What is algorithm confusion?
Attacker changes alg to HS256 and signs with the RSA public key as HMAC secret. Server verifies with same public key string as secret.
How do I prevent it?
Whitelist allowed algorithms explicitly. Never derive verification algorithm from token header alone.