Skip to content
IDOR Write-up Intermediate

View-Private-Instagram-Photos

An internal Facebook GraphQL object called ShadowIGUser could be accessed by users not connected to the page or Instagram account, allowing them to view private Instagram photos. A second bug allowed a mentioned business account to see and comment on private photos.

Philippe Harewood Follow

Published on philippeharewood.com

There exists a certain object type in Facebook’s internal API (GraphQL) that is shared in the legacy GraphAPI called the “ShadowIGUser”. This type is usually scoped to the owner of the Instagram account, except for a few cases.

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

Facebook's internal API is GraphQL, but some objects are also exposed through the legacy GraphAPI. One of those object types is the "ShadowIGUser", which represents an Instagram user inside Facebook's graph. This type is usually scoped to the owner of the Instagram account, except for a few cases.

The report describes two related issues. The first is that anyone who has an ID for a ShadowIGUser can view the private photos of that Instagram user, including users on private accounts, through a specific call. The second is that an Instagram business account mentioned in a comment on a private photo can retrieve that private photo through the mentioned_comment edge.

Setup

The researcher worked with a Facebook page that had an Instagram account connected, and with a malicious user who was not connected to the page or to the Instagram account. The Instagram section of the Facebook mobile app (Facebook for iOS in this case) was used as the starting point, because it is shown to page owners who connected Instagram accounts. A proxy of the researcher's choice was used to bypass Facebook's certificate pinning so that the GraphQL calls building that section could be observed.

No specific app version or proxy product is named in the report.

Finding it

The first step is getting the ShadowIGUser ID. One way to do this is to collect comments left on Instagram photos connected to a Facebook page. The Instagram photo is presented within the unified Facebook page inbox and has the following format in GraphAPI:

{
    "comments": {
        "data": [{
            "user": {
                "id": "ShadowIGUserID",
                "username": "someinstagramusername"
            },
            "id": "IGCOMMENTID"
        }]
    },
    "id": "IGPHOTOID"
}

For the rest of the post, the Instagram target user ID is labelled "ShadowIGUserID".

With that ID in hand, the next step is to find a call that creates a simple insecure direct object reference for the specified ShadowIGUserID. The Instagram section in the mobile app is built by a GraphQL call, and that call is the one to look at.

Exploitation

Step 1: Capture the GraphQL call

Using the proxy to bypass certificate pinning, the GraphQL call that builds the Instagram section can be seen. Using a malicious user not connected to the page or the Instagram account, the following query can be made:

HTTP
HTTP POST
graph.facebook.com/graphql
access_token=AccessTokenBelongingToAUserNotConnectedToThePage
query_id=1
query_params={
    "1": 1,
    "2": {
        "payload": "core/simple-paging/?cursor=AQ&provider=MorePhotosPagingProvider&args={"
        instagram_id ": ShadowIGUserID,"
        page_id ":113702895386410,"
        photos_count ":4}",
    },
---SNIPPED
}

The request is a POST to graph.facebook.com/graphql carrying an access token that belongs to a user with no connection to the page or the Instagram account. The query_params object holds the paging payload, and inside it the instagram_id argument is the value of interest. The page_id is 113702895386410 and photos_count is 4.

Step 2: Swap in the target ID

The instagram_id was switched out for the Instagram user "phwd" and used the instagram_id for ShadowIGUserID instead. The researcher notes this is also a privacy issue, since the app states that no one should be able to see this, but opted to show the larger impact outside of business accounts, that is, against private users.

The GraphQL response was snipped as follows:

{
      {
        ---SNIPPED---"page_id=113702895386410&ig_account_id=ShadowIGUserID&photo_id=1---SNIPPED}",
        "": [
          {
            "name": "1",
            "actor_value": {
              "id": "113702895386410"
            }
          },
          {
            "name": "2",
            "node_value": {
              "id": "113702895386410"
            },
          },
          {
            "name": "3",
            "attachment_info": {
              "image_uri": "[REDACTED]"
            }
          },
          {
            "name": "4",
            "image_value": {
              "uri": "[REDACTED]",
              "scale": 1,
              "name": null,
              "width": 0,
              "height": 0
            }
          }
        ],
      }
    ]
  }
}

The [REDACTED] URL points to a photo in the private account for the ShadowIGUserID. The image_uri and uri fields are the media references that were returned.

Step 3: The second issue, via a mentioned comment

The previous bug only returns the photo URLs and media IDs, not the Instagram object itself. If a malicious Instagram business account was mentioned in a private photo, it will be possible for that account to see the private photo.

Given an Instagram business account that was mentioned via a comment (SOME_COMMENT_ID), call the mentioned comment edge:

HTTP
https://graph.facebook.com/IGBUSINESSID?fields=mentioned_comment.comment_id(SOME_COMMENT_ID){media{id,media_url,owner{id,username}},timestamp,text,id}&access_token=TOKENFORFACEBOOKPAGECONNECTEDTOINSTAGRAM

The request asks for the mentioned_comment field, scoped to the comment ID, and expands media with id, media_url and owner{id,username}, plus timestamp, text and id. The token is one for a Facebook page connected to the Instagram business account.

JSON
{
"mentioned_comment": {
"media": {
"id": "IG_MEDIA_ID",
"media_url": "[REDACTED]",
"owner": {
"id": "IGBUSINESSID",
"username": "heknodawae"
}
},
"timestamp": "1984-05-14T00:00:10+0000",
"text": "@heknodawae",
"id": "COMMENT_ID"
},
"id": "IGBUSINESSID"
}

The [REDACTED] URL contains the private Instagram photo on which the business account was mentioned. For additional impact, the business account can reply and leave a comment using the /IGBUSINESSID/mentions edge.

Root cause

The ShadowIGUser object is normally scoped to the owner of the Instagram account, but the paging payload used by the Instagram section of the mobile app accepts an instagram_id argument, and supplying another user's ShadowIGUserID returned that user's private media. Supplying the ShadowIGUserID of another user therefore returns that user's private media, a classic insecure direct object reference on an object identifier. The second issue is on the mentioned_comment edge: a business account that was mentioned in a comment can read the media of the comment, even when the media belongs to a private account.

Impact

An attacker who obtains a ShadowIGUser ID, for example by collecting comments left on Instagram photos connected to a Facebook page, can view the private photos of that Instagram user, including users on private accounts. The first issue returns photo URLs and media IDs rather than the Instagram object itself. The second issue lets a malicious Instagram business account that was mentioned in a private photo see that private photo, and reply and leave a comment through the /IGBUSINESSID/mentions edge.

Fix

Facebook fixed the first issue on Mar 19, 2018, three days after the report was sent, and awarded a bounty on Mar 28, 2018. The second issue was fixed on May 14, 2018, and a bounty plus a bonus for an incomplete fix were awarded on May 18, 2018. The report does not describe the code changes themselves.

Variants to test

Timeline

  • Mar 16, 2018: report sent
  • Mar 16, 2018: further investigation by Facebook
  • Mar 19, 2018: fixed by Facebook
  • Mar 28, 2018: bounty awarded by Facebook

Second issue:

  • Apr 5, 2018: report sent
  • Apr 9, 2018: clarification requested by Facebook
  • Apr 9, 2018: clarification sent
  • Apr 11, 2018: further clarification requested by Facebook
  • Apr 11, 2018: video sent
  • Apr 12, 2018: further details sent
  • Apr 16, 2018: standalone proof of concept minisite and video sent
  • May 1, 2018: further investigation by Facebook
  • May 8, 2018: confirmation of fix requested by Facebook
  • May 8, 2018: further details sent
  • May 11, 2018: confirmation of fix requested by Facebook
  • May 11, 2018: further details sent
  • May 14, 2018: fixed by Facebook
  • May 18, 2018: bounty awarded by Facebook
  • May 18, 2018: bonus awarded by Facebook for incomplete fix

Thanks to Josip Franjković for reading a draft of this.

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. 14 min read.

What happened, in plain words

Instagram lets you mark your account as private, which means only people you approve can see your photos. Facebook and Instagram are owned by the same company, and behind the scenes the two products share data through internal systems. This report is about two ways in which that sharing went too far: a person who should not have been able to see a private Instagram account's photos could get hold of them anyway.

The first way needed only one piece of information: an internal identifier for the Instagram user. With that number, a request to one of Facebook's internal interfaces returned links to that user's private photos. The second way involved Instagram business accounts. If a business account was mentioned in a comment on a private photo, that business account could fetch the private photo itself, and even reply and leave a comment.

The first problem is an example of a very common class of bug: the server trusts an identifier that the client sends, and never checks whether the person sending it is allowed to use that identifier.

Background you need first

A few ideas come up constantly in this report, so here they are from zero.

An API is the way one piece of software asks another for data. Think of a restaurant: the menu is the API, the kitchen is the server, and you are the client. You do not walk into the kitchen; you order from the menu, and the kitchen decides what to send back. Facebook's apps talk to Facebook's servers through APIs all day.

GraphQL is a particular style of API. Instead of many separate addresses for many separate things, there is usually one address, and the client sends a description of exactly the data it wants. The server reads that description and returns matching data. Facebook's internal API is GraphQL.

The legacy GraphAPI is Facebook's older API style, where each kind of data has its own address (an endpoint) and you ask for fields with a query string. Some objects are still reachable through it even though the newer GraphQL API is the main one.

An object here means a record of something: a user, a photo, a comment. Each object has an ID, a unique identifier, like a customer number in a shop's database.

An access token is a long string that proves who is making a request. It works like a wristband at an event: the door staff do not ask your name every time, they just check the wristband. If you have a valid wristband, you get in. The important question in this report is not whether the wristband is real, but what it is allowed to open.

A proxy is a tool that sits between an app and the internet and records the traffic passing through it. Security testers use one to see exactly what an app sends to its servers, which is normally hidden.

Certificate pinning is a defence where an app refuses to trust any encryption certificate except the specific one it expects. It stops someone with a proxy from reading the app's traffic, because the proxy presents a different certificate. Testers work around it on their own devices so they can inspect their own traffic.

An insecure direct object reference (IDOR) is the bug class at the heart of this report. The server receives an identifier from the client and fetches the matching object without checking that this particular client is allowed to see it. The everyday comparison: a hotel where room numbers are the only key. If you change the number on your key card from 204 to 305 and the door opens, the hotel has an IDOR. The number was never secret; the missing part was the check.

Scoping means limiting who can reach an object. Saying the ShadowIGUser type is "usually scoped to the owner" means that, normally, only the owner of the Instagram account can reach it.

The object at the centre: ShadowIGUser

Facebook's internal API is GraphQL, but some objects are also exposed through the legacy GraphAPI. One of those object types is the "ShadowIGUser", which represents an Instagram user inside Facebook's graph. This type is usually scoped to the owner of the Instagram account, except for a few cases.

The report describes two related issues. The first is that anyone who has an ID for a ShadowIGUser can view the private photos of that Instagram user, including users on private accounts, through a specific call. The second is that an Instagram business account mentioned in a comment on a private photo can retrieve that private photo through the mentioned_comment edge.

An edge is GraphAPI's word for a connection between objects: a photo has a comments edge, a comment has a mentions edge, and so on. You reach an edge by adding its name to an object's address.

Setting up the test

The researcher worked with a Facebook page that had an Instagram account connected, and with a malicious user who was not connected to the page or to the Instagram account. That second account matters: it is the "attacker" in the story, and it should have no rights over the page or the Instagram account at all.

The Instagram section of the Facebook mobile app (Facebook for iOS in this case) was the starting point, because it is shown to page owners who connected Instagram accounts. A proxy of the researcher's choice was used to bypass Facebook's certificate pinning so that the GraphQL calls building that section could be observed.

Why start there? Because that section is a place where the app already asks Facebook for Instagram photos belonging to a page. If the app can ask for one account's photos, the interesting question is whether the same request can be pointed at a different account. Watching the app's own traffic shows you the exact request to copy and modify.

No specific app version or proxy product is named in the report.

Finding it

The first step is getting the ShadowIGUser ID. One way to do this is to collect comments left on Instagram photos connected to a Facebook page. The Instagram photo is presented within the unified Facebook page inbox and has the following format in GraphAPI:

{
    "comments": {
        "data": [{
            "user": {
                "id": "ShadowIGUserID",
                "username": "someinstagramusername"
            },
            "id": "IGCOMMENTID"
        }]
    },
    "id": "IGPHOTOID"
}

Line by line:

  • The outer braces open one JSON object, a bundle of named values.
  • "comments" is the comments edge of the photo, and "data" is the list of comment records inside it.
  • Each comment has a "user" object with an "id" and a "username". The id here is the ShadowIGUser ID of the Instagram user who left the comment, and the username is their Instagram handle.
  • "id": "IGCOMMENTID" is the identifier of the comment itself.
  • The final "id": "IGPHOTOID" is the identifier of the Instagram photo the comments belong to.

For the rest of the post, the Instagram target user ID is labelled "ShadowIGUserID".

The identifier is public; what should be protected is the data behind it.

With that ID in hand, the next step is to find a call that creates a simple insecure direct object reference for the specified ShadowIGUserID. The Instagram section in the mobile app is built by a GraphQL call, and that call is the one to look at.

Exploitation

Step 1: Capture the GraphQL call

Using the proxy to bypass certificate pinning, the GraphQL call that builds the Instagram section can be seen. Using a malicious user not connected to the page or the Instagram account, the following query can be made:

HTTP
HTTP POST
graph.facebook.com/graphql
access_token=AccessTokenBelongingToAUserNotConnectedToThePage
query_id=1
query_params={
    "1": 1,
    "2": {
        "payload": "core/simple-paging/?cursor=AQ&provider=MorePhotosPagingProvider&args={"
        instagram_id ": ShadowIGUserID,"
        page_id ":113702895386410,"
        photos_count ":4}",
    },
---SNIPPED
}

Line by line:

  • HTTP POST says this is a POST request, the kind used to send data to a server rather than just ask for a page.
  • graph.facebook.com/graphql is the address being called: Facebook's GraphQL endpoint.
  • access_token=AccessTokenBelongingToAUserNotConnectedToThePage is the wristband. The name spells out the point: it belongs to a user with no connection to the page or the Instagram account.
  • query_id=1 identifies which stored query the server should run. Facebook's GraphQL endpoint lets clients refer to queries by number instead of sending the whole query text.
  • query_params is the bundle of arguments for that query. Inside it, "1": 1 is a small parameter, and "2" holds the interesting part.
  • The payload string is a paging request: core/simple-paging/ is the paging component, cursor=AQ is a position marker, and provider=MorePhotosPagingProvider names the component that supplies more photos.
  • Inside args, instagram_id is the account whose photos are being requested, page_id is 113702895386410, and photos_count is 4, the number of photos to return.
  • ---SNIPPED marks where the report cut the request short.

The request is a POST to graph.facebook.com/graphql carrying an access token that belongs to a user with no connection to the page or the Instagram account. The query_params object holds the paging payload, and inside it the instagram_id argument is the value of interest. The page_id is 113702895386410 and photos_count is 4.

Why this step: the app builds this request itself when a page owner opens the Instagram section. Copying it and sending it with a different account's token tests whether the server checks who is asking, or only what is being asked for.

Step 2: Swap in the target ID

The instagram_id was switched out for the Instagram user "phwd" and used the instagram_id for ShadowIGUserID instead. The researcher notes this is also a privacy issue, since the app states that no one should be able to see this, but opted to show the larger impact outside of business accounts, that is, against private users.

In other words, the instagram_id was replaced with the target's ShadowIGUserID, and the response pointed to a photo in that private account.

The GraphQL response was snipped as follows:

{
      {
        ---SNIPPED---"page_id=113702895386410&ig_account_id=ShadowIGUserID&photo_id=1---SNIPPED}",
        "": [
          {
            "name": "1",
            "actor_value": {
              "id": "113702895386410"
            }
          },
          {
            "name": "2",
            "node_value": {
              "id": "113702895386410"
            },
          },
          {
            "name": "3",
            "attachment_info": {
              "image_uri": "[REDACTED]"
            }
          },
          {
            "name": "4",
            "image_value": {
              "uri": "[REDACTED]",
              "scale": 1,
              "name": null,
              "width": 0,
              "height": 0
            }
          }
        ],
      }
    ]
  }
}

Line by line:

  • The first quoted string is a URL fragment: page_id=113702895386410&ig_account_id=ShadowIGUserID&photo_id=1. It ties the page, the Instagram account and a photo together. The & characters separate the parameters, exactly as in a normal web address.
  • The list that follows holds four entries, each with a name from "1" to "4". These are the pieces the app uses to draw the photo tiles.
  • Entries 1 and 2 carry actor_value and node_value, both with the page ID 113702895386410. These are references to the page the photos belong to.
  • Entry 3 has attachment_info with an image_uri. That is a link to an image file.
  • Entry 4 has image_value with a uri, plus scale, name, width and height describing how to display it.
  • [REDACTED] marks where the real image links were removed before publication.

The response contains a URL with page_id=113702895386410&ig_account_id=ShadowIGUserID&photo_id=1, and the [REDACTED] URL points to a photo in the private account for the ShadowIGUserID. The image_uri and uri fields are the media references that were returned.

Why this is the bug: the request used a token from a user not connected to the page or the Instagram account, and the response still pointed to a photo in the private account.

Step 3: The second issue, via a mentioned comment

The previous bug only returns the photo URLs and media IDs, not the Instagram object itself. If a malicious Instagram business account was mentioned in a private photo, it will be possible for that account to see the private photo.

A mention is when someone writes another account's handle in a comment, for example @heknodawae. Instagram records that mention as a link between the comment and the mentioned account. The second issue lives on that link.

Given an Instagram business account that was mentioned via a comment (SOME_COMMENT_ID), call the mentioned comment edge:

HTTP
https://graph.facebook.com/IGBUSINESSID?fields=mentioned_comment.comment_id(SOME_COMMENT_ID){media{id,media_url,owner{id,username}},timestamp,text,id}&access_token=TOKENFORFACEBOOKPAGECONNECTEDTOINSTAGRAM

Line by line:

  • https://graph.facebook.com/IGBUSINESSID is the address of the business account object in GraphAPI.
  • ?fields= starts the list of fields to return, the same way a normal web address carries parameters after a question mark.
  • mentioned_comment.comment_id(SOME_COMMENT_ID) asks for the mentioned comment, narrowed to one specific comment ID.
  • {media{id,media_url,owner{id,username}},timestamp,text,id} is the expansion: for that comment, return the media with its id, media_url and owner details, plus the comment's timestamp, text and id.
  • &access_token=TOKENFORFACEBOOKPAGECONNECTEDTOINSTAGRAM is the wristband, this time for a Facebook page connected to the Instagram business account.

The request asks for the mentioned_comment field, scoped to the comment ID, and expands media with id, media_url and owner{id,username}, plus timestamp, text and id. The token is one for a Facebook page connected to the Instagram business account.

Why this step: the business account was mentioned in a comment, so it has a legitimate reason to know that a comment exists. The question is whether that small connection also unlocks the photo the comment sits on, even when the photo belongs to a private account.

JSON
{
"mentioned_comment": {
"media": {
"id": "IG_MEDIA_ID",
"media_url": "[REDACTED]",
"owner": {
"id": "IGBUSINESSID",
"username": "heknodawae"
}
},
"timestamp": "1984-05-14T00:00:10+0000",
"text": "@heknodawae",
"id": "COMMENT_ID"
},
"id": "IGBUSINESSID"
}

Line by line:

  • mentioned_comment is the comment the business account was mentioned in.
  • media is the photo that comment sits on, with its id and a media_url. The [REDACTED] marks where the real link was removed.
  • owner describes the account that owns the media, with an id and username.
  • timestamp is when the comment was posted, text is the comment body, here @heknodawae, and id is the comment's identifier.
  • The final "id": "IGBUSINESSID" is the business account object itself.

The [REDACTED] URL contains the private Instagram photo on which the business account was mentioned. For additional impact, the business account can reply and leave a comment using the /IGBUSINESSID/mentions edge.

So the mention also revealed the photo. And because the same account can write through its mentions edge, it could reply and leave a comment.

Root cause

The ShadowIGUser object is normally scoped to the owner of the Instagram account, but the paging payload used by the Instagram section of the mobile app accepts an instagram_id argument, and supplying another user's ShadowIGUserID returned that user's private media. Supplying the ShadowIGUserID of another user therefore returns that user's private media, a classic insecure direct object reference on an object identifier. The second issue is on the mentioned_comment edge: a business account that was mentioned in a comment can read the media of the comment, even when the media belongs to a private account.

Impact

An attacker who obtains a ShadowIGUser ID, for example by collecting comments left on Instagram photos connected to a Facebook page, can view the private photos of that Instagram user, including users on private accounts. The first issue returns photo URLs and media IDs rather than the Instagram object itself. The second issue lets a malicious Instagram business account that was mentioned in a private photo see that private photo, and reply and leave a comment through the /IGBUSINESSID/mentions edge.

Fix

Facebook fixed the first issue on Mar 19, 2018, three days after the report was sent, and awarded a bounty on Mar 28, 2018. The second issue was fixed on May 14, 2018, and a bounty plus a bonus for an incomplete fix were awarded on May 18, 2018. The report does not describe the code changes themselves.

Variants to test

Timeline

  • Mar 16, 2018: report sent
  • Mar 16, 2018: further investigation by Facebook
  • Mar 19, 2018: fixed by Facebook
  • Mar 28, 2018: bounty awarded by Facebook

Second issue:

  • Apr 5, 2018: report sent
  • Apr 9, 2018: clarification requested by Facebook
  • Apr 9, 2018: clarification sent
  • Apr 11, 2018: further clarification requested by Facebook
  • Apr 11, 2018: video sent
  • Apr 12, 2018: further details sent
  • Apr 16, 2018: standalone proof of concept minisite and video sent
  • May 1, 2018: further investigation by Facebook
  • May 8, 2018: confirmation of fix requested by Facebook
  • May 8, 2018: further details sent
  • May 11, 2018: confirmation of fix requested by Facebook
  • May 11, 2018: further details sent
  • May 14, 2018: fixed by Facebook
  • May 18, 2018: bounty awarded by Facebook
  • May 18, 2018: bonus awarded by Facebook for incomplete fix

Thanks to Josip Franjković for reading a draft of this.

Glossary

  • API: the agreed way for one piece of software to ask another for data, like a menu you order from.
  • GraphQL: an API style where the client sends one request describing exactly which fields it wants, and the server returns matching data.
  • GraphAPI: Facebook's older API style, where each kind of data has its own address and fields are requested in the query string.
  • Endpoint: the address a request is sent to.
  • Object: a record of something, such as a user, photo or comment.
  • ID: a unique identifier for an object, like a customer number.
  • Access token: a string that proves who is making a request, like a wristband at an event.
  • Proxy: a tool that sits between an app and the internet and records the traffic passing through it.
  • Certificate pinning: an app defence that only trusts one specific encryption certificate, which blocks a proxy from reading the app's traffic.
  • ShadowIGUser: Facebook's internal object type representing an Instagram user, normally scoped to the account owner.
  • Scoping: limiting who is allowed to reach an object.
  • Edge: GraphAPI's term for a connection between objects, such as a photo's comments or a comment's mentions.
  • Insecure direct object reference (IDOR): a bug where the server fetches an object from an identifier supplied by the client without checking that the client is allowed to see it.
  • Payload: the part of a request that carries the actual data or arguments.
  • Query string: the part of a web address after the ?, made of name=value pairs separated by &.
  • Mention: writing another account's handle in a comment, which Instagram records as a link to that account.
  • Business account: an Instagram account type intended for companies, which can be connected to a Facebook page.
  • Private account: an Instagram account whose photos are visible only to approved followers.
  • Bounty: a payment a company makes to a researcher who reports a valid security bug.
  • Proof of concept: a small demonstration that a bug is real and can be triggered.

More by Philippe Harewood

View all

56 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.

Insecure direct object reference (IDOR)

The lesson behind this report.

One user can read or change another user's data, usually by changing an identifier the server trusts without checking who is asking. One of the most paid bug classes on web programs.