Firefox iOS download feature SECURITY_TOKEN check bypass and path traversal
Firefox for iOS injects a JavaScript object into every page that exposes a download handler, and the handler's security token check can be bypassed by sending the message directly. The filename parameter is then passed unsanitised to a path-building function, allowing path traversal that writes files outside the intended download directory within the app sandbox.
Originally disclosed on Mozilla
- Fixed in 29 hours
- Paid in 19 days
- Disclosed after 29 hours
Firefox on iOS injects an object named '__firefox__' to every page.
For example, __firefox__.download is implemented here:
https://github.com/mozilla-mobile/firefox-ios/blob/52e120c83644891d0137655fa18e3ef81433d005/Client/Frontend/UserContent/UserScripts/AllFrames/AtDocumentEnd/DownloadHelper.js#L13
To prevent abuse, it has a random SECURITY_TOKEN check:
'''js
if (securityToken !== SECURITY_TOKEN) {
return;
}
'''
It makes no sense at all since we can manually send the message:
'''js
const str = 'hello world'
webkit.messageHandlers.downloadManager.postMessage({
filename: '../oops.js',
base64String: btoa(str),
mimeType: 'application/octet-stream',
size: str.length
})
'''
Yeah, poc is pretty simple. DownloadContentScript does no further security check so we can trigger download without user interaction.
https://github.com/mozilla-mobile/firefox-ios/blob/2cf1b45864733724730a95b6c65d2167ddd3ba92/Client/Frontend/Browser/DownloadContentScript.swift#L24
This function `uniqueDownloadPathForFilename` simply takes our filename param and pass to appendingPathComponent, hence it suffers from path traversal:
https://github.com/mozilla-mobile/firefox-ios/blob/cc3972532e9d66f07038d4528a77a8937751268d/Client/Frontend/Browser/DownloadQueue.swift#L42
This bug is less exploitable, because:
* It can only write file in app sandbox
* It does not override existing files. A new file will be created with a suffix like "hello (1).js"
* There's no such thing like "dynamically loading a jar" on iOS
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 security token check is performed inside page-injected JavaScript that the page itself can bypass, and the filename is passed to appendingPathComponent without sanitisation.
Impact
An attacker could write arbitrary files into the app sandbox without user interaction, but cannot overwrite existing files and cannot execute the written files on iOS.
What the attacker needed
Victim opens a malicious page in Firefox iOS; no user interaction needed
How it was found
- Load a page in Firefox for iOS that runs attacker-controlled JavaScript.
- Send a message directly to the downloadManager message handler with a filename containing '../'.
- The handler writes the decoded content to a path built from the unsanitised filename.
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.
Firefox on iPhone adds a small helper object to every web page so pages can ask the browser to download a file. The helper was supposed to check a secret code before doing anything, but any page can just send the same message itself and skip the check. The filename is then used to build a file path without cleaning it, so a name containing '..' can place the file in a different folder inside the app's own storage.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.