Disclose-Users-With-Roles-On-Facebook-Pages
The typeahead search for page roles did not restrict which page's roles were checked, allowing a user to infer whether any given user had a role on any page by observing presence or absence in results. An attacker could determine role membership for arbitrary users on arbitrary pages.
Published on philippeharewood.com
There is a typeahead feature to find users on Facebook within a page role section. This feature gives the option to search users who do not have a role on the page.
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 Pages have a role section where page admins manage who holds which role on the page. Inside that section there is a typeahead feature used to find users on Facebook, so an admin can add them to a role. The typeahead supports a search mode that returns users who do not have a role on the page, which is exactly what you want when you are about to grant someone a role: you search for a name, and the people who already hold a role are filtered out of the suggestions.
The problem Philippe Harewood found is that the feature did not limit which page the session user could check. The request carries a page_id, and the backend did not restrict that parameter to the page the session user actually administers. The result is an oracle: whether a given user appears in the response tells you whether that user holds a role on the page named in page_id, for any page.
Setup
The report describes the following preconditions:
- A page, referenced as
https://www.facebook.com/22222. - A user who holds a role on that page, referenced as
https://www.facebook.com/111111. - A second page, referenced as
https://www.facebook.com/3333333, on which that same user does not hold a role. - A session able to reach the typeahead endpoint, sending requests as another user.
The user is referred to in the searches by the display name Radric Davis. The requests are plain curl calls against the typeahead endpoint; no special tooling is involved.
Finding it
The typeahead in the page role section offers a search mode for users who do not have a role on the page. That mode is meant to help an admin pick someone to add. The request takes the page as a parameter, and the feature did not tie that parameter to the page the session user owns or administers. If the exclusion is computed against whatever page is supplied, then the presence or absence of a user in the results leaks role membership for that page.
That is the whole bug: the feature answers a question about a page it should not be answering questions about, and the answer is observable through an empty or non-empty payload.
Exploitation
Step 1: search a page where the user has no role
The request is sent with the search mode that excludes users holding a role on the page, and with page_id set to the page where the target user has no role. The fields are:
q=Radric Davis
search_mode=ANYONE_EXCEPT_PAGE_ROLE
page_id=3333333
As a request:
curl 'https://www.facebook.com/presma/user_search_typeahead/'
'q=Radric Davis&search_mode=ANYONE_EXCEPT_PAGE_ROLE&page_id=3333333'
q is the name being searched, search_mode=ANYONE_EXCEPT_PAGE_ROLE selects the "anyone except page role" filter, and page_id names the page whose role holders should be excluded. Because the user has no role on page 3333333, the filter does not remove them, and the response contains them:
for (;;);{"__ar":1,"__sf":"h0","payload":[{"id":"111111","name":"Radric Davis","profilePicUrl":"https","description":""}],"bootloadable":{},"ixData":{},"lid":"1"}
The payload array holds one object with the user's id and name. The for (;;); prefix is the usual anti-JSON-hijacking guard in front of the JSON body.
Step 2: search a page where the user has a role
The same request is repeated, changing only page_id to the page where the user does hold a role:
curl 'https://www.facebook.com/presma/user_search_typeahead/'
'q=Radric Davis&search_mode=ANYONE_EXCEPT_PAGE_ROLE&page_id=22222'
Now the filter removes the user, and the response comes back with an empty payload:
for (;;);{"__ar":1,"__sf":"h0","payload":[],"bootloadable":{},"ixData":{},"lid":"1"}
An empty payload means the user was excluded, which means the user holds a role on page 22222. A populated payload means the user does not. The two responses differ only in that array, and that difference is the disclosure.
Step 3: confirm the oracle follows role changes
The researcher also describes the case where an admin removes the user from the page and the request is sent again. The response then returns the user once more:
for (;;);{"__ar":1,"__sf":"h0","payload":[{"id":"111111","name":"Radric Davis","profilePicUrl":"https","description":""}],"bootloadable":{},"ixData":{},"lid":"1"}
Once the role is gone, the user is no longer excluded.
Root cause
The typeahead feature did not limit the search to the current page or to the pages of the current owner. The feature did not limit the search to the current page or the pages of the current owner. The exclusion logic itself was correct; the authorisation around which page it could be applied to was missing.
In the researcher's words, the feature "was not limiting to restrict for the current page or the pages of the current owner". The only thing wrong is that a legitimate parameter was trusted to name a page the caller has no relationship with, and the response shape (empty versus populated) is enough to leak the answer.
Impact
An attacker could determine whether a given user has a role on a given page. The researcher's summary is that this "could have resulted in determining whether a given user has a role on the page". The disclosure is limited to role membership: the response shows the user's id and name when they are not excluded, and nothing when they are. It does not, per the report, expose the role itself or any other page data.
Fix
Facebook applied a temporary fix to mitigate the issue on the same day the report was triaged, and a full fix followed a few days later. The report does not describe the code change. A fix consistent with the root cause would be to bind the page_id to the session user: only allow the exclusion search against the current page or pages the user owns or administers.
Timeline
| Time | Event |
|---|---|
| Sep 18, 2017 at 3:43 am | Report sent |
| Sep 18, 2017 at 4:49 am | Triaged by Facebook |
| Sep 18, 2017 at 7:49 am | Temporary fix to mitigate the issue |
| Sep 22, 2017 | Fixed by Facebook |
| Sep 26, 2017 | Bounty awarded by Facebook |
- Other search modes on the same endpoint. Try the typeahead with modes other than
ANYONE_EXCEPT_PAGE_ROLEand an arbitrarypage_id. A positive result is a response whose contents change with the role state of a page you do not administer. - Other role-scoped typeaheads. Look for similar user pickers elsewhere in the product (group admins, business managers, ad accounts) that take an object id and an exclusion filter. A positive result is the same empty-versus-populated difference when you vary the id to an object you do not control.
- Enumeration at scale. If the oracle holds, script the request across candidate user ids and page ids and compare payloads. A positive result is a stable mapping between ids and role membership that matches what an admin of the page sees.
- State changes. Remove or add a role on a page you do control and re-run the request against that page from another account. A positive result is the payload flipping as the role changes, as in step 3 above.
What happened, in plain words
Facebook Pages are public profiles for businesses, bands, public figures and so on. Each page can have several people working on it, and each of those people holds a role on the page, for example admin or editor. A page admin can open a section of the page settings where roles are managed, and inside that section there is a search box that suggests people as you type. This kind of search-as-you-type box is called a typeahead.
The typeahead has a special search mode: it can suggest only the people who do not already have a role on the page. That makes sense when you are about to give someone a role, because the people who already have one should not appear in the list.
Philippe Harewood found that the feature did not limit which page the request could ask about, so it was not tied to the page the person sending the request actually manages. The request contains a page identifier, page_id, and the server trusted it. So you could ask the search box a question about any page on Facebook, and the answer would tell you something you were not supposed to know: whether a particular user holds a role on that page.
The trick is indirect. You do not get a list of roles back. You search for a person's name, and you look at whether the person appears in the results or not. If they appear, they do not have a role on that page. If the list comes back empty, they do have a role. An answer that reveals a hidden fact in this indirect way is often called an oracle: you ask a question, and the shape of the reply tells you the secret.
This is a case of a missing authorisation check. The feature worked correctly, but nobody checked that the person making the request was allowed to ask about that page.
Background: pages, roles and the typeahead
A Facebook Page has a role section where page admins manage who holds which role on the page. Inside that section there is a typeahead feature used to find users on Facebook, so an admin can add them to a role. The typeahead supports a search mode that returns users who do not have a role on the page, which is exactly what you want when you are about to grant someone a role: you search for a name, and the people who already hold a role are filtered out of the suggestions.
The problem is that the feature did not limit which page the session user could check. The request carries a page_id, and the backend did not restrict that parameter to the page the session user actually administers. The result is an oracle: whether a given user appears in the response tells you whether that user holds a role on the page named in page_id, for any page.
A useful comparison is a members-only club. The person at the door has a list of members. If you ask "is this person a member?" the doorman is supposed to check only the club you belong to. Here, the doorman would answer for any club in the world, and the answer is visible simply by whether the name is read out or not.
The setup
The report describes the following preconditions:
- A page, referenced as
https://www.facebook.com/22222. - A user who holds a role on that page, referenced as
https://www.facebook.com/111111. - A second page, referenced as
https://www.facebook.com/3333333, on which that same user does not hold a role. - A session able to reach the typeahead endpoint, sending requests as another user.
The user is referred to in the searches by the display name Radric Davis. The requests are plain curl calls against the typeahead endpoint; no special tooling is involved.
A few words on the pieces here. A session is the state of being logged in: your browser holds a small piece of data, often a cookie, that the server uses to recognise you on each request. curl is a command-line tool for sending HTTP requests, the same kind of request your browser sends when you load a page or type in a search box. An endpoint is a specific address on a server that accepts requests, in this case the address that powers the typeahead search.
Finding it
The typeahead in the page role section offers a search mode for users who do not have a role on the page. That mode is meant to help an admin pick someone to add. The request takes the page as a parameter, and the feature did not tie that parameter to the page the session user owns or administers. If the exclusion is computed against whatever page is supplied, then the presence or absence of a user in the results leaks role membership for that page.
That is the whole bug: the feature answers a question about a page it should not be answering questions about, and the answer is observable through an empty or non-empty payload.
A parameter is a named value sent along with a request, like a field in a form. The server reads it and acts on it. If the server trusts a parameter that names an object, and never checks that the caller is allowed to touch that object, you have what security people call an IDOR (insecure direct object reference): the client hands over an identifier and the server uses it without checking permission.
Exploitation
Step 1: search a page where the user has no role
The request is sent with the search mode that excludes users holding a role on the page, and with page_id set to the page where the target user has no role. The fields are:
q=Radric Davis
search_mode=ANYONE_EXCEPT_PAGE_ROLE
page_id=3333333
Line by line:
q=Radric Davisis the text being searched for, the name typed into the search box.search_mode=ANYONE_EXCEPT_PAGE_ROLEselects the special mode: return anyone except the people who hold a role on the page.page_id=3333333names the page whose role holders should be excluded. This is the page where the target user has no role.
As a request:
curl 'https://www.facebook.com/presma/user_search_typeahead/'
'q=Radric Davis&search_mode=ANYONE_EXCEPT_PAGE_ROLE&page_id=3333333'
Line by line:
curlis the tool sending the request.'https://www.facebook.com/presma/user_search_typeahead/'is the endpoint, the address of the typeahead feature on Facebook's server.- The second quoted string is the query string, the part of a URL after the
?that carries parameters. Here it carries the three fields above, joined with&.
q is the name being searched, search_mode=ANYONE_EXCEPT_PAGE_ROLE selects the "anyone except page role" filter, and page_id names the page whose role holders should be excluded. Because the user has no role on page 3333333, the filter does not remove them, and the response contains them:
for (;;);{"__ar":1,"__sf":"h0","payload":[{"id":"111111","name":"Radric Davis","profilePicUrl":"https","description":""}],"bootloadable":{},"ixData":{},"lid":"1"}
Line by line:
for (;;);is a small piece of JavaScript placed in front of the data. It is a loop that never ends. Its purpose is to stop another website from reading the response as ordinary data, a defence known as anti-JSON-hijacking. A browser that tried to run the response as a script would get stuck in the loop.- The rest is JSON, a text format for structured data, made of names and values in curly braces.
"payload"is the interesting part: an array (a list, written with square brackets) of results.- Inside the array is one object with the user's
id(111111) andname(Radric Davis). - The other fields (
__ar,__sf,bootloadable,ixData,lid) are bookkeeping values the page uses; they are not the point here.
The payload array holds one object with the user's id and name. The for (;;); prefix is the usual anti-JSON-hijacking guard in front of the JSON body.
Step 2: search a page where the user has a role
The same request is repeated, changing only page_id to the page where the user does hold a role:
curl 'https://www.facebook.com/presma/user_search_typeahead/'
'q=Radric Davis&search_mode=ANYONE_EXCEPT_PAGE_ROLE&page_id=22222'
Line by line:
- The endpoint and the search text are unchanged.
- The search mode is unchanged.
- Only
page_iddiffers: it is now22222, the page where the user does hold a role.
Now the filter removes the user, and the response comes back with an empty payload:
for (;;);{"__ar":1,"__sf":"h0","payload":[],"bootloadable":{},"ixData":{},"lid":"1"}
Line by line:
- The prefix and the bookkeeping fields are the same as before.
"payload":[]is an empty list. No results were returned.
An empty payload means the user was excluded, which means the user holds a role on page 22222. A populated payload means the user does not. The two responses differ only in that array, and that difference is the disclosure.
Changing one input and watching the output is the basic method for turning a feature into an oracle.
Step 3: confirm the oracle follows role changes
The researcher also describes the case where an admin removes the user from the page and the request is sent again. The response then returns the user once more:
for (;;);{"__ar":1,"__sf":"h0","payload":[{"id":"111111","name":"Radric Davis","profilePicUrl":"https","description":""}],"bootloadable":{},"ixData":{},"lid":"1"}
Line by line:
- The response is the same shape as in step 1: the
payloadlist contains the user again. - That means the user is no longer excluded, because the role has been removed.
Once the role is gone, the user is no longer excluded. A cache is a stored copy of an earlier answer kept to save time; if the answer had come from a cache, it would not have changed when the role changed.
Root cause
The typeahead feature did not limit the search to the current page or to the pages of the current owner. The feature did not limit the search to the current page or the pages of the current owner. The exclusion logic itself was correct; the authorisation around which page it could be applied to was missing.
In the researcher's words, the feature "was not limiting to restrict for the current page or the pages of the current owner". The only thing wrong is that a legitimate parameter was trusted to name a page the caller has no relationship with, and the response shape (empty versus populated) is enough to leak the answer.
Some of those terms deserve a plain explanation. Authentication is proving who you are, for example by logging in. Authorisation is what you are allowed to do once you are known. This bug is an authorisation failure: the server knew who was asking, but never asked whether that person was allowed to ask about that page. Injection means slipping extra commands into an input so the server runs them; nothing like that happens here. Privilege escalation means gaining more power than you should have; the attacker here gains no power, only information.
Impact
An attacker could determine whether a given user has a role on a given page. The researcher's summary is that this "could have resulted in determining whether a given user has a role on the page". The disclosure is limited to role membership: the response shows the user's id and name when they are not excluded, and nothing when they are. It does not, per the report, expose the role itself or any other page data.
That is information the page owner may not want public, and it can be useful to someone planning a social engineering attack, for example pretending to be a colleague of a page admin.
Fix
Facebook applied a temporary fix to mitigate the issue on the same day the report was triaged, and a full fix followed a few days later. The report does not describe the code change. A fix consistent with the root cause would be to bind the page_id to the session user: only allow the exclusion search against the current page or pages the user owns or administers.
In everyday terms: before answering the question, check that the person asking is a member of the club they are asking about.
Timeline
| Time | Event |
|---|---|
| Sep 18, 2017 at 3:43 am | Report sent |
| Sep 18, 2017 at 4:49 am | Triaged by Facebook |
| Sep 18, 2017 at 7:49 am | Temporary fix to mitigate the issue |
| Sep 22, 2017 | Fixed by Facebook |
| Sep 26, 2017 | Bounty awarded by Facebook |
Triaged means the security team looked at the report and confirmed it was a real issue worth working on. A bounty is a payment some companies make to people who report security problems responsibly.
- Other search modes on the same endpoint. Try the typeahead with modes other than
ANYONE_EXCEPT_PAGE_ROLEand an arbitrarypage_id. A positive result is a response whose contents change with the role state of a page you do not administer. - Other role-scoped typeaheads. Look for similar user pickers elsewhere in the product (group admins, business managers, ad accounts) that take an object id and an exclusion filter. A positive result is the same empty-versus-populated difference when you vary the id to an object you do not control.
- Enumeration at scale. If the oracle holds, script the request across candidate user ids and page ids and compare payloads. A positive result is a stable mapping between ids and role membership that matches what an admin of the page sees. Enumeration means trying many values one after another, usually with a script, to build up a picture.
- State changes. Remove or add a role on a page you do control and re-run the request against that page from another account. A positive result is the payload flipping as the role changes, as in step 3 above.
Glossary
- API: a defined way for one piece of software to ask another for data or actions, usually over HTTP.
- Authentication: proving who you are, for example by logging in.
- Authorisation: what a known user is allowed to do or see.
- Bounty: a payment a company makes for a responsibly reported security problem.
- Cache: a stored copy of an earlier answer, kept to save time.
- Cookie: a small piece of data a browser stores for a site and sends back with each request, often used to keep you logged in.
- curl: a command-line tool for sending HTTP requests.
- Endpoint: a specific address on a server that accepts requests.
- Enumeration: trying many values one after another, often with a script, to gather information.
- IDOR: insecure direct object reference, where a server uses an identifier supplied by the client without checking the client is allowed to access that object.
- Injection: slipping extra commands or data into an input so the server executes or misinterprets them.
- JSON: a text format for structured data, made of names and values.
- Oracle: a way of asking a question whose answer, even indirectly, reveals a hidden fact.
- Parameter: a named value sent with a request, like a field in a form.
- Payload: here, the part of a response that carries the actual results.
- Privilege escalation: gaining more power or access than you are entitled to.
- Query string: the part of a URL after the
?that carries parameters. - Role: a named set of permissions a person holds on a page, such as admin or editor.
- Session: the state of being logged in, usually tracked with a cookie.
- Triaged: reviewed and confirmed as a real issue by a security team.
- Typeahead: a search box that suggests results as you type.