Instagram App Access Token
An application access token for Instagram was embedded in a Base64-encoded Bloks bundle, allowing retrieval of the token. The token could be used to access app-level admin endpoints, potentially giving administration access to certain Instagram endpoints.
Published on philippeharewood.com
In Facebook Graph API as defined by the developer documentation, there are several access tokens, to authenticate against various API endpoints.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
## Context
Facebook's Graph API uses several kinds of access token, and the report opens by laying out the taxonomy from the developer documentation:
- **User Access Token**: makes requests on behalf of the user, normally obtained via OAuth at `facebook.com/dialog/oauth`.
- **Page Access Token**: makes requests on behalf of the page, obtained via `graph.facebook.com/pageID?fields=access_token`.
- **Client Token**: used for app level (not admin) endpoints, obtained by getting the alphanumeric secret from `graph.facebook.com/appID?fields=login_secret` and concatenating it in the form `appID|login_secret`.
- **Application Access Token**: used for app level admin role endpoints, providing administration in an application. The token is normally in the form `appID|[alphanumeric+special characters]`.
A token can belong to a third party app (for example one created via developers.facebook.com) or to a first party app such as Facebook or Instagram on iOS and Android. The target here is the latter: the researcher found that it was possible to retrieve multiple application access tokens for Instagram, which may have given administration access to certain endpoints for Instagram.
The feature involved is **Bloks**, which Meta has been developing for a few years. The report describes it as "a framework that enables both management logic to be defined once server-side and rendered as a native application". It is commonly seen in Facebook and Instagram shops as *Blok applications*.
## Setup
The write-up does not describe a particular account, role or tooling setup. The work involved Instagram's Bloks-based commerce screens, in particular the ratings and reviews flow.
## Finding it
A Bloks request has the general parameters `app_id`, `params` and `versioning_id`, and the response comes back as a bundle tree. In the reviews page the `app_id` is `com.bloks.www.bk.commerce.ratings_and_reviews.all_reviews`. Inside the bundle, Blok components and actions are embedded as Base64 encoded strings.
Decoding one of those Base64 strings yielded a section like the following:
```text
ispy0_main_f01�
#$&camera_rollChoose photobk.action.bloks.InflateSyncig.action.navigation.[redacted].action.logging.[redacted]|[redacted].action.media.[redacted]:is_image_uploading:17841401338810001bk.action.bloks.WriteGlobalConsistencyStorephoto_upload_startcom.bloks.www.bk.commerce.ratings_and_reviews.composer.media_upload.asyncparamsserver_paramsclient_input_paramscontainer_component_idrating_and_review_typeserialized_composer_contextmedia_source_typeis_local_selectedproduct{"rating_and_review_type":"product","merchant_id":90010214936182,"product_id":3537638846322537,"is_modal":false,"referral_surface":"pdp_all_reviews_screen","seeded_star_index":null,"rating_and_review_metadata":null,"extra_logging_info":null,"survey_entry_point":"product_detail_page","root_screen_id":null,"invoice_id":null}[redacted].action.bloks.GetVariable2bk.action.string.JsonEncode_f04_f05current-screenbk.action.bloks.AsyncActionWithDataManifest
```
The section to notice is:
```text
[redacted]|[redacted].action.media.UploadMediaV3
```
These values are used via the `ig.action.media.UploadMediaV3` action as a request to upload a photo as part of the review. The value does not match the client token pattern, which is what caught the researcher's eye: it is a token embedded in a client-side bundle.
## Exploitation
### Step 1: Observe the upload request
The Bloks action produces the following request to upload a photo as part of a review:
```http
POST /catalog_item_uploads/D52D5D86-308F-4DA5-B353-46B58BF47BD4 HTTP/2
Host: rupload.facebook.com
Priority: u=2, i
Offset: 0
X-Entity-Type: image/jpeg
X-Entity-Length: 10234
Content-Type: application/octet-stream
X-Ig-Bandwidth-Speed-Kbps: 7623.000
Content-Length: 10234
Authorization: OAuth 124024574287414|Jor32q7Rh50x2LZL1Aw2F4f8bjw
```
The `Authorization` header carries `OAuth 124024574287414|Jor32q7Rh50x2LZL1Aw2F4f8bjw`. The researcher notes that this is not a client token. A useful indicator, in the researcher's experience, is that a client token follows the pattern `[0-9]|[a-z0-9]*`. This value does not match that pattern, so it is an application token.
### Step 2: Confirm what the token is
Rather than start testing against Instagram, where the effect of intense testing was unknown, the researcher made a non destructive call to `graph.facebook.com/app/roles` with the token. That call listed about 25 Facebook user IDs with administrator or developer access. The researcher did not check further pagination requests and did not browse any of the profiles. Based on the short length of some of the Facebook IDs, it made sense to the researcher that these were Meta employees.
### Step 3: Report and stop
At this point the researcher sent a report and pinged an employee in Whitehat Workplace to raise attention to the issue and to ask for permission to push for impact. The proof of concept was enough: the researcher was instructed not to touch the token any more.
### Step 4: Look for variants
To cover variants, the researcher used a GraphQL bug that was current at the time to fuzz possible Bloks similar to `com.bloks.www.bk.commerce.ratings_and_reviews.composer`, and found an additional application token. Meta said it had checked this app as well. All the endpoints with tokens embedded were removed within hours.
## Root cause
A first party application access token, in the form `appID|secret`, was embedded in a Base64 encoded string inside a Bloks bundle that is delivered to the client. Because the bundle is rendered client-side, anyone who can load the reviews screen can decode the string and read the token. The token is an application access token rather than a client token, so it is the class used for app level admin role endpoints. The report does not describe the server-side logic that placed the token in the bundle, so the precise design mistake is not stated; what is clear is that a credential intended for administration was shipped in data the client receives.
## Impact
The researcher's summary is that it was possible to retrieve multiple application access tokens for Instagram, which may have given administration access to certain endpoints for Instagram. The confirmation call to `graph.facebook.com/app/roles` listed about 25 Facebook user IDs with administrator or developer access. Meta's own impact statement reads:
> You identified an endpoint issue that could have allowed a malicious actor to retrieve a first-party app IG access token. While we have protections in place that would have prevented further impact, your report led us to strengthen our defences, make changes to prevent similar issues in the future across our codebase. We have fixed this bug and have not seen any evidence of abuse.
So the potential is stated with hedges: the token could have allowed retrieval of a first-party IG access token, and Meta says protections would have prevented further impact. The report does not enumerate which endpoints an attacker could have reached with the token.
## Fix
Meta confirmed the fix, and the report states that all the endpoints with tokens embedded were removed within hours. Meta also says the report led it to strengthen defences and make changes to prevent similar issues across its codebase.
## Variants to test
1. **Decode every Base64 string in a Bloks bundle.** A positive result is a value that does not match the client token pattern `[0-9]|[a-z0-9]*` and that returns data from an app level endpoint.
2. **Check upload and media actions specifically.** A positive result is an `Authorization: OAuth appID|secret` header in a request the client itself makes.
3. **Fuzz sibling Bloks app IDs.** Fuzz Bloks similar to `com.bloks.www.bk.commerce.ratings_and_reviews.composer` and look for another bundle containing an embedded token. A positive result is another bundle containing an embedded token.
4. **Validate non destructively.** Call `graph.facebook.com/app/roles` with the candidate token and see whether it returns a list of user IDs with administrator or developer access. A positive result shows the token can list users with administrator or developer access.
## Timeline
| Time | Event |
| --- | --- |
| Feb 24, 2022 @ 1:10 am | Report sent |
| Feb 24, 2022 @ 1:11 am | Pinged Meta Security via Workplace |
| Feb 24, 2022 @ 2:56 am | Report triaged by Meta |
| Feb 24, 2022 @ 5:20 am | Confirmation of fix by Meta |
| May 19, 2022 | $30,000 bounty awarded by Meta, $6,000 Platinum league bonus, $2,250 Time delay bonus, $50 BountyConEdu bonus |
## References
- https://developers.facebook.com/docs/facebook-login/guides/access-tokens
- https://techcrunch.com/2021/03/10/facebook-targets-emerging-markets-with-instagram-lite-a-new-android-app-that-takes-up-just-2mb-in-170-countries/## What happened, in plain words
Instagram lets you write reviews for products in its shops, and you can attach a photo to a review. To upload that photo, the Instagram app on your phone sends a request to a Facebook server. That request carries a password-like string in a header called `Authorization`. The researcher Philippe Harewood noticed that this string was not the ordinary, low-power kind of key that apps normally use for small jobs. It was a much more powerful key: an application access token, the kind that can administer an app.
Worse, that key was not hidden on a server. It was sitting inside data that Instagram sends to the phone, encoded in a way that anyone can reverse (Base64). So anyone who could load the reviews screen could decode the data and read the key. A non destructive check listed about 25 Facebook user IDs with administrator or developer access to the app. The researcher reported it, was told to stop touching the key, and Meta removed the exposed endpoints within hours. Meta paid a $30,000 bounty plus bonuses.
This article walks through the same steps for someone who has never done security work: what an API is, what a token is, why a token in the wrong place is a problem, and how the researcher found and confirmed it.
## Background: what an API and a token are
An **API** (Application Programming Interface) is a way for one piece of software to ask another piece of software to do something. A simple comparison: a restaurant. You (the app) do not walk into the kitchen; you tell the waiter (the API) what you want, and the waiter brings it back. Facebook's **Graph API** is the waiter for Facebook and Instagram data: apps ask it for profiles, photos, reviews and so on.
A **token** is a short string that proves who is asking. Think of a cloakroom ticket: you hand over your coat, you get a ticket, and later the ticket gets your coat back. You do not need to prove your identity again, you just show the ticket. On the web, tokens are often sent in an HTTP header, which is a small labelled line attached to a request. The `Authorization` header is the standard place to put proof of who you are.
Tokens come in different strengths, like keys to different doors. Facebook's developer documentation describes several kinds, and the report lists them:
- **User Access Token**: acts on behalf of a person. Normally obtained through **OAuth**, a standard login dance at `facebook.com/dialog/oauth` where you sign in and the site hands your app a token.
- **Page Access Token**: acts on behalf of a Facebook Page (a business or public figure's page), obtained via `graph.facebook.com/pageID?fields=access_token`.
- **Client Token**: a weaker, app-level key used for endpoints that do not need admin rights. It is built by taking an alphanumeric secret from `graph.facebook.com/appID?fields=login_secret` and joining it to the app ID with a pipe character, in the form `appID|login_secret`.
- **Application Access Token**: a stronger, app-level key used for admin-role endpoints, meaning it can administer the application. It normally has the form `appID|[alphanumeric+special characters]`.
A token can also belong to a **third party app** (one an outside developer created at developers.facebook.com) or a **first party app** such as the official Facebook or Instagram apps on iOS and Android.
The finding: it was possible to retrieve multiple application access tokens for Instagram, which may have given administration access to certain endpoints for Instagram.
## The feature involved: Bloks
Meta has spent a few years building **Bloks**, which the report describes as "a framework that enables both management logic to be defined once server-side and rendered as a native application". In plain terms: instead of shipping a whole new app for every screen, Meta defines the screen's layout and behaviour once on its servers, and the phone app draws it. You see Bloks in Facebook and Instagram shops, where they are called *Blok applications*.
A useful comparison is a flat-pack furniture instruction sheet. The factory (the server) writes the instructions once, and any customer (any phone) can follow them to build the same shelf. If someone slips a spare house key into the instruction envelope, every customer receives that key too. That is essentially what happened here.
## How the researcher found it
A Bloks request has three general parameters: `app_id` (which Blok application is being asked for), `params` (the inputs), and `versioning_id` (which version of the layout to use). The server answers with a **bundle tree**: a structured package describing the screen and the actions it can perform.
On the reviews page, the `app_id` is `com.bloks.www.bk.commerce.ratings_and_reviews.all_reviews`. Inside the bundle, Blok components and actions are embedded as **Base64** encoded strings. Base64 is not encryption; it is just a way of writing arbitrary data using only letters, digits and a few symbols, so it can travel safely inside text. Anyone can decode it, much like a recipe written in a substitution code that comes with the key printed on the box.
Decoding one of those strings gave a long section of text:
```text
ispy0_main_f01�
#$&camera_rollChoose photobk.action.bloks.InflateSyncig.action.navigation.[redacted].action.logging.[redacted]|[redacted].action.media.[redacted]:is_image_uploading:17841401338810001bk.action.bloks.WriteGlobalConsistencyStorephoto_upload_startcom.bloks.www.bk.commerce.ratings_and_reviews.composer.media_upload.asyncparamsserver_paramsclient_input_paramscontainer_component_idrating_and_review_typeserialized_composer_contextmedia_source_typeis_local_selectedproduct{"rating_and_review_type":"product","merchant_id":90010214936182,"product_id":3537638846322537,"is_modal":false,"referral_surface":"pdp_all_reviews_screen","seeded_star_index":null,"rating_and_review_metadata":null,"extra_logging_info":null,"survey_entry_point":"product_detail_page","root_screen_id":null,"invoice_id":null}[redacted].action.bloks.GetVariable2bk.action.string.JsonEncode_f04_f05current-screenbk.action.bloks.AsyncActionWithDataManifest
```
Line by line, in plain words:
- The whole block is one long string of concatenated names and values. It is not meant to be read by a human; it is a machine-readable description of the screen.
- `camera_roll`, `Choose photo`, `add_photo_pressed` and `photo_count` are labels for the photo-adding part of the review form.
- `bk.action.bloks.InflateSync`, `ig.action.navigation.LaunchMediaPickerV2` and `ig.action.media.UploadMediaV3` are **actions**: named operations the screen can trigger. `LaunchMediaPickerV2` opens the phone's photo picker; `UploadMediaV3` uploads the chosen photo.
- `com.bloks.www.bk.commerce.ratings_and_reviews.composer` is the name of the Blok application that draws the review-writing screen.
- The JSON-looking part (`{"rating_and_review_type":"product",...}`) is the set of parameters for the review: product ID, merchant ID, which screen the user came from, and so on.
- The important part is the string `124024574287414|Jor32q7Rh50x2LZL1Aw2F4f8bjw`, which sits right next to `catalog_item_uploads` and `ig.action.media.UploadMediaV3`.
The section to notice is:
```text
[redacted]|[redacted].action.media.UploadMediaV3
```
In plain words: the upload action needs a credential to talk to the upload server, and that credential is written directly into the bundle that the phone receives. The shape `appID|secret` is exactly the shape of an application access token from the list above. That is what caught the researcher's eye: a powerful key, shipped to the client.
## Step 1: Observe the upload request
When the user picks a photo and submits the review, the `ig.action.media.UploadMediaV3` action produces this request:
```http
POST /catalog_item_uploads/D52D5D86-308F-4DA5-B353-46B58BF47BD4 HTTP/2
Host: rupload.facebook.com
Priority: u=2, i
Offset: 0
X-Entity-Type: image/jpeg
X-Entity-Length: 10234
Content-Type: application/octet-stream
X-Ig-Bandwidth-Speed-Kbps: 7623.000
Content-Length: 10234
Authorization: OAuth 124024574287414|Jor32q7Rh50x2LZL1Aw2F4f8bjw
```
Line by line:
- `POST /catalog_item_uploads/D52D5D86-308F-4DA5-B353-46B58BF47BD4 HTTP/2`: a POST request (a request that sends data) to a path that names a specific upload slot, identified by a random-looking ID. HTTP/2 is the version of the web protocol used.
- `Host: rupload.facebook.com`: the server being contacted. `rupload` is Facebook's upload host.
- `Priority: u=2, i`: a hint about how urgent this request is.
- `Offset: 0`: where in the file this chunk starts. Zero means the beginning.
- `X-Entity-Type: image/jpeg`: the file is a JPEG image.
- `X-Entity-Length: 10234`: the file is 10,234 bytes long.
- `Content-Type: application/octet-stream`: the body is raw binary data.
- `X-Ig-Bandwidth-Speed-Kbps: 7623.000`: the phone's measured upload speed, so the server can tune the transfer.
- `Content-Length: 10234`: the body is 10,234 bytes, matching the entity length.
- `Authorization: OAuth 124024574287414|Jor32q7Rh50x2LZL1Aw2F4f8bjw`: the credential. This is the same string found in the bundle.
The researcher's reasoning: this is not a client token. A handy indicator from experience is that a client token follows the pattern `[0-9]|[a-z0-9]*`, meaning digits, a pipe, then lowercase letters and digits only. The value here has uppercase letters and other characters, so it does not match. That makes it an application token, the stronger kind.
## Step 2: Confirm what the token is, without breaking anything
Before poking at Instagram, the researcher wanted to know what the key could do, without risking damage. Intense testing against a live product can have unknown effects, so the safer route was a **non destructive** call: a request that only reads information.
The call was to `graph.facebook.com/app/roles` with the token. In plain words, this asks the Graph API: "for this app, which users have roles such as administrator or developer?" It is a read-only question.
The result listed about 25 Facebook user IDs with administrator or developer access. The researcher did not fetch further pages of results and did not look at any of the profiles. Some of the IDs were short, which made sense to the researcher as Meta employees.
Why this step matters: it turned a suspicion into evidence. The token could read the list of people who administer the app.
## Step 3: Report and stop
At this point the researcher sent a report and pinged an employee in Whitehat Workplace (Meta's channel for security researchers) to draw attention to the issue and to ask permission to push further for impact. The proof of concept was already enough. The researcher was instructed not to touch the token any more.
This is a good habit to copy: once you have shown that a problem is real, stop and ask before going further. Continuing to use a live credential can cause harm and can complicate the fix.
## Step 4: Look for variants
To make sure the report covered all the similar cases, the researcher used a GraphQL bug that was current at the time to fuzz possible Bloks similar to `com.bloks.www.bk.commerce.ratings_and_reviews.composer`. **Fuzzing** means trying many small variations of an input to see which ones produce something interesting. Here, the variations were sibling Blok names, and the search found an additional application token. Meta said it had checked this app as well. All the endpoints with tokens embedded were removed within hours.
## Why it happened (root cause)
A first party application access token, in the form `appID|secret`, was embedded in a Base64 encoded string inside a Bloks bundle that is delivered to the client. Because the bundle is rendered on the phone, anyone who can load the reviews screen can decode the string and read the token. The token is an application access token rather than a client token, so it belongs to the class used for app-level admin-role endpoints. The report does not describe the server-side logic that put the token in the bundle, so the precise design mistake is not stated. What is clear is that a credential meant for administration was shipped in data the client receives.
A comparison: it is like a hotel giving every guest a welcome folder that happens to contain the master key card, taped inside the folder. The folder is meant to be read by guests; the key is not.
## Impact
The researcher's summary is that it was possible to retrieve multiple application access tokens for Instagram, which may have given administration access to certain endpoints for Instagram. The confirmation call to `graph.facebook.com/app/roles` listed about 25 Facebook user IDs with administrator or developer access. Meta's own impact statement reads:
> You identified an endpoint issue that could have allowed a malicious actor to retrieve a first-party app IG access token. While we have protections in place that would have prevented further impact, your report led us to strengthen our defences, make changes to prevent similar issues in the future across our codebase. We have fixed this bug and have not seen any evidence of abuse.
So the potential is stated with hedges: the token could have allowed retrieval of a first-party IG access token, and Meta says protections would have prevented further impact. The report does not list which endpoints an attacker could have reached with the token.
## Fix
Meta confirmed the fix, and the report states that all the endpoints with tokens embedded were removed within hours. Meta also says the report led it to strengthen defences and make changes to prevent similar issues across its codebase. The report does not describe the code change itself.
## Variants to test
1. **Decode every Base64 string in a Bloks bundle.** A positive result is a value that does not match the client token pattern `[0-9]|[a-z0-9]*` and that returns data from an app-level endpoint.
2. **Check upload and media actions specifically.** A positive result is an `Authorization: OAuth appID|secret` header in a request the client itself makes.
3. **Fuzz sibling Bloks app IDs.** Fuzz Bloks similar to `com.bloks.www.bk.commerce.ratings_and_reviews.composer` and look for another bundle containing an embedded token. A positive result is another bundle containing an embedded token.
4. **Validate non destructively.** Call `graph.facebook.com/app/roles` with the candidate token and see whether it returns a list of user IDs with administrator or developer access. A positive result shows the token can list users with administrator or developer access.
## Timeline
| Time | Event |
| --- | --- |
| Feb 24, 2022 @ 1:10 am | Report sent |
| Feb 24, 2022 @ 1:11 am | Pinged Meta Security via Workplace |
| Feb 24, 2022 @ 2:56 am | Report triaged by Meta |
| Feb 24, 2022 @ 5:20 am | Confirmation of fix by Meta |
| May 19, 2022 | $30,000 bounty awarded by Meta, $6,000 Platinum league bonus, $2,250 Time delay bonus, $50 BountyConEdu bonus |
## References
- https://developers.facebook.com/docs/facebook-login/guides/access-tokens
- https://techcrunch.com/2021/03/10/facebook-targets-emerging-markets-with-instagram-lite-a-new-android-app-that-takes-up-just-2mb-in-170-countries/
## Glossary
- **API**: a way for one piece of software to ask another to do something, like a waiter taking your order to the kitchen.
- **Graph API**: Facebook's API for reading and changing Facebook and Instagram data.
- **Token**: a short string that proves who is asking, like a cloakroom ticket.
- **Access token**: a token that grants access to an API.
- **User Access Token**: a token that acts on behalf of a person, normally obtained through OAuth.
- **Page Access Token**: a token that acts on behalf of a Facebook Page.
- **Client Token**: a weaker app-level token used for endpoints that do not need admin rights, shaped like `appID|login_secret`.
- **Application Access Token**: a stronger app-level token used for admin-role endpoints, shaped like `appID|[alphanumeric+special characters]`.
- **OAuth**: a standard login flow where you sign in and a site hands your app a token.
- **First party app**: an app made by the platform owner itself, such as the official Facebook or Instagram apps.
- **Third party app**: an app made by an outside developer.
- **Header**: a small labelled line attached to an HTTP request or response, such as `Authorization`.
- **Authorization header**: the standard header for carrying proof of who you are.
- **HTTP/2**: a version of the protocol browsers and apps use to talk to web servers.
- **POST**: an HTTP request that sends data to the server.
- **Bloks**: Meta's framework for defining a screen's layout and behaviour once on the server and rendering it as a native app screen.
- **Blok application**: a screen built with Bloks, such as the Instagram shop reviews screen.
- **app_id**: the identifier of which Blok application is being requested.
- **params**: the inputs passed to a Blok application.
- **versioning_id**: which version of a Blok layout to use.
- **Bundle tree**: the structured package the server returns to describe a Bloks screen and its actions.
- **Base64**: a way of writing arbitrary data using letters, digits and a few symbols so it can travel as text. It is encoding, not encryption, and anyone can decode it.
- **Action**: a named operation a Bloks screen can trigger, such as opening the photo picker or uploading a photo.
- **Fuzzing**: trying many small variations of an input to see which ones produce something interesting.
- **Non destructive**: a request that only reads information and does not change anything.
- **Endpoint**: a specific address on a server that accepts requests, such as `graph.facebook.com/app/roles`.
- **Root cause**: the underlying reason a bug exists, as opposed to its visible symptom.
- **Bounty**: a payment a company makes to a researcher who reports a security problem.
- **Triaged**: reviewed and accepted as a valid report by the company's security team.
- **Whitehat Workplace**: Meta's channel for security researchers to communicate with its security team.
- **GraphQL**: a query language for APIs that lets a client ask for exactly the data it wants.
- **Pagination**: fetching results in pages, one batch at a time.
- **User ID**: a number that identifies a Facebook account.
- **Administrator / developer access**: roles within an app that allow managing it.
- **Proof of concept (PoC)**: a minimal demonstration that a problem is real.
- **Impact**: what harm a security problem could cause.
- **Variant**: a different but related instance of the same kind of problem.