A JWT Is Signed, Not Encrypted, So Anyone Can Read Its Payload

In progress AppSec

A JSON Web Token has three Base64URL-encoded parts separated by dots: a header (algorithm and type), a payload (the claims) and a signature. The signature proves the token was issued by someone holding the key and hasn't been changed. It doesn't hide anything: decoding the payload takes one command, so a JWT must never carry secrets, and the server must actually verify the signature before trusting a single claim.

Anatomy

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0MiIsImV4cCI6MTcwMDAwMDAwMH0.<signature>
        header                          payload
{"alg": "HS256", "typ": "JWT"}
{"sub": "42", "exp": 1700000000}
Claim Meaning
sub subject: who the token is about
exp expiry, in seconds since the epoch
iat, nbf issued at, not valid before
iss, aud issuer and intended audience

HS256 signs with one shared secret; RS256 or ES256 sign with a private key and verify with a public one, so verifiers can't issue tokens.

Verify Properly

  • Verify the signature with a maintained library, and pin the accepted algorithms (algorithms=["HS256"]): never let the token's own header choose, and reject alg: none.
  • Check exp, and iss and aud when several services share keys.
  • Keep lifetimes short: a JWT is valid until it expires, and the server can't revoke one without keeping state (a deny list, or short access tokens with refresh tokens).

References

Review cards

Flashcard Why must a JWT never carry secrets?

It's signed, not encrypted: the payload is Base64URL-encoded JSON that anyone can decode. Secret data needs JWE or stays server-side.

Flashcard What does the `exp` claim do, and why keep it short?

It's the expiry time in seconds since the epoch; after it, verification rejects the token. A JWT can't be revoked without server state, so a short exp limits how long a stolen token works.

Quiz What does `alg` in a JWT header name, and how should the server treat it?
  • The signing algorithm; the server pins the algorithms it accepts
  • The signing algorithm; the server verifies with whichever it names
  • The encryption algorithm that hides the payload
  • The encoding used for the payload, such as Base64URL

alg is a header parameter, not a claim, naming the signature algorithm (HS256, RS256). Letting the token choose opens algorithm confusion and alg: none, so pass algorithms=["HS256"].