JWT Header Injection Attacks
What you'll learn: How attackers exploit JWT header parameters like jku, jwk, and kid to inject malicious keys or trigger server-side request forgery (SSRF).
The Vulnerability
While you've learned about JWT signature verification and algorithm attacks, the JWT header itself can be a vector for exploitation. Three optional parameters deserve special scrutiny:
jku(JWK Set URL): Points to a URL hosting public keysjwk(JSON Web Key): Embeds a public key directly in the headerkid(Key ID): References which key to use for verification
How the Attacks Work
JKU Injection
If a server blindly trusts the jku parameter, an attacker can point it to their own malicious server hosting attacker-controlled keys. The server fetches their key and verifies the token against it—effectively bypassing security.
Analogy: It's like someone changing the locksmith's phone number on your door, so when you call to verify a key, you're actually calling the burglar's friend who says "Yep, that key is legit!"
JWK Injection
Similar to jku, but the attacker embeds their own public key directly in the JWT header. If the server uses this embedded key for verification, the signature check becomes meaningless.
KID Exploitation
The kid parameter might be used in path traversal (../../public.pem) or SQL injection attacks, or even trigger SSRF if the server makes external requests based on it.
Real-World Impact
These attacks can lead to complete authentication bypass or expose internal services through SSRF, allowing attackers to forge tokens for any user.
Key Takeaway: Never trust JWT header parameters like jku, jwk, or kid without strict validation—always use server-controlled, pre-configured keys for signature verification.