1 JWT Attacks
JSON Web Tokens are widely used for authentication but are frequently misconfigured. Three critical attack classes exist:
1. Algorithm: none bypass
// Attacker modifies header to: { "alg": "none" }
// Then removes the signature
// Vulnerable servers that accept "none" skip verification!2. RS256 → HS256 algorithm confusion
When a server uses RS256 (RSA), its public key is often published. An attacker can change the algorithm to HS256 (HMAC) and sign the token with the public key. A vulnerable server that does not pin the expected algorithm will verify this as valid.
import jwt
# Attacker uses the PUBLIC RSA key as the HMAC secret!
token = jwt.encode(payload, public_key, algorithm="HS256")3. Weak secrets
HS256 tokens signed with guessable secrets (like "secret", "password", or the app name) can be cracked offline using tools like hashcat or jwt-cracker.