Skip to content
Pwnversity
WEB-JWTadvanced · 10 min · upd. 2026-10

JWT attacks

OWASP A04:2025CWE-347

A JWT (JSON Web Token) carries signed claims between parties; it’s heavily used for sessions and API authorization. Its security depends entirely on the server verifying the signature correctly and pinning the expected algorithm. When that verification is weak, optional or confusable, the attacker forges or tampers the token and becomes another user or an admin —without touching passwords or sessions—. It’s one of the highest-impact bug-bounty flaws because the token is usually the only proof of identity the backend accepts.

flowchart LR
    A[Attacker] -->|"tamper payload: role=admin"| T["Forged token"]
    T -->|"sig: none / HMAC with public key / cracked secret"| V["JWT verifier"]
    V -->|"verifies sig and alg?"| D{Weak?}
    D -->|"yes"| W["Access as admin"]
    D -->|"no"| R["401 / rejected"]

What the attacker gains depends on what the server verifies poorly:

  • Impersonation: change sub/user/email and act as another account.
  • Privilege escalation: set role: admin, isAdmin: true, scope/groups.
  • Authentication bypass: forge a valid token with no credentials.
  • Persistence: with no exp, or if it isn’t honored, or there’s no revocation, a stolen or forged token works indefinitely.
  • Cross-service pivot: reuse one service’s token on another that trusts the same issuer but doesn’t validate aud.

Three Base64URL parts separated by dots: header.payload.signature.

  • header: algorithm (alg) and, optionally, parameters saying where the key comes from: kid (key id), jku/x5u (URL to a JWKS/cert), jwk (embedded public key).
  • payload: the claims (sub, role, exp, iss, aud, nbf…). It is signed, not encrypted: anyone can read it.
  • signature: symmetric HMAC (HS256, shared key) or asymmetric signature (RS256/ES256, private key signs, public key verifies).

The invariant every correct verifier holds —and every attack breaks— is: (1) it checks the signature, (2) against an algorithm the server chooses (not the token), (3) with a key from a trusted source, and (4) it validates the claims (exp/iss/aud).

  • alg: none — the token declares it is unsigned and the verifier accepts it.
  • Algorithm confusion (RS256 → HS256) — the server verifies with HMAC using the RSA public key as the secret, which the attacker knows.
  • Weak HMAC secret — HS256 with a guessable secret: crack it offline and sign at will.
  • kid injection — the kid value is used unsanitized in a file path, a SQL query or a command.
  • jku/x5u/jwk — the attacker controls the source of the verification key (their own JWKS, or a key embedded in the header).
  • Claim-validation flaws — exp not honored, aud/iss not checked, cross-tenant reuse.

Find the JWT (cookie, Authorization: Bearer, JSON body, parameter). Decode header and payload (they’re Base64URL, not encrypted):

Ventana de terminal
# decode header and payload with no libraries
cut -d. -f1 token.txt | base64 -d 2>/dev/null; echo
cut -d. -f2 token.txt | base64 -d 2>/dev/null; echo

Note alg (HS or RS/ES?), whether there’s kid/jku/x5u/jwk, and which claim decides access (role, sub, scope). Two gold tests before anything else:

  1. Is the signature verified? Alter a payload claim without touching the signature and resend. If you get through, the server doesn’t verify (or accepts none).
  2. Is exp honored? Resend an expired token. If it still works, there’s no validity control and any stolen token is permanent.

The verifier accepts a token that declares it is unsigned. Set {"alg":"none"} in the header, alter the payload and leave the signature empty (the token ends in a dot):

eyJhbGciOiJub25lIn0.eyJzdWIiOiJhZG1pbiIsInJvbGUiOiJhZG1pbiJ9.

Try case variants (None, NONE, nOnE) to bypass poor blocklists. With a tool: jwt_tool <token> -X a.

If the server expects RS256 but lets the token choose alg and verifies HS256 using the public key as the HMAC secret, you can sign it yourself: the public key is public. Steps:

  1. Get the public key: /.well-known/jwks.json, the IdP endpoint, or recover it from two legitimate tokens with rsa_sign2n.
  2. Change alg to HS256, alter the payload and sign with HMAC-SHA256 using the public key’s PEM as the key.
Ventana de terminal
jwt_tool <token> -X k -pk public.pem # automated key confusion

If HS256 uses a short or dictionary secret (common in templates and copy-pasted examples), crack it offline and then sign any token:

Ventana de terminal
hashcat -m 16500 token.jwt /usr/share/wordlists/rockyou.txt
# other lists: jwt.secrets.list, SecLists; also john --format=HMAC-SHA256

Once cracked, sign yourself a role: admin with jwt_tool <token> -S hs256 -p '<secret>'.

kid tells the verifier which key to use; if it’s interpolated unsanitized:

  • Path traversal: "kid":"../../../../dev/null" forces an empty/known key and you sign the token with that same known key (e.g. HMAC with an empty secret).
  • SQLi: if kid queries a key table, inject so it returns a value you control (see SQL injection).
  • Command injection / LFI: depending on how the value is used.

jku / x5u / jwk — controlling the key source

Section titled “jku / x5u / jwk — controlling the key source”

If the verifier fetches the public key from where the header says, the attacker controls it:

  • jku/x5u: point to a JWKS/cert on your server with your public key and sign with your private key. Often chains with SSRF (the server makes the outbound request).
  • jwk: embed your own public key in the header and sign with the private key; if the verifier trusts the token’s jwk, it passes.
{"alg":"RS256","typ":"JWT","jku":"https://attacker.tld/jwks.json"}

Automated: jwt_tool <token> -X s (jwk), -X i (jku), -X x (x5u).

Even with the signature verified correctly, check: exp/nbf not checked, aud missing (one service’s token accepted by another), iss not validated, and authorization claims the backend trusts without re-checking against the database (trusts the token’s role instead of the server).

  1. Is the signature verified? (alter a claim; if you pass, it doesn’t).
  2. Which alg family? HS → try weak secret and none; RS/ES → try confusion, jku/x5u/jwk, and, on Java, blank signatures (see CVEs).
  3. Do I control the key source? (kid, jku, x5u, jwk).
  4. Does the claim I forge grant real access? Prove impact with a minimal PoC.

jwt_tool (automates none, confusion, jku/x5u/jwk, kid, claim fuzzing), hashcat -m 16500 and john (HMAC secret), Burp’s JWT Editor extension (edit and re-sign in Repeater), jwt.io (decode/inspect).

Full ATO, admin access, and access to other users’ data combined with IDOR/BOLA when the forged token reaches an API that trusts it. A JWT forged in the OAuth/OIDC flow can lead to account takeover across every service behind the SSO.

  • Tokens with alg: none/None, alg other than expected, or family changes (RS→HS) within the same flow.
  • jku/x5u pointing to domains not in an allow-list, or jwk present on inbound tokens.
  • kid with ../, quotes, SQL metacharacters or nulls.
  • Expired tokens being accepted; spikes of verification errors (sign of secret brute-forcing or claim fuzzing).

Verifier/IdP logs with the alg and kid used, API gateway/WAF, service egress (outbound requests to external JWKS via jku), and token-validation metrics.

  1. Pin the algorithm on the server (allow-list); never derive it from the header. Reject none.
  2. Don’t use the same routine for HS and RS: separate symmetric from asymmetric verification to prevent confusion.
  3. Strong HMAC secret (random, ≥256 bits) or well-managed, rotated asymmetric keys.
  4. kid, jku, x5u only against an origin allow-list; prefer local keys. Ignore inbound jwk.
  5. Always validate iss, aud, exp, nbf. Short expiry + revocable refresh tokens; don’t store secrets in the payload (it’s readable).
  6. Keep the JWT library current (see CVEs); on Java ≥15, patch ECDSA verification.

Rotate the signing key/secret (invalidates all tokens), review access made with suspicious tokens, fix the verification, and deploy a detection rule for none/external jku.

  • Auth0 / Tim McLean (2015) — foundational disclosure of alg:none and RS/HS confusion across multiple JWT libraries; the origin of almost all current defenses.
  • CVE-2015-9235 — node-jsonwebtoken < 4.2.2: algorithm confusion letting an attacker forge tokens by treating an RS public key as the HS secret.
  • CVE-2022-21449 “Psychic Signatures” — Java 15–18 accepted blank ECDSA signatures (r=s=0) as valid: any ES256/ES384/ES512 JWT with a null signature passed verification. A critical crypto flaw.
  • CVE-2022-23529 — node-jsonwebtoken < 9.0.0: a crafted secretOrPublicKey in jwt.verify() could lead to code execution on the verifier.

Per-library, per-version CVEs in NVD (https://nvd.nist.gov/vuln/search) and GitHub Advisories (https://github.com/advisories).

  • Is the signature verified? (alter a claim without touching the signature).
  • alg:none and case variants tested.
  • RS256→HS256 algorithm confusion tested (public key as secret).
  • HS256 secret cracking attempted (hashcat -m 16500).
  • kid (path traversal/SQLi), jku, x5u, jwk tested.
  • exp/nbf/iss/aud validation and cross-service reuse checked.
  • On a Java backend, blank ECDSA signature tested (CVE-2022-21449).
  • Impact proven with a minimal PoC (e.g. admin access), without harming real data.