target://jwt-alg-none
mediumOPEN
Trusting Token Verifier
jwtbroken-authcryptography
// Scenario
A microservice verifies compact HS256 JWT tokens using verify_jwt(token, secret, now_ts) / verifyJwt(token, secret, nowTs).
// The Vulnerability
- It trusts the token header's
algblindly: ifalgis"none"(or"None"), it skips signature verification completely! - It ignores token expiration (
exp). - It compares signatures with
==/===instead of a constant-time comparison.
// Your Task
Harden JWT verification:
- Strictly require
typ(if present) andalg === "HS256"(rejectnone,RS256, etc.). - Require a non-empty signature and verify HMAC-SHA256 using constant-time comparison (
hmac.compare_digest/crypto.timingSafeEqual). - Require numeric
expand reject expired tokens (now_ts >= exp). - Return the decoded payload dict/object on success, or
None/nullon any failure.
Sample Sanity Checks (1)
- Valid HS256 token passesProperly signed unexpired HS256 token returns payload
Hints (0/3)
initializing editor...
[idle] Press RUN to execute visible sample checks, or SUBMIT to run hidden exploit & functionality suites.