⚙️ 06. — Stealing OAuth access tokens via a proxy page
The OAuth implicit flow's redirect_uri validation could be bypassed with directory traversal to point to an iframe page, and that iframe page used postMessage with a wildcard origin to send its full URL, including the access token, to any parent window. An attacker could embed the OAuth URL in a page to steal a victim's access token and then use it to read the victim's API key.
medium.com
Published on medium.com
The original lives on medium.com
We do not hold its text, 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
Likely the OAuth server validated redirect_uri with a prefix check that allowed path traversal, and the comment-form iframe sent its full URL to any parent window via postMessage with a wildcard target origin.
Impact
An attacker could steal a victim's OAuth access token and use it to obtain the victim's API key, but the exploit relies on the victim having an active OAuth session and using Chrome.
What the attacker needed
Victim has an active OAuth session; victim uses Chrome; attacker can host a page
The fix
The redirect_uri should be validated by exact match against a whitelist and reject traversal, and postMessage should specify a trusted target origin and avoid sending sensitive URLs.
How it was found
- Log in as wiener via the social media login and observe the GET /me request returning an apikey.
- Locate the GET /auth request and test redirect_uri with a directory traversal path.
- Find the comment form iframe and observe its postMessage code sending window.location.href with a wildcard origin.
- Create an exploit page with an iframe pointing to the OAuth URL using the traversal redirect_uri and a script that logs received messages.
- Deliver the exploit to the victim and check the access log for the leaked token.
- Use the stolen token in the GET /me request to retrieve the admin's API 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.
When you log in with another service, that service sends a secret token back to the website. The website's login check only looked at the start of the return address, so adding '../' let an attacker redirect the token to a different page. That page then used a browser feature called postMessage to tell its parent window its own address, which included the token, without checking who the parent was. The attacker's page was the parent, so it received the token.
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.