Skip to content
OAuth / SSO Write-up Intermediate

Critical Account Takeover via JWT Public Key Injection (JKU Hijac

The API gateway's JWT validator fetched signing keys from any URL in the token's jku header, and its only check was a naive substring match for the trusted domain. An attacker could host their own key set at a URL containing that substring, sign a token with their own private key, and be authenticated as any user, including a system administrator.

T4nv1 Follow

Published on medium.com

While analyzing an enterprise API gateway for a large fintech platform, I discovered a critical authentication bypass. By exploiting a combination of improper JSON Web Key Set (JWKS) header parsing, missing URL whitelist validation in the jku (JWK Set URL) header, and key confusion handling, I was able to forge valid…

T4nv1, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The jku header was trusted to choose the key source, and its validation used a substring check on the raw string instead of parsing the URL and comparing the exact host.

Impact

An unauthenticated attacker could forge tokens for any account, including global system administrators, achieving full account takeover with no user interaction.

What the attacker needed

No account needed; attacker hosts a key set on their own server; victim identity known (e.g. admin email)

The fix

The jku-driven key fetching should be disabled so keys come only from statically configured trusted URLs, or, if dynamic retrieval is required, the URL should be parsed and its host compared exactly against a whitelist, with allowed key IDs pinned.

How it was found

  1. Probe the token validator with altered JWT headers and read its error messages to learn how it handles the jku header.
  2. Host a key set on an attacker-controlled server at a URL whose path contains the trusted domain string.
  3. Generate a local RSA keypair and publish its public key in that hosted key set.
  4. Sign a forged token with the local private key, setting the jku header to the malicious URL and the payload to an administrator identity.
  5. Send the forged token to an administrative API endpoint and receive an authenticated administrator response.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A JSON Web Token (JWT) is a signed note a server gives you to prove who you are; the server checks the signature using a public key. Here the server let the note itself say where to fetch that key, and only checked that the address contained the trusted domain name somewhere. So the attacker put their own key at an address that merely mentioned the trusted domain, signed their own note, and the server believed it.

What is OAuth / SSO?

Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.

More by T4nv1

View all

113 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

OAuth and single sign-on flaws

The lesson behind this report.

Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.