Back to Blog
Application Security

JWT Security: 8 Common Vulnerabilities in Token-Based Authentication

5 min read
JWTAuthenticationToken Security

Understanding JWT Security

JSON Web Tokens (JWT) are the de facto standard for stateless authentication in modern web applications. A JWT consists of three Base64-encoded parts: Header, Payload, and Signature. While JWTs solve many distributed authentication problems, their implementation is riddled with security pitfalls.

8 Critical JWT Vulnerabilities

1. Algorithm Confusion (Critical)

The most severe JWT attack. If a server uses RS256 (asymmetric), an attacker changes the algorithm to HS256 (symmetric) and signs the token with the public key (which is, by definition, public):

# Attacker's approach:
header = {"alg": "HS256", "typ": "JWT"}
payload = {"sub": "admin", "role": "superadmin"}
# Sign with the server's PUBLIC key (treating it as HMAC secret)
token = hmac_sign(header + payload, public_key)

Prevention: Explicitly specify the expected algorithm in verification:

jwt.decode(token, key, algorithms=["RS256"])  # Never ["RS256", "HS256"]

2. None Algorithm Attack

Setting alg: "none" bypasses signature verification entirely:

{"alg": "none", "typ": "JWT"}

Prevention: Reject tokens with alg: none. Most modern libraries do this by default, but legacy versions may not.

3. Key Confusion with JWK/JKU

Attackers inject their own public key into the token header:

{
  "alg": "RS256",
  "jwk": {"kty": "RSA", "n": "attacker_key...", "e": "AQAB"}
}

Prevention: Never trust keys embedded in token headers. Use a pre-configured key store.

4. Weak Signing Keys

HMAC-signed JWTs with weak secrets can be brute-forced:

hashcat -m 16500 jwt.txt wordlist.txt

Common weak secrets: secret, password, application name, default values.

Prevention: Use cryptographically random keys of at least 256 bits. Prefer asymmetric algorithms (RS256, ES256).

5. Missing Expiration

Tokens without exp claims never expire, giving attackers unlimited access if stolen:

{"sub": "user123", "role": "admin"}
// No "exp" field — valid forever

Prevention: Always include exp with short lifetimes (15-60 minutes). Use refresh tokens for session continuation.

6. Claim Injection and Manipulation

Applications that trust JWT payload data without server-side validation:

{"sub": "user123", "role": "user", "plan": "enterprise", "rate_limit": 999999}

Prevention: Never use JWT claims as the sole source of authorization. Validate claims against the database.

7. Token Replay

Intercepted tokens can be replayed from different locations:

Prevention:

  • Bind tokens to client fingerprints (IP, User-Agent hash)
  • Implement token revocation lists
  • Use short expiration times
  • Add jti (JWT ID) claims for replay detection

8. Cross-Service Token Abuse

In microservice architectures, a token issued for Service A is used against Service B:

Prevention: Include aud (audience) claims and validate them:

jwt.decode(token, key, audience="api.service-b.com")

JWT Security Checklist

  • Use asymmetric algorithms (RS256 or ES256) for distributed systems
  • Validate alg, exp, iss, and aud claims
  • Rotate signing keys regularly
  • Store tokens securely (httpOnly cookies, not localStorage)
  • Implement token revocation for compromised sessions
  • Set reasonable expiration times

Testing with SuperClue

SuperClue's JWT and token attack module tests several of these automatically, including the none algorithm, expired token replay, weak HMAC secrets, and kid header injection.

Ready to Test Your Applications?

Start your comprehensive security scan with SuperClue's security modules.

Request access