Skip to content

Lesson 5 of 14 · 13m

JWT Anatomy: Signed, Not Secret

Three base64url segments, attacker-controlled header metadata, and claims that are checks you're supposed to run — not facts you're given.

Three segments, no secrets

A JWT (RFC 7519) is base64url(header) + "." + base64url(payload) + "." + base64url(signature) — you can spot one by the eyJ lead-in, because every JSON header starts with {". Decode the first two segments and you get everything inside:

const [h, p] = token.split('.');
JSON.parse(atob(h.replaceAll('-','+').replaceAll('_','/'))); // {"alg":"RS256","typ":"JWT","kid":"key-2025-11"}
JSON.parse(atob(p.replaceAll('-','+').replaceAll('_','/'))); // {"iss":"https://auth.example","sub":"u_4517","aud":"billing","exp":...}

The signature is computed over the literal header.payload string — RS256 is RSA-SHA256, HS256 is an HMAC with a shared secret, ES256 is ECDSA. It provides integrity, not confidentiality. The payload is readable by anyone holding the token, which includes the user's browser, every proxy log it touched, and any referrer that saw it in a URL. Never put anything in a JWT you wouldn't print.

The wrong mental model

Three stacked assumptions, all wrong:

  1. "JWT is encrypted." It is base64url. The signature means you can trust claims only after you've correctly verified it — verification is where everything goes wrong, which is the next lesson.
  2. "The signature makes the header trustworthy." The header is attacker-controlled input that happens to be covered by a signature you haven't checked yet. alg, kid, jku, x5u are instructions the token gives the verifier. Trusting them is the canonical JWT failure.
  3. "JWTs make auth stateless." Signing keys, key rotation, refresh tokens, revocation lists, and iss/aud expectations are all state. What JWTs move is the claims — verification still requires shared context.

Evidence it mattered

In July 2023 Microsoft disclosed Storm-0558: a threat actor acquired a signing key and forged tokens that Exchange Online and Azure AD accepted as legitimate authentication — access to government email without touching a password. The tokens' claims were attacker-authored; the signatures verified because the key scope was wrong — a consumer key signed enterprise tokens. Nothing about "JWT" broke. Everything about verification context did. That incident is the entire lesson: the claims a JWT carries are only as good as the key, issuer, and audience checks wrapped around them.

The claims that gate access

iss (issuer), sub (subject), aud (audience), exp, nbf, iat, jti, and app-specific claims like aal (Supabase/GoTrue's auth-assurance level — aal1 vs the aal2 MFA-verified state) or role. Every single one is a check you're supposed to run, not a fact you're given. exp is the only one every lib enforces by default, which is why skipping aud is the classic account-confusion bug. jti is the claim that makes a JWT addressable — the token ID you put in a denylist when revocation can't wait for exp.

Two taxonomy notes that bite in practice. JWS vs JWE: the three-part token everyone calls "a JWT" is a signed token (JWS); the encrypted form (JWE, five segments) exists but is rare in auth use — "JWT = signed" is the convention, which is why the confidentiality assumption is wrong. And tokens in URLs: the dead implicit grant put access_token in the fragment for a reason — fragments don't hit server logs, while query strings land in access logs, Referer headers, and proxy chains. If you ever see ?token=eyJ in a system you're building, that's not an API design, it's a leak in progress.

What to actually do

Decode every JWT you issue by hand once — jwt.io or the snippet above — and inventory the claims. If sub or email alone would surprise a stranger reading it, it doesn't belong in the token. Treat the token as public, integrity-protected data: nothing secret inside, nothing trusted before verification. And know that a JWT's security story lives entirely in the verify step — which is where we go next.

Keep reading

Related articles from the SudoSecurity blog.