Five JWT Validation Failures You Can Reproduce Locally

A JWT validator rarely fails because SHA-256 stopped working. It fails because an application asks the cryptographic library the wrong question.
The dangerous question is “does this signature match whatever algorithm the token requested?” The useful question is much narrower: “does this token match the algorithm, key, issuer, audience and lifetime configured for this endpoint?” Every value inside the JWT, including the header, is untrusted until that full policy succeeds.
Five recurring failures make the difference concrete.
1. alg:none turns verification into an option
The alg header describes how a JWS was signed. If a verifier treats that untrusted value as a command, an attacker can change the payload, set alg to none, remove the signature and present an unsigned token.
The failure is not that the format can represent an unsecured JWT. The failure is that an authenticated endpoint did not decide its algorithm independently. The server should already know that this issuer uses RS256 or HS256. Any other value must be rejected before a claim such as sub, role or scope reaches authorization.
2. HS256 and RS256 are not interchangeable
RS256 uses a private key to sign and a public key to verify. HS256 uses one shared secret for both operations. A confused validator can read HS256 from a forged header and reuse its configured RSA public key bytes as the HMAC secret.
That public key is meant to be public. The attacker can therefore sign an HS256 token with the same bytes. A validator that switches primitives from the header sees a valid HMAC; a validator pinned to RS256 rejects the token before touching the key.
The defensive rule is simple: bind one key to its intended algorithm and purpose. A public RSA verification key is never an HMAC secret.
3. kid is an identifier, not a path
Key rotation often introduces a kid header so the verifier can choose one key from a set. Trouble starts when code turns it into a filesystem path or remote URL:
/var/app/keys/ + token.header.kid
A value containing ../ can escape that directory. Depending on the library and key type, bytes from another readable file may then be treated as verification material.
The fix is not better path normalization. Keep a server-side map such as { "primary-2026": keyObject }, validate the identifier against a small character set, and reject every ID that is not already in the trusted map.
4. HS256 cannot rescue a weak secret
HMAC-SHA256 is strong when the secret has enough unpredictable entropy. A human word such as secret123 gives an attacker a much smaller problem: calculate the token signature for each likely candidate until one matches.
This test is offline. The attacker needs one token and makes no requests to the API, so rate limiting the login endpoint does not help. Generate at least 256 random bits for HS256, store the secret like any other signing credential and rotate it after exposure. If many services only need to verify tokens, asymmetric signing keeps private signing authority out of those services.
5. A valid signature can belong to an expired token
The HMAC or RSA signature does not decay when exp passes. A validator that checks only the signature will keep accepting the same bearer token indefinitely.
Time validation belongs in the same policy as cryptographic verification. Check exp and nbf with a deliberately small clock-skew allowance. Check iss and aud so a valid token issued for another service cannot cross a trust boundary. Where immediate revocation matters, add server-side state such as a token version or denylist rather than pretending a self-contained token can revoke itself.
Run the failures without targeting a live service
The JWT Attack Playground builds synthetic tokens for all five cases in the browser. The algorithm-confusion lab generates an ephemeral RSA pair and performs the real RS256 and HMAC operations. The weak-secret lab runs candidates in a Web Worker. The path-traversal lab resolves against a two-entry JavaScript object, not a device or server filesystem.
Each scenario ends with the same comparison: the unsafe verifier that accepts the token and the narrow policy check that rejects it. Nothing is uploaded, persisted or sent to a target.
A production acceptance checklist
Treat JWT acceptance as one indivisible operation:
- Pin the allowed algorithm for the issuer and endpoint.
- Resolve a trusted key from an allowlisted identifier.
- Verify the signature with the matching primitive.
- Validate issuer, audience, expiry and not-before time.
- Apply application-specific revocation and authorization after validation.
If a library makes any one of those steps implicit, configure it explicitly or wrap it behind one validator that the rest of the application cannot bypass.
Related tools
Frequently asked questions
Is decoding a JWT the same as verifying it?
No. Decoding only reverses Base64URL so the header and payload become readable. Those two segments are attacker-controlled input until a trusted key verifies the signature and the application validates the expected algorithm, issuer, audience and time claims.
Why is alg:none dangerous if JWT libraries support it?
An unsigned JWT can be legitimate only inside a protocol that explicitly expects an unsecured token. It becomes dangerous when an API lets the untrusted alg header decide whether verification is required. An authenticated endpoint should pin an allowed signing algorithm and reject none before using claims.
Can an RSA public key really become an HMAC secret?
Only in a confused implementation. Some historical validation paths selected HS256 from the token header and passed the server's configured RSA public key bytes into HMAC verification. The attacker knows those public bytes, so they can create a matching HMAC. Pinning RS256 prevents that type switch.
Does a valid JWT signature mean the token should be accepted?
No. A signature proves that the signed bytes match a key. Acceptance also requires policy checks such as the allowed algorithm, expected issuer and audience, exp and nbf time claims, and often application-specific revocation or token-version state.



