Lab 06: JWT Algorithm Confusion

Objective

Exploit two critical JWT vulnerabilities to forge admin tokens from Kali Linux:

  1. alg:none bypass — remove the signature entirely and set alg to none; the server skips verification

  2. RS256→HS256 algorithm confusion — trick the server into verifying an RS256 token using the public key as an HMAC secret, forging an admin token without the private key


Background

JSON Web Tokens are widely used for stateless authentication. The vulnerability class "algorithm confusion" is one of the most impactful JWT attacks because it exploits the server's trust in the client-controlled alg header.

Real-world examples:

  • 2015 Auth0 alg:none — the original disclosure showed that many JWT libraries accepted alg: none and skipped signature verification entirely if the header said so. Affected Flask-JWT, python-jwt, and dozens of other libraries.

  • 2022 CVE-2022-21449 "Psychic Signatures" — Java's ECDSA verifier accepted all-zero signatures for any message. Any JWT with alg: ES256 and a blank signature was accepted as valid.

  • 2017 kid SQL injection — the kid (key ID) header field was passed to a SQL query to look up the signing key; SQL injection allowed returning an empty key, making HMAC(message, "") trivially forgeable.

  • RS256→HS256 confusion — documented by Tim McLean (2015); still found in production apps that use libraries exposing the raw algorithm parameter without validation.

OWASP: A02:2021 Cryptographic Failures, A07:2021 Identification and Authentication Failures


Architecture

Time

45 minutes


Lab Instructions

Step 1: Setup


Step 2: Launch Kali and Decode the Token


Step 3: Attack 1 — alg:none Bypass

📸 Verified Output:


Step 4: Attack 2 — RS256→HS256 Algorithm Confusion

📸 Verified Output:

💡 The confusion: RS256 uses a key pair. The server signs with the private key and verifies with the public key. If the server lets the client choose alg=HS256, it switches to symmetric mode and uses the same key for both — but uses the public key as that symmetric key. The attacker already has the public key (it's public!) and can produce valid HMAC signatures with it.


Step 5: Enumerate Claims with alg:none


Step 6–8: kid Header Injection + Cleanup


Remediation

Further Reading

Last updated