JWT X5C Header Injection
| Severity | High |
|---|---|
| Classifications | |
| OWASP Category | OWASP 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.
Example
Section titled “Example”- The attacker generates a key pair and a self-signed certificate.
- They build a token with the desired claims and a header
"x5c": ["<attacker certificate>"]. - They sign it with the matching private key.
- The server extracts the certificate from
x5c, uses its public key to verify the signature, and accepts the token.
How to test?
Section titled “How to test?”If you want to test only the “JWT X5C Header Injection” vulnerability, you can use the following command:
vulnapi scan curl [url] -H "Authorization: Bearer [JWT]" --scans jwt.x5c_injectionecho "[JWT]" | vulnapi scan openapi [OpenAPI_Path_Or_URL] --scans jwt.x5c_injectionvulnapi scan graphql -H "Authorization: Bearer [JWT]" --scans jwt.x5c_injection [url]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.
What is the impact?
Section titled “What is the impact?”- 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.
How to remediate?
Section titled “How to remediate?”- Ignore token-supplied certificates: Never resolve the verification key from the
x5corx5uheader. Use a key or certificate configured out of band. - Validate the chain: If
x5cmust 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.