Skip to content
Account takeover Write-up Intermediate

Pre-Access to Victim’s Account via Facebook Signup

An attacker could create an account using a victim's email address by signing up via Facebook with an unverified email, leading to pre-account takeover. When the victim later tries to sign up or reset their password, the attacker retains access because the application links accounts by Facebook ID.

Akshansh Jaiswal Follow

Published on medium.com

Bounty$500 View original

{{media:0}}

Akshansh JaisWal, on medium.com

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

This is a write-up about a pre-account takeover (pre-access) issue that arises when a third-party application offers a Facebook signup flow. The researcher found the issue in some programs and was rewarded for it. The asset listed for the write-up is medium.com, where the article was published on 28 July 2020.

The feature at the centre of the report is "Sign-up/login with Facebook". Normally, when a user chooses this option, the application opens a Facebook pop-up, the user allows the integration, an access token is generated, and the application reads the user's profile information from Facebook to create or match a local account. The report describes what happens when that flow accepts an email address that the Facebook account owner has added but never verified.

Setup

The report does not describe a specific target application, version, tooling or test accounts. The scenario is generic: any third-party application that offers account creation via Facebook. The preconditions described are:

  1. The victim has no account on the target application yet.
  2. The attacker signs up via Facebook using a Facebook account that was registered with a phone number, then adds the victim's email address during the signup flow.
  3. The attacker adds the victim's email address during the signup flow.
  4. The victim has not previously created a normal account or a Facebook-linked account and signed in.

The researcher notes that Facebook allows an email address to be added to an account and used for sign-in to Facebook and in third-party app integrations without that email being verified. On its own this is not treated as an issue, but it can be used as a chaining action.

Finding it

The researcher shows that when the Facebook account was created with a mobile number, the data returned to the third-party application does not include an email field. The application is then expected to stop the registration and redirect to the home page, or to report that no email is present. In some applications, however, the flow continues into a signup form where the user can enter any email address, including one belonging to someone else.

A second observation is that if the application checks whether an email is present, the response can be tampered with manually to add an email field before the signup flow proceeds.

Exploitation

Step 1: Start the Facebook signup

The attacker opens the target application and chooses account creation via Facebook. The report shows the signup option as it appears on such an application.

Clicking "Sign-up/login with Facebook" opens a pop-up asking whether the user wants to allow the integration. When the user allows it, an access token is generated. The report shows the request in this form:

HTTP
https://example.com/auth2/access_token=Eposkdskdpo.........Request Method: POST

The application then reads the user's information from Facebook. When an email is available, the response looks like this:

JSON
{"email":"[redacted]","name":"hey","id":"fb-id"}

Based on the token, the server generates user cookies and the user can use the application. The flaw appears at the point where the application handles the email field during development: by default, if the application requests the user's email as input, it should verify whether that email is verified or not. The report shows that the email is returned only if it is verified.

Image for post
the email is returned only if verified From the original on medium.com

Step 2: Sign up with a phone-number Facebook account

When the Facebook account was created with a mobile number, the application response does not contain an email:

JSON
{"id":"facebookidnumber","name":"Myname"}

At this point the application should not proceed with user registration and should redirect to the home page or state that the email is not present. In the cases the researcher found, the application instead directs the user to a signup flow where an account can be created by email and any email input can be supplied.

Image for post
Image for post From the original on medium.com

Step 3: Tamper the response if an email check exists

If the application checks that an email is present, the researcher describes a small trick: tamper the response manually to add the victim's email:

JSON
{"id":"facebookidnumber","name":"Myname","email":"[redacted]"}

If the application allows it, the signup flow proceeds and an account is created using the victim's email address.

Step 4: The victim arrives later

When the victim later tries to create an account, they receive:

Text
Account already exists

Even if the victim realises that someone has logged in and changes the password, nothing changes, because sign-in via Facebook remains available and the attacker still has access to the victim's account. The reason is that the application uses the Facebook id as the variable to match the user account.

Root cause

The mistake is in how the application handles the identity returned by Facebook during signup. The application uses the Facebook id as the variable to match the user account, and the signup flow continues with an email address supplied by the user. Because the email is not verified, the attacker can attach the victim's email to an account that is keyed to the attacker's Facebook id. When the victim later signs in, the application matches the account by the Facebook id, so the attacker retains access even after a password change.

The report describes the email verification as a small flaw that can be caused during development.

Impact

An attacker can create an account on behalf of a victim who has not yet registered, using the victim's email address, and later access that account when the victim signs in via Facebook. The victim may not know that someone made an account on their behalf before. The report notes that the impact depends on the complexity of reaching the account and on the victim not knowing about the prior account.

The researcher lists several conditions that prevent the issue or make it more complex:

  1. The victim should not have created a normal account or a Facebook account and signed in before.
  2. If the application alerts users about sign-in via Facebook and allows social sign-in to be removed, the impact goes down considerably.
  3. Most applications, when facing no email, redirect to the home page with a response such as:
JSON
{"statusCode":400,"error":"invalid_grant","message":"Bad Request","error_description":"Bad credentials"}

The researcher found the issue in some programs and was rewarded, with rewards depending on the complexity to reach the account and on the victim not knowing that someone had made an account on their behalf. The report describes this as a case of pre-account takeover that is still active on many applications.

Image for post
Image for post From the original on medium.com

Fix

The report does not describe a specific fix that was applied. Based on the described behaviour, the application should not proceed with registration when the Facebook response contains no verified email, and it should not accept an email address supplied by the user in place of a verified one. The response should be treated as untrusted, so tampering with it should not allow the signup flow to continue.

Variants to test

  1. Sign up via Facebook with a phone-number-only Facebook account and see whether the application continues into a signup form. A positive result is a form that accepts an arbitrary email address.
  2. Tamper the Facebook response to add an email field when the application checks for its presence. A positive result is that the signup flow proceeds and creates an account with the supplied email.
  3. Check whether the application matches accounts by Facebook id. A positive result is that a password change by the victim does not remove the attacker's access.
  4. Check whether the application alerts users about sign-in via Facebook and whether social sign-in can be removed. A positive result is that the user is not warned and cannot remove the link, which keeps the impact high.
  5. Check how the application handles a response with no email. A positive result is that it does not redirect to the home page or return an error such as the invalid_grant response shown above.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

What happened, in plain words

Imagine you want to join a new website, and the site offers a shortcut: "Sign up with Facebook". Instead of filling in a form, you click a button, Facebook asks if you are happy to share a few details with the site, and you are in. This is convenient, and it is also where a subtle mistake can happen.

The researcher describes how, on some websites, an attacker could use this shortcut to create an account that belongs to someone else, before that person ever arrives. The victim has no account yet. The attacker signs up with Facebook, adds the victim's email address during the signup, and the website accepts it. Later, when the victim tries to sign up, the site says the account already exists. Even if the victim changes the password, the attacker still gets in, because the site links the account to the attacker's Facebook identity rather than to the email.

This kind of problem is called a pre-account takeover. "Pre" because the attacker acts before the victim has an account. "Account takeover" because the attacker ends up controlling an account that should belong to the victim. The researcher found it in some programs and was rewarded for it. A bug bounty program is a scheme where a company invites people to look for security problems in its products and pays for good reports.

The article was published on medium.com on 28 July 2020. The researcher is Akshansh Jaiswal.

Akshansh JaisWal
Akshansh JaisWal From the original on medium.com

The feature at the centre of it

The feature is the "Sign-up/login with Facebook" button. When you click it, a small Facebook window (a pop-up) opens and asks whether you want to allow the website to see some of your Facebook details. If you allow it, Facebook gives the website a short-lived pass, called an access token. The website then uses that pass to ask Facebook for your profile information, such as your name, your Facebook id and, if you have one, your email address. With that information the website creates a local account for you, or finds the one you already have.

An access token is like a cloakroom ticket: it is a small piece of text that proves to the website that Facebook has already checked who you are. The website does not need your Facebook password. It just shows the ticket to Facebook and gets your details back.

A cookie is a small piece of text that a website stores in your browser after you sign in, so that on your next click the site remembers who you are. When the report says the server "generates user cookies", it means the site has decided you are signed in and gives your browser the ticket that keeps you signed in.

An API (Application Programming Interface) is the way two pieces of software talk to each other. In everyday terms, it is like a waiter in a restaurant: you tell the waiter what you want, the waiter goes to the kitchen, and brings back a plate. Here, the website is the customer, Facebook is the kitchen, and the API is the waiter that carries the request for your profile and brings back the answer.

The answer comes back in a format called JSON. JSON is just a way of writing data as labelled values, like a shopping list with names next to each item. For example, "name":"hey" means the field called name has the value hey.

The setup

The report does not name a specific target application, version, tool or test account. The scenario is generic: any third-party website that offers account creation via Facebook. The conditions described are:

  1. The victim has no account on the target website yet.
  2. The attacker signs up via Facebook using a Facebook account that was registered with a phone number, then adds the victim's email address during the signup flow.
  3. The attacker adds the victim's email address during the signup flow.
  4. The victim has not previously created a normal account or a Facebook-linked account and signed in.

The researcher notes that Facebook lets you add an email address to your account and use it for signing in to Facebook and in third-party app integrations without that email being verified. On its own this is not treated as a problem, but it can be used as part of a chain of steps. "Chaining" means combining several small behaviours, none of which is serious alone, into something that is.

Finding it

The researcher shows that when the Facebook account was created with a mobile number, the data returned to the third-party website does not include an email field. The website is then expected to stop the registration and send the user back to the home page, or to say that no email is present. In some websites, however, the flow continues into a signup form where the user can type any email address, including one that belongs to someone else.

A second observation is that if the website checks whether an email is present, the response can be tampered with manually to add an email field before the signup flow proceeds. "Tampering" here means changing the data on its way from Facebook to the website, for example with a tool that lets you edit the response before the website reads it. The report does not describe which tool was used.

Exploitation

Step 1: Start the Facebook signup

The attacker opens the target website and chooses account creation via Facebook. The report shows the signup option as it appears on such a website.

Clicking "Sign-up/login with Facebook" opens a pop-up asking whether the user wants to allow the integration. When the user allows it, an access token is generated. The report shows the request in this form:

HTTP
https://example.com/auth2/access_token=Eposkdskdpo.........Request Method: POST

Line by line, in plain words:

  • https://example.com/auth2/access_token=Eposkdskdpo......... is the address the browser or the website calls. example.com is a placeholder for the real website. auth2 is the path that handles the Facebook sign-in. access_token=Eposkdskdpo......... is the pass being carried in the address.
  • Request Method: POST means the browser is sending data to the server, not just asking for a page. A request method is the verb of a web request: GET asks for something, POST sends something.

The website then reads the user's information from Facebook. When an email is available, the response looks like this:

JSON
{"email":"[redacted]","name":"hey","id":"fb-id"}

Line by line:

  • "email":"[redacted]" is the email address Facebook returned. The report uses a placeholder address.
  • "name":"hey" is the display name on the Facebook account.
  • "id":"fb-id" is the Facebook id, a unique number or string that identifies the Facebook account. The website can use it to recognise the same person next time.

Based on the token, the server generates user cookies and the user can use the website. The flaw appears at the point where the website handles the email field during development: by default, if the website requests the user's email as input, it should verify whether that email is verified or not. The report shows that the email is returned only if it is verified.

Image for post
the email is returned only if verified From the original on medium.com

Step 2: Sign up with a phone-number Facebook account

When the Facebook account was created with a mobile number, the response does not contain an email:

JSON
{"id":"facebookidnumber","name":"Myname"}

Line by line:

  • "id":"facebookidnumber" is the Facebook id of the attacker's account. The report uses a placeholder value.
  • "name":"Myname" is the display name. There is no email field at all, because the Facebook account has no verified email.

At this point the website should not proceed with user registration and should send the user back to the home page or say that the email is not present. In the cases the researcher found, the website instead sends the user to a signup form where an account can be created by email and any email input can be supplied.

Image for post
Image for post From the original on medium.com

Step 3: Tamper the response if an email check exists

If the website checks that an email is present, the researcher describes a small trick: tamper the response manually to add the victim's email:

JSON
{"id":"facebookidnumber","name":"Myname","email":"[redacted]"}

Line by line:

  • "id":"facebookidnumber" is still the attacker's Facebook id.
  • "name":"Myname" is still the attacker's display name.
  • "email":"[redacted]" is the field the attacker has added by hand. It is the victim's email address, not one that Facebook verified.

If the website allows it, the signup flow proceeds and an account is created using the victim's email address.

Step 4: The victim arrives later

When the victim later tries to create an account, they receive:

Text
Account already exists

This is the website's message saying that an account with that email is already registered. The victim has never registered, so the message is confusing.

Even if the victim realises that someone has logged in and changes the password, nothing changes, because sign-in via Facebook remains available and the attacker still has access to the victim's account. The reason is that the website uses the Facebook id as the variable to match the user account. In other words, when the victim signs in with Facebook, the website looks up the account by the Facebook id, and that id belongs to the attacker's Facebook account.

Root cause

The mistake is in how the website handles the identity returned by Facebook during signup. The website uses the Facebook id as the variable to match the user account, and the signup flow continues with an email address supplied by the user. Because the email is not verified, the attacker can attach the victim's email to an account that is keyed to the attacker's Facebook id. When the victim later signs in, the website matches the account by the Facebook id, so the attacker keeps access even after a password change.

The report describes the email verification as a small flaw that can be caused during development.

Impact

An attacker can create an account on behalf of a victim who has not yet registered, using the victim's email address, and later access that account when the victim signs in via Facebook. The victim may not know that someone made an account on their behalf before. The report notes that the impact depends on the complexity of reaching the account and on the victim not knowing about the prior account.

The researcher lists several conditions that prevent the issue or make it more complex:

  1. The victim should not have created a normal account or a Facebook account and signed in before.
  2. If the website alerts users about sign-in via Facebook and allows social sign-in to be removed, the impact goes down considerably.
  3. Most websites, when facing no email, redirect to the home page with a response such as:
JSON
{"statusCode":400,"error":"invalid_grant","message":"Bad Request","error_description":"Bad credentials"}

Line by line:

  • "statusCode":400 is the HTTP status code. A status code is a number that tells the browser how the request went. 400 means the request was bad or incomplete.
  • "error":"invalid_grant" is the error name. "Grant" here means the permission or pass that was being used, and "invalid" means it was not accepted.
  • "message":"Bad Request" is a short human-readable summary.
  • "error_description":"Bad credentials" says the credentials (the pass) were not good enough.

The researcher found the issue in some programs and was rewarded, with rewards depending on the complexity to reach the account and on the victim not knowing that someone had made an account on their behalf. The report describes this as a case of pre-account takeover that is still active on many websites.

Image for post
Image for post From the original on medium.com

Fix

Based on the described behaviour, the website should not proceed with registration when the Facebook response contains no verified email, and it should not accept an email address supplied by the user in place of a verified one. The response should be treated as untrusted, so tampering with it should not allow the signup flow to continue.

Variants to test

  1. Sign up via Facebook with a phone-number-only Facebook account and see whether the website continues into a signup form. A positive result is a form that accepts an arbitrary email address.
  2. Tamper the Facebook response to add an email field when the website checks for its presence. A positive result is that the signup flow proceeds and creates an account with the supplied email.
  3. Check whether the website matches accounts by Facebook id. A positive result is that a password change by the victim does not remove the attacker's access.
  4. Check whether the website alerts users about sign-in via Facebook and whether social sign-in can be removed. A positive result is that the user is not warned and cannot remove the link, which keeps the impact high.
  5. Check how the website handles a response with no email. A positive result is that it does not redirect to the home page or return an error such as the invalid_grant response shown above.

Glossary

  • Access token: a short piece of text that proves a website has permission to read your details from another service, like Facebook.
  • API: the way two pieces of software talk to each other, like a waiter carrying requests between a customer and a kitchen.
  • Bug bounty program: a scheme where a company invites people to look for security problems and pays for good reports.
  • Chaining: combining several small behaviours, none serious alone, into something that is.
  • Cookie: a small piece of text stored in your browser so a website remembers who you are between clicks.
  • Facebook id: a unique number or string that identifies a Facebook account.
  • HTTP status code: a number that tells the browser how a request went, such as 400 for a bad request.
  • JSON: a way of writing data as labelled values, like a list with names next to each item.
  • OAuth: the system that lets a website ask another service, such as Facebook, for permission to read your details without giving it your password.
  • Pre-account takeover: an attack where someone creates an account on behalf of a victim before the victim registers, and later gains access to it.
  • Request method: the verb of a web request, such as GET to ask for something or POST to send something.
  • Tampering: changing data on its way from one place to another, for example editing a response before the website reads it.
  • Token: a piece of text that stands in for a password or permission, like a cloakroom ticket.
  • Verification: checking that something is true, for example that an email address really belongs to the person who entered it.

Similar reports

View all

Same bug class and techniques, clearest first.

Account takeover

The lesson behind this report.

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.