skip to content

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

level: middleimportance: should knowfreq 42%

answer

  1. Metadata about protection, not about the user
  2. One field types the whole token
  3. Another types the payload
  4. Nested tokens need a content type
  5. Signed, but not trusted before verification

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.

solid answer

~50 s

The JOSE header is a JSON object of parameters describing how the token is protected. `alg` is mandatory. `typ` declares the media type of the complete token — conventionally `"JWT"`, though profiles define specific values such as `at+jwt` for OAuth access tokens so a verifier can reject a token minted for a different purpose. `cty` describes the *payload's* type and is set to `"JWT"` when the payload is itself a nested token. `kid` is a hint naming which key the issuer used, so a verifier holding several keys can pick the right one. `crit` lists header parameters that a verifier must understand or else reject the token outright. There are also parameters that point at keys or certificates. Everything here is protected by the signature, since the encoded header is part of the signing input — but it is attacker-*supplied* until that signature is checked.

code

json · 5 lines
json
{
  "alg": "RS256",
  "typ": "at+jwt",
  "kid": "2026-05-rotation-key"
}

go deeper

for a junior

Know that the first segment carries metadata — algorithm, token type, key id — and that user claims never belong there.

for a middle

State what typ, cty, kid and crit each mean without swapping them, and explain nesting as the reason cty exists.

for a senior

Argue for explicit typing across a platform's token kinds and show you treat kid as an untrusted lookup key into a trusted key set.

for a principal

Own the token taxonomy: which token types exist, which media type each carries, and which service accepts which — so a valid signature never becomes a licence to accept any token.

## What the header is for The first segment of a JWT is the JOSE header: metadata telling the recipient how to process the rest. It answers "which algorithm?", "which key?", "what kind of thing is this?" — never "who is the user?", which is the payload's job. Keeping that line clean matters: application data in the header is a smell, and header parameters treated as trusted input are a vulnerability. ## typ — the media type of the whole token `typ` declares the media type of the complete JWT. The historical convention is the value `"JWT"`, and it is optional — plenty of tokens omit it. The modern, better practice is **explicit typing**: giving each kind of token a distinct media type so a verifier can reject a token that is structurally valid but was minted for another purpose. The OAuth access-token profile, for example, specifies `typ` of `at+jwt`. Without explicit typing, a service that accepts "any token this issuer signed" can be handed an ID token, a refresh artefact or an internal service token and treat it as an access token, because all of them verify. A detail worth stating: the media-type prefix `application/` may be omitted in `typ`, which is why you see the short forms. ## cty — the type of the payload `cty` describes what the payload contains, and it is only needed when the payload is *not* a plain claims set. Its standard use is nesting: when a JWT is signed and then encrypted (or otherwise wrapped), the inner token becomes the outer token's payload, and the outer header sets `cty` to `"JWT"` so the recipient knows to run the decoded payload through JWT processing again rather than parsing it as claims. ## kid — which key `kid` is a key identifier: an opaque string the issuer chooses so that a verifier holding several keys can select the right one instead of trying each. It is a *hint*, and that word is load-bearing — it is attacker-supplied text that must be used as a lookup into a trusted set of keys, never as anything that touches a filesystem, a URL or a query. ## crit — extensions that must be understood `crit` is an array naming header parameters that the recipient is required to understand. If a verifier does not implement one of them, it must reject the token rather than ignore the parameter. This exists because JSON's tolerance for unknown members would otherwise let a security-relevant extension be silently skipped. It is rare in practice, but knowing what it means demonstrates you have read the header specification rather than guessed. ## Other parameters The JOSE specification also defines parameters that carry or point at keys and certificates — an embedded public key, a URL to a key set, certificate chains and thumbprints. Their existence is worth knowing; whether a verifier should ever act on them is a separate, sharper question. ## The header is signed, but not trusted Two statements that sound contradictory and are both true. The encoded header is part of the signing input, so once verification succeeds you know the header is exactly what the issuer wrote. But *before* verification, every field in it — including `alg` and `kid` — is text supplied by whoever sent the token. The correct posture is therefore to decide the acceptable algorithms and the key set from your own configuration, and to use the header only to select among choices you already trust. ## What interviewers listen for Naming `typ`, `cty` and `kid` with accurate meanings, not swapping `typ` and `cty`; understanding explicit typing as a way to stop cross-purpose token reuse; and articulating the signed-but-not-yet-trusted status of header values.

  • What is the difference between typ and cty in a JOSE header?
    `typ` describes the media type of the complete token — what this object as a whole is. `cty` describes the payload's type, and is only needed when the payload is not an ordinary claims set: setting it to `"JWT"` signals a nested token that must be processed as a JWT rather than parsed as claims.
  • Why is explicit typing recommended rather than always sending typ as "JWT"?
    Because a verifier that accepts anything the issuer signed can be handed a token minted for a different purpose — an identity token used where an access token is expected. Distinct media types let each verifier accept only its own kind, turning a cross-use attack into a rejected token.
  • Is a JOSE header value safe to use once the signature verifies?
    It is authentic then — you know the issuer wrote it. But selection decisions must still come from your configuration: choose the expected algorithm and the trusted key set yourself and use the header only to pick among them, because you must read alg and kid before you have verified anything.

saying these in an interview costs you the question

  • Swaps the meanings of typ and cty
  • Puts user or role claims in the header
  • Trusts kid as a path or URL to fetch a key
  • Says the header is unsigned because it precedes the signature
  • Thinks typ is mandatory in every JWT

context