Closed Bug 1684349 Opened 5 years ago Closed 2 years ago

DownloadHelper.js in Firefox for iOS leaks cross-origin download URLs

Categories

(Firefox for iOS :: General, defect, P4)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: sdna.muneaki.nishimura, Unassigned, NeedInfo)

References

()

Details

(Keywords: csectype-sop, reporter-external, sec-moderate, Whiteboard: [reporter-external] [client-bounty-form] [verif?])

Attachments

(1 file)

Attached image blob_url_leakage.gif —

DownloadHelper.js is a javascript used for downloading content of blob: URLs in web pages.
When downloading a blob: URL, this handler is executed in WKWebView and the handler gets the corresponding content of given blob: URL.

The handler is executed regardless of frames. If a blob: URL is downloaded in a subframe of a page then the handler in the parent window is called.
This behavior can be abused for stealing downloaded URLs in cross-origin subframes.

Actual attack is that the handler uses startsWith function of a page.
https://github.com/mozilla-mobile/firefox-ios/blob/ca2f5c98dd25b8f3026b2bd976450edff1853172/Client/Frontend/UserContent/UserScripts/AllFrames/AtDocumentStart/DownloadHelper.js#L30
So if a parent window manipulates startsWith in a page, download contents in cross-origin subframes are stolen.

The PoC of the attack is below.
http://csrf.jp/2020/download_handler_injection_cross_origin_data_leakage2.html

The attached animated GIF file also shows the attack.

Flags: sec-bounty?
Group: firefox-core-security → mobile-core-security
Type: task → defect
Component: Security → General
Product: Firefox → Firefox for iOS

violating the same-origin policy is horrible, but as a practical attack seems limited. what site uses blob: urls for downloads and why would users trust some random framed content on your site more than what you could do directly?

Flags: sec-bounty? → sec-bounty+
Priority: -- → P4

Tracking in JIRA for priority with https://mozilla-hub.atlassian.net/browse/FXIOS-4598

Hello, I'm an iOS developer considering giving this a try to fix. I'm trying to understand how the exploit works. Is the error still applicable?

Flags: needinfo?(sdna.muneaki.nishimura)

Thank you for your response.
This bug is no longer reproduced today because, during the past two years, relevant processing of DownloadHelper has been moved to the default content world, which separates the JavaScript context from the website's context.
https://github.com/mozilla-mobile/firefox-ios/blob/main/firefox-ios/Client/Frontend/Browser/OpenInHelper/DownloadHelper.swift#L68

The reason for this bug previously was that Firefox iOS injected the following JavaScript code into the parent window when downloading blob: data.
https://github.com/mozilla-mobile/firefox-ios/blob/main/firefox-ios/Client/Frontend/UserContent/UserScripts/AllFrames/AtDocumentStart/DownloadHelper.js#L8

By abusing this, it was possible to steal the URL of the blob: data downloaded in the subframe by tampering with startsWith method called internally by the JavaScript (see below).
https://github.com/mozilla-mobile/firefox-ios/blob/main/firefox-ios/Client/Frontend/UserContent/UserScripts/AllFrames/AtDocumentStart/DownloadHelper.js#L30

Currently, this JavaScript execution space is separated from website, so tampering with the startsWith method on the website doesn't affect DownloadHelper.

Flags: needinfo?(sdna.muneaki.nishimura)

Thank you for the response! Tagging Andrei and Andy for visibility

Flags: needinfo?(nfurlan)
Flags: needinfo?(abodea)
Flags: needinfo?(nfurlan)

It sounds like this is no longer reproducible but if anyone believes there are any remaining issues here which are still a concern please let me know. Thank you

Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Group: mobile-core-security → core-security-release
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: