Order-Facebook-Friends-By-Facebook-Recruiting-Technical-Coefficient
A GraphQL endpoint allowed ordering a user's friends by a hidden 'technical_coefficient' field, which was intended for internal recruiting. An attacker could use this to infer which friends Facebook considered technically skilled, though the impact was minimal.
Published on philippeharewood.com
There is a way to order the list of Facebook friends for a user based on what Facebook views as technical background. Originally when I saw this, I thought it was intended to be used for jobs, e.g. https://www.facebook.com/pg/SureCosmetics/jobs/ However given that the measure used, was solely based on some technical…
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's friend list is normally presented in an order the platform chooses. This write-up looks at a GraphQL edge, referral_recommendations, that returns a list of the viewer's friends, and at an orderby argument that can be applied to it. The researcher's first assumption was that this list was intended for job listings, such as the jobs page on a Page:
https://www.facebook.com/pg/SureCosmetics/jobs/
On reflection, the measure used to order the list was based solely on some technical factor, which made it seem relevant only within a Facebook career context. The researcher reasoned that a regular user does not need to know about this call, since a regular user is probably not a Facebook recruiter.
Setup
The only precondition shown is an access token that can access GraphQL. The report does not describe any particular account type, role or tooling beyond that. The token is obtained through the OAuth dialog in step 1 below, and the same token is then reused for both GraphQL calls.
Finding it
The researcher noticed that the referral_recommendations edge returns friends in a default order, and that the edge accepts an orderby argument. Setting that argument to the technical_coefficient constant changes the order of the returned friends. Because the ordering factor was technical, it seemed relevant only within a Facebook career context, probably for staff and recruiters.
Exploitation
Step 1: obtain an access token that can access GraphQL
https://www.facebook.com/v2.5/dialog/oauth?response_type=token&display=popup&client_id=124024574287414&redirect_uri=fb124024574287414%3A%2F%2Fauthorize
This is the OAuth dialog with response_type=token, so the token is returned in the fragment of the redirect to the app's redirect_uri. The client_id identifies the application, and the redirect_uri is the app's own scheme, fb124024574287414://authorize. The resulting token is the one used in the next two calls.
Step 2: call the edge without ordering
https://graph.facebook.com/graphql?q=viewer%28%29%7Breferral_recommendations%7D&access_token=[redacted]
The q parameter is a URL-encoded GraphQL query, viewer(){referral_recommendations}, which asks for the viewer's referral recommendations. The partial response was:
{
"viewer": {
"referral_recommendations": {
"nodes": [
{
"id": "100000000000000000000",
"url": "https://www.facebook.com/100000000000000000000",
"name": "Friend One"
},
{
"id": "200000000000000000000",
"url": "https://www.facebook.com/200000000000000000000",
"name": "Friend Two"
},
{
"id": "300000000000000000000",
"url": "https://www.facebook.com/300000000000000000000",
"name": "Friend Three"
},
{
"id": "400000000000000000000",
"url": "https://www.facebook.com/400000000000000000000",
"name": "Friend Four"
},
{
"id": "500000000000000000000",
"url": "https://www.facebook.com/500000000000000000000",
"name": "Friend Five"
},
Each node carries the friend's id, a profile url and a name. This is the default ordering of referral recommendations for the user.
Step 3: call the edge with orderby(technical_coefficient)
https://graph.facebook.com/graphql?q=viewer%28%29{referral_recommendations.orderby(technical_coefficient)}&access_token=[redacted]
Here the query is viewer(){referral_recommendations.orderby(technical_coefficient)}, with orderby set to the technical_coefficient constant. The partial response was:
{
"viewer": {
"referral_recommendations": {
"nodes": [
{
"id": "900000000000000000000",
"url": "https://www.facebook.com/900000000000000000000",
"name": "Friend Nine"
},
{
"id": "200000000000000000000",
"url": "https://www.facebook.com/200000000000000000000",
"name": "Friend Two"
},
{
"id": "800000000000000000000",
"url": "https://www.facebook.com/800000000000000000000",
"name": "Friend Eight"
},
{
"id": "100000000000000000000",
"url": "https://www.facebook.com/100000000000000000000",
"name": "Friend One"
},
{
"id": "600000000000000000000",
"url": "https://www.facebook.com/600000000000000000000",
"name": "Friend Six"
},
The partial response comes back in a different order. Looking through the about sections of the profiles, the researcher made the assumption that the technical_coefficient is based on words and phrases such as "engineering, computer, science, google". The report is explicit that this is guesswork.
Root cause
The referral_recommendations edge exposes an orderby argument that accepts the technical_coefficient constant, and the GraphQL layer honoured it for the researcher's session. The feature was probably built for Facebook staff and recruiters, yet an ordinary session could still use the ordering argument. The report does not describe the server-side implementation, so the exact location of the missing check is not stated.
Impact
The researcher assesses the privacy impact as minimal. The list of friends is already known to the user, the ordering can only be done for the session user's own friends, and the technical_coefficient value itself is not known. The real issue is that the feature overall is not meant for users, and is probably intended for Facebook staff and recruiters.
Fix
The natural fix, given the analysis above, would be to restrict the orderby(technical_coefficient) argument to the staff and recruiter contexts the feature was built for, rather than exposing it to any session that can query the edge.
Variants to test
- Try other
orderbyconstants on the same edge and on other recommendation edges. A positive result is a response whose node order differs from the default and correlates with a property of the profiles that an ordinary user should not be able to rank by. - Apply
orderbyto edges that return other people's data, not just the viewer's friends. A positive result is an ordered list that includes users outside the viewer's friend list. - Compare the default order with the ordered result across several accounts. A positive result is a consistent reordering that tracks the same profile attributes each time, which would confirm what the coefficient is derived from rather than leaving it as guesswork.
- Check whether the ordering argument is accepted without the audience restriction on related recruiter or jobs surfaces. A positive result is the same ordering behaviour being reachable from a context where it was not intended.
Timeline
- Jan 4, 2017: report sent
- Jan 13, 2017: escalation by Facebook
- Jan 24, 2017: bounty awarded by Facebook
What happened, in plain words
Facebook keeps a list of your friends, and normally Facebook decides what order to show them in. This write-up is about a hidden way to ask Facebook for that list in a different order: an order based on how "technical" Facebook thinks each friend is. The researcher found that a request to a GraphQL endpoint accepts a setting that sorts your friends by something called a technical_coefficient, whose basis is guesswork.
The researcher first assumed this list was meant for job listings, for example the jobs page of a business Page:
https://www.facebook.com/pg/SureCosmetics/jobs/
On reflection, the thing used to sort the list was based only on some technical factor, which made it seem relevant only inside a Facebook careers context. The researcher reasoned that a regular user does not need to know about this request, since a regular user is probably not a Facebook recruiter.
To follow the rest of this article you only need a browser and a basic idea of what a web request is. Everything else is explained as it comes up.
The pieces you need to know first
API. An API is a way for one piece of software to talk to another. Think of a restaurant: you do not walk into the kitchen, you tell the waiter what you want and the waiter brings it back. An API is the waiter. Facebook's website itself uses Facebook's APIs to fetch your friend list, your feed and so on.
GraphQL. GraphQL is a particular style of API where you send a query describing exactly which pieces of data you want, and the server sends back just those pieces. It is like filling in a form that says "I want the name and the phone number, nothing else" instead of being handed a whole folder.
Edge. In GraphQL, an edge is one named thing you can ask for, such as a list of friends. The name of the edge in this report is referral_recommendations.
Argument. An argument is an extra instruction attached to an edge, like saying "and please sort it this way". The argument here is called orderby.
Access token. A token is a long string of characters that proves who you are, a bit like a wristband at an event: show it at the door and you are let in without explaining who you are again. Facebook hands these out to apps so the app can make requests on your behalf. In this report the token is obtained in step 1 and reused in the next two steps.
OAuth dialog. OAuth is the standard way an app asks you to log in to another service without giving the app your password. The dialog is the pop-up page where you approve that request. When it finishes, it sends the token back to the app.
URL encoding. Some characters are not allowed to appear raw in a web address, so they are written as codes such as %28 for ( and %29 for ). That is why the queries below look full of percent signs.
Vulnerability class. This is not a classic break-in. Nothing is stolen and no password is guessed. It is closer to a feature probably built for staff being reachable by ordinary users. The researcher calls the privacy impact minimal, and the real issue is that the feature is not meant for users at all.
Setup
The only precondition shown is an access token that can access GraphQL. The report does not describe any particular account type, role or tooling beyond that. The token is obtained through the OAuth dialog in step 1 below, and the same token is then reused for both GraphQL calls.
Finding it
The researcher noticed that the referral_recommendations edge returns friends in a default order, and that the edge accepts an orderby argument. Setting that argument to the technical_coefficient constant changes the order of the returned friends. Because the ordering factor was technical, it seemed relevant only within a Facebook career context, probably for staff and recruiters.
Exploitation
Step 1: obtain an access token that can access GraphQL
https://www.facebook.com/v2.5/dialog/oauth?response_type=token&display=popup&client_id=124024574287414&redirect_uri=fb124024574287414%3A%2F%2Fauthorize
Line by line, in plain words:
https://www.facebook.com/v2.5/dialog/oauthis the address of Facebook's OAuth dialog, the pop-up page that asks you to approve an app.response_type=tokentells the dialog that what you want back is a token, rather than, say, a short-lived code that would need a second exchange.display=popupasks for the dialog to be shown as a pop-up window.client_id=124024574287414identifies which application is asking. Every Facebook app has a number like this.redirect_uri=fb124024574287414%3A%2F%2Fauthorizeis where the answer is sent afterwards. The%3A%2F%2Fis URL encoding for://, so the real value isfb124024574287414://authorize, a scheme belonging to that same app.
Why this step: every later request needs to prove who is asking, and this is the standard way to get that proof. Because response_type=token, the token comes back in the fragment of the redirect to the app's redirect_uri. The resulting token is the one used in the next two calls.
Step 2: call the edge without ordering
https://graph.facebook.com/graphql?q=viewer%28%29%7Breferral_recommendations%7D&access_token=[redacted]
Line by line:
https://graph.facebook.com/graphqlis the GraphQL endpoint, the address that accepts GraphQL queries.q=is the parameter that carries the query itself.viewer%28%29%7Breferral_recommendations%7Dis the query, URL-encoded. Decoded,%28is(,%29is)and%7Band%7Dare{and}, so the query isviewer(){referral_recommendations}. In words: "for the person making the request (the viewer), give me the referral recommendations".access_token=[redacted]is where the token from step 1 goes.
Why this step: it establishes the baseline. Before changing anything, the researcher wanted to see the normal order of the list, so that any change in step 3 could be compared against it. The partial response was:
{
"viewer": {
"referral_recommendations": {
"nodes": [
{
"id": "100000000000000000000",
"url": "https://www.facebook.com/100000000000000000000",
"name": "Friend One"
},
{
"id": "200000000000000000000",
"url": "https://www.facebook.com/200000000000000000000",
"name": "Friend Two"
},
{
"id": "300000000000000000000",
"url": "https://www.facebook.com/300000000000000000000",
"name": "Friend Three"
},
{
"id": "400000000000000000000",
"url": "https://www.facebook.com/400000000000000000000",
"name": "Friend Four"
},
{
"id": "500000000000000000000",
"url": "https://www.facebook.com/500000000000000000000",
"name": "Friend Five"
},
Reading the response: viewer is the person who made the request. Inside it, referral_recommendations holds a list called nodes. Each node is one friend, carrying the friend's id (a long number), a profile url and a name. This is the default ordering of referral recommendations for the user.
Step 3: call the edge with orderby(technical_coefficient)
https://graph.facebook.com/graphql?q=viewer%28%29{referral_recommendations.orderby(technical_coefficient)}&access_token=[redacted]
Line by line:
- The address and the
q=parameter are the same as before. - The query is now
viewer(){referral_recommendations.orderby(technical_coefficient)}. The only difference is the.orderby(technical_coefficient)attached to the edge. In words: "give me the referral recommendations, sorted by the technical coefficient". technical_coefficientis a constant, a fixed name the server recognises, not a number the user supplies.- The same token from step 1 is reused.
Why this step: this is the actual test. If the server accepts the extra instruction, the list should come back in a different order, and that difference is the finding. The partial response was:
{
"viewer": {
"referral_recommendations": {
"nodes": [
{
"id": "900000000000000000000",
"url": "https://www.facebook.com/900000000000000000000",
"name": "Friend Nine"
},
{
"id": "200000000000000000000",
"url": "https://www.facebook.com/200000000000000000000",
"name": "Friend Two"
},
{
"id": "800000000000000000000",
"url": "https://www.facebook.com/800000000000000000000",
"name": "Friend Eight"
},
{
"id": "100000000000000000000",
"url": "https://www.facebook.com/100000000000000000000",
"name": "Friend One"
},
{
"id": "600000000000000000000",
"url": "https://www.facebook.com/600000000000000000000",
"name": "Friend Six"
},
The partial response comes back in a different order. Looking through the about sections of the profiles, the researcher made the assumption that the technical_coefficient is based on words and phrases such as "engineering, computer, science, google". The report is explicit that this is guesswork.
Root cause
The referral_recommendations edge exposes an orderby argument that accepts the technical_coefficient constant, and the GraphQL layer honoured it for the researcher's session. The feature was probably built for Facebook staff and recruiters, yet an ordinary session could still use the ordering argument. The report does not describe the server-side implementation, so the exact location of the missing check is not stated.
In everyday terms: the sorting option was probably meant for the recruiting team, yet an ordinary user could still use it.
Impact
The researcher assesses the privacy impact as minimal. The list of friends is already known to the user, the ordering can only be done for the session user's own friends, and the technical_coefficient value itself is not known. The real issue is that the feature overall is not meant for users, and is probably intended for Facebook staff and recruiters.
Fix
The natural fix, given the analysis above, would be to restrict the orderby(technical_coefficient) argument to the staff and recruiter contexts the feature was built for, rather than exposing it to any session that can query the edge.
Variants to test
- Try other
orderbyconstants on the same edge and on other recommendation edges. A positive result is a response whose node order differs from the default and correlates with a property of the profiles that an ordinary user should not be able to rank by. - Apply
orderbyto edges that return other people's data, not just the viewer's friends. A positive result is an ordered list that includes users outside the viewer's friend list. - Compare the default order with the ordered result across several accounts. A positive result is a consistent reordering that tracks the same profile attributes each time, which would confirm what the coefficient is derived from rather than leaving it as guesswork.
- Check whether the ordering argument is accepted without the audience restriction on related recruiter or jobs surfaces. A positive result is the same ordering behaviour being reachable from a context where it was not intended.
Timeline
- Jan 4, 2017: report sent
- Jan 13, 2017: escalation by Facebook
- Jan 24, 2017: bounty awarded by Facebook
Glossary
- API: a way for one piece of software to ask another for data or actions, like a waiter carrying your order to the kitchen.
- GraphQL: an API style where the request describes exactly which pieces of data to return.
- Edge: a named thing you can ask for in a GraphQL query, such as a list of friends.
- Argument: an extra instruction attached to an edge, such as how to sort the result.
- Constant: a fixed name the server recognises, here
technical_coefficient, rather than a value supplied by the user. - Access token: a string that proves who is making a request, like a wristband at an event.
- OAuth dialog: the pop-up page where you approve an app's request to act on your behalf.
response_type=token: the setting that asks the OAuth dialog to return a token directly.client_id: the number identifying which application is making the request.redirect_uri: the address the answer is sent to after the dialog finishes.- URL encoding: writing characters that are not allowed in a web address as codes such as
%28for(. - Endpoint: the address that accepts a particular kind of request, here
https://graph.facebook.com/graphql. - Query parameter: a named value in a web address after a
?, such asq=oraccess_token=. - Node: one item in a returned list, here one friend with an
id,urlandname. - Default ordering: the order the server uses when no sorting instruction is given.
orderby: the argument that tells the server how to sort a list.technical_coefficient: the constant used here to sort friends by an apparent technical background.- Authorisation check: the server-side test of whether the person making a request is allowed to do it.
- Vulnerability class: the general category a security issue belongs to; here, a staff-only feature reachable by ordinary users.
- Bounty: a payment a company makes to a researcher who reports a valid security issue.