Application-Secret-Embedded-In-Login-Flow-For-Facebook-Swag-Store
The login flow for Facebook's swag stores included the application secret in the OAuth URL, exposing it to anyone who initiated login. An attacker could use the leaked secret to obtain an app access token and query Facebook's Graph API for application roles and insights.
Published on philippeharewood.com
The login flow for facebookswagstore.com and facebookswagemea.com discloses the application secret when logging into the site. Since the owner is Brandvia (the authorized distributor of Facebook-branded merchandise), one should be able to use the app token (the application ID and application secret concatenated) to…
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
The target here is the login flow used by two Facebook-branded merchandise storefronts, facebookswagstore.com and facebookswagemea.com. Both sites are operated by Brandvia, described in the report as the authorised distributor of Facebook-branded merchandise. The stores sit behind Facebook Login, so a visitor signs in with their Facebook account before reaching the shop.
Facebook Login is an OAuth 2.0 flow. The client application is issued an application ID (public) and an application secret (private). The secret is meant to stay on the server and is used, among other things, to build an app access token of the form APP_ID|APP_SECRET, which the Graph API accepts for application-level calls. The login flow should only ever send the client ID to the browser; the secret belongs in server-side code.
Setup
The report does not describe any special accounts, roles, tools or versions. The researcher simply visited the login flow of the two storefronts and observed the URL the site presented. No authentication beyond the normal Facebook Login flow is mentioned as a precondition.
Finding it
When logging into the site, the login flow disclosed the application secret. The URL presented at the time was:
https://www.facebook.com/dialog/oauth?client_id=APP_ID&client_secret=APP_SECRET&redirect_uri=https%3A%2F%2Fwww.facebookswagstore.com%2FFBLoginHandlerOAuth.ashx&response_type=code&scope=public_profile%2Cemail
This is the standard Facebook OAuth dialog endpoint, but it carries a client_secret parameter alongside client_id. That parameter has no business being in a URL that the browser sees: it is visible in the address bar, in browser history, in any proxy or server log along the way, and to anyone who can observe the request. The redirect_uri points at FBLoginHandlerOAuth.ashx on www.facebookswagstore.com, and the requested scope is public_profile,email.
Because the application belongs to Brandvia, the researcher reasoned that the leaked secret could be combined with the application ID to act as the application itself, and in particular to read insights about the Facebook employees visiting the site.
Exploitation
Step 1: Build the app access token
The Graph API accepts an app access token formed by concatenating the application ID and the application secret with a pipe character:
APP_ID|APP_SECRET
Both halves came from the leaked login URL, so no further access was needed to construct it.
Step 2: Read the application's roles
With the app token, the researcher queried the application's roles:
This call returns the owner of the application. The report shows the URL with a numeric application ID in the access_token position, followed by the literal APP_ID|APP_SECRET placeholder, so the real token is the concatenation described above.
Step 3: Read application insights
Finally, the researcher queried the application's insights for the api_calls metric:
Again the token is the concatenated app token. The report does not include the response bodies for either Graph API call.
Root cause
The mistake is in how the storefront's login handler built the OAuth dialog URL: it placed the application secret into the query string of a URL sent to the browser, rather than keeping it server-side and using it only in back-channel calls. Any party who could see that URL, including the user themselves, obtained the secret. The report does not describe what server-side code produced the URL, so the exact implementation is not stated; the observable defect is the client_secret parameter in the browser-facing URL.
Impact
In the researcher's words, this could have let an attacker gain access to the application client secret. With the secret, an attacker can form the app access token and make application-level Graph API calls, which the report demonstrates against the roles and insights endpoints. The report frames the practical consequence as being able to see insights for Facebook employees visiting the site. The report does not enumerate any other capabilities of the leaked secret.
Fix
The timeline records the remediation:
| Date | Event |
|---|---|
| Jul 12, 2018 | Report sent |
| Jul 13, 2018 | Further investigation by Facebook |
| Jul 13, 2018 | App secret removed |
| Aug 1, 2018 | Bounty awarded by Facebook |
So the secret was removed from the login flow the day after the report.
Variants to test
- Inspect the OAuth dialog URL your target builds for
client_secret,client_tokenor similar parameters. A positive result is any secret value appearing in a URL the browser requests. - Check redirects and intermediate hops in the login flow, not just the first URL. A positive result is a secret appearing in a
Locationheader or in a form field posted to the browser. - Look at client-side JavaScript that constructs the login URL. A positive result is the secret embedded in a script served to the browser.
- If a secret is found, try the
APP_ID|APP_SECRETapp token against application-level Graph API endpoints such as roles and insights. A positive result is a successful response rather than an OAuth error.
What happened, in plain words
Two online shops sell Facebook-branded merchandise: facebookswagstore.com and facebookswagemea.com. They are run by a company called Brandvia, which the report describes as the authorised distributor of Facebook-branded merchandise. To get into the shop, a visitor signs in with their Facebook account. That sign-in is handled by a system called Facebook Login.
Facebook Login works like a members-only club with a guest list. The shop is the club, Facebook is the doorman, and you are the guest. To be let in, the shop has to tell Facebook who it is. Facebook gives every shop two pieces of paper: a public name badge (the application ID) and a private password (the application secret). The name badge can be shown to anyone. The password must never leave the shop's back office.
In this case the shop was handing out its private password to every visitor. It was written directly into the web address (the URL) that the browser was sent to when you clicked "log in with Facebook". Anyone who looked at their address bar, or at their browser history, or at any log along the way, could read it.
With that password, the researcher could pretend to be the shop when talking to Facebook's own systems. With that password, the researcher reasoned they could pretend to be the shop when talking to Facebook's own systems, look up who owns the shop's Facebook app and see insights about the Facebook employees visiting the site.
Background you need first
What an API is
An API (Application Programming Interface) is a way for one computer program to ask another for information or to do something, without a human clicking buttons. A useful comparison: a restaurant menu. You do not walk into the kitchen and cook; you pick an item from the menu, the kitchen makes it, and the waiter brings it back. The menu is the API: a fixed list of things you can ask for, in a fixed format.
Facebook's menu is called the Graph API. It lives at https://graph.facebook.com/. You ask for a particular item by putting a path after that address, and you attach your credentials so Facebook knows who is asking.
What a token is
A token is a short piece of text that proves who you are, like a cloakroom ticket. You hand it over, and the staff give you your coat without asking for ID again. In web systems, a token is usually a long string of letters and numbers that the server can check.
What an app access token is
Facebook accepts a special kind of token that represents an application rather than a person. It is built by gluing two things together with a vertical bar (the | character) in between: the application ID, then the application secret. The report writes the shape of it as:
APP_ID|APP_SECRET
Read that as: the public name badge, a pipe, the private password. If you have both halves, you can act as the application itself.
What OAuth and Facebook Login are
OAuth 2.0 is a standard way for one website to let you sign in using another website's account, without ever seeing your password. Facebook Login is Facebook's implementation of it. When you click "Log in with Facebook" on a shop, your browser is sent to a Facebook address (the OAuth dialog) that asks you to approve sharing some information with the shop. The shop tells Facebook which shop it is by including its application ID in that address.
The report notes that the login flow should only ever send the client ID (the public half) to the browser. The secret belongs in server-side code, on the shop's own computers, never in anything the visitor's browser receives.
What the vulnerability class means
This is a case of a secret being exposed to the client (the client being your browser). The general idea: some values are meant to be known only to the server, and if they end up in a place the browser can see, they are no longer secret. The browser is not a private place. Anything in a URL is stored in your history, may be copied into the address bar when you share a link, and is recorded by every server and proxy the request passes through.
Setting the scene
The report does not describe any special accounts, roles, tools or software versions. The researcher simply visited the login flow of the two storefronts and looked at the URL the site presented. Nothing beyond the normal Facebook Login flow is mentioned as a precondition.
Finding it
While logging into the site, the login flow disclosed the application secret. The URL presented at the time was:
https://www.facebook.com/dialog/oauth?client_id=APP_ID&client_secret=APP_SECRET&redirect_uri=https%3A%2F%2Fwww.facebookswagstore.com%2FFBLoginHandlerOAuth.ashx&response_type=code&scope=public_profile%2Cemail
Line by line, in plain words:
https://www.facebook.com/dialog/oauthis Facebook's standard sign-in dialog address. This is the doorman's desk.?marks the start of the parameters, the extra instructions attached to the address.client_id=APP_IDis the shop's public name badge. This one is supposed to be here.client_secret=APP_SECRETis the shop's private password. This one is not supposed to be here. It is the whole problem.redirect_uri=https%3A%2F%2Fwww.facebookswagstore.com%2FFBLoginHandlerOAuth.ashxtells Facebook where to send the visitor back to after they approve. The%3A,%2Fand similar sequences are just how special characters like:and/are written inside a URL so they are not confused with the URL's own structure. Decoded, it points atFBLoginHandlerOAuth.ashxonwww.facebookswagstore.com.response_type=codeasks Facebook to send back a short-lived code rather than the user's data directly.scope=public_profile%2Cemailasks for permission to see the visitor's basic public profile and their email address. The%2Cis a comma.
Why this matters: the secret is visible in the address bar, in browser history, in any proxy or server log along the way, and to anyone who can observe the request. The researcher did not need to break into anything. The secret was handed over.
Because the application belongs to Brandvia, the researcher reasoned that the leaked secret could be combined with the application ID to act as the application itself, and in particular to read insights about the Facebook employees visiting the site.
Exploitation
Step 1: Build the app access token
The Graph API accepts an app access token formed by concatenating the application ID and the application secret with a pipe character:
APP_ID|APP_SECRET
Both halves came from the leaked login URL, so no further access was needed to construct it. Think of it as: the name badge was already on the counter, and the password was printed on the same piece of paper, so you just staple them together.
Step 2: Read the application's roles
With the app token, the researcher queried the application's roles:
Line by line:
https://graph.facebook.comis the Graph API's front door./app/rolesis the menu item: "tell me who has roles on this application". This returns the owner of the application.?access_token=is where you hand over your cloakroom ticket.APP_ID|APP_SECRETis the ticket itself, the concatenated app token from Step 1.
The report shows the URL with a numeric application ID in the access_token position, followed by the literal APP_ID|APP_SECRET placeholder, so the real token is the concatenation described above.
Why this step: reading the roles is how the report says the owner of the application can be obtained.
Step 3: Read application insights
Finally, the researcher queried the application's insights for the api_calls metric:
Line by line:
/app/app_insightsis the menu item for the application's statistics dashboard.metric_key=api_callsasks for one specific number: how many API calls were made. The report does not say what other metrics exist or what the response contained.access_token=APP_ID|APP_SECRETis the same app token again.
The report does not include the response bodies for either Graph API call.
Why this step: this is the practical consequence the researcher described. Insights are the application's statistics.
Root cause
The mistake is in how the storefront's login handler built the OAuth dialog URL. It placed the application secret into the query string of a URL sent to the browser, rather than keeping it server-side and using it only in back-channel calls. Any party who could see that URL, including the user themselves, obtained the secret.
The observable defect is the client_secret parameter in the browser-facing URL.
A comparison: it is like a shop printing its safe combination on the outside of the front door so the staff can read it quickly. Convenient for staff, but everyone walking past can read it too.
Impact
In the researcher's words, this could have let an attacker gain access to the application client secret. With the secret, an attacker can form the app access token and make application-level Graph API calls, which the report demonstrates against the roles and insights endpoints. The report frames the practical consequence as being able to see insights for Facebook employees visiting the site. The report does not enumerate any other capabilities of the leaked secret.
Fix
The timeline records the remediation:
| Date | Event |
|---|---|
| Jul 12, 2018 | Report sent |
| Jul 13, 2018 | Further investigation by Facebook |
| Jul 13, 2018 | App secret removed |
| Aug 1, 2018 | Bounty awarded by Facebook |
So the secret was removed from the login flow the day after the report.
Variants to test
If you want to look for the same kind of mistake on other sites, here are the checks the technical version lists. Each one is a way of asking: is a private value sitting somewhere the browser can see it?
- Inspect the OAuth dialog URL your target builds for
client_secret,client_tokenor similar parameters. A positive result is any secret value appearing in a URL the browser requests. In plain words: click the login button and read the address bar carefully. - Check redirects and intermediate hops in the login flow, not just the first URL. A positive result is a secret appearing in a
Locationheader or in a form field posted to the browser. In plain words: the login may bounce you through several pages; look at each one, not just the first. - Look at client-side JavaScript that constructs the login URL. A positive result is the secret embedded in a script served to the browser. In plain words: the page's own code may contain the password; anyone can read that code.
- If a secret is found, try the
APP_ID|APP_SECRETapp token against application-level Graph API endpoints such as roles and insights. A positive result is a successful response rather than an OAuth error. In plain words: prove the password works by using it.
Glossary
- API: a fixed menu of requests one program can make to another, with defined inputs and outputs.
- Application ID: the public identifier for a Facebook application; safe to show to anyone.
- Application secret: the private password for a Facebook application; must stay on the server.
- App access token: a credential representing an application, built as
APP_ID|APP_SECRET. - Client: in this context, the visitor's browser, as opposed to the server.
- Client ID: the public half of an OAuth application's credentials (the same idea as the application ID).
- Client secret: the private half of an OAuth application's credentials (the same idea as the application secret).
- Graph API: Facebook's API at
https://graph.facebook.com/, used to read and act on Facebook data. - Insights: an application's statistics dashboard, for example counts of API calls.
- OAuth 2.0: a standard for signing into one site using another site's account without sharing your password.
- OAuth dialog: the Facebook page that asks you to approve sharing information with a third-party site.
- Query string: the part of a URL after the
?, made ofname=valuepairs joined by&. - Redirect URI: the address a login flow sends you back to after you approve.
- Roles: the list of people and accounts with permissions on an application, including its owner.
- Scope: the list of permissions a login flow is asking for, such as
public_profileandemail. - Token: a piece of text that proves identity or permission, like a cloakroom ticket.
- URL encoding: writing special characters in a URL as
%followed by codes, for example%3Afor:and%2Ffor/.