labs / jwt
JWT Forgery Lab
Crack a weak HMAC secret and forge yourself an admin JSON Web Token.
Your issued token (role: guest)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiZ3Vlc3QiLCJyb2xlIjoidXNlciIsImlhdCI6MTc5NTU2NDI3N30.bhZWiIIQ-oUUKJV16wNtr6quRGMA_lReZEkWw7-rtLk
It's an HS256 JWT. The header and payload are just Base64 — decode them with the JWT decoder. The signature is HMAC-SHA256 using a secret the developers chose badly.
Step 1 — crack the signing secret
Step 2 — forge an admin token
Found the secret. Now mint a new token with role: "admin", signed with it.
How the fix works
Two bugs here. First, a weak, guessable signing secret — use a long random key. Second, a
server that trusts alg from the token (including none) instead of
pinning the expected algorithm. Verify with a strong key and a fixed algorithm and both attacks die.