Extensions can run content scripts in local files and read any other local file
Categories
(WebExtensions :: General, defect, P1)
Tracking
(firefox73 wontfix, firefox74 fixed)
People
(Reporter: robwu, Assigned: robwu)
References
Details
(Keywords: csectype-priv-escalation, sec-moderate, Whiteboard: webext-sec)
Attachments
(3 files)
Assignee | ||
Comment 1•6 years ago
|
||
str |
Assignee | ||
Comment 2•6 years ago
|
||
Updated•6 years ago
|
Assignee | ||
Updated•6 years ago
|
Comment 3•6 years ago
|
||
Comment 4•6 years ago
|
||
Comment 5•6 years ago
|
||
Comment 6•6 years ago
|
||
Comment 7•6 years ago
|
||
Assignee | ||
Comment 8•6 years ago
|
||
Comment 9•6 years ago
|
||
Updated•6 years ago
|
Comment 10•6 years ago
|
||
Comment 11•6 years ago
|
||
Assignee | ||
Comment 12•6 years ago
|
||
Comment 13•6 years ago
|
||
Updated•6 years ago
|
Updated•6 years ago
|
Comment 14•6 years ago
|
||
When I open file:///tmp/d/e/e/p/, I can still read /etc/passwd with the PoC extension (whereas running the same fetch call from the console in the context of the tab fails as expected).
We have now fixed bug 1500435, but given the above description the new checks will be bypassed as much as the original ones were.
Assignee | ||
Comment 15•6 years ago
•
|
||
I can confirm that this bug still happens on the latest Nightly.
This bug is the reason that I do generally not load untrusted add-ons in Firefox. It is reasonable for extensions to be able to access the content of a local file in a browser, but not to be able to read any other file on the local filesystem (e.g. from ~/.ssh/
) via a content script in an unrelated local file.
Comment 16•5 years ago
|
||
This bug concerns me too, I think that opening a local file url is not something that regular users do that often, but developers may be much more likely to do it and this would allow an extension content script to read any of their local files (include sensible ones like .npmrc and .ssh/* files).
I agree with the last comment from Shane (Comment 13) that in the long run we should implement a user-controlled "file access" permission as we did for the "private browsing access" (and I would personally prefer to not fix Bug 1266960 until we have done that), but it is likely going to not be a small project (it may be a bit smaller than the "private browsing access" one, but still more than just a few changes).
And so in the meantime (at least in my opinion) it would be good to fix this one (it has been open for a while now) by making the content script fetch/XHR requests to behave exactly like the "file://"-url webpage that the content script is wrapping (and eventually re-evaluate if we should allow the content scripts to access files from any localition only after we have implemented a user-controller "file access" permission).
ExpandedPrincipal::MayLoadInternal
method (which is currently returning true if any of the principal is allowed to load the url) seems to be a reasonable place to apply a fix for this issue.
My proposal is to leave the webpage principal to decide if the target file url should be accessible by the content script (which would make the content script to behave like the "file://"-url webpage when the target url is a file url), e.g. by doing something like the following:
bool ExpandedPrincipal::MayLoadInternal(nsIURI* uri) {
bool isFile = uri && uri->SchemeIs("file");
for (uint32_t i = 0; i < mPrincipals.Length(); ++i) {
auto principal = BasePrincipal::Cast(mPrincipals[i]);
if (isFile && principal->AddonPolicy()) {
// If the uri has a file scheme and the ExpandedPrincipal is
// from an extension content script, leave the outcome to be
// consistent with the webpage principal.
continue;
}
if (principal->MayLoadInternal(uri)) {
return true;
}
}
}
We could then revisit (or revert) this change once we have implemented the user-controller "file access" permission.
Updated•5 years ago
|
Assignee | ||
Updated•5 years ago
|
Comment 17•5 years ago
|
||
I can no longer reproduce this using the str provided in comment 1. I get the "expected" outcome.
Assignee | ||
Comment 18•5 years ago
|
||
Can still reproduce with str from comment 1 on Linux in Nightly 72.0a1 buildID 20191028094851 .
Note that even at the time of reporting, the expected result happens in the background page.
You need to look at the console of the tab to see that the content script unexpectedly has access to file:-URLs.
Comment 19•5 years ago
|
||
Correction on my results from the str in comment 1 for osx, results repeated here:
Expected:
Extension has should not have access to files:
- After step 2, the page should look normal.
- After step 3, the console should display Security Error: Content at moz-extension://.../_generated_background_page.html may not load or link to file:///..."
- After step 4, the tab's console should not contain anything.
Actual:
- After step 2, the page is read
- After step 3, the console should display Security Error: Content at moz-extension://.../_generated_background_page.html may not load or link to file:///..."
- After step 4, the tab's console should not contain anything.
Step3/4 are as I expect.
Step 2, the content script is injected, but I would expect that since the extension has file permissions and I opened the file myself.
Rob, why should the file look normal at step 2?
Comment 20•5 years ago
|
||
The entire STR is still reproducible linux.
Assignee | ||
Comment 21•5 years ago
|
||
Should have been:
Expected:
After step 2, the page should look normal.
Actual:
After step 2, the page is red (edited: not "read")
This is because the original report also asserted that extensions should not be able to run scripts in file:-URLs, unless explicit approval was given. Later (e.g. comment 5), this was deemed an intended feature, and the scope of the report was reduced to only cover the part where a content script could read any other file.
The most accurate expectations are now:
Expected:
- After step 2, the page is red.
- After step 3, the console should display Security Error: Content at moz-extension://.../_generated_background_page.html may not load or link to file:///..."
- After step 4, the tab's console should not contain anything.
Actual:
- After step 2, the page is red
- After step 3, the global console contains the expected message.
- After step 4, the tab's console contains the content of a local file (e.g. /etc/passwd).
Assignee | ||
Comment 22•5 years ago
|
||
Assignee | ||
Comment 23•5 years ago
|
||
Patch for this bug was attached in https://bugzilla.mozilla.org/show_bug.cgi?id=1420296#c60 . The test case here should land in the future, when the bugfix has landed.
Comment 24•5 years ago
|
||
There's a r+ patch which didn't land and no activity in this bug for 2 weeks.
:robwu, could you have a look please?
For more information, please visit auto_nag documentation.
Assignee | ||
Comment 25•5 years ago
|
||
It's a regression test for a security bug. Will land later.
Assignee | ||
Comment 27•5 years ago
|
||
This bug has been fixed in bug 1420296 (in Firefox 74, not on ESR68). The only patch here is a unit test, which I intend to land together with the unit test from the other patch (https://phabricator.services.mozilla.com/D54543).
To avoid drawing too much attention to the tests (which are functional exploits), I want to hold off with landing this at least until 74 reaches release. Maybe even until the next ESR.
Assignee | ||
Comment 28•5 years ago
|
||
(updating bug flags; fixed in 74 (shipping today); will land unit test and close bug)
Comment 29•5 years ago
|
||
Test for file requests from content scripts:
https://hg.mozilla.org/integration/autoland/rev/69a2553a6c864503207056b8784d7a03c06b6303
https://hg.mozilla.org/mozilla-central/rev/69a2553a6c86
Updated•4 years ago
|
Description
•