Exploiting OAuth: Journey to Account Takeover
The application failed to validate the redirectUrl parameter in its OAuth flow and reflected it into a script context without sanitisation, allowing an attacker to inject JavaScript. Combined with a weak CSP that permitted inline scripts, an attacker could steal session tokens and take over a user's account.
Published on blog.dixitaditya.com
Most of the web and mobile applications these days use OAuth to secure their authorization endpoints. It allows them to easily grant access to their users to particular resources as per the application's requirements.
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
Likely the redirectUrl parameter was not validated and was reflected into a script context without proper output encoding, and the CSP allowed unsafe-inline scripts.
Impact
An attacker could steal a user's session tokens and take over their account with a single interaction, though the CSP's connect-src directive limited data exfiltration to redirect-based methods.
What the attacker needed
Victim clicks a crafted link; attacker controls a server to receive tokens
The fix
The application should validate the redirectUrl parameter, implement CSRF protection with a state parameter, sanitise output to prevent XSS, and avoid unsafe-inline in CSP.
How it was found
- Visit the login URL with a redirectUrl parameter pointing to the dashboard.
- Modify redirectUrl to include a closing script tag and HTML to test for reflection.
- Observe that the application reflects the injected HTML.
- Craft a payload that uses window.location to redirect to an attacker server with the token data.
- Receive the session tokens on the attacker server.
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.
OAuth is a way for websites to let you log in using another service, like Microsoft. This site didn't check where it sent you after login, and it also put user input directly into a script without cleaning it. That let an attacker run their own code in your browser and steal your login tokens.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.