The JWK Set URL
RFC 7515 §4.1.2 defines the jku (JWK Set URL) header parameter as a URI that refers to a resource for a set of JSON-encoded public keys, one of which corresponds to the key used to sign the JWT. The server fetches this URL to retrieve the public key for verification - a server-side request triggered by a value in the attacker-controlled token header.
The attack is conceptually simple: point jku at an attacker-controlled endpoint that returns a JWKS containing the attacker's public key. The server fetches the JWKS, finds the attacker's key, and uses it to verify the forged token - which was signed by the corresponding private key. Verification succeeds.
The JWKS format
JWT Arsenal generates this file automatically after keypair generation. Host it at any publicly accessible HTTPS URL, then set jkuto that URL in the forged token's header.
Full attack walkthrough
Domain bypass techniques
Many implementations attempt to restrict valid jku domains. A common but ineffective pattern is checking whether the URL starts withor contains a trusted domain string. Attackers have a catalogue of bypasses:
1. Open redirect
2. URL @ confusion
3. URL fragment / query tricks
4. Subdomain takeover
If the server validates that the jku host ends with .trusted.example.com, a taken-over subdomain (expired-cname.trusted.example.com) passes validation. Subdomain takeovers on cloud providers (Azure, AWS, GitHub Pages) are regularly discovered via tools like subjack and nuclei.
5. SSRF pivot
The server-side HTTP request to fetch the JWKS can be redirected to internal network resources:
Hosting options for the JWKS
- ngrok / Cloudflare Tunnel - expose localhost in seconds; HTTPS included
- GitHub Gist (raw) - static HTTPS hosting, no server required; click "Raw" for a direct URL without redirects
- Pastebin raw - similar to Gist; check that the raw URL doesn't use JS-rendered content
- requestbin / webhook.site - logs the incoming request, useful to confirm SSRF/fetch happens
- Burp Collaborator - confirms server-side DNS/HTTP requests for out-of-band validation
- Exploited in multiple OAuth 2.0 and OIDC providers where the JWS library fetched
jkuwithout domain allowlist enforcement - Open redirect chains have been used to bypass domain restrictions in production identity providers
- Combined with SSRF to pivot to AWS IMDS and retrieve temporary credentials - chained to full AWS account compromise
- GitHub Security Lab and PortSwigger researchers have demonstrated practical exploitation against real identity providers
Mitigations
- Maintain a server-side allowlist of trusted JWKS URLs - pre-configured, not derived from the token
- Perform exact URL matching, not prefix/contains matching
- Disable following of HTTP redirects when fetching JWKS
- Reject tokens containing
jkuorx5uheaders unless explicitly required - If
jkuis required, pin the expected URL in configuration and reject any other value - Cache JWKS responses server-side with appropriate TTL - prevents real-time SSRF probing