"Block all cookies" bypass for localstorage using about:blank iframe, plus document.cookie weirdness
Categories
(Core :: Privacy: Anti-Tracking, defect, P2)
Tracking
()
People
(Reporter: textshell, Assigned: timhuang)
Details
(4 keywords, Whiteboard: [reporter-external] [client-bounty-form] [verif?][adv-main115+])
Attachments
(5 files)
[originally submitted via email, but the autoresponder asked to resubmit via bugzilla]
While testing a cookie auto deletion addon, i came across what seem to be a cookie/storage permission bypass.
Steps to reproduce:
-
As usual serve the attached files using a local webserver (like python3 -mhttp.server) and access them on a
non localhost ip. -
I have tested this with a fresh firefox nightly (116.0a1 (2023-06-16)(64bit).
-
In the fresh profile set cookie blocking to "custom" and select to block "All cookies".[1]
-
Confirm that normal access to local storage is blocked by using the attached test-noiframe.html
3a: Access to the storage APIs gives a "DOMException: The operation is insecure.", the storage tab in developer tools show no saved data. -
But Using the attached test2.html give unblocked access to local storage.
Expected Result:
Firefox blocks storage access the same as when using the non iframe version of the test. No data stored.
Actual Result:
The storage apis work and ignore the setting to block the access:
- No exception on usage
- When entering data in the textbox and pressing save, on reloading the page, the page can retrieve the data.
- The saved data is not visible in developer tools, but even after restarting firefox the page can still read back the data.
- The origin with the saved data is shown in "Manage Cookies and Site Data" as having used storage.
I have not tracked done the regression point, but using firefox 100, the blocking works and the api access gives the expected exceptions.
This seems to be a recent regression.
The core part of test2.html is as follows. It seems by just using the contentWindow of a otherwise defaulted iframe,
the blocking of the storage api is evaded.
<iframe id="preview" name="preview"></iframe>
<script>
let p = document.getElementById('preview');
let currentData = p.contentWindow.localStorage.getItem('blah');
document.getElementById('odata').innerText = currentData;
function setTest() {
p.contentWindow.localStorage.setItem('blah', document.getElementById('idata').value);
}
</script>
From looking at the profile directory the local storage seems to be attributed to the origin used to access test2.html.
storage.sqlite
INSERT INTO origin VALUES(2,'','192.168.123.123','http://192.168.123.123:4567','L9',9,1686945337316151,1,0);
storage/default/http+++192.168.123.123+4567/ls/data.sqlite
INSERT INTO "database" VALUES('http://192.168.123.123:4567',9,1686944680773745,0,6144);
I've played around a bit if this also allows evading storage isolation, but i did not the storage to leak across.
But this still evades supported data privacy settings.
[1] The problem also manifests with other global settings and blocking the specific origin.
Updated•2 years ago
|
Comment 1•2 years ago
|
||
Paul, Tim: is "Storage" the right component for this, or is "Privacy: anti-tracking" better?
Updated•2 years ago
|
Comment 2•2 years ago
|
||
Comment 3•2 years ago
|
||
Comment 4•2 years ago
|
||
From looking at the profile directory the local storage seems to be attributed to the origin used to access test2.html.
A frame (or window.open()) with no source URL contains an "about:blank" document, which inherits the origin of the browsing context that created it. The "same origin policy" means that If the frame were not the same origin, when your code tried to access anything inside the frame it would have have thrown security errors. "p" is OK (the frame element is part of the outer document), "p.contentWindow" wouldn't have worked
Comment 5•2 years ago
|
||
Interesting. Similarly, p.contentDocument.cookie
or p.contentWindow.document.cookie
can be used to set cookies but I'm not sure where they live. When you switch the cookie setting back to normal (and refresh the testcase to pick up the new settings) those cookies are gone. If you switch back to blocking all cookies and refresh, the cookie you set on the frame's document.cookie is back again. At least as seen by the document.cookie API. It doesn't get sent to the site nor does it show up in devtools cookie storage either way the cookie blocking is set.
Since cookies are a different group than storage but the DOM level confusion is similar I think anti-tracking is probably a better place to start. There's some confusion wrt that "about:blank" frame. Is some code checking against the URL and getting a null host rather than checking the principal for the true origin?
Updated•2 years ago
|
Reporter | ||
Comment 6•2 years ago
|
||
Reporter | ||
Comment 7•2 years ago
|
||
Yes, the cookie behavior is strange.
I'm testing with
let p = document.getElementById('preview');
let currentData = p.contentWindow.document.cookie
document.getElementById('odata').innerText = currentData;
function setTest() {
p.contentWindow.document.cookie = 'blah=' + document.getElementById('idata').value + '; expires=Mon, 01 Jan 2024 00:00:00 GMT';
}
In contrast to local storage, setting a new cookie case seem to get blocked by setting an explicit "block" exception for the origin.
And the cookie data disappears when i use about:processes to kill the content process of the tab. Testing further using 2 tabs the cookie jar seems to have different storage for each tab/content process (each tab can set a different value and read it back on page reload).
And using the "clear recent history" feature selecting "today" does not clear the cookie, but selecting "everything" does clear it.
So the cookie code seems to do different checks in different code paths and so has more than one behavior. And its behavior is different to the detailed behavior with storage.
Assignee | ||
Updated•2 years ago
|
Assignee | ||
Comment 9•2 years ago
|
||
The bypass of cookie blocking is because we exempt the storage access check for the "about:blank" iframe due to here. So, we will get StorageAccess::eAllow
even in the setting with blocking all cookies. I think this is an oversight of the storage access check for about:blank
iframe.
After talking with Ben about this issue, we think we should restrict more storage access checks on about pages. We think we should still do storage access checks for content exposed about pages.
Assignee | ||
Comment 10•2 years ago
|
||
Comment 11•2 years ago
|
||
This bug has been marked as a regression. Setting status flag for Nightly to affected
.
Reporter | ||
Comment 12•2 years ago
|
||
I've applied the patch to a slightly older checkout of the release branch (around 114), and i can no longer reproduce the problem with the patch applied.
Comment 13•2 years ago
|
||
Check storage access in content accessible about pages. r=bvandersloot,anti-tracking-reviewers
https://hg.mozilla.org/integration/autoland/rev/d451c1b17cfda3ebedad6d117c5022f2871f1018
https://hg.mozilla.org/mozilla-central/rev/d451c1b17cfd
Updated•2 years ago
|
Comment 14•2 years ago
|
||
Looks like this affects all branches. Can we assign a sec rating to this bug please?
Comment 15•2 years ago
|
||
Relatedly, this should have gotten sec-approval before landing.
Comment 16•2 years ago
|
||
Very odd: Searchfox gives blame to bug 1765313 for touching the code pointed at in comment 9 that you patched in D181807. That would indicate it regressed in Fx103, which is consistent with the reporter's statement that Firefox 100 was fine. It would also mean Firefox 102 was unaffected.
But I don't see those lines touched in the patches for bug 1765313. Nor was it in the patch as actually checked in to mozilla-centra so it's hard to claim a check-in merge introduced phantom blame. I see the same code in ESR 91 blamed on bug 1612378.
https://searchfox.org/mozilla-esr91/source/toolkit/components/antitracking/StorageAccess.cpp#154-157
Is something else interacting with this that made the reporter experience OK behavior in Firefox 100? Maybe this code was there, but the isolation was off by default?
I'm unhappy with these custom scheme checks and code that has to have deep knowledge of protocols (such as checking a list of specific URLs or matches and pulling out a couple that are causing problems. That means when we add more such URLs or protocols, or someone writes new code that needs to behave like this it will potentially break in unsafe ways. That's the whole point of using principal comparisons and bundling knowledge into protocol flags (and even "dynamic" protocol flags for schemes like "about" where different URLs have different properties).
Comment 17•2 years ago
|
||
Looks like the TCP roll-out was in Firefox 103, and I assume this bug doesn't happen without partitioning enabled. Some folks might have stumbled on it slightly earlier and manually enabled it in about:config but that's not going to be a huge number of people.
We should definitely get this fix into Firefox 115 based on it's privacy severity, and because that will be the next ESR. We don't need to go out of our way to fix ESR-102, though it looks like it might apply pretty cleanly so I wouldn't object to it.
Comment 18•2 years ago
|
||
:timhuang could you please add a release uplift request on this?
Assignee | ||
Comment 19•2 years ago
|
||
Comment on attachment 9340567 [details]
Bug 1839464 - Check storage access in content accessible about pages. r?bvandersloot!
Beta/Release Uplift Approval Request
- User impact if declined: The iframe can access the storage/cookies even if the user disables cookie/storage access.
- Is this code covered by automated tests?: No
- Has the fix been verified in Nightly?: Yes
- Needs manual test from QE?: No
- If yes, steps to reproduce:
- List of other uplifts needed: None
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): The code change of the patch is small.
- String changes made/needed: none
- Is Android affected?: Yes
Assignee | ||
Comment 20•2 years ago
|
||
Do I need to request another uplift for beta, or is the release uplift enough?
Comment 21•2 years ago
|
||
The patch landed in nightly and beta is affected.
:timhuang, is this bug important enough to require an uplift?
- If yes, please nominate the patch for beta approval.
- If no, please set
status-firefox115
towontfix
.
For more information, please visit BugBot documentation.
Comment 22•2 years ago
|
||
(In reply to Tim Huang[:timhuang] from comment #20)
Do I need to request another uplift for beta, or is the release uplift enough?
Release is enough, 115 is now in release and there's where the uplift needs to happen
Updated•2 years ago
|
Updated•2 years ago
|
Updated•2 years ago
|
Updated•2 years ago
|
Updated•2 years ago
|
Comment 23•2 years ago
|
||
Comment on attachment 9340567 [details]
Bug 1839464 - Check storage access in content accessible about pages. r?bvandersloot!
Approved for 115.0 RC2
Comment 24•2 years ago
|
||
uplift |
Comment 25•2 years ago
|
||
uplift |
Updated•2 years ago
|
Comment 26•2 years ago
|
||
I've reproduced this issue with STR from comment 0, on an affected Nightly build (116.0a1, 2023-06-20) with macOS 11.
The issue is verified as fixed on the latest builds, 115.0-build2 RC, 115.0-build2 ESR, and latest Nightly 116.0a1, across platforms: Win 11 x64, macOS 11 and Ubuntu 18.04 x64.
Updated•2 years ago
|
Updated•2 years ago
|
Updated•2 years ago
|
Updated•1 year ago
|
Updated•8 months ago
|
Description
•