Cracking JWTs: A Bug Bounty Hunting Guide [Part 4]
The server trusted the jku header in JWTs without validating the source domain, so an attacker could host their own JWK Set and sign tokens with their private key. This allowed forging a token with the administrator subject to access the admin panel and delete a user.
medium.com
Published on medium.com
Welcome back to Cracking JWTs: A Bug Bounty Hunting Guide — a series where I dive into real-world JWT vulnerabilities exposed through PortSwigger labs and how they can be exploited in bug bounty scenarios.
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 application did not validate the domain of the jku header, allowing an attacker to supply a URL to their own JWK Set.
Impact
An attacker could impersonate any user, including administrators, leading to full takeover of admin panels, user accounts, or sensitive APIs.
What the attacker needed
A free account; victim clicks a link; none
The fix
The application should whitelist trusted domains for the jku header and avoid remote key fetching unless necessary.
How it was found
- Log in to the lab with the provided credentials.
- Attempt to access /admin and observe the admin interface is restricted.
- Capture the /admin request and send it to Burp Repeater.
- In JWT Editor, create a new RSA key and generate a keypair.
- Host a JWK Set on the exploit server containing the public key.
- Modify the JWT: change sub to administrator, set kid to the key's kid, add jku pointing to the hosted JWK Set, and sign with the generated key.
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 JWT is a token a website uses to remember who you are. The jku header tells the server where to find the public key to check the token's signature. If the server trusts any web address in that header, an attacker can point it to their own key and create fake tokens that the server accepts.
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.