Skip to content

JWT X5C Header Injection

SeverityHigh
Classifications
OWASP CategoryOWASP API2:2023 Broken Authentication

The “JWT X5C Header Injection” vulnerability occurs when a server verifies a token using the X.509 certificate chain supplied in the token’s own x5c header, without checking that the certificate chains to a trusted CA. Because the attacker controls the header, they can embed a self-signed certificate for a key pair they generated and sign the token with the matching private key.

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

  1. The attacker generates a key pair and a self-signed certificate.
  2. They build a token with the desired claims and a header "x5c": ["<attacker certificate>"].
  3. They sign it with the matching private key.
  4. The server extracts the certificate from x5c, uses its public key to verify the signature, and accepts the token.

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

Terminal window
vulnapi scan curl [url] -H "Authorization: Bearer [JWT]" --scans jwt.x5c_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 certificates: Never resolve the verification key from the x5c or x5u header. Use a key or certificate configured out of band.
  • Validate the chain: If x5c must be used, verify that the certificate chains to a pinned, trusted CA and matches the expected subject.
  • Strict Algorithm Enforcement: Always pin the expected algorithm(s) when verifying a JWT.