JWT Header Injection
Abuse of the five JOSE header parameters that point at key material (
jwk,jku,x5c,x5u,kid) to make the verifier trust a key the attacker controls, or to turn key lookup into an injection sink.
How it works
A JWS header is attacker-controlled JSON, base64url-encoded (not encrypted), and read before the signature is checked because the verifier needs it to pick the key. RFC 7515 defines five parameters that tell the verifier where the key is, and §10.3 is explicit that none of them makes a key trustworthy — kid is only “a hint indicating which key was used”. A signature that verifies under a key the attacker chose proves only that the attacker signed it.
jwk — embedded public key
The header carries the verification key itself. A verifier that uses it accepts a token that vouches for itself: generate a key pair, write arbitrary claims, sign with the private key, embed the public half.
{ "alg":"RS256", "typ":"JWT", "jwk":{ "kty":"RSA", "e":"AQAB", "n":"<attacker modulus>" } }
Still shipping in 2026: node-jose fixed it in 2018 (CVE-2018-0114); Authlib (CVE-2026-27962, CVSS 9.1, fixed 1.6.9) and Dart jose (CVE-2026-34240) repeated it. Authlib’s subtle trigger was a key-resolver that returned None (e.g. a JWKS lookup that misses an unknown/rotated kid): instead of failing, _prepare_algorithm_key() fell through to the header jwk, so even an app that looked keys up correctly could be bypassed with an unseen kid plus an embedded key. Panva jose instead makes embedded-key use opt-in via an explicit EmbeddedJWK resolver (correct for DPoP, where trust comes from a separate binding).
jku / x5u — URL to the key set
The token says “my key is at this URL” and a naive verifier fetches it. Host your own JWKS, set kid to match, sign with your key. This is also a pre-auth SSRF primitive (RFC 8725 warns against blindly following jku/x5u). Allow-list failures to probe:
- String
startsWith/containson the trusted host instead of parsing scheme+host+port for equality (see URL Parser Differentials). - Open redirect on the allow-listed host when the HTTP client follows redirects.
- Attacker-writable content on the trusted origin (upload bucket, profile field, paste) serving a JWK Set.
x5c / x5u — certificate chain
Same as embedded jwk wearing a certificate. RFC 7515 requires RFC 5280 chain validation to a controlled trust anchor; a verifier that just reads the public key from the first cert accepts a self-signed cert minted a minute ago.
kid — key lookup becomes an injection sink
Legitimate kid semantics: verifiers look up the JWK whose kid equals the header’s, never assume the first key, and refresh the cached JWKS once on an unknown kid before rejecting — a bounded retry, not a loop (JWKS and kid).
kid cannot introduce a new key by itself, but it reaches whatever code turns the identifier into a key, often as a trusted string:
- Path traversal:
"kid":"../../../../../../dev/null". With HMAC, the file’s contents become the shared secret;/dev/null(empty) or any predictable static file lets the attacker sign with a known/empty secret. A null byte encodes asAA==. - SQL injection:
"kid":"nonexistent' UNION SELECT 'attacker_secret'-- -"returns an attacker-known key from the key-lookup query. - Command injection / SSRF:
kidpassed to a shell or to a remote key-fetch endpoint. - Predictable-file HMAC:
kidpointing at a web-served static file (e.g.../../var/www/html/index.html) makes its fetchable contents the secret; withkidSQLi the injectedUNION SELECTvalue becomes the key. Confirmjkufetching with an out-of-band callback before building a JWKS (robinx0).
Notable cases
- Authlib (CVE-2026-27962) and Dart jose (CVE-2026-34240): embedded-
jwkacceptance, March 2026, eight years after node-jose’s CVE-2018-0114. - PortSwigger Web Security Academy labs: jwk injection, jku injection (trusted-domain check bypass), kid path traversal; the canonical reproductions.
- Invicti: forgery via unvalidated
jku(also a blind SSRF), signature bypass viakidpath traversal, signature bypass viakidSQL injection. - Hammer (TryHackMe): 4-digit lottery → JWT
kidabuse → RCE, a worked chain fromkidmanipulation to code execution. - “Off the Curve” CTF:
kid=/made the HMAC key empty, forging arole=admintoken (empty-key forgery meeting header injection) as stage one of a crypto chain. - xalgorix survey: catalogs the whole
jwk/jku/x5c/x5u/kidclass and the key-resolution rules that close it.
Detection and testing
- Inspect the header for any of the five parameters; many servers process them even when the issuer never sets them.
jwk: embed your public key, sign with your private key, updatekidto match (Burp JWT Editor “Embedded JWK” does both).jku/x5u: point at a collaborator host; if fetched, test allow-list bypass (parser differential, open redirect, same-origin writable content) and watch for SSRF.kid: try../../../dev/nullwith an empty HMAC secret, SQL metacharacters, and command/SSRF payloads; observe differential responses.
Defenses
- Resolve keys only from configuration (the IdP’s
jwks_urifrom metadata). Ignorejwk,jku,x5u,x5centirely unless a protocol genuinely needs them. - If
jku/x5uis required: exact scheme+host+port allow-list on the parsed URL, no redirects, no cookies, DNS-rebinding-safe client. - Validate
x5cchains to a pinned application-specific root (not the OS CA store) plus expected subject. - Treat
kidas untrusted: map it to keys via an allow-list or static table, never a filesystem path, SQL string, or shell argument. - Audit the published JWKS itself: no private (
d,p,q,dp,dq,qi) or symmetric (oct/k) material, uniquekidper key (JWKS and kid).
Related
- JSON Web Tokens
- JWT Algorithm Confusion
- JWT Empty Key Forgery
- JWT None Algorithm
- SSRF
- URL Parser Differentials
Sources
- JWT libraries keep trusting the key an attacker puts in the header (jwk/jku/kid) · original
- JWT attacks (PortSwigger Web Security Academy) · original
- Lab: JWT authentication bypass via jku header injection · original
- JWT Signature Bypass via kid Path Traversal · original
- JWT Signature Bypass via kid SQL injection · original
- JWT Signature Bypass via unvalidated jku parameter · original
- JWT Forgery via unvalidated jku parameter (Invicti) · original
- Bug bounty tip: exploiting JWT kid header injection for auth bypass · original
- JWT authentication bypass via kid header path traversal (siunam) · original
- Hammer (TryHackMe): From a 4-Digit Lottery to RCE via JWT kid Abuse · original
- Off the Curve: JWT forgery CTF writeup · original
- JWT Header Parameter Injections · original
- Known Exploits and Attacks (jwt_tool Wiki) · original
- JWKS and kid Explained: How to Find the Key That Signed Your Token (and Spot a Leaked Private Key) · original
- JWT algorithm confusion: none, HS256/RS256 mix-ups, and kid injection · original