Skip to content
CSRF Write-up Intermediate

Facebook for Android - CSRF Attack

The Facebook for Android app allowed an attacker to launch internal and non-exported deeplinks by supplying an unvalidated URI through a music bar feature, bypassing deeplink restrictions. This could lead to cross-site request forgery attacks, arbitrary JavaScript execution in a webview, and phishing.

Ashley King Follow

Published on ash-king.co.uk

Bounty$4,000 View original

The report was submitted as a collaboration between myself and Rahul Kankrale. The split was 70% Ash & 30% Rahul.

Ashley King, on ash-king.co.uk

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 for Android (FB4a) is the main Android client for Facebook, and Facebook Workplace ships as a separate application. Both were affected by the issue described here. The target of the attack is the main tab activity of the app, FbMainTabActivity, which is the activity that hosts the primary UI of the application.

Normally, the main tab activity is launched by the app itself and its intent is not something a third party application should be able to shape. The feature involved here is a "music" bar that can be attached across the bottom of the main view. When that bar is present, tapping anywhere in it opens a destination URI supplied through the intent extras. That destination is meant to be a Facebook-controlled deeplink, but nothing in the routine checked where it came from.

From the original on ash-king.co.uk

The report was submitted as a collaboration between Ashley King and Rahul Kankrale, with a 70% / 30% split.

Setup

The preconditions are simple and do not require any special access to the victim's account:

  • UserA is authenticated with FB4a on their device.
  • UserA has a Fb_PoC.apk installed on the same device.

The proof of concept is a separate Android application. There is no mention of a rooted device, a debug build, or any special permission being required.

Finding it

The issue lay in the class com.facebook.katana.activity.FbMainTabActivity, under the handleNewIntent method.

From the original on ash-king.co.uk

As shown in the image of that routine, it required the following ruleset to be satisfied before it would act on the incoming intent:

  • Must include an extra boolean of should_show_rum_player with a value of true
  • Must include an extra string of rum_destination_uri
  • Must include a flag of FLAG_ACTIVITY_NEW_TASK

What made this interesting is that rum_destination_uri does not go through any sort of validation. Any valid deeplink can be supplied, including deeplinks that are internal to Facebook or belong to activities that are not exported. Those deeplinks are normally protected by custom restrictions around deeplink handling, and this path bypasses them entirely.

Exploitation

The attack is a cross-site request forgery against the Android application: a malicious app on the device causes the Facebook app to perform an action on behalf of the signed-in user, without that user intending it.

Step 1: Launch the proof of concept

UserA launches the installed application FB_PoC.

Step 2: The Facebook app is brought to the front with an injected music bar

UserA is redirected to the Facebook application with a new "Music" bar attached to the bottom of the view. This happens because FbMainTabActivity is launched with the extras and flag described above, so the main UI is overridden and the bar is drawn across the bottom of the screen.

Step 3: The victim taps the bar

UserA clicks anywhere in this bar, which opens an attacker-controlled deeplink. Because the destination URI is taken from rum_destination_uri without validation, the attacker chooses what opens: a non-exported deeplink or an internal Facebook deeplink.

The behaviour flow can be seen here:

Or watch on YouTube
From the original on ash-king.co.uk

An attacker's payload may look similar to the below. The report does not reproduce the exact intent code, so the three requirements above are the payload: the boolean extra should_show_rum_player set to true, the string extra rum_destination_uri carrying the chosen deeplink, and the FLAG_ACTIVITY_NEW_TASK flag on the intent that starts FbMainTabActivity.

Root cause

The mistake is in handleNewIntent in com.facebook.katana.activity.FbMainTabActivity. The method uses the rum_destination_uri extra as the target of the music bar, and that URI goes through no validation. The three conditions (the should_show_rum_player boolean, the rum_destination_uri string and FLAG_ACTIVITY_NEW_TASK) form the ruleset the routine required.

The existing defence was the custom restriction layer around deeplinks, which is meant to stop third parties from launching internal or non-exported deeplinks. The music bar path bypasses the custom restrictions around deeplinks, so internal and non-exported deeplinks can be launched. The report does not describe the internals of that restriction layer.

Impact

  • A malicious actor is able to launch internal and non-exported deeplinks on a device on behalf of a user, bypassing custom restrictions around deeplinks.
  • A chained vulnerability allows an actor to run arbitrary JavaScript on a webview inside the FB4a app on behalf of a user. During the research, two additional internal deeplinks vulnerable to XSS were identified, making the chain very similar to the earlier report "Breaking The Facebook For Android application".
  • Overriding webviews with custom URLs can lead to phishing, because the activity does not expose the URL.

Facebook's own summary of the risk was that this could have allowed a third party to launch internal deeplinks, which could result in various CSRF attack possibilities such as de-anonymisation.

Fix

The resolution was to completely remove the code block relating to this music bar.

Timeline

Date Event
14 Dec 2020 Reported to Facebook
21 Dec 2020 More information requested; unable to reproduce
5 Jan 2021 Triaged
18 Jan 2021 Fixed
28 Jan 2021 $4000 total bounty paid

The response from the Facebook security team stated that they had decided to award a bounty of $2800, and that Facebook fulfils its bounty awards through Bugcrowd and HackerOne.

Variants to test

  • Other activities that accept extras from external intents and use a URI or destination string from those extras. A positive result is an activity that can be started by a third-party app and that opens an attacker-chosen deeplink without validation.
  • Deep link handlers that check a boolean or flag extra as a precondition for a privileged path. A positive result is a path where the extra is the only gate and the destination is not validated.
  • Webview-hosting activities that do not display the URL. A positive result is a webview that can be pointed at an attacker-controlled URL, which enables phishing.
  • Internal deeplinks that render HTML or accept parameters reflected into a webview. A positive result is JavaScript execution inside the app's webview, which turns the deeplink launch into an XSS chain.
  • Non-exported activities reachable through an exported activity that forwards intents. A positive result is a non-exported component being launched on behalf of the user from a third-party app.

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

What happened, in plain words

Facebook for Android is the main Facebook app you install from the Play Store. Facebook Workplace is a separate app for companies, built on the same code. Both apps had a flaw that let another app on the same phone take over part of the Facebook screen and make it open a link of the attacker's choosing.

The part of the app involved is the main screen with the tabs at the bottom (the activity called FbMainTabActivity). An activity is one screen of an Android app. Normally only the Facebook app itself decides what that screen shows. But the app also had a feature: a "music" bar that could be attached across the bottom of the main screen. When that bar is there, tapping anywhere in it opens a link (a deeplink) that was passed in when the screen was started. The app never checked where that link came from.

So a malicious app on the phone could start the Facebook main screen, ask for the music bar, and supply its own link. The victim sees the normal Facebook app with an extra bar at the bottom, taps it, and the app opens whatever the attacker wanted, including links that Facebook normally blocks other apps from opening.

From the original on ash-king.co.uk

The report was a collaboration between Ashley King and Rahul Kankrale, with a 70% / 30% split.

The pieces you need to know

Before the steps, a few ideas from zero:

  • App (application): a program on a phone. On Android, apps are packaged as .apk files.
  • Activity: one screen of an Android app. When you tap an icon, Android starts an activity.
  • Intent: the message Android uses to ask an app to start an activity. It can carry small pieces of data called extras (for example a true/false value, or a piece of text), and flags, which are switches that change how the activity is started.
  • Exported activity: an activity that other apps are allowed to start. A non-exported activity is meant to be startable only from inside its own app.
  • Deeplink: a link that opens a specific place inside an app, rather than a web page in a browser. Think of it as a shortcut that jumps straight to a particular screen.
  • CSRF (cross-site request forgery): an attack where one site or app makes another one do something on the user's behalf, without the user meaning to. The everyday comparison: someone quietly fills in a form for you and hands you the pen so your signature ends up on it. Here the "someone" is a malicious app and the "form" is an action inside Facebook.
  • XSS (cross-site scripting): getting a web page or webview to run JavaScript that the site's owner did not intend. JavaScript is the programming language browsers run; if an attacker can run their own, they can do things in the page as the user.
  • Webview: a small browser window embedded inside an app, used to show web content without leaving the app.
  • Phishing: tricking someone into entering information on a fake page that looks real.

Setup

The preconditions are simple and do not need any special access to the victim's account:

  • UserA is signed in to Facebook for Android on their phone.
  • UserA has a Fb_PoC.apk installed on the same phone.

The proof of concept is just another Android app. Nothing in the report mentions a rooted phone, a special developer build, or any extra permission being needed.

Finding it

The problem was in the class com.facebook.katana.activity.FbMainTabActivity, in the method handleNewIntent. A class is a named block of code inside an app, and a method is a named routine inside that class. handleNewIntent is the routine that runs when the activity receives a new intent, that is, when another app asks it to do something.

From the original on ash-king.co.uk

As the image of that routine shows, it only acted on the incoming intent if three conditions were met:

  • Must include an extra boolean of should_show_rum_player with a value of true
  • Must include an extra string of rum_destination_uri
  • Must include a flag of FLAG_ACTIVITY_NEW_TASK

In plain words: the intent had to carry a true/false value named should_show_rum_player set to true (this is what turns the music bar on), a piece of text named rum_destination_uri (this is the link the bar will open), and a switch named FLAG_ACTIVITY_NEW_TASK (this tells Android to start the activity as a fresh task, which is how the Facebook app gets brought to the front).

The important part is that rum_destination_uri was never checked. Any valid deeplink could be supplied, including links that are internal to Facebook or that belong to activities which are not exported. Those links are normally protected by Facebook's own restrictions on deeplink handling, and this path skipped those restrictions completely.

Exploitation

The attack is a CSRF against the Android app: a malicious app on the phone makes the Facebook app do something on behalf of the signed-in user, without the user intending it.

Step 1: Launch the proof of concept

UserA launches the installed application FB_PoC.

Why: the proof of concept is the attacker's app. Starting it is the only thing the victim does deliberately. Everything after this happens because the proof of concept sends an intent to Facebook.

Step 2: The Facebook app is brought to the front with an injected music bar

UserA is redirected to the Facebook application with a new "Music" bar attached to the bottom of the view. This happens because FbMainTabActivity is started with the extras and flag described above. The main screen is overridden and the bar is drawn across the bottom.

Why: the attacker needs the victim to see something that looks like normal Facebook, so the victim trusts it. The bar is the trap.

Step 3: The victim taps the bar

UserA clicks anywhere in this bar, which opens an attacker-controlled deeplink. Because the destination comes from rum_destination_uri without validation, the attacker chooses what opens: a non-exported deeplink or an internal Facebook deeplink.

Why: this is the moment the attacker's link is followed inside the Facebook app, with the victim's session. The victim thinks they tapped a Facebook feature.

The behaviour flow can be seen here:

Or watch on YouTube
From the original on ash-king.co.uk

An attacker's payload may look similar to the below. The report does not reproduce the exact intent code, so the three requirements above are the payload: the boolean extra should_show_rum_player set to true, the string extra rum_destination_uri carrying the chosen deeplink, and the FLAG_ACTIVITY_NEW_TASK flag on the intent that starts FbMainTabActivity.

Line by line, in plain words:

  • should_show_rum_player set to true is the switch that asks Facebook to draw the music bar.
  • rum_destination_uri is the text that says where the bar should go when tapped. The attacker fills this in with their own link.
  • FLAG_ACTIVITY_NEW_TASK is the switch that makes Android start the Facebook screen as a new task, bringing the Facebook app to the front.

Root cause

The mistake is in handleNewIntent in com.facebook.katana.activity.FbMainTabActivity. The method uses the rum_destination_uri extra as the target of the music bar, and that URI is not validated. The three conditions (the should_show_rum_player boolean, the rum_destination_uri string and FLAG_ACTIVITY_NEW_TASK) are what the routine required.

The existing defence was the custom restriction layer around deeplinks, meant to stop third parties from launching internal or non-exported deeplinks. The music bar path bypasses Facebook's custom restrictions around deeplinks, so internal and non-exported deeplinks can be opened. The report does not describe how that restriction layer works inside.

Impact

  • A malicious actor is able to launch internal and non-exported deeplinks on a device on behalf of a user, bypassing custom restrictions around deeplinks.
  • A chained vulnerability allows an actor to run arbitrary JavaScript on a webview inside the FB4a app on behalf of a user. During the research, two additional internal deeplinks vulnerable to XSS were identified, making the chain very similar to the earlier report "Breaking The Facebook For Android application".
  • Overriding webviews with custom URLs can lead to phishing, because the activity does not show the URL.

Facebook's own summary of the risk was that this could have allowed a third party to launch internal deeplinks, which could result in various CSRF attack possibilities such as de-anonymisation. De-anonymisation means linking activity back to a real person who expected to stay anonymous.

Fix

The resolution was to completely remove the code block relating to this music bar. In other words, the feature was taken out rather than patched.

Timeline

Date Event
14 Dec 2020 Reported to Facebook
21 Dec 2020 More information requested; unable to reproduce
5 Jan 2021 Triaged
18 Jan 2021 Fixed
28 Jan 2021 $4000 total bounty paid

Triaged means the security team accepted the report as a real issue and started tracking it. The response from the Facebook security team stated that they had decided to award a bounty of $2800, and that Facebook fulfils its bounty awards through Bugcrowd and HackerOne.

Variants to test

If you want to look for similar issues in other apps, these are the patterns worth trying. Each one is a question you ask about the app, and a sign that you found something.

  • Other activities that accept extras from external intents and use a URI or destination string from those extras. A positive result is an activity that can be started by a third-party app and that opens an attacker-chosen deeplink without validation.
  • Deeplink handlers that check a boolean or flag extra as a precondition for a privileged path. A positive result is a path where the extra is the only gate and the destination is not validated.
  • Webview-hosting activities that do not display the URL. A positive result is a webview that can be pointed at an attacker-controlled URL, which enables phishing.
  • Internal deeplinks that render HTML or accept parameters reflected into a webview. A positive result is JavaScript execution inside the app's webview, which turns the deeplink launch into an XSS chain.
  • Non-exported activities reachable through an exported activity that forwards intents. A positive result is a non-exported component being launched on behalf of the user from a third-party app.

Glossary

  • Activity: one screen of an Android app; the unit Android starts when you open part of an app.
  • APK: the file format Android apps are packaged in.
  • Boolean: a value that is either true or false.
  • Class: a named block of code inside a program.
  • CSRF (cross-site request forgery): an attack where one app or site makes another act on the user's behalf without the user intending it.
  • De-anonymisation: revealing who a person is when they expected to stay anonymous.
  • Deeplink: a link that opens a specific place inside an app rather than a web page.
  • Extra: a small piece of data attached to an intent, such as a true/false value or a piece of text.
  • Flag: a switch attached to an intent that changes how Android starts the activity.
  • Intent: the message Android uses to ask an app to start an activity, optionally carrying extras and flags.
  • JavaScript: the programming language web pages run in a browser or webview.
  • Method: a named routine inside a class.
  • Non-exported activity: an activity meant to be startable only from inside its own app.
  • Proof of concept (PoC): a small program built to demonstrate that a vulnerability is real.
  • String: a piece of text.
  • Triaged: accepted by a security team as a real issue and put into their tracking.
  • Webview: a small browser window embedded inside an app.
  • XSS (cross-site scripting): getting a page or webview to run JavaScript the owner did not intend.

More from Meta

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site request forgery (CSRF)

The lesson behind this report.

Another site makes a signed-in user's browser perform an action they did not intend.