See-If-Any-Facebook-User-Is-Marked-In-A-Crisis
The safety-check endpoint returned different responses for non-friends depending on whether they were marked safe in a crisis, letting an attacker infer that status. An attacker could learn whether any chosen user had been marked in a crisis area without being their friend.
Published on philippeharewood.com
Within https://www.facebook.com/safetycheck, has the feature to allow the current user to see “safe” stories from friends. If a user is requested, that is not a friend, it is possible to check whether this user was marked in a crisis area based on error responses.
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 is Facebook's Safety Check feature, reachable at https://www.facebook.com/safetycheck. Among other things, Safety Check lets the current user see "safe" stories from friends: posts from people who have marked themselves safe during a crisis. The endpoint involved is friend_safe_stories, which takes a crisis_id and a user_id.
The feature is meant to surface content from friends. The question this write-up answers is what happens when the requested user_id is not a friend of the caller, and whether the difference in responses leaks anything about that person.
Setup
No special accounts or tooling are described beyond an authenticated Facebook session and the ability to send requests with curl. The requests carry the parameters __user, __a and __dyn. The caller needs a valid session, since the endpoint is served to a logged-in user. The two preconditions that matter are:
- A
user_idfor a non-friend who is not in a crisis zone. - A
user_idfor a non-friend who is in a crisis zone.
Both requests use the same crisis_id, so the only variable is the target user.
Finding it
The friend_safe_stories call can be made for a user who is not a friend. The feature is designed for friends, yet the error responses differ for non-friend user_id values. Instead, the response differs depending on whether the target user was marked in a crisis. That difference is the bug: the error behaviour itself becomes an oracle.
Exploitation
Step 1: request a non-friend who is not in a crisis zone
Send the request with a crisis_id and a user_id of your choosing, where the user is not in a crisis zone:
curl 'https://www.facebook.com/safetycheck/friend_safe_stories/?crisis_id=1&user_id=100000000000000000&dpr=1' --data '__user=AAA&__a=1&__dyn=fb_dtsg='
The query string carries crisis_id=1, the chosen user_id, and dpr=1. The POST body carries __user, __a and __dyn. The response is:
HTTP/1.1 500 Internal Server Error: Sorry, something went wrong.
A server error, with no useful body.
Step 2: request a non-friend who is in a crisis zone
Send the same request, changing only the user_id to a non-friend who is in a crisis zone:
curl 'https://www.facebook.com/safetycheck/friend_safe_stories/?crisis_id=1&user_id=200000000000000000&dpr=1' --data '__user=AAA&__a=1&__dyn=fb_dtsg='
This time the response is HTTP/1.1 200 OK, with a JSON body:
for (;;);{"__ar":1,"__sf":"i0","error":1357031,"errorSummary":"This content is no longer available","errorDescription":"The content you requested cannot be displayed right now. It may be temporarily unavailable, the link you clicked on may have expired, or you may not have permission to view this page.","payload":null,"bootloadable":{},"ixData":{},"lid":"1"}
The body is prefixed with for (;;);, Facebook's anti-JSON-hijacking prefix, and contains error code 1357031 with the summary "This content is no longer available" and a description saying the content cannot be displayed, may be temporarily unavailable, the link may have expired, or the caller may not have permission to view the page. The payload is null.
Step 3: distinguish the two cases
Once it is established that the error response for a non-friend in a crisis zone is the one above, the two requests can be told apart. A 500 means the target is not in a crisis zone; a 200 with error 1357031 means the target is in a crisis zone. The stories themselves are never returned, but the error code is enough to classify the user.
Root cause
The researcher's reading is that the call is pulling in stories from non-friends, since the privacy of those stories is probably lower than public (or perhaps another internal privacy rule applies), and that this produces the 1357031 permission error. In other words, the endpoint does not reject a non-friend user_id before it evaluates the privacy of the underlying stories. The difference between those two paths is what leaks the fact that the person was marked in a crisis.
Impact
Although the stories themselves are not seen, the error message follows the privacy rules, so it can be used to infer that a person was marked in a crisis. That is information the caller would not otherwise have for a non-friend. The impact is limited to that inference: the report does not claim that story content, names of other users, or any other data is exposed.
Fix
Facebook fixed the issue on 18 January 2017, after escalating it on 11 January 2017. The report does not describe the code change.
Variants to test
- A positive result is a response that differs between a user in a crisis and a user not in one.
- A positive result is a response that still distinguishes users by their crisis membership.
- A positive result is a
200with an error code for one class of users and a500for another. - A positive result is a per-ID error that reveals which ones are in a crisis.
Timeline
- Jan 4, 2017: report sent
- Jan 11, 2017: escalation by Facebook
- Jan 18, 2017: fixed by Facebook
- Jan 24, 2017: bounty awarded by Facebook
What happened, in plain words
Facebook has a feature called Safety Check. During a crisis, people can mark themselves as safe, and their friends can then see "safe" stories. The page lives at https://www.facebook.com/safetycheck.
Behind that page there is a small web address, an endpoint, that the page calls to fetch those stories. It is called friend_safe_stories, and it is given two pieces of information: a crisis_id (which crisis you are asking about) and a user_id (whose stories you want).
The feature is meant for friends. But the researcher, Philippe Harewood, found that the error responses for a non-friend differ depending on whether that person was marked in a crisis. And the answer was different depending on whether that stranger had marked themselves safe in that crisis. One case gave a generic server error, the other gave a specific permission error. Neither answer contained the stories, but the difference between the two answers was enough to tell whether a stranger was in a crisis zone. That is the bug: the error itself becomes a way to learn a fact you should not be able to learn.
Background you need first
A few everyday ideas make the rest easy to follow.
- An endpoint is a specific address on a website that returns data rather than a full page. Think of a restaurant: the website is the dining room, the endpoint is the kitchen hatch where a specific dish is handed out.
friend_safe_storiesis one such hatch. - A query string is the part of a web address after the
?. It carries small labelled values, likecrisis_id=1. Think of it as the order slip: which dish, for whom. - A POST body is extra data sent along with the request, separate from the address. It is like the note you hand over with the order slip.
curlis a command-line tool that sends a web request and prints the reply. It is the same thing your browser does when you click a link, just without the pictures.- A session is how a website remembers that you are logged in. Your browser holds a cookie, a small piece of text the site gave you at login, and sends it with every request. The parameters
__user,__aand__dynin these requests are part of that logged-in machinery. - An HTTP status code is a three-digit number at the top of every reply.
200 OKmeans "here is your answer".500 Internal Server Errormeans "something broke on our side". - JSON is a common text format for data, made of labels and values in curly braces. Facebook wraps its JSON in a small prefix,
for (;;);, so that other websites cannot quietly read it. That prefix is a defence against a class of attack called JSON hijacking. - An oracle in security is any behaviour that answers a yes/no question you were not supposed to be able to ask. A login page that says "wrong password" versus "no such user" is an oracle: it tells you which usernames exist. Here, the error response is the oracle.
- An information leak (sometimes called an information disclosure) is when a system reveals a fact through a side channel, such as an error message or a difference in timing, rather than through the data it was meant to return.
The setup
The researcher needed only two things: a logged-in Facebook session, and the ability to send requests with curl. The requests carry Facebook's usual session parameters, so the caller must be logged in. Two target users were needed:
- A
user_idfor a non-friend who is not in a crisis zone. - A
user_idfor a non-friend who is in a crisis zone.
Both requests use the same crisis_id, so the only thing that changes between them is the target user. That is good experimental practice: change one thing at a time, so any difference in the answer must come from that one thing.
Finding it
The friend_safe_stories call could be made for a user who is not a friend. The feature is designed for friends, yet the error responses differed for non-friend user_id values. Instead, the reply differed depending on whether the target user had been marked in a crisis. That difference is the bug: the error behaviour itself becomes an oracle.
Exploitation
Step 1: ask about a non-friend who is not in a crisis zone
Send the request with a crisis_id and a user_id of your choosing, where the user is not in a crisis zone:
curl 'https://www.facebook.com/safetycheck/friend_safe_stories/?crisis_id=1&user_id=100000000000000000&dpr=1' --data '__user=AAA&__a=1&__dyn=fb_dtsg='
Line by line:
curlruns the tool.- The address in quotes is the endpoint,
friend_safe_stories, followed by a query string.crisis_id=1says which crisis to ask about.user_id=100000000000000000is the stranger we are asking about.dpr=1is a display-related parameter Facebook's pages send along. --data '__user=AAA&__a=1&__dyn=fb_dtsg='attaches a POST body with the session parameters. The values here are placeholders; in a real request they would be your own session values.
The reply is:
HTTP/1.1 500 Internal Server Error: Sorry, something went wrong.
A server error, with no useful body. The request broke somewhere on Facebook's side before it could produce a proper answer.
Step 2: ask about a non-friend who is in a crisis zone
Send the same request, changing only the user_id to a non-friend who is in a crisis zone:
curl 'https://www.facebook.com/safetycheck/friend_safe_stories/?crisis_id=1&user_id=200000000000000000&dpr=1' --data '__user=AAA&__a=1&__dyn=fb_dtsg='
This is identical to the first request except for the user_id. That is deliberate: the only variable is the target user, so any difference in the reply must be caused by that user's situation.
This time the reply is HTTP/1.1 200 OK, with a JSON body:
for (;;);{"__ar":1,"__sf":"i0","error":1357031,"errorSummary":"This content is no longer available","errorDescription":"The content you requested cannot be displayed right now. It may be temporarily unavailable, the link you clicked on may have expired, or you may not have permission to view this page.","payload":null,"bootloadable":{},"ixData":{},"lid":"1"}
Line by line:
for (;;);is Facebook's anti-JSON-hijacking prefix. It is a tiny loop that does nothing, placed in front so that a malicious page cannot easily read the data as JSON."error":1357031is a specific error code. This is the important part."errorSummary":"This content is no longer available"is a short human-readable label for that code."errorDescription"explains that the content cannot be displayed, may be temporarily unavailable, the link may have expired, or the caller may not have permission to view the page."payload":nullmeans no actual data was returned. The stories themselves are not in the reply.
The key point: the server reached its permission check and answered with a structured error, rather than crashing.
Step 3: tell the two cases apart
Once it is established that the error response for a non-friend in a crisis zone is the one above, the two requests can be told apart:
| Reply | What it means |
|---|---|
500 Internal Server Error |
The target is not in a crisis zone. |
200 OK with error 1357031 |
The target is in a crisis zone. |
The stories themselves are never returned, but the error code is enough to classify the user. That is the whole attack: ask a question you should not be able to ask, and read the answer from which error comes back.
Why it happens
The researcher's reading is that the call is pulling in stories from non-friends, since the privacy of those stories is probably lower than public (or perhaps another internal privacy rule applies), and that this produces the 1357031 permission error. In other words, the endpoint does not reject a non-friend user_id before it evaluates the privacy of the underlying stories. The difference between those two paths is what leaks the fact that the person was marked in a crisis.
A comparison: imagine a library clerk who is supposed to only fetch books for members. Ask for a book that does not exist and the clerk shrugs and says "no idea". Ask for a book that exists but is restricted and the clerk says "you are not allowed to borrow that one". The second answer tells you the book exists, even though you never get it. Here, the 500 is the shrug and the 1357031 is the "not allowed", and the second answer reveals that the person has crisis stories.
Impact
Although the stories themselves are not seen, the error message follows the privacy rules, so it can be used to infer that a person was marked in a crisis. That is information the caller would not otherwise have for a non-friend. The impact is limited to that inference: the report does not claim that story content, names of other users, or any other data is exposed.
The fix
Facebook fixed the issue on 18 January 2017, after escalating it on 11 January 2017. The report does not describe the code change. If both cases look identical from the outside, the oracle disappears.
Variants to test
- A positive result is a response that differs between a user in a crisis and a user not in one.
- A positive result is a response that still distinguishes users by their crisis membership.
- A positive result is a
200with an error code for one class of users and a500for another. - A positive result is a per-ID error that reveals which ones are in a crisis.
Timeline
- Jan 4, 2017: report sent
- Jan 11, 2017: escalation by Facebook
- Jan 18, 2017: fixed by Facebook
- Jan 24, 2017: bounty awarded by Facebook
Glossary
- Endpoint: a specific web address that returns data rather than a full page.
- Query string: the part of a web address after the
?, carrying labelled values such ascrisis_id=1. - POST body: extra data sent along with a request, separate from the address.
curl: a command-line tool that sends a web request and prints the reply.- Session: how a website remembers you are logged in, usually via a cookie.
- Cookie: a small piece of text a site stores in your browser and receives back with each request.
- HTTP status code: a three-digit number at the top of every reply, such as
200 OKor500 Internal Server Error. - JSON: a common text format for data, made of labels and values in curly braces.
- JSON hijacking: an older attack where a malicious page tries to read another site's JSON data; the
for (;;);prefix defends against it. - Oracle: any behaviour that answers a yes/no question you were not supposed to be able to ask.
- Information leak: when a system reveals a fact through a side channel, such as an error message, rather than through the data it was meant to return.
- Safety Check: Facebook's feature that lets people mark themselves safe during a crisis and lets friends see those safe stories.
crisis_id: the identifier of a particular crisis in Safety Check.user_id: the identifier of a particular Facebook user.friend_safe_stories: the endpoint that returns a user's safe stories for a crisis.1357031: the specific Facebook error code returned when the caller lacks permission to view the requested content.- Escalation: when a company passes a report to a team that can act on it.
- Bounty: a payment a company makes to a researcher who reports a valid security bug.