labs / jwt

JWT Forgery Lab

Crack a weak HMAC secret and forge yourself an admin JSON Web Token.

Broken Authentication Intermediate Server lab
leaderboard →
    Objective Forge a token with role=admin that the server will accept, then submit it.

    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

    
          
    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.

    $ patch ./jwt

    You broke it — now fix it. Which fix defeats both the weak-secret and alg:none attacks?

    jwt.verify(token, secret); // algorithm taken from the token header