Path traversal in upload feature allows internal file overwrite
A malicious file picker app could return a crafted display name containing path traversal sequences, causing Firefox to overwrite its own profile.ini file. This allowed the attacker to redirect Firefox's profile to a directory controlled by the malicious app.
Originally disclosed on Mozilla
- Fixed in 4 days
- Paid in 16 days
- Disclosed after 4 days
Summary
A missing sanitisation of file names allows a malicious file picker to overwrite any file in Firefox's internal directory.
Environment
- Device: HTC m8
- OS version: Android 9
- Package name: org.mozilla.firefox
- App version: 68.10.1
Proof of concept
Pre-conditions:
- PoC installed (see attachments)
- Firefox installed
- Server running the attached HTML page (or directly open it)
Steps:
- Open the webpage containing the upload logic
- Tap Upload and choose Files
- Choose
mozillatraverseas the file picker - Restart Firefox
- Check PoC public app directory
/sdcard/Android/app.kans.mozillatraverse/files/
Result
profile.ini is overwritten and now points to the location of the profile to another apps directory
Expected result
There should be no private file overwrite.
Detailed explanation
When the PoC app is chosen as the picker, the following URI is returned to Firefox:
content://app.kans.mozillatraverse.provider
This URI is a content:// URI that belongs to the PoC app itself. Firefox will process this URI and queries the contents of the cursor which are:
| _display name | _size |
|---|---|
/../../../../../../../../../data/data/org.mozilla.firefox/files/mozilla/profiles.ini |
123 |
Firefox will create a temporary file with the contents of content://app.kans.mozillatraverse.provider and to create this temporary file, it uses the _display_name column to create a file with the same name.
Because the contents of this column are not sanitised, the path concatenation leads to a path traversal:
String fileName = cursor.getString(0);
//...
tempDir = FileUtils.createTempDir(cacheDir, "tmp_");
File file = new File(tempDir, fileName);
This causes the contents of profile.ini to be overwritten with:
[Profile0]
Name=default
Default=1
IsRelative=0
Path=/../../../../../../../../../../sdcard/Android/data/app.kans.mozillatraverse/files/
[General]
StartWithLastProfile=1
After restarting Firefox, sensitive information is now stored and under controll of the malicious app.
Vulnerable code
String fileName = cursor.getString(0);
Remediation
Firefox should sanitise the contents of this column before using them:
String fileName = cursor.getString(0);
// sanitize
int index = fileName.lastIndexOf(separatorChar)
fileName = index < prefixLength ? path.substring(prefixLength) : path.substring(index + 1)
Attachments
- PoC.zip - Source code of PoC
- poc.apk - Compiled binary
- index.html - HTML file uploaded
- video.mp4 - Video showing exploit in action
Impact
A malicious file picker could deploy a targeted attack for Firefox (by calling getCallingActivity for example) and tamper any file inside the private directory of Firefox.
In this PoC, I've changed the path of the profile to another one. Any file can be affected by this.
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
Firefox did not sanitise the file name obtained from the file picker's content provider before using it to create a temporary file, allowing path traversal.
Impact
A malicious file picker could overwrite any file in Firefox's private directory, potentially leading to further compromise.
What the attacker needed
Firefox installed on Android; Malicious file picker app installed; User selects the malicious picker during upload
The fix
Firefox should sanitise the file name from the content provider before using it to create a file.
How it was found
- Open the webpage containing the upload logic
- Tap Upload and choose Files
- Choose mozillatraverse as the file picker
- Restart Firefox
- Check PoC public app directory /sdcard/Android/app.kans.mozillatraverse/files/
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.
When you pick a file in an app, the app asks another app (the file picker) for the file's name and location. Firefox trusted that name without checking it, so a malicious file picker could give a name like '../../profile.ini' and trick Firefox into overwriting its own settings file. This let the attacker change where Firefox stores your data.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.