content:// provider allows websites to remotely steal any file from the device if the path is known
Firefox for Android's content provider was misconfigured to allow access to any file on the device, and a website could exploit this by using an intent to open a crafted file that then loads private files and exfiltrates their contents. An attacker could steal cookies or any other file if the path is known.
Originally disclosed on Mozilla
- Fixed in 16 days
- Paid in 17 days
- Disclosed after 16 days
Created attachment 9158004 attachments.zip
The following report is in Markdown format, consider using a reader for better experience.
Environment
- Device: HTC m8
- OS version: Android 9
- Package name: org.mozilla.firefox
- App version: 68.9.0 (
versionCode2015701353) (stable channel)
Proof of concept
Pre-conditions:
- Firefox installed
- Python3 installed
- ngrok (optional for easy tunneling)
Steps:
-
Start the
server.py(see attachments) using the following command:$ python3 server.py <WEBSITE> <PORT_TO_LISTEN>The
<WEBSITE>is the URL that is going to be opened in the device without scheme (Examples:192.1.1.1,myDomain.com,192.6.1.3:8080).The
<PORT>is the port for the server -
Open the website above in Firefox for Android
Result
- A javascript alert is shown with the contents of the cookies database
Expected result
- No private file should be accessed
Detailed explanation
When the webiste is opened in Firefox, a webpage is served that contains a <iframe> that downloads a file named profile.ini to /sdcard/Download/profile.ini and opens it after a short delay using this href:
android-app://org.mozilla.firefox/content/org.mozilla.firefox.fileprovider/root/sdcard/Download/profiles.ini#Intent;type=text/html;end
This Intent orders Firefox to open the URI content://org.mozilla.firefox.fileprovider/root/sdcard/Download/profiles.ini. Firefox will download this content:// URI to /data/data/org.mozilla.firefox/cache/contentUri while rendering it. The name is maintained so a new file called /data/data/org.mozilla.firefox/cache/contentUri/profiles.ini has been now created.
The contents of profile.ini can be seen in server.py (method get_profiles_html) but basically it's a HTML page that contains an <iframe> that loads another content:// URI and trigger a javascript function after a while (more info bellow).
The URI loaded is:
content://org.mozilla.firefox.fileprovider/data/user/0/org.mozilla.firefox/files/mozilla/profiles.ini
This provider is misconfigured and contains the following entry in its XML configuration file (provider_paths.xml):
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<root-path name="root" path="."/>
</paths>
Firefox is using root-path with path . which essentially allows all files to be resolved by this provider. This allows private files from Firefox to be accessed.
The logic to download the file from a content:// URI is rewriting the file, so the contents of profile.ini (the current page loaded) were now overriden and contains the values of /data/user/0/org.mozilla.firefox/files/mozilla/profiles.ini.
After the above <iframe> is loaded, the javascript function triggers. This javascript reads the contents of the current page (this bypass CORS protections because the file is the same). The current page is now the profiles.ini file from Firefox. This file contains the path to the cookies directory. After the path has been retrieved from the file, it repeats the process again but for /data/user/0/org.mozilla.firefox/files/mozilla/<PATH>/cookies.sqlite.
**Resuming: **
This is a combination of multiple misconfigurations/flawed logic:
- Firefox allows private files to be opened in it
- Content provider from Firefox allows private file inclusion
- Files downloaded from content providers with the same name are downloaded to the same place.
Vulnerable code
res/xml/provider_paths.xml
<root-path name="root" path="."/>
Remediation
Firefox should not allow private files to be accessed by it's provider. A suggested fix here is to use instead:
<root-path name="root" path="/storage/"/>
Firefox should also not override the contents from contentUri otherwise it'll be possible to override the contents of a file and retrieve it afterwards.
Attachments
-
server.py
Python3 server containg the full proof of concept.
-
video.mp4
A video showing the exploit in action.
Impact
- Remote file steal of cookies or any other file if the attacker knows the path which is easy for common applications.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the content provider's path configuration used a root-path with path '.' allowing access to all files, and the app downloaded content URIs to a predictable location without proper validation.
Impact
An attacker could steal cookies or any other file if the path is known, which is easy for common applications.
What the attacker needed
Firefox for Android installed; Victim visits attacker's website; Attacker knows file path
The fix
Firefox should restrict the content provider to only allow access to specific directories like /storage/ and avoid overriding downloaded content URIs.
How it was found
- Start the Python server with the target website and port.
- Open the website in Firefox for Android.
- The served page contains an iframe that downloads a file to the Downloads folder and opens it via an intent.
- The intent causes Firefox to open a content URI, which downloads the file to a cache location.
- The downloaded file contains JavaScript that reads the current page (now the private file) and repeats the process to read the cookies database.
- A JavaScript alert displays the contents of the cookies database.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A content provider is a way for Android apps to share data with other apps. Firefox for Android had a setting that let its content provider access any file on the phone, not just its own. A malicious website could trick Firefox into opening a file that then reads private files like cookies and sends them to the attacker.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.