WebExtension can bypass warnings and run arbitrary programs with download.download & downloads.open
A WebExtension could bypass the warning dialog that normally appears before opening a downloaded executable file. By using a filename with a trailing null byte, the extension could cause the operating system to launch a dangerous file (such as a batch script) without any user warning.
- Fixed in 2 months
- Paid in 5 months
- Disclosed after 2 months
Created attachment 8897851
downloads-download-open.zip
Tested on Windows 7, Firefox 55.0.1 (20170809080026) and Firefox 57.0a1 (20170815100349)
Extensions written using the WebExtensions API are usually shielded from the user's OS and filesystem.
An extension can save arbitrary data to the user's filesystem using downloads.download.
And with downloads.open, the extension can open the file. If the file is dangerous (e.g. .exe opposed to .txt), then normally there is a warning dialog to make users aware that a program is being downloaded and run.
However, this check is trivial to bypass.
1. Load the attached extension (e.g. download, unzip it and load it via about:debugging).
2. On Windows, the extension will open a cmd shell (and start mspaint) without warning.
(When I tested on Linux, a text editor was opened without warning)
What happens is that:
1. The extension calls downloads.download with a file name that ends with a NULL byte (e.g. "foo.bat\x00").
2. downloads.open ultimately ends up calling DownloadIntegration.launchDownload, where the download prompt is only guarded behind whether a file is "executable" [1].
3. isExecutable is implemented in nsLocalFileWin.cpp, as nsLocalFile::IsExecutable. When faced with a trailing NUL byte, the blacklist-based check fails (because "cmd\x00" is not equal to "cmd").
4. Then mimeInfo.preferredAction is set to system, and mimeInfo.launchWithFile is called. [2]
5. The system will ignore the NUL byte and treat the file as "foo.bat" and spawn a shell.
In Firefox beta (56), a user gesture requirement was added to downloads.open (bug 1369782), which makes this bug only a tiny little bit less severe (extensions can open tabs at will and it is not unlikely for the user to click or type within that page).
What should have happened is that the file extension was recognized as dangerous, either at the WebExtension layer in ext-downloads.js, or in nsLocalFile::IsExecutable in nsLocalFileWin.cpp
[1] https://searchfox.org/mozilla-central/rev/13148faaa91a1c823a7d68563d9995480e714979/toolkit/components/jsdownloads/src/DownloadIntegration.jsm#607-617
[2] https://searchfox.org/mozilla-central/rev/13148faaa91a1c823a7d68563d9995480e714979/toolkit/components/jsdownloads/src/DownloadIntegration.jsm#648-657
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 executable check in nsLocalFile::IsExecutable compares the full filename including a trailing null byte against a blacklist, so a name like 'cmd\x00' does not match 'cmd' and the file is not flagged as executable.
Impact
An attacker could run arbitrary programs on the user's system without the usual warning dialog; in Firefox 56 and later a user gesture is required for downloads.open, which slightly reduces the severity.
What the attacker needed
Victim installs a malicious extension; Firefox on Windows (or Linux)
The fix
The file extension should have been recognised as dangerous, either in the WebExtension layer or in the executable check.
How it was found
- Load the provided extension via about:debugging.
- On Windows, the extension opens a command shell and starts Paint without any warning.
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 download a file that might run a program, your browser usually shows a warning. This report shows that a browser extension could trick the browser into skipping that warning by adding a hidden character to the filename. The operating system ignores that hidden character, so it still runs the program, but the browser's safety check does not recognise the file as dangerous.
What is Access control?
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.