Skip to content

JWT JWK Header Injection

SeverityHigh
CVEsCVE-2018-0114
Classifications
OWASP CategoryOWASP API2:2023 Broken Authentication

The “JWT JWK Header Injection” vulnerability occurs when a server verifies an asymmetrically signed JWT using the public key supplied in the token’s own jwk header, rather than a key it already trusts. Because the attacker controls that header, they can generate their own key pair, embed the public key in jwk, and sign the token with the matching private key. The signature is internally consistent, so a naive verifier accepts it.

For more details, you can refer to the jwtop documentation on JWK Injection.

An application expects tokens signed with RS256 and verified against a fixed public key. If it is vulnerable, an attacker can:

  1. Generate a fresh RSA key pair.
  2. Build a token with the desired claims and a header containing "jwk": { ...attacker public key... }.
  3. Sign it with the attacker’s private key.
  4. Send the forged token; the server verifies it with the embedded key and accepts it.

If you want to test only the “JWT JWK Header Injection” vulnerability, you can use the following command:

Terminal window
vulnapi scan curl [url] -H "Authorization: Bearer [JWT]" --scans jwt.jwk_injection

This check only runs when the token under test uses an asymmetric algorithm and a live server is available.

VulnAPI supports scanning against various types of other vulnerabilities as well.

  • Full Authentication Bypass: An attacker can forge tokens for any user, including administrative accounts.
  • Account Takeover: Impersonating any user in the system.
  • Unauthorized Access: Access to sensitive data and privileged functionality.
  • Ignore token-supplied keys: Never resolve the verification key from the jwk, jku, x5c, or x5u header. Use a key or key set configured out of band.
  • Allowlist key identifiers: If key rotation is needed, resolve kid against a trusted, server-side key set.
  • Strict Algorithm Enforcement: Always pin the expected algorithm(s) when verifying a JWT.