Skip to main content
MediumAPIOWASP A02:2021CWE-347

How to fix: JWT header declares a jku or x5u key-location claim

A JSON Web Token found in the response body or a Set-Cookie header decodes to a header segment containing a jku (JWK Set URL) or x5u (X.509 URL) claim that points to an external URL, meaning whichever server verifies this token may fetch the verification key from a location named inside the token itself.

Why it matters

If the verification code resolves the signing key from the jku/x5u URL without checking it against an allowlist, an attacker can host their own key pair, sign a token with their own private key, and point jku/x5u at their own JWKS endpoint. The server then verifies the attacker-forged token successfully because it fetched the attacker's own public key to check it against.

The token's header segment is base64url-decoded directly from a token found in the page or a cookie value, so this confirms the claim's literal presence in an issued token, not that the server's verification logic actually trusts it unvalidated. Many JWT libraries require jku/x5u handling to be wired up explicitly by the developer, so presence of the claim alone does not confirm the vulnerable code path exists.

How to fix it

  1. 1Never resolve jku or x5u directly from an untrusted token; validate the URL's host against an explicit allowlist before fetching anything
  2. 2Prefer distributing keys out-of-band, a fixed JWKS endpoint your own code controls or an embedded public key, instead of trusting the token to name its own key source
  3. 3If jku support is required, pin the set of allowed hosts and reject any URL that does not match

Code examples

Node.js (jose): allowlist the jku host before fetching

JavaScript
import { jwtVerify, createRemoteJWKSet, decodeProtectedHeader } from 'jose';

const ALLOWED_JKU_HOSTS = new Set(['keys.example.com']);

function resolveJwks(token) {
  const header = decodeProtectedHeader(token);
  if (typeof header.jku !== 'string') {
    throw new Error('No jku present');
  }
  const jkuUrl = new URL(header.jku);
  if (!ALLOWED_JKU_HOSTS.has(jkuUrl.hostname)) {
    throw new Error('Untrusted jku host: ' + jkuUrl.hostname);
  }
  return createRemoteJWKSet(jkuUrl);
}

Safer: ignore jku/x5u entirely, verify against a fixed JWKS endpoint

JavaScript
import { jwtVerify, createRemoteJWKSet } from 'jose';

// Always fetch keys from your own known JWKS endpoint,
// never from a URL named inside the token being verified.
const JWKS = createRemoteJWKSet(
  new URL('https://auth.example.com/.well-known/jwks.json'),
);

const { payload } = await jwtVerify(token, JWKS);

References

Detected automatically by VulnRadar. The check id is api-jwt-jku-x5u-header-claim, stable across every scan so you can filter or diff on it.

See every api check

Questions

How severe is JWT header declares a jku or x5u key-location claim?
VulnRadar rates this medium severity in the api category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id api-jwt-jku-x5u-header-claim, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does JWT header declares a jku or x5u key-location claim map to?
It maps to CWE-347. In the OWASP Top 10 it falls under A02:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for jwt header declares a jku or x5u key-location claim

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

JWT header declares a jku or x5u key-location claim | VulnRadar