Closed Bug 1293931 Opened 10 years ago Closed 10 years ago

Firefox Account command handler can be called from any origin

Categories

(Firefox for iOS :: General, defect)

Other
iOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
Tracking Status
fxios 5.2+ ---
fxios-v5.2 --- fixed
fxios-v6.0 --- fixed
fxios-v7.0 --- fixed

People

(Reporter: sdna.muneaki.nishimura, Assigned: bnicholson)

Details

(Keywords: reporter-external, sec-high)

Attachments

(1 file, 1 external file)

Attached image reproduced.png —
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7 Steps to reproduce: Account command handler doesn't check caller's origin (see following code) so any websites can call it. https://github.com/mozilla/firefox-ios/blob/master/FxAClient/Frontend/SignIn/FxAContentViewController.swift#L142 This handler is shown only in a special webview that is used for Firefox Account sign-in, but the webview still can open untrusted contents in some ways. The attacker can set his/her accounts to a victim's Firefox by invoking "Login" command with "accountCommandHandler" interface through malicious contents he/she sets. Actual results: 1. Tap "Sign In to Firefox" button in Settings menu and launch Firefox launch screen 2. Tap "Terms of Service" -> tap "Mozilla Privacy Policy" -> tap link of "Creative Commons license" 3. http://creativecommons.org can be loaded on the special webview that page is hosted by third-party and through plain text http: channel 4. If following JS code is injected from the attacker ----- var json = {"detail":{"bubbles":true,"data":{"customizeSync":false,"sessionToken":"*****","keyFetchToken":"*****","verified":true,"unwrapBKey":"*****","email":"PWNED@gmail.com","uid":"***","verifiedCanLinkAccount":true},"command":"login"},"type":"FirefoxAccountsCommand"} webkit.messageHandlers.accountsCommandHandler.postMessage(json); } ----- Here attacker's sessionToken, keyFetchToken and uid can be obtained from a response of following request beforehand. https://api.accounts.firefox.com/v1/account/login?keys=true It seems parameter unwrapBKey is not required. The attached is a picture when reproduced. Expected results: Account command handler should not be accessed from third-party resources.
This sounds bad, though it requires a bit of user interaction, so I'm marking it sec-high. Stefan, do you know who could look into fixing this? Thanks.
Flags: needinfo?(sarentz)
Keywords: sec-high
Should be a relatively straightforward fix -- just need to check origin of the message frame.
Assignee: nobody → bnicholson
Status: NEW → ASSIGNED
Flags: needinfo?(sarentz)
Muneaki: thanks for the great bug report! This is certainly a bug, and I think this can be leveraged to produce a security issue. This allows a 3rd party site to be compromised and pretend to be the Firefox Account server by messaging directly to the Chrome code. It can be exploited to exfiltrate the contents of the device as follows: 1) attacker creates account on FxA production service; 2) attacker gets FxA tokens for attack account; 3) attacker comprised 3rd party, injecting attack accounts "FxA tokens" in place of users real tokens; 4) iOS device syncs immediately, before user notices FxA email has been changed. (This could be very hard to notice even after change, if targeted email addresses with Unicode, etc are selected.) 5) attacker fetches user's synced data from attack account. The iOS FxA implementation is intended to never reveal sensitive tokens to the trusted content -- and it's worth auditing the code to ensure that password reset requests, for example, don't do something foolish in this way. Therefore, my initial analysis is that this attack doesn't allow to exfiltrate sensitive tokens from the user's actual account. As Brian says, as long as the origin of the postMessage in the attack scenario is correctly scoped to the 3rd party content, we can mitigate this attack. Again, thanks for the valuable report!
markh, kit: this is a novel attack on FxA's hosted content that I hadn't seen or considered. I believe that the WebChannel apparatus protects Desktop (and Android), but I want you to be aware of the method and consider ramifications in your area of expertise. (NI rather than CC so it doesn't get lost in the noise. Please add others you think should be aware.)
Flags: needinfo?(markh)
Flags: needinfo?(kcambridge)
(In reply to Nick Alexander :nalexander (Away Aug 9 - Aug 27) from comment #4) > markh, kit: this is a novel attack on FxA's hosted content that I hadn't > seen or considered. Wow!, I'd be happy if it could reach the border of your _novel_ vulnerability criteria here :-) https://www.mozilla.org/en-US/security/client-bug-bounty/
(In reply to Muneaki Nishimura from comment #5) > (In reply to Nick Alexander :nalexander (Away Aug 9 - Aug 27) from comment > #4) > > markh, kit: this is a novel attack on FxA's hosted content that I hadn't > > seen or considered. > > Wow!, I'd be happy if it could reach the border of your _novel_ > vulnerability criteria here :-) > https://www.mozilla.org/en-US/security/client-bug-bounty/ Muneaki -- heh, I'm not one of the folks who determines such bounties, so I wasn't trying to use _novel_ in such a precise way. It was, however, new to me: an inversion of the attack process, from "I take your credentials" to "I make you use my credentials". Novelty, however, might not be correct: the WebChannel process that all other Mozilla clients use explicitly prevents against this. That's a decision for the Bug Bounty program administrators to make. Thanks again!
As Nick mentioned, I strongly believe the WebChannel mechanism provides effective defense against this - not only is the origin of the message checked, that origin must be HTTPs, and the message must come directly from the site being trusted. While I'd be devastated to hear that's not true, I encourage anyone CCd on this bug to try and prove me wrong. (Also, see bug 1146724, fixed in 38+ - in that bug, a https page could wrap channel-hosting content in a webframe and "spy" on the messages going back and forwards between them. The fix for that caused the webchannel code to better check that only the actual trusted sender of the message gets the response. Even though the FXA servers are set to disallow iframing, any mitigation here should also take this vector into account.
Flags: needinfo?(markh)
oops - to be clear - s/a webframe/an iframe/
I see we also use WebChannels for about:newtab and remote troubleshooting on Desktop. At first glance, both of those look good: remote troubleshooting does a permission check, which requires HTTPS, and newtab uses HTTPS URLs for production and staging. Bug 1146724 looks quite subtle. On iOS, do we need an explicit check to make sure we're posting the reply to the same frame that sent the request, or is that already handled? Thanks for the report, Muneaki!
Flags: needinfo?(kcambridge)
(In reply to Kit Cambridge [:kitcambridge] from comment #9) > I see we also use WebChannels for about:newtab and remote troubleshooting on > Desktop. At first glance, both of those look good: remote troubleshooting > does a permission check, which requires HTTPS, and newtab uses HTTPS URLs > for production and staging. > > Bug 1146724 looks quite subtle. On iOS, do we need an explicit check to make > sure we're posting the reply to the same frame that sent the request, or is > that already handled? Yes, we do. I always intended to implement and use WebChannels on iOS, but we didn't do it, and I missed this check :(
Verified (via JS console) that this blocks the message from comment 0 if the origins don't match.
Attachment #8786502 - Flags: review?(nalexander)
Comment on attachment 8786502 [details] [review] Link to Github pull-request: https://github.com/mozilla/firefox-ios/pull/2073 Comments on GH. Looks good with notes.
Attachment #8786502 - Flags: review?(nalexander) → review+
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Group: firefox-core-security → core-security-release
Flags: sec-bounty?
Flags: sec-bounty? → sec-bounty+
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: