Skip to content
Access control Disclosed report Advanced CVE-2020-15662

Rogue download handler can be injected by any web contents

Firefox for iOS injects its privileged download handler into web pages only at document end, so any page can define that same property first as non-writable and keep control of it. A malicious page could then capture the URL a victim chooses to download from another origin, and also capture the security token used to call privileged browser features, letting it disable Tracking Protection.

Muneaki Nishimura Follow

Originally disclosed on Mozilla

  • Fixed in 4 days
  • Paid in 9 days
  • Disclosed after 4 days
Text
Created attachment 9164587
Demo cross_origin_data_leakage (Example A)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.2 Safari/605.1.15

Steps to reproduce:

Any web content can define rogue download handler (window.__firefox__.download).
That can be a cause of several security issue.

Example (A). Cross Origin URL Leakage
(1) Victim visits http://csrf.jp/2020/download_handler_injection_cross_origin_data_leakage.html .
    This page has an <iframe> that shows CERN's website (info.cern.ch).
(2) Victim long taps a hyperlink in the CERN's page and choose "Download Link" from context menu.
(3) Parent frame (csrf.jp) shows the URL that Victim tries to download in <iframe>.

Example (B). Security Token Leakage
At first, Firefox for iOS uses Security Token to identify that privileged JS bridge is called from browser frame (but not from web contents). If the Token is leaked, any web contents can abuse browser feature, e.g., disabling Tracking Protection.
(1) Victim visits http://csrf.jp/2020/download_handler_injection_security_token_leakage.html
(2) Victim long taps a hyperlink "Download Juicy Content Here".
    Then the leaked Security Token is shown in the page.
(3) Push "Disable Tracking Protection by abusing securityToken" button in the page.
    Then Tracking Protection is disabled for csrf.jp.
(4) In order to check if the protection is really off, push "Show window.fetch object" button.
    If the protection is on, window.fetch object should be the following function code because Tracking Protection overrides the navive fetch() function.
    https://github.com/mozilla-mobile/firefox-ios/blob/76faae8c6c94e22c8fbc0de72e2d06f615738e2c/content-blocker-lib-ios/js/TrackingProtectionStats.js#L132
    But if the protection is disabled, window.fetch object shows [native code].


Actual results:

The reason why legitimate download handler is changed is that DownloadHelper.js is injected at the timing of AtDocumentEnd.
https://github.com/mozilla-mobile/firefox-ios/blob/76faae8c6c94e22c8fbc0de72e2d06f615738e2c/Client/Frontend/UserContent/UserScripts/AllFrames/AtDocumentEnd/DownloadHelper.js#L8

WKWebView's JS hook lifecycle is below.
[1] AtDocumentStart -> [2] Load web document -> [3] AtDocumentEnd

The exploit code below is executed at [2] and then define the handler as an immutable object. So the setting of legitimate handler at [3] is rejected.
'''
Object.defineProperty(window.__firefox__, "download", {
  enumerable: true,
  configurable: true,
  writable: false,
  value: function(url, securityToken) {
    window.securityToken = securityToken
  }
});
'''


Expected results:

The legitimate download handler (window.__firefox__.download) should be set at [1] AtDocumentStart.

The original report as published on Mozilla's Bugzilla, by Muneaki Nishimura. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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

The privileged download handler is injected at AtDocumentEnd, after page scripts have run, so page script can pre-define the property as non-writable and block the legitimate handler.

Impact

A malicious page could learn which URL a victim downloads from another site and could obtain the browser's security token to disable Tracking Protection for itself.

What the attacker needed

Victim uses Firefox for iOS; victim visits attacker page; victim long-taps a link and downloads

The fix

The legitimate download handler should be installed at AtDocumentStart, before any page script runs.

How it was found

  1. Victim opens the attacker's page, which contains an iframe showing another site.
  2. Victim long-taps a link inside the framed site and chooses the download option.
  3. The attacker's parent page reads and displays the URL the victim tried to download.
  4. In the second example, the victim long-taps a link and the leaked security token is shown on the page.
  5. The victim presses a button that uses the token to disable Tracking Protection for the attacker's site.
  6. The victim checks the fetch object to confirm protection is off.

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 for iOS adds a small helper object into every page so the browser can offer a 'download this link' option. The page's own code runs before that helper is added, so a malicious page can claim the name first and lock it, meaning the browser's real helper never takes effect. The fake helper then receives the download link and a secret token the browser uses to trust privileged requests.

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.

More by Muneaki Nishimura

View all

74 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.