CSRF Email Confirmation Vulnerability for Gmail & G-Suite in Facebook
The OAuth login flow for confirming a new Facebook account with a Gmail address did not properly validate the CSRF state token, so the same token could be reused in any browser. An attacker could embed a crafted URL in a web page and, once the victim clicked it, have the victim's email address confirmed on the attacker's Facebook account.
Published on medium.com
{{media:0}}
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 lets a new user confirm a Gmail or G-Suite address in one of two ways when creating an account: by typing a five digit confirmation code, or by signing in through Google OAuth. This write-up covers a flaw in the second path, the OAuth login flow, that let an attacker confirm their own Facebook account with a victim's email address after only minimal interaction from the victim.

The two confirmation methods, as described in the report:
- Confirming by entering the 5 digit confirmation code.
- Confirming by OAuth login.

Setup
The report does not describe a particular test account setup, tooling or browser versions beyond the observation that a state value generated in Firefox should only be valid in that same browser. The precondition for the attack is that the attacker's Facebook account is logged into the victim's browser at the moment the crafted page runs, which the researcher arranges with a one-tap login URL described below.
Finding it
The researcher first considered the code-based method and rejected it: method 1 is hard to bypass because there is a rate limit on the confirmation code, and repeated guessing leads Facebook to block the account with a Checkpoint block for suspicious activity.
Attention moved to method 2, the OAuth login flow. While testing it, the researcher found that CSRF token validation was missing. The OAuth authorisation request looks like this:
https://accounts.google.com/o/oauth2/auth?client_id=15057814354-[redacted].apps.googleusercontent.com&state=[redacted]-[redacted]-xPTwoggineLFh34F61bbYGsg&response_type=code&redirect_uri=https%3A%2F%2Fwww.facebook.com%2Foauth2%2Fredirect%2F&scope=openid+email&login_hint=[redacted]
In this request the state parameter is the CSRF token, and it is what should validate the request and its response. The expected behaviour, as the researcher puts it: if a state parameter is generated in Firefox, it should work only in the same browser where it was generated. Here that validation was missing, so the same CSRF token could be used in any browser. That makes the URL embeddable in a web page: once the victim clicks the link, the victim's email address is confirmed on the attacker's account.
Exploitation
There is one obstacle: before the link is clicked, the attacker's account has to be logged into the victim's browser. Facebook has some one-tap login URLs for this, and the researcher used the following:
https://www.facebook.com/recover/password/?u=<UID>&n=<6Digit code>&ars=one_click_login&fl=one_click_login&spc=1&ocl=1&sih=0
Step 1: log the attacker's account into the victim's browser
When the malicious page loads, this link is loaded in an IFrame, and the attacker's account gets logged into the victim's browser. The URL contains placeholders for a user identifier in u and a six digit code in n, plus one-click login parameters.
Step 2: trigger the OAuth confirmation
With the attacker's session now present in the victim's browser, the OAuth authorisation URL from the finding is loaded. Once the OAuth popup loads, the victim's email address is confirmed on the attacker's account. Because the state value is not bound to the browser that generated it, the token taken from the attacker's own flow is accepted in the victim's browser.
Step 3: log the attacker's account out again
Once the popup is closed, the attacker's account is logged out of the victim's browser using the logout endpoint below:
https://m.facebook.com/logout.php?h=17AfealsadvYomDS
By combining all of this in a single web page, the attacker's account is logged into the victim's browser, the confirmation happens, and the account is logged out again. The report includes a video proof of concept for the flow.
Root cause
The OAuth login flow did not properly validate the state parameter. The state value is meant to tie an authorisation response to the browser session that started the request; here a value generated in one browser was accepted in another, so an attacker could reuse their own token in a victim's browser. The code-based confirmation path had a rate limit, and repeated guessing led to a Checkpoint block.
Impact
An attacker could confirm their own new Facebook account with a victim's Gmail or G-Suite address, with minimal interaction from the victim: the victim only has to load the malicious page. The attack depends on the attacker's account being logged into the victim's browser first, which the one-tap login URL accomplishes, and and the attacker's account is logged out again afterwards. The report does not describe any further consequences of the confirmed address.
Fix
Facebook fixed the issue on 31 May 2019, after further investigation that started on 17 May 2019.
Timeline
| Date | Event |
|---|---|
| 10 May 2019 | Report sent |
| 17 May 2019 | Further investigation by Facebook |
| 31 May 2019 | Fixed by Facebook |
| 19 June 2019 | $3,000 bounty awarded by Facebook |

The researcher thanks the Facebook Security Team for the bounty.

Variants to test
- OAuth
statereuse across browsers. Start an OAuth flow in one browser, capture thestatevalue, and replay the full authorisation URL in a different browser or profile. A positive result is the authorisation completing and the account being linked or confirmed in the second browser. statereuse after logout or session change. Complete the flow, log out, then replay the same URL. A positive result is the request being accepted again instead of rejected as stale or mismatched.- One-tap login URLs as a session-fixation primitive. Check whether a login URL containing a user identifier and code can silently authenticate an account in a browser that does not belong to that user, for example inside an IFrame. A positive result is the target account's session appearing in the victim's browser without any credential entry.
- Combining silent login with a CSRF-prone confirmation step. Look for other account-linking or verification flows (email, phone, third-party identity) that accept a token not bound to the session, and chain them with a silent login and a logout call. A positive result is an account being verified with someone else's identifier and the attacker's session being removed afterwards.
What happened, in plain words
Facebook lets you create a new account and attach an email address to it. If that address is a Gmail or G-Suite address (G-Suite is Google's paid email service for organisations), Facebook gives you two ways to prove the address really belongs to you. The first is to type a five digit confirmation code. The second is to sign in to Google through a button on Facebook, a process called OAuth. OAuth is a way for one website to ask another website, on your behalf, "is this person really the owner of this account?" without ever handing over your password.

The researcher found a flaw in the second path. By putting together a few links on a single web page, an attacker could get their own Facebook account confirmed with a victim's email address, and the victim only had to open that page. The attacker's account was quietly signed in to the victim's browser, the confirmation happened, and then the attacker's account was signed out again so the victim would be less likely to notice anything.

This is a beginner's walkthrough of that report. Every concept is explained from scratch, and every link and code snippet is copied exactly as it appeared.
The two ways to confirm an email address
When you create a new Facebook account with a Gmail address, Facebook needs proof that the mailbox is yours. The report describes two methods:
- Confirming by entering the 5 digit confirmation code.
- Confirming by OAuth login.

Method 1, the five digit code. Google sends a short number to the mailbox. You read it and type it into Facebook. This is like a shop texting you a code before it lets you change your delivery address: it proves you control the phone number on file.
Method 2, OAuth login. Instead of a code, you click a button and Google asks you to sign in (or you are already signed in) and then tells Facebook "yes, this person controls this mailbox". This is like showing your passport at a border instead of answering questions: a trusted authority vouches for you.
Why the code method was not the target
The researcher first looked at method 1 and set it aside. The report says method 1 is hard to bypass because there is a rate limit on the confirmation code. A rate limit is a cap on how many times you can try something in a given period, like a cash machine that swallows your card after three wrong PINs. Even if you try to brute force the code, Facebook will block your account with a Checkpoint block due to suspicious activity. Brute forcing means guessing every possible value until one works; with only five digits there are not that many combinations, so without a limit it would be practical. A Checkpoint block is Facebook's security checkpoint that freezes an account when it sees behaviour that looks automated or abusive.
So the researcher moved to method 2, the OAuth login flow, and while testing it found that CSRF token validation was missing.
What CSRF and a CSRF token are
CSRF stands for Cross-Site Request Forgery. The idea: your browser is already signed in to a website, and a page on a completely different site makes your browser send a request to the first website. Because your browser automatically attaches your login, the first website thinks the request came from you. A simple comparison: a company's receptionist knows your face, so if someone hands you a signed form and walks you to the desk, the receptionist accepts the form as yours.
A CSRF token is a random value that a website hands to your browser when it starts a sensitive operation, and expects back with the result. An attacker on another site cannot guess it, so a forged request without the right token is rejected. It is like a cloakroom ticket: only the person holding the matching ticket gets the coat.
In OAuth, the parameter that carries this token is called state. The OAuth provider (here, Google) sends it out with the authorisation request and expects it back unchanged, so it can tie the answer to the browser session that started the request.
The vulnerable request
The OAuth authorisation request the researcher examined looks like this:
https://accounts.google.com/o/oauth2/auth?client_id=15057814354-[redacted].apps.googleusercontent.com&state=[redacted]-[redacted]-xPTwoggineLFh34F61bbYGsg&response_type=code&redirect_uri=https%3A%2F%2Fwww.facebook.com%2Foauth2%2Fredirect%2F&scope=openid+email&login_hint=[redacted]
Line by line, in plain words:
https://accounts.google.com/o/oauth2/authis Google's OAuth endpoint, the address that starts the "sign in with Google" conversation. An endpoint is simply a URL that a service listens on to perform a particular job.client_id=15057814354-[redacted].apps.googleusercontent.comidentifies which application is asking. Here it is Facebook's registered application with Google. Think of it as the name badge of the shop asking for your details.state=[redacted]-[redacted]-xPTwoggineLFh34F61bbYGsgis the CSRF token. It is a long random string, and it is the value that should tie the request to one browser session.response_type=codesays what kind of answer Google should give back. A code here is a short-lived value that the application can exchange for the user's details.redirect_uri=https%3A%2F%2Fwww.facebook.com%2Foauth2%2Fredirect%2Fis where Google should send the browser afterwards. The%3Aand%2Fare just the encoded forms of:and/, because URLs cannot contain certain characters literally. Decoded, it ishttps://www.facebook.com/oauth2/redirect/.scope=openid+emaillists what information is being asked for: the user's identity and email address. A scope is the list of permissions requested, like the items on a shopping list.login_hint=[redacted]tells Google which account is expected, so the right person is prompted.
What went wrong with the token
The state parameter is the CSRF token, and it is what should validate the request and its response. The expected behaviour, as the researcher puts it: if a state parameter is generated in Firefox, it should work only in the same browser where it was generated. In other words, the cloakroom ticket should only work at the cloakroom that issued it.
But in this endpoint proper validation was missing, and the same CSRF token could be used in any browser. That is the whole bug. Because the token was not tied to a browser, an attacker could take the token from their own OAuth flow, put the whole URL on a web page, and have it work when a victim opened that page. Once the victim clicks the link, the victim's email address is confirmed on the attacker's account.
The obstacle: the attacker's account must be signed in
There is one problem. Before clicking the link, the attacker's account should be logged into the victim's browser. Why? The report says the attacker's account should be logged into the victim's browser before the link is clicked. The attacker needs their own account to be the one active in the victim's browser at that moment.
Facebook has some one-tap login URLs, and the researcher used this one:
https://www.facebook.com/recover/password/?u=<UID>&n=<6Digit code>&ars=one_click_login&fl=one_click_login&spc=1&ocl=1&sih=0
Line by line:
https://www.facebook.com/recover/password/is the address of Facebook's account recovery page. Account recovery is the flow you use when you have forgotten your password.u=<UID>is a placeholder for the user identifier, the number that identifies the attacker's account. A UID is a unique number a service gives each account.n=<6Digit code>is a placeholder for a six digit code.ars=one_click_login,fl=one_click_login,ocl=1are parameters whose meaning the report does not explain. A flag is a parameter whose presence or value switches a behaviour on.oclmost likely stands for one-click login, though the report does not spell it out.spc=1andsih=0are further parameters whose meaning the report does not explain.
The angle brackets around <UID> and <6Digit code> are placeholders: the attacker fills in their own values. The researcher used this link so that the attacker's account gets logged into the victim's browser. This is sometimes called session fixation: forcing a known session (here, the attacker's) onto someone else's browser.
Putting the attack together
When the malicious page loads, the one-tap login link is loaded in an IFrame, and the attacker's account gets logged into the victim's browser. An IFrame is a small window inside a web page that loads another page; to the browser it is still a normal request, so the login happens silently in the background.
With the attacker's session now present in the victim's browser, the OAuth authorisation URL from earlier is loaded. Once the OAuth popup loads, the victim's email address is confirmed on the attacker's account. Because the state value is not bound to the browser that generated it, the token taken from the attacker's own flow is accepted in the victim's browser. A popup is a separate small browser window opened by a page; the OAuth conversation happens there.
Once the popup is closed, the attacker's account is logged out of the victim's browser using the logout endpoint below:
https://m.facebook.com/logout.php?h=17AfealsadvYomDS
Line by line:
https://m.facebook.com/logout.phpis the mobile Facebook logout address. Them.prefix is Facebook's mobile site.
By combining all of this in a single web page, the attacker's account is logged into the victim's browser, the confirmation happens, and the account is logged out again. The report includes a video proof of concept for the flow. A proof of concept (POC) is a demonstration that the attack really works, usually a recording or a set of steps.
Why this matters
An attacker could confirm their own new Facebook account with a victim's Gmail or G-Suite address, with minimal interaction from the victim: the victim only has to load the malicious page. The attack depends on the attacker's account being logged into the victim's browser first, which the one-tap login URL accomplishes, and and the attacker's account is logged out again afterwards.
The root cause, restated simply
The OAuth login flow did not properly validate the state parameter. The state value is meant to tie an authorisation response to the browser session that started the request; here a value generated in one browser was accepted in another, so an attacker could reuse their own token in a victim's browser. The code-based confirmation path had a rate limit, and repeated guessing led to a Checkpoint block.
The fix and the timeline
Facebook fixed the issue on 31 May 2019, after further investigation that started on 17 May 2019.
| Date | Event |
|---|---|
| 10 May 2019 | Report sent |
| 17 May 2019 | Further investigation by Facebook |
| 31 May 2019 | Fixed by Facebook |
| 19 June 2019 | $3,000 bounty awarded by Facebook |

The researcher thanks the Facebook Security Team for the bounty.

Similar things worth testing
These are the kinds of checks a security tester would run to see whether the same weakness exists elsewhere. Each one is described in plain terms.
- OAuth
statereuse across browsers. Start an OAuth flow in one browser, capture thestatevalue, and replay the full authorisation URL in a different browser or profile. A positive result is the authorisation completing and the account being linked or confirmed in the second browser. In everyday terms: use a cloakroom ticket from one cloakroom at another and see whether the coat comes out. statereuse after logout or session change. Complete the flow, log out, then replay the same URL. A positive result is the request being accepted again instead of rejected as stale or mismatched. This checks whether old tickets are ever cancelled.- One-tap login URLs as a session-fixation primitive. Check whether a login URL containing a user identifier and code can silently authenticate an account in a browser that does not belong to that user, for example inside an IFrame. A positive result is the target account's session appearing in the victim's browser without any credential entry. This is the silent sign-in step of the attack, tested on its own.
- Combining silent login with a CSRF-prone confirmation step. Look for other account-linking or verification flows (email, phone, third-party identity) that accept a token not bound to the session, and chain them with a silent login and a logout call. A positive result is an account being verified with someone else's identifier and the attacker's session being removed afterwards. This is the full recipe applied to other features.
Glossary
- API: a defined set of addresses and rules that one piece of software uses to talk to another, like a service counter with a fixed list of requests it accepts.
- Brute force: trying every possible value of a secret until one works, like trying every key on a keyring.
- Checkpoint block: Facebook's security checkpoint that freezes an account when it detects suspicious or automated activity.
- Client ID: a public identifier that tells an OAuth provider which application is making the request.
- CSRF (Cross-Site Request Forgery): an attack where a page on one site makes your browser send a request to another site where you are already signed in, so the request looks like yours.
- CSRF token: a random value issued to a browser for a sensitive operation and required back with the result, so a forged request from elsewhere cannot succeed.
- Endpoint: a URL that a service listens on to perform a specific job.
- Flag (parameter): a URL parameter whose presence or value switches a behaviour on or off.
- G-Suite: Google's paid email and productivity service for organisations.
- IFrame: a small window inside a web page that loads another page, letting a request happen without the visitor noticing.
- OAuth: a way for one website to ask another website, with the user's consent, whether a person controls a given account, without sharing the password.
- One-tap login: a login link that signs an account in to whichever browser opens it, without typing credentials.
- POC (proof of concept): a demonstration that an attack works, such as a recording or a set of reproducible steps.
- Popup: a separate small browser window opened by a page, often used for sign-in conversations.
- Rate limit: a cap on how many attempts are allowed in a period, which makes guessing impractical.
- Redirect URI: the address a service sends the browser to after an authorisation step finishes.
- Response type: a parameter saying what kind of answer the authorisation request wants back, such as a short-lived code.
- Scope: the list of permissions or pieces of information an application asks for.
- Session: the state of being signed in, represented by a value the browser sends with each request so the site recognises you.
- Session fixation: forcing a known session, such as the attacker's, onto someone else's browser.
- State parameter: the OAuth parameter that carries the CSRF token and should tie a response to the browser session that started the request.
- UID: a unique number a service assigns to each account.
- URL encoding: writing characters that are not allowed in a URL in a percent form, such as
%3Afor:and%2Ffor/.