Vulnerability class

How to prove a JWT is forgeable or misvalidated

Updated

A JWT weakness is proven when a token you forged or altered is accepted by the API. Test alg: none, algorithm confusion, a changed role or sub claim, and any endpoint that decodes without verifying.

Where this class of bug actually lives in a service that trusts JWTs

  • alg: none. Some libraries accept an unsigned token if the header says so, especially when the algorithm is taken from the token.
  • RS256 to HS256 confusion. The public key is used as an HMAC secret, so anyone holding the public key can mint tokens.
  • Unverified claims. role, tenant and scope read straight from the payload after a decode that skipped verify.
  • Verification on some paths only. A middleware that verifies for /api and a websocket or an internal route that only decodes.

What to try first

  1. Decode the token and alter one claim, keeping the signature. If it is accepted, verification is missing.
  2. Re-sign with alg: none and an empty signature.
  3. Re-sign with HS256 using the server's public key as the secret.
  4. Check exp and aud: an expired token and a token for another audience should both be rejected.

A reproduction you can keep

Claim alteration is the cheapest proof. Decode, change, re-encode without a valid signature:

Forged claim and alg:none
python3 - <<'PY'
import base64, json
def b64(b): return base64.urlsafe_b64encode(b).rstrip(b'=').decode()

tok = "***"
h, p, _ = tok.split('.')
claims = json.loads(base64.urlsafe_b64decode(p + '=' * (-len(p) % 4)))
claims['role'] = 'admin'
print(b64(json.dumps({"alg": "none", "typ": "JWT"}).encode()), end='.')
print(b64(json.dumps(claims).encode()), end='.')
print()   # empty signature
PY

# send it
curl -sS -i https://staging.example.com/api/admin/users   -H 'Authorization: Bearer <forged>'

# vulnerable: 200 — signature was not checked, or alg was taken from the header
# fixed: 401 invalid signature

What "fixed" has to look like

Pin the algorithm server-side, verify the signature on every path that reads a claim, and reject none explicitly. Verify with the forged token returning 401 and with an expired token and a wrong-audience token also returning 401.

Where people get this wrong

  • Reading the algorithm from the token header is the vulnerability, not a convenience.
  • A decode that returns claims without throwing on a bad signature is accepted by more libraries than you would expect; assert the return value is checked.
  • Claim expiry is checked by the library only if you do not disable it — and people disable it to debug clock skew.

What Offense does here

Offense runs an agent swarm against your app in a disposable sandbox, keeps the request, the identity and the vulnerable response as evidence, and replays the same attack after the fix so the retest is a control comparison rather than a green check. It does not read your source and it does not patch your code: the finding goes to your coding agent with the reproduction attached. The hosted workspace is invite-only — join the waitlist — and the free dependency audit in /install needs no account.

Questions this page answers

Is <code>alg: none</code> still exploitable?

In any service that takes the algorithm from the token header or does not pin it. It costs one request to find out.

What should a JWT verifier pin?

Algorithm, issuer, audience and expiry, with the key fixed server-side. Nothing about those may come from the token.

Written by Offense Research, reviewed December 2, 2026. Correct something? Email imran@offenseresearch.com.