Facebook OAuth Bug: The $55,000 Token Leak
Facebook OAuth Bug: The $55,000 Token Leak

Facebook OAuth Bug: The $55,000 Token Leak

AI-generated illustration
A loosely matched redirect path and one script that posted messages to any origin let a web page silently steal Login with Facebook tokens
AI-assisted: drafted with AI help from public sources, then reviewed and edited. This is an analytical case study of a public disclosure, not my own discovery.
Visit the wrong web page while logged in to Facebook, and that page could quietly collect your access tokens, with no click and no consent prompt. This Facebook OAuth bug could reach first-party apps such as Instagram, and could lead to full Facebook account takeover. Facebook paid $55,000 for the finding and a bypass of its first fix.
Disclaimer: * Educational and defensive use only. Facebook fixed both issues in December 2019 and January 2020. URLs, app IDs and exploit code are intentionally omitted.*
Vulnerability Overview
- Type: OAuth token leakage through redirect path confusion and an unrestricted cross-origin message
- CWE (analytical mapping): CWE-346 (Origin Validation Error), CWE-1021 (Improper Restriction of Rendered UI Layers or Frames)
- CVE / CVSS: Not reported
- Bounty: $55,000 combined, which the researcher described as the highest bounty for a client-side account takeover at that time
How the Facebook OAuth Bug Worked (high level)
Researcher Amol Baikar looked at the plumbing behind the JavaScript SDK. The SDK fetched tokens through an endpoint whose return address was a cross-domain helper file on Facebook’s static domain. That helper was allowed by default for every app.
He found the check on that return address was loose. The helper’s name had to appear, but extra path segments after it were accepted. That mattered because a different script on the same static domain read the page fragment, where tokens travel, and posted it to the parent window addressed to any origin.
Put together:
- A malicious page loaded the token flow in a hidden frame. The flow could be framed, so no pop-up or click was needed.
- The return address pointed at the allowed helper path, extended so it served the chatty script instead.
- That script handed the fragment, token included, to the attacker’s page.
Facebook deprecated the endpoint within hours. Weeks later he showed the main OAuth dialog could still reach the same script through a lightweight mobile subdomain that redirected. The final fix required the exact helper file, blocked redirects to it and removed the script.
Business Impact
Tokens for first-party apps carried broad privileges. The researcher showed they could add a recovery phone number, which means full takeover even of content marked “Only me”. Any site visit was enough.
Fixing Facebook OAuth-Style Token Leaks (my own analysis)
1. Match redirect URIs exactly. No prefix, path or suffix tolerance.
2. Name the receiver in every postMessage. A wildcard target turns a helper into a broadcaster.
3. Refuse framing for token flows. Deny all ancestors on authorization pages.
// Pseudocode: exact redirect match, explicit message target, no framing
function authorize(req, app) {
if (!app.redirectUris.includes(req.redirectUri)) { // exact string compare
return deny("redirect_uri mismatch");
}
res.setHeader("Content-Security-Policy", "frame-ancestors 'none'");
return redirectWithToken(req.redirectUri, issueToken(app, req.user));
}
function relayToParent(payload, expectedOrigin) {
if (!ALLOWED_ORIGINS.has(expectedOrigin)) return; // never "*"
window.parent.postMessage(payload, expectedOrigin);
}
// Test: helper path plus extra segment -> mismatch; frame from another site -> blocked
Key Takeaways
- An allow-listed path is only as safe as everything reachable under it.
- Patch every entry point to the same sink, or a bypass will find the one you missed.
- Clickless, framed flows turn token bugs into drive-by account takeover.
Credit & Sources
Discovered and reported by Amol Baikar. Primary source: Facebook OAuth Framework Vulnerability, published 1 March 2020 (archived copy, as the original domain no longer hosts the post). Facts come from that write-up; analysis and code are original.
Next breakdown: the SQL injection that let anyone add crew to TSA’s Known Crewmember system. Follow @masimshahzad for daily bug bounty breakdowns.
First published by Adam Hale on Medium.
Sources
Share
Reactions
Comments
Your name and comment appear on this article for other readers.
Corrections and tips:[email protected]

