Closed
Bug 1109276
Opened 11 years ago
Closed 8 years ago
Trusted Hosted App can be hosted by untrusted third-party
Categories
(Firefox OS Graveyard :: General, defect)
Firefox OS Graveyard
General
Tracking
(firefox37 disabled, firefox38 disabled, firefox39 disabled)
RESOLVED
WONTFIX
People
(Reporter: sdna.muneaki.nishimura, Unassigned)
Details
(Keywords: reporter-external, sec-other)
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.28 Safari/537.36
Steps to reproduce:
In TrustedHostedAppsUtils.getCSPWhiteList(), THA is allowed to use 'self' keyword for script-src and style-src in it's CSP.
http://dxr.mozilla.org/mozilla-central/source/dom/apps/tests/test_tha_utils.html#125
This spec allows untrusted third-party to host malicious THA, without Mozilla's approval, by cloning legitimate THA manifest and corresponding sig file from trusted application host server.
The neccessary conditions for exploit are as follows:
(a) There is a legitimate THA that has 'self' keyword on CSP directive in it's app-manifest.
ex: "csp" : "script-src 'self' https://www.google.com; style-src https://www.google.com 'self'"
(b) An attacker can download manifest.webapp and manifest.sig of (a) from legitimate app hosting server.
(c) An attacker can host a HPKP protected server, i.e., the server uses https: with sends valid Public-Key-Pins header
Then, the attacker can host fake THA (a) on their server (c) and the untrusted code can gain same privilege as legitimate app.
Here is the easy PoC of exploit:
(0) Due to avoid manifest signature verification, change following code as follows:
http://dxr.mozilla.org/mozilla-central/source/dom/apps/TrustedHostedAppsUtils.jsm#182
+ deferred.resolve(aCert);
- deferred.reject("MANIFEST_SIGNATURE_VERIFICATION_ERROR");
Install patched TrustedHostedAppsUtils.jsm to omni.ja on your device, or if you use simulator save it under \fxos_2_2_simulator@mozilla.org\b2g\modules\.
(1) Open https://csrf.jp/installer.html on your device
(2) Click "install" button then malicious THA, named Legitimate Trusted App, is installed
(3) Launch Legitimate Trusted App from home screen and you can see the app access to device storage.
Note: About procedure(0), it's not crutial part of the exploit. The reason why I need (0) is that I don't have any legitimate THA needed for artack.
I tried to use test certificate with "dom.mozApps.use_trustedapp_test_certs", but the test key and certificate is dynamically generated by unit-test code with /dev/urandam so valid test key is changed in every build time.
Updated•11 years ago
|
Flags: sec-bounty?
| Reporter | ||
Comment 1•11 years ago
|
||
I think possible solutions against this bug are:
#1. Require 'origin' field in app manifest mandatory, and validate the 'origin' and manifest URL is same origin.
#2. Disallow 'self' keyword for 'csp' field, in other words, only allow to declare origins starting with https://.
FWIW, we haven't shipped any products with THA enabled, and we don't have any current products scheduled to ship with it enabled.
I feel like we must have discussed this issue during the review of this feature, but I can't actually remember any. Which seems pretty shocking since this is indeed a pretty big security hole.
So it could simply be that we had an intended solution to this which I'm forgetting.
Simply forbidding 'self' doesn't seem like a good solution since that'd still allow the manifest to be hosted elsewhere and the HTML of the app to be loaded from a different origin. Which likely is enough to trick the various scripts into doing bad things.
One possible solution would be to require that a property is added to the manifest which contains the intended origin of the manifest. If the manifest is loaded from any other origin installation is prevented.
Updated•11 years ago
|
Updated•11 years ago
|
status-firefox37:
--- → disabled
Comment 3•11 years ago
|
||
(In reply to Jonas Sicking (:sicking) from comment #2)
> FWIW, we haven't shipped any products with THA enabled, and we don't have
> any current products scheduled to ship with it enabled.
>
> I feel like we must have discussed this issue during the review of this
> feature, but I can't actually remember any. Which seems pretty shocking
> since this is indeed a pretty big security hole.
>
> So it could simply be that we had an intended solution to this which I'm
> forgetting.
If I remember correctly, it was an omission in judgment - we decided to trust origin and its pins. (Shouldn't have.)
> Simply forbidding 'self' doesn't seem like a good solution since that'd
> still allow the manifest to be hosted elsewhere and the HTML of the app to
> be loaded from a different origin. Which likely is enough to trick the
> various scripts into doing bad things.
>
> One possible solution would be to require that a property is added to the
> manifest which contains the intended origin of the manifest. If the manifest
> is loaded from any other origin installation is prevented.
Agree. An element like 'trusted-origin' could be added to double check against app's origin.
Comment 4•11 years ago
|
||
(In reply to Muneaki Nishimura from comment #1)
> I think possible solutions against this bug are:
> #1. Require 'origin' field in app manifest mandatory, and validate the
> 'origin' and manifest URL is same origin.
We are looking at this solution now.
Comment 5•11 years ago
|
||
(In reply to Jonas Sicking (:sicking) from comment #2)
> FWIW, we haven't shipped any products with THA enabled, and we don't have
> any current products scheduled to ship with it enabled.
>
> I feel like we must have discussed this issue during the review of this
> feature, but I can't actually remember any. Which seems pretty shocking
> since this is indeed a pretty big security hole.
THA has not had a formal security review. With no plans to ship a device with THA in the near future, I put this review on hold. Do I need to revisit this decision and prioritise a review here? (I thought THA support required a build flag to enable, but it looks like I was wrong about this).
>
> So it could simply be that we had an intended solution to this which I'm
> forgetting.
My original understanding was that THAs would need to served a specific whitelisted origin, one that is blessed to serve trusted-hosted apps.
Comment 6•11 years ago
|
||
(In reply to Zoran Jovanovic from comment #3)
> (In reply to Jonas Sicking (:sicking) from comment #2)
> > FWIW, we haven't shipped any products with THA enabled, and we don't have
> > any current products scheduled to ship with it enabled.
> >
> > I feel like we must have discussed this issue during the review of this
> > feature, but I can't actually remember any. Which seems pretty shocking
> > since this is indeed a pretty big security hole.
> >
> > So it could simply be that we had an intended solution to this which I'm
> > forgetting.
> If I remember correctly, it was an omission in judgment - we decided to
> trust origin and its pins. (Shouldn't have.)
>
> > Simply forbidding 'self' doesn't seem like a good solution since that'd
> > still allow the manifest to be hosted elsewhere and the HTML of the app to
> > be loaded from a different origin. Which likely is enough to trick the
> > various scripts into doing bad things.
> >
> > One possible solution would be to require that a property is added to the
> > manifest which contains the intended origin of the manifest. If the manifest
> > is loaded from any other origin installation is prevented.
> Agree. An element like 'trusted-origin' could be added to double check
> against app's origin.
I wonder - could you just re-use the existing installs_allowed_from field? That can already be used to restrict a hosted app to a specific installation origin.
[1] https://developer.mozilla.org/en-US/Apps/Build/Manifest#installs_allowed_from
Comment 7•11 years ago
|
||
Do you think that origin/installs_allowed_from will be sufficent or should we require the absolute manifest url?
If we only require origin then we would get the same problem if the app is hosted on a "public" server, e.g. if you put your valid app on https://apps.example-cloud.net/my-trusted-app/ an attacker might be able to host his app on https://apps.example-cloud.net/evil-app/ and re-use the valid webapp/sig files.
Hmm.. if the manifest contains a relative start-url then we would indeed need to worry about the file being moved. So maybe we should require the start-url to be absolute.
In that case moving the manifest within the same origin wouldn't affect what the app actually does.
Note that we have a property call "Origin" already, so we can't use that name.
install_allowed_from has a different meaning. It just limits where the code which calls .install() can live. It doesn't affect where the manifest can be loaded from.
| Reporter | ||
Comment 9•11 years ago
|
||
Here you say "single app per origin" security policy for all hosted apps.
https://developer.mozilla.org/ja/Marketplace/Options/Hosted_apps
If the limitation is still valid and is working correctly, your concern in Comment 7 can be ignored.
Meanwhile, if you need to support multi apps per origin, please consider more tight CSP whitelist in order to allow scripts and styles only under trusted path.
I'm not sure current "csp" in manifest supports path syntax introduced in CSP2.0, so if you don't have you should keep "single app per origin" for the time being.
We've removed the "single app per origin" restriction in the 2.2 release I believe.
Comment 11•11 years ago
|
||
(In reply to Jonas Sicking (:sicking) from comment #10)
> We've removed the "single app per origin" restriction in the 2.2 release I
> believe.
No, that landed in gecko34 which is what 2.1 is shipping.
Comment 12•11 years ago
|
||
So it seems that we can't re-use the any of the existing manifest properies and that requiring only the origin isn't enough.
Would a good solution then be to create a new manifest property that specifies the absolute manifest url? E.g.
"manifest_url": "https://apps.example-cloud.net/my-trusted-app/manifest.webapp"
Comment 13•11 years ago
|
||
I'm picking Jonas out of a hat to answer comment 12 :)
Flags: needinfo?(jonas)
Yes, I think the solution here would be to add something like:
"tha_manifest_url": "...";
And require that:
1. The property is defined.
2. That the resolved URL of the manifest matches the value of the property.
Flags: needinfo?(jonas)
Comment 15•11 years ago
|
||
(In reply to Jonas Sicking (:sicking) from comment #14)
> Yes, I think the solution here would be to add something like:
>
> "tha_manifest_url": "...";
>
> And require that:
>
> 1. The property is defined.
> 2. That the resolved URL of the manifest matches the value of the property.
Would it make sense to give the element a more generic name along the lines of "manifest_url" for possible later reuse? Or should we stick to THA specific needs?
Flags: needinfo?(jonas)
Updated•11 years ago
|
Group: b2g-core-security
Unless we plan to enforce it for all manifests, I think we should use a THA-specific name.
And I don't see a reason to enforce it for all manifests.
So tha_manifest_url sounds good to me.
Flags: needinfo?(jonas)
Updated•11 years ago
|
status-firefox38:
--- → disabled
status-firefox39:
--- → disabled
Updated•11 years ago
|
Flags: sec-bounty? → sec-bounty+
Comment 17•11 years ago
|
||
CritSmash group has been discussing this. Is this feature actually available to the public? According to comment 2, THA hasn't been enabled in any products.
Can anyone confirm?
Comment 18•11 years ago
|
||
That's correct, no device shipped or plans to ship with THA support.
Comment 19•11 years ago
|
||
Thanks Fabrice. Based on our rating system [1], I am changing the rating of this bug, as it does not affect actual users at this time.
[1] https://wiki.mozilla.org/Security_Severity_Ratings
Keywords: sec-critical → sec-other
Updated•11 years ago
|
Group: core-security
Comment 20•8 years ago
|
||
Firefox OS is not being worked on
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → WONTFIX
Updated•8 years ago
|
Group: b2g-core-security
Updated•2 years ago
|
Keywords: reporter-external
You need to log in
before you can comment on or make changes to this bug.
Description
•