Skip to content
Access control Write-up Intermediate

Twitterのフリート機能に対する権限昇格

blog.ryotak.net

Published on blog.ryotak.net

TwitterはBug Bountyプログラム(脆弱性報奨金制度とも呼ばれる)を実施しており、脆弱性の診断行為を行うことが認められています。 本記事は、そのプログラムを通して報告された脆弱性についてを解説したものであり、Twitterが認知していない未修正の脆弱性を� �開する事を意図したものではありません。 また、Twitter上で脆弱性を発見した場合はTwitterのBug Bountyプログラムより報告してください。

RyotaK, on blog.ryotak.net

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

Context

Twitter launched a feature called Fleets in Japan on 10 November 2020. Fleets are short-lived posts: the report describes them as having an expiration, and the API responses shown below carry an expiration field set roughly 24 hours after creation. The feature was initially implemented only in the iOS client, and the next day, 11 November, the Fleet update arrived on the researcher's own Android device, which prompted an analysis of the API behind it.

The target of the research is the set of Fleet endpoints used by the official Android client, and in particular the authorisation behaviour of those endpoints when they are called by a third-party application authenticated with a read-only access token.

Setup

Twitter for Android is written in Java and, like most Android applications, is obfuscated, but the report notes that this does not make analysis especially hard. The tools used were:

  • apktool
  • dex2jar
  • CFR

The application was decompiled with these tools to bring it back to a reasonably readable state. The report does not describe the decompilation steps in detail.

On the account side, the researcher used a third-party application registered with Twitter that held only the READ permission. This is the key precondition for the whole finding: the token used for the requests below is not supposed to be able to write anything.

Finding it

Without endpoint names the API cannot be analysed, so the researcher used grep to search the decompiled .java files for the string fleet. This turned up a file containing the string /fleet/v1/user_fleets. Looking at the files in the same directory revealed other strings that looked like endpoint names, and these were analysed and collected in a Gist.

While reviewing the contents of that Gist, the researcher found that calling the Fleet-related APIs while authenticated as a third-party application worked without any problem. The intention at that point was to publish a detailed API document so that the authors of unofficial clients could use it, and a detailed API document was written. Before publishing, the Gist was being checked for correctness, and during that check the researcher found that sending a request to POST /fleets/v1/create as an application holding only read permission actually created a Fleet.

APIから作ったフリートの画像
APIから作ったフリートの画像 From the original on blog.ryotak.net

The image shows the Fleet that was created through the API during this verification.

Exploitation

Step 1: confirm the token really is read-only

The first suspicion was that the test application had accidentally been granted write permission. The permissions were checked, and the application clearly had only read permission. At this point the researcher began to suspect a vulnerability but did not have confirmation, so the investigation went deeper.

Step 2: compare against a normal Twitter API endpoint

A normal Twitter API endpoint such as POST /1.1/statuses/update.json performs a permission check before the API logic runs, and rejects a read-only application. The Fleet endpoints, by contrast, did not perform the permission check that normal APIs perform.

The first command below calls the ordinary status update endpoint with a read-only token, and the second calls the Fleet creation endpoint with the same kind of token:

Bash
$ twurl /1.1/statuses/update.json --header 'Content-Type: application/json' -d '{"status":"Test"}'
{"request":"\/1.1\/statuses\/update.json","error":"Read-only application cannot POST."}

$ twurl /fleets/v1/create -X POST --header 'Content-Type: application/json' -d '{"text":"Hey yo"}'
{"fleet":{"created_at":"2020-11-12T12:29:16.180000000Z","deleted_at":null,"expiration":"2020-11-13T12:29:16.189235445Z","fleet_id":"F1-328253875041691174","fleet_thread_id":"T1-328253875041625638","mentions":null,"mentions_str":null,"read":false,"text":"Hey yo","user_id":1195137762027962368},"fleet_thread_id":"T1-328253875041625638","fleet_id":"F1-328253875041691174","users":null}

The first response is the expected refusal: Read-only application cannot POST. The second response is a success. It contains a fleet object with a fleet_id, a fleet_thread_id, the submitted text of Hey yo, a created_at timestamp and an expiration timestamp about 24 hours later, plus the user_id of the account the Fleet belongs to. In other words, the write went through with a token that should only be able to read.

Root cause

The report's conclusion is that the Fleet-related endpoints did not run the permission check that the ordinary Twitter API endpoints run before processing a request. On POST /1.1/statuses/update.json the check happens before the API logic and produces the Read-only application cannot POST. error; on POST /fleets/v1/create the request was processed and the Fleet was created.

The report does not describe the server-side implementation, so the exact reason the check was missing from the Fleet code path is not stated. What the report does establish is the observable difference in behaviour between the two endpoint families for the same class of token.

Impact

A third-party application holding only the READ permission could create and delete Fleets through the Fleet API. The researcher's own demonstration is the creation of a Fleet with a read-only token. The report's summary states that creation and deletion were both possible; the request and response shown in the article cover creation.

The condition for exploitation is that the attacker has a third-party application authorised with a read-only token.

Fix

Twitter fixed the issue quickly: it was reported on 12 November and fixed by 18 November. The fix was not to add the missing permission check to the Fleet endpoints. Instead, Twitter changed things so that third-party applications cannot call the Fleet-related APIs at all. The report notes that the fact that third-party applications could use the Fleet APIs at all appears to have been considered the problem, and the fix was to stop third-party applications from calling them.

Variants to test

  • New feature endpoints on the same platform. Enumerate endpoints introduced with a recently shipped feature and call each one with a read-only token. A positive result is a successful write response, such as a created object with an ID, where the equivalent call on an established endpoint returns a read-only refusal.
  • Endpoint families that bypass the shared authorisation layer. Compare the error behaviour of an old endpoint and a new one for the same token and method. A positive result is the old endpoint rejecting the request before any processing while the new one returns a normal success body.
  • Permission scope checks per HTTP method. For each endpoint, try the write methods (POST, DELETE, and so on) with a token that only has read scope. A positive result is any state change visible in the response or in the account afterwards.
  • Client-side endpoint discovery. Decompile or otherwise inspect an official client for a new feature and grep for the feature name to find endpoint strings, then test those endpoints directly. A positive result is an endpoint that accepts requests from a third-party application context at all.

Timeline

Date Event
2020/11/10 Twitter releases Fleets in Japan
2020/11/11 Fleets become available on the researcher's device
2020/11/12 Vulnerability found and reported
2020/11/13 Twitter: currently investigating
2020/11/14 Twitter: accepted as a vulnerability
2020/11/18 Twitter: vulnerability fixed
2020/12/15 Twitter: bounty amount decided
2021/01/05 Vulnerability disclosed

Three days after the fix, another researcher tweeted that Fleet images were not removed from the CDN after 24 hours, so deleted Fleets could still be viewed. The report mentions this as an aside on how short the window for working on the Fleet implementation was.

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

Twitter added a new feature called Fleets in Japan on 10 November 2020. A Fleet is a short-lived post: it disappears after a set time, and in the responses shown in this article the expiry is set about 24 hours after the Fleet is created. At first the feature existed only in the iPhone app. The next day, 11 November, the update that added Fleets arrived on the researcher's own Android phone, and that is what started the investigation.

The researcher wanted to understand the programming interface behind Fleets. An API (application programming interface) is the set of addresses a program can send requests to in order to make a service do something, much like a restaurant menu: you can only order the dishes that are listed, and the kitchen decides what happens when you do. Twitter's apps talk to Twitter's servers through such a menu of addresses, and so do third-party apps, which are separate programs made by other people that are allowed to use a limited part of Twitter.

When a third-party app is allowed to use Twitter, it is given a token, a long secret string that works like a wristband at an event: it proves which app is asking and what it is allowed to do. Some apps get a read-only token, meaning they may look at things but not change anything. The researcher had registered such an app, with only the READ permission.

The finding: the new Fleet addresses did not check that wristband properly. An app holding a read-only token was able to create a Fleet, and according to the report's summary also to delete one. The rest of this article walks through how that was discovered, how it was confirmed, and how Twitter responded.

Background: what Fleets are and what was being tested

Fleets are short-lived posts. The report describes them as having an expiration, and the API responses below carry an expiration field set roughly 24 hours after creation. The feature was first implemented only in the iOS client. On 11 November the Fleet update arrived on the researcher's Android device, which prompted an analysis of the API behind it.

The target of the research is the set of Fleet endpoints used by the official Android client, and in particular how those endpoints behave when they are called by a third-party application authenticated with a read-only access token. An endpoint is one specific address on the server, for example the address that creates a Fleet. Authentication means proving who you are; authorisation means what you are then allowed to do. The whole finding lives in the gap between the two: the app was correctly identified, but the Fleet endpoints did not enforce what that identity was permitted to do.

Setting up the analysis

Twitter for Android is written in Java and, like most Android applications, it is obfuscated. Obfuscation means the code has been deliberately made hard for humans to read, for example by renaming things to meaningless short names, the way a recipe could be written in shorthand only the cook understands. The report notes that this does not make analysis especially hard.

The tools used were:

  • apktool
  • dex2jar
  • CFR

These are programs that take an installed Android app apart and turn its compiled code back into something close to readable source code. The application was decompiled with them to bring it back to a reasonably readable state. The report does not describe the decompilation steps in detail.

On the account side, the researcher used a third-party application registered with Twitter that held only the READ permission. This is the key precondition for the whole finding: the token used for the requests below is not supposed to be able to write anything.

Finding the Fleet endpoints

Without endpoint names the API cannot be analysed, so the researcher used grep to search the decompiled .java files for the string fleet. grep is a command-line search tool: you give it a word and a pile of files, and it prints the files and lines that contain that word, like using the search box in a document viewer but across thousands of files at once.

This turned up a file containing the string /fleet/v1/user_fleets. Looking at the files in the same directory revealed other strings that looked like endpoint names, and these were analysed and collected in a Gist. A Gist is a small page on GitHub used for sharing snippets of text or code.

While reviewing the contents of that Gist, the researcher found that calling the Fleet-related APIs while authenticated as a third-party application worked without any problem. The intention at that point was to publish a detailed API document so that the authors of unofficial clients could use it, and a detailed API document was written. Before publishing, the Gist was being checked for correctness, and during that check the researcher found that sending a request to POST /fleets/v1/create as an application holding only read permission actually created a Fleet.

APIから作ったフリートの画像
APIから作ったフリートの画像 From the original on blog.ryotak.net

The image shows the Fleet that was created through the API during this verification.

Confirming it was real

Step 1: check that the token really is read-only

The first suspicion was that the test application had accidentally been granted write permission. That would be the boring explanation: a mistake in the app's settings rather than a flaw in Twitter. The permissions were checked, and the application clearly had only read permission. At this point the researcher began to suspect a vulnerability but did not have confirmation, so the investigation went deeper.

Step 2: compare against a normal Twitter API endpoint

A normal Twitter API endpoint such as POST /1.1/statuses/update.json performs a permission check before the API logic runs, and rejects a read-only application. The Fleet endpoints, by contrast, did not perform the permission check that normal APIs perform.

Think of it as two doors in the same building. The old door has a guard who reads your badge before you get in. The new door has no guard, so the badge is never read and anyone who reaches the door walks through.

The first command below calls the ordinary status update endpoint with a read-only token, and the second calls the Fleet creation endpoint with the same kind of token:

Bash
$ twurl /1.1/statuses/update.json --header 'Content-Type: application/json' -d '{"status":"Test"}'
{"request":"\/1.1\/statuses\/update.json","error":"Read-only application cannot POST."}

$ twurl /fleets/v1/create -X POST --header 'Content-Type: application/json' -d '{"text":"Hey yo"}'
{"fleet":{"created_at":"2020-11-12T12:29:16.180000000Z","deleted_at":null,"expiration":"2020-11-13T12:29:16.189235445Z","fleet_id":"F1-328253875041691174","fleet_thread_id":"T1-328253875041625638","mentions":null,"mentions_str":null,"read":false,"text":"Hey yo","user_id":1195137762027962368},"fleet_thread_id":"T1-328253875041625638","fleet_id":"F1-328253875041691174","users":null}

Line by line:

  1. $ twurl /1.1/statuses/update.json --header 'Content-Type: application/json' -d '{"status":"Test"}' runs twurl, a command-line program for talking to Twitter's API. The $ is just the shell prompt. The first argument is the endpoint being called, the ordinary status update endpoint. --header 'Content-Type: application/json' tells the server that the body of the request is formatted as JSON, a common text format for structured data. -d '{"status":"Test"}' is the body itself: a JSON object with one field, status, set to Test. In plain terms: "post the word Test as a status".
  2. {"request":"\/1.1\/statuses\/update.json","error":"Read-only application cannot POST."} is the server's answer. It repeats which request was made and returns an error field saying the application is read-only and cannot POST. POST is the HTTP method used to send data and create or change something; GET is the method used to fetch something. The server refused before doing anything.
  3. $ twurl /fleets/v1/create -X POST --header 'Content-Type: application/json' -d '{"text":"Hey yo"}' calls the Fleet creation endpoint instead. -X POST states the HTTP method explicitly. The body is a JSON object with one field, text, set to Hey yo. Same kind of token, same kind of request, different address.
  4. The long response is a success. It contains a fleet object with a fleet_id (F1-328253875041691174), a fleet_thread_id (T1-328253875041625638), the submitted text of Hey yo, a created_at timestamp, an expiration timestamp about 24 hours later, and the user_id of the account the Fleet belongs to. The same fleet_id and fleet_thread_id are repeated at the top level of the response.

The first response is the expected refusal: Read-only application cannot POST. The second response is a success. In other words, the write went through with a token that should only be able to read.

Why it happened

The report's conclusion is that the Fleet-related endpoints did not run the permission check that the ordinary Twitter API endpoints run before processing a request. On POST /1.1/statuses/update.json the check happens before the API logic and produces the Read-only application cannot POST. error; on POST /fleets/v1/create the request was processed and the Fleet was created.

The report does not describe the server-side implementation, so the exact reason the check was missing from the Fleet code path is not stated. What the report does establish is the observable difference in behaviour between the two endpoint families for the same class of token.

In security terms this is a privilege escalation: a program that was only supposed to be able to look at things was able to change things. The permission it held was lower than the action it managed to perform.

What an attacker could have done

A third-party application holding only the READ permission could create and delete Fleets through the Fleet API. The researcher's own demonstration is the creation of a Fleet with a read-only token. The report's summary states that creation and deletion were both possible; the request and response shown in the article cover creation.

The condition for exploitation is that the attacker has a third-party application authorised with a read-only token.

How Twitter fixed it

Twitter fixed the issue quickly: it was reported on 12 November and fixed by 18 November. The fix was not to add the missing permission check to the Fleet endpoints. Instead, Twitter changed things so that third-party applications cannot call the Fleet-related APIs at all. The report notes that the fact that third-party applications could use the Fleet APIs at all appears to have been considered the problem, and the fix was to stop third-party applications from calling them.

In the door comparison: rather than putting a guard on the new door, Twitter bricked it up for outside apps entirely.

Similar things worth testing

  • New feature endpoints on the same platform. Enumerate endpoints introduced with a recently shipped feature and call each one with a read-only token. A positive result is a successful write response, such as a created object with an ID, where the equivalent call on an established endpoint returns a read-only refusal.
  • Endpoint families that bypass the shared authorisation layer. Compare the error behaviour of an old endpoint and a new one for the same token and method. A positive result is the old endpoint rejecting the request before any processing while the new one returns a normal success body.
  • Permission scope checks per HTTP method. For each endpoint, try the write methods (POST, DELETE, and so on) with a token that only has read scope. A positive result is any state change visible in the response or in the account afterwards.
  • Client-side endpoint discovery. Decompile or otherwise inspect an official client for a new feature and grep for the feature name to find endpoint strings, then test those endpoints directly. A positive result is an endpoint that accepts requests from a third-party application context at all.

Timeline

Date Event
2020/11/10 Twitter releases Fleets in Japan
2020/11/11 Fleets become available on the researcher's device
2020/11/12 Vulnerability found and reported
2020/11/13 Twitter: currently investigating
2020/11/14 Twitter: accepted as a vulnerability
2020/11/18 Twitter: vulnerability fixed
2020/12/15 Twitter: bounty amount decided
2021/01/05 Vulnerability disclosed

Three days after the fix, another researcher tweeted that Fleet images were not removed from the CDN after 24 hours, so deleted Fleets could still be viewed. A CDN is a network of servers that delivers files such as images to users. The report mentions this as an aside on how short the window for working on the Fleet implementation was.

Glossary

  • API: the set of addresses and rules a program uses to ask a service to do something, like a menu you can order from.
  • Endpoint: one specific address in an API, for example the one that creates a Fleet.
  • Authentication: proving who you are to a service.
  • Authorisation: what a service then allows you to do.
  • Token: a secret string that proves which app or user is making a request and what it may do, like a wristband at an event.
  • Read-only token: a token that may fetch information but not change anything.
  • Permission / scope: the specific rights attached to a token, such as READ.
  • Privilege escalation: doing something with more power than your permissions should allow.
  • Third-party application: a program made by someone other than the platform owner that is allowed to use part of the platform's API.
  • Fleet: a short-lived post on Twitter that expires after a set time.
  • Obfuscation: deliberately making code hard for humans to read, for example by renaming things to meaningless names.
  • Decompiling: turning a compiled program back into something close to readable source code.
  • apktool, dex2jar, CFR: tools used to take an Android app apart and make its code readable.
  • grep: a command-line tool that searches files for a word and prints the matching lines.
  • Gist: a small GitHub page for sharing snippets of text or code.
  • twurl: a command-line program for sending requests to Twitter's API.
  • HTTP method: the verb of a request; GET fetches, POST sends data and creates or changes something, DELETE removes.
  • JSON: a common text format for structured data, made of names and values in curly braces.
  • Header: extra information attached to a request, such as the format of the body.
  • CDN: a network of servers that delivers files such as images to users.
  • Bug bounty programme: a scheme where a company pays researchers for reporting vulnerabilities to it.

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.