skip to content

JWT

The compact token format that carries signed — and optionally encrypted — claims between parties, plus the checks a verifier owes it. Asked constantly because JWTs are everywhere and misused as often.

part ofFederated identityoverview, primer and where to startread it →
on this pageshow

questions

29

What do a JWT's iss, sub, aud, exp and iat claims mean?

level: juniorimportance: must knowfreq 85%

answer

  1. Who made it, who it is about, who it is for
  2. Two of them are timestamps
  3. A shared vocabulary, not a mandate
  4. One stops replay across services
  5. All of them are optional in the format

basics

~20 s

iss names who issued the token, sub the principal the claims describe, aud the intended recipients, exp the moment from which it must not be accepted, and iat when it was issued. All are optional registered claim names.

solid answer

~50 s

These are *registered* claim names — a shared vocabulary so independent systems agree on meaning. **`iss`** identifies the issuer, the party that minted and signed the token. **`sub`** identifies the subject, the principal the claims are statements about — typically the user, sometimes a service. **`aud`** identifies the intended recipients; a recipient is expected to find itself named there and reject the token otherwise. **`exp`** is the expiry: on or after this time the token must not be accepted. **`iat`** records when the token was issued, which lets a recipient reason about its age independently of expiry. Values of `iss`, `sub` and `aud` are strings (URI-shaped values are common); `exp` and `iat` are numeric timestamps. Every one is optional in the format itself — the specification defines what they *mean*, while your application decides which it requires.

code

json · 8 lines
json
{
  "iss": "https://auth.example.com",
  "sub": "user-42",
  "aud": "https://billing.example.com",
  "iat": 1767225600,
  "exp": 1767229200,
  "jti": "3f8b1c9e-0a2d-4c77-9f1e-6b5a2d0c7e14"
}

go deeper

for a junior

Be able to expand each abbreviation and give a one-line meaning without hesitation. This is a rapid-fire screening question and hesitation reads as inexperience.

for a middle

Explain that these names are registered vocabulary rather than mandatory fields, and that a claim only does something when a verifier acts on it.

for a senior

Show you decide per service which claims are required, and that you use iss and aud to keep tokens from one service or issuer from being honoured by another.

for a principal

Own the claim contract across the platform: which claims every token carries, who may add more, and how services avoid becoming coupled through an informal shared payload schema.

## Why registered claims exist A JWT payload is an arbitrary JSON object, so without an agreed vocabulary two systems would invent different names for the same idea and no library could validate anything generically. The JWT specification therefore *registers* a small set of claim names with fixed meanings. Registering the name does not make it mandatory: the specification is explicit that use of each is optional. What it fixes is semantics — if you emit `exp`, it means expiry, and you may not repurpose it. ## iss — the issuer The party that created and signed the token. Its value is a string, and in practice it is almost always a URL identifying the authorization server or identity provider, because a URL is naturally collision-resistant across organizations. Its job is to tell the recipient *whose keys* should be used and whose statements these are. In a system that accepts tokens from more than one issuer, `iss` is what selects the trust configuration; in a single-issuer system it still matters, because a token from a different issuer that happens to verify against a shared secret would otherwise be accepted. ## sub — the subject The principal the claims are about. "The claims in a JWT are normally statements about the subject" is the specification's own phrasing, and it is a good mental model: everything else in the payload describes this entity. For a user-facing token that is a user identifier; for machine-to-machine tokens it is often the client or service identity. Its value must be unique at least within the issuer's namespace. ## aud — the audience Who the token was minted *for*. The value is a string, or an array of strings when a token is intended for several recipients. The semantics are recipient-directed: each recipient is expected to look for a value that identifies itself. This is what stops a token from being replayed across services — a token minted for the billing API should not be usable at the admin API, even though both trust the same issuer and both would find the signature valid. ## exp — expiry A numeric timestamp: on or after this instant the token must not be accepted. It is the format's only built-in lifetime control, and it is what makes a self-contained token tolerable at all, because a token you cannot look up is one you can only stop honouring by waiting. Short lifetimes shrink the window in which a leaked token is useful. ## iat — issued at When the token was minted. It is distinct from expiry: `exp` says when to stop accepting, `iat` says how old this token is. That enables policies expiry alone cannot express — refusing tokens older than a threshold for a sensitive operation even if they have not yet expired, or invalidating every token issued before a password change by comparing `iat` against a per-user timestamp. ## nbf and jti Two more registered names round out the set: `nbf` ("not before") marks the start of the validity window, and `jti` carries a unique identifier for the token itself. ## Presence versus meaning The most common junior mistake is treating a claim's *presence* as protection. A payload containing `exp` does nothing on its own; some verifier has to read it and refuse the token. Equally, a claim that is present and readable is not authoritative until the token's signature has been checked — until then the whole payload is attacker-supplied text. Knowing the vocabulary is step one; knowing that something must act on it is what the rest of the topic is about.

  • Are any of these claims required for a token to be a valid JWT?
    No. The format defines their meaning, not their presence — a payload with no registered claims at all is still a well-formed JWT. Requirements come from the application or a profile: an access-token profile may demand iss, sub, aud and exp, and a verifier should refuse tokens missing what it requires.
  • What is the difference between iss and aud?
    iss names who minted and signed the token; aud names who it was minted for. iss selects whose keys and whose statements you are evaluating; aud tells you whether this token was meant for *you*. A token can be perfectly authentic — right issuer, valid signature — and still be addressed to a different service.
  • Why keep iat when the token already carries exp?
    They answer different questions. exp says when to stop accepting; iat says how old the token is. Age enables policies expiry cannot express — requiring a recently issued token for a sensitive action, or rejecting every token issued before a credential change by comparing iat to a per-user cutoff.

saying these in an interview costs you the question

  • Says sub is the token's subject line or purpose
  • Confuses iss with aud
  • Believes the claims are mandatory in every JWT
  • Thinks including exp expires the token automatically
  • Treats claims as authoritative before verifying the signature

context

open as a page

In JOSE, what is the difference between a JWS and a JWE, and who can read each payload?

level: juniorimportance: must knowfreq 75%

basics

~20 s

A JWS is signed but not encrypted: anyone holding it can decode and read the claims, and the signature only proves they were not altered. A JWE encrypts the payload, so only a holder of the decryption key can read it.

open as a page

Why must you never put a secret in a JWT payload even though the token is signed?

level: juniorimportance: must knowfreq 74%

basics

~20 s

Signing protects integrity, not confidentiality. A JWS payload is only Base64url-encoded, so anyone holding the token — or reading a log, a proxy trace or browser storage — can decode every claim. Secrets belong outside the token or inside an encrypted one.

open as a page

Why can anyone read a signed JWT's payload, and what does that mean for what you put in it?

level: juniorimportance: must knowfreq 78%

basics

~20 s

Base64url is an encoding, not encryption, and a signature protects integrity rather than confidentiality. Anyone holding a signed JWT can decode its claims, so it must carry no secrets and no data the holder should not see.

open as a page

What are the three dot-separated parts of a JWT, and what does each contain?

level: juniorimportance: must knowfreq 88%

basics

~10 s

A signed JWT is three Base64url segments joined by dots: a JOSE header naming the algorithm and key, a JSON claims payload, and a signature computed over the first two segments.

open as a page

In a JWT, what is the difference between decoding a token and verifying it?

level: juniorimportance: must knowfreq 78%

basics

~20 s

Decoding only Base64url-unpacks a JWT's header and payload, which anyone holding the token can do. Verifying recomputes the signature with a trusted key and checks the claims; only verification tells you the token is authentic and still usable.

open as a page

In a JWT, how does alg HS256 differ from RS256 in who can mint a valid token?

level: middleimportance: must knowfreq 75%

basics

~20 s

HS256 is a shared-secret MAC, so every party that can verify a token can also create one. RS256 is asymmetric: the issuer signs with a private key and verifiers hold only the public key, so verification never confers the ability to issue.

open as a page

What is a JWKS endpoint, and what does a resource server do with the keys it returns?

level: middleimportance: must knowfreq 62%

basics

~20 s

A JWKS endpoint serves a JSON Web Key Set: a JSON document with a keys array of public keys in JWK form. A verifier fetches it over HTTPS, caches it, selects the key matching the token's kid, and verifies the signature with that key.

open as a page

How do a JWT's exp, nbf and iat claims differ, and how are their values represented?

level: middleimportance: must knowfreq 65%

basics

~20 s

exp is the instant from which a token must not be accepted, nbf the instant before which it must not be accepted, and iat when it was minted. All three are NumericDate values: seconds — not milliseconds — since the Unix epoch in UTC.

open as a page

How does the JWT alg:none attack let an attacker forge an accepted token?

level: middleimportance: must knowfreq 68%

basics

~20 s

The attacker edits the payload, sets the JOSE header's alg to none, and sends the token with an empty signature. A verifier that obeys the header's algorithm instead of its own configuration runs no signature check and accepts the forged claims.

open as a page

What checks must a verifier run before accepting a JWT, and in what order?

level: middleimportance: must knowfreq 82%

basics

~20 s

Verify the signature first, using a key from a trusted source and an algorithm the verifier chose, not the token. Then check the time claims exp and nbf with a small leeway, the issuer, and the audience. Reject on any failure.

open as a page

How do you rotate a JWT signing key using kid and a JWKS without rejecting live tokens?

level: seniorimportance: must knowfreq 50%

basics

~20 s

Publish the new public key in the JWKS alongside the old one, wait longer than every verifier's cache lifetime, then switch signing to the new kid. Keep the old public key published until the last token signed with it has expired, and only then remove it.

open as a page

How does RS256-to-HS256 algorithm confusion let an attacker forge a valid JWT?

level: seniorimportance: must knowfreq 62%

basics

~20 s

The attacker rewrites the header to HS256 and signs the forged token using the issuer's public key bytes as the HMAC secret. A verifier that trusts the header's algorithm hands those same public bytes to the HMAC check, which then succeeds.

open as a page

A JWT is stateless, so how do you revoke one before its exp time arrives?

level: seniorimportance: must knowfreq 70%

basics

~20 s

You cannot un-sign a token, so you add state on the verifier side: short access-token lifetimes with revocable refresh tokens, a jti denylist consulted during validation, or a per-user cutoff timestamp compared against iat. Each trades statelessness for revocation latency.

open as a page

What is a JWT's jti claim for, and what uniqueness must the issuer guarantee?

level: middleimportance: should knowfreq 38%

basics

~20 s

jti is a unique identifier for the token itself. The issuer must assign it so the chance of accidentally reusing a value is negligible, and when several issuers are in play, values must not collide across them either.

open as a page

What does a JWT's sub claim identify, and why is sub alone not a global user identifier?

level: middleimportance: should knowfreq 45%

basics

~20 s

sub names the principal the claims are about. It is only required to be unique within its issuer's namespace, so the identity key is the issuer and subject together — the same sub value from two issuers can mean two different people.

open as a page

In a JWE, what do the JOSE header's alg and enc fields each specify?

level: middleimportance: should knowfreq 40%

basics

~20 s

In a JWE, alg names the key management algorithm that delivers the per-token content encryption key to the recipient, while enc names the authenticated encryption algorithm applied to the claims themselves. A JWS header has only alg, and there it names a signature algorithm.

open as a page

Why is a short HMAC secret dangerous for an HS256-signed JWT?

level: middleimportance: should knowfreq 55%

basics

~20 s

An attacker holding one token can guess the secret offline at full speed, because every candidate is checked locally against a known signature. A dictionary word or short string falls quickly, and the secret is also the signing key — so cracking it means minting valid tokens.

open as a page

Why does a JWT use Base64url encoding rather than standard Base64, and why is padding dropped?

level: middleimportance: should knowfreq 45%

basics

~20 s

Standard Base64 uses '+', '/' and '=', which need escaping in URLs, query strings and some headers. Base64url substitutes '-' and '_' and JOSE omits the '=' padding, so a token is safe to place anywhere unescaped.

open as a page

Besides alg, what fields can appear in a JWT's JOSE header, and what does typ mean?

level: middleimportance: should knowfreq 42%

basics

~20 s

Common JOSE header fields are typ (the token's media type), cty (content type, set to JWT for a nested token), kid (which key was used) and crit (extensions a verifier must understand). All are metadata about the cryptography, not application claims.

open as a page

In a JWT, what practical differences decide between RS256, PS256 and ES256?

level: seniorimportance: should knowfreq 33%

basics

~20 s

All three are asymmetric JWS algorithms. ES256 produces a far smaller signature than the two RSA options, so tokens are shorter; RS256 has the widest library and platform support; PS256 uses the modern RSA padding on the same RSA key pair but is less universally implemented.

open as a page

How should custom claims be named in a JWT so they do not collide with other parties' claims?

level: seniorimportance: should knowfreq 36%

basics

~20 s

Use a collision-resistant name — typically a URI in a namespace you control — or a name registered in the IANA JWT Claims registry. Short private names like roles are fine only inside a closed system where producer and consumer agree.

open as a page

What is a nested JWT, and why is the payload signed before it is encrypted?

level: seniorimportance: should knowfreq 32%

basics

~20 s

A nested JWT is a JWT whose payload is itself a JWT — in practice a JWS wrapped inside a JWE, flagged by cty set to JWT on the outer header. Signing first binds the signature to the real claims and keeps origin proof from being stripped or replaced.

open as a page

When is a JWE the right answer for sensitive claims in a token, and when is it not?

level: seniorimportance: should knowfreq 42%

basics

~20 s

A JWE is right when the token must pass through a party that relays it but must not read it. It is the wrong answer when the sensitive value did not need to travel at all — an opaque reference the recipient resolves server-side removes the exposure instead of moving it.

open as a page

Why must a JWT verifier never take its key from the token's own kid or jku header?

level: seniorimportance: should knowfreq 42%

basics

~20 s

Those header fields are attacker-controlled. A jku or x5u URL can point at a key set the attacker hosts, and a kid used as a file path or SQL fragment can select a key they control or inject into the query. Either way they sign their own forged token.

open as a page

A gateway decodes a JWT, re-serializes its JSON and forwards it; verification now fails. Why?

level: seniorimportance: should knowfreq 40%

basics

~20 s

A JWS signature covers the exact encoded bytes of the header and payload segments joined by a dot, not the abstract JSON. Re-serializing changes whitespace, key order or escaping, so the signing input differs and verification fails.

open as a page

How should a JWT verifier cache and refresh issuer keys so rotation causes no outage?

level: seniorimportance: should knowfreq 48%

basics

~20 s

Cache the issuer's key set in memory, select keys by the token's kid, and on an unknown kid trigger one rate-limited refresh shared across threads. Serve from cache while refreshing, keep old keys through the overlap window, and reject rather than skip verification when no key is found.

open as a page

Twelve services share one HS256 secret to verify access tokens — what is the risk, and how do you migrate?

level: principalimportance: should knowfreq 45%

basics

~20 s

Every one of those twelve services can forge tokens for the whole system, and no one can tell which copy of the secret leaked. Migrate to asymmetric signing in phases: publish a JWKS, teach verifiers to accept both algorithms by kid, switch issuance, then retire the secret.

open as a page

In JOSE, when would you use the JSON serialization of a JWS instead of the compact one?

level: middleimportance: nice to knowfreq 25%

basics

~20 s

Use the JSON serialization when you need several signatures over one payload, unprotected header parameters, or a detached payload. Compact serialization supports exactly one signature and only the protected header, but it is URL-safe and is the only form RFC 7519 permits for a JWT.

open as a page