Closed Bug 1856645 Opened 3 years ago Closed 2 months ago

Cookies set in normal window show up in cookies in devtools within Private Mode

Categories

(DevTools :: Storage Inspector, defect, P2)

Firefox 118
defect

Tracking

(relnote-firefox 155+, firefox155 fixed)

RESOLVED FIXED
155 Branch
Tracking Status
relnote-firefox --- 155+
firefox155 --- fixed

People

(Reporter: kontakt, Assigned: r.majdodin)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/118.0

Steps to reproduce:

Open two windows - one regular, one in private mode. Go to mozilla.org in both of them. Open Devtools in both of them, navigate to Storage. In regular mode, run document.cookie="leaks=true". Navigate to Private Mode, open the mozilla.org tree in cookies view, see that this cookie is visible there, as well.

Actual results:

The "leaks=true" cookie is visible in the devtools in the Private Mode window

Expected results:

It should be separate, cookies set in regular windows should not leak to private windows

Summary: Editing cookies in devtools while in private mode leaks them to regular mode → Cookies set in normal window show up in cookies in devtools within Private Mode

This also happens across Firefox Containers

The Bugbug bot thinks this bug should belong to the 'DevTools::General' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → General
Product: Firefox → DevTools

The exact STRs seem to be:

  • open a tab in a regular Firefox window
  • open the same tab in a Private Browsing Firefox window
  • open the storage inspector in the Private Browsing Firefox window
  • run document.cookie="leaks=true" in the regular Firefox window

You will see the cookie appear in the Storage inspector of the Private Browsing Firefox window. However the cookie is not actually set. If you close/reopen devtools, the leaks cookie is gone. And using document.cookie to read cookies will also not show this cookie.

So this is most likely only a UI bug where we incorrectly show the cookie in the UI and not an actual leak of the cookie between regular and private windows.

Severity: -- → S3
Priority: -- → P2
See Also: → 1755220
Status: UNCONFIRMED → NEW
Ever confirmed: true
Duplicate of this bug: 1891929
Duplicate of this bug: 1919470

I suspect it's an issue with how we listen for cookie changes. I see that devtool subscribes to both normal and private browsing cookie changes here: https://searchfox.org/mozilla-central/rev/3966e5534ddf922b186af4777051d579fd052bad/devtools/server/actors/resources/storage/cookies.js#528
It then calls onCookieChanged here: https://searchfox.org/mozilla-central/rev/3966e5534ddf922b186af4777051d579fd052bad/devtools/server/actors/resources/storage/cookies.js#201
but doesn't do any filtering for normal or private browsing as far as I can see? Really it should look at the cookie's OriginAttributes and compare them to the OriginAttributes of the principal of the content window the devtools instance is attached to.

Duplicate of this bug: 1934955

Note: this work in other direction too. If the site in Private windows changes the cookie, the change is shown in the devtools in the normal window.

Another bug that makes Firefox less desirable for web developers.

See Also: → 2006850
Duplicate of this bug: 2006850
Component: General → Storage Inspector
Duplicate of this bug: 2028570

The cookies storage actor is a parent-process resource: one instance
per toolbox, and every instance observes both "cookie-changed" and
"private-cookie-changed". getMatchingHosts() decided whether a changed
cookie belongs to this toolbox by host string alone, so every cookie
change was forwarded to every same-host panel regardless of cookie
jar: a cookie set in a normal window shows up in a private window's
Storage panel and vice versa, and the same happens across containers
(comment 2). The panel then lists rows its own jar does not contain;
the enumeration path is already scoped by the host's originAttributes,
which is why such rows vanish on reopen and cannot be deleted.

Following the suggestion in comment 7, getMatchingHosts() now compares
the cookie's originAttributes with the originAttributes of the host's
browsing context and ignores mismatches, for privateBrowsingId and
userContextId.

partitionKey is deliberately not compared: a top-level document's
principal has an empty partitionKey while getCookiesFromHost also
collects the cookies partitioned under the site itself (from
cookieJarSettings), so a plain equality check would suppress updates
for partitioned cookies that enumeration legitimately lists. The
cross-partition case on this push path is left for bug 2060029.

The new test opens Storage panels on the same host in a normal window,
a private window and a container tab, and asserts that cookie adds and
changes appear only in the panel whose jar they belong to, in both
directions, while same-jar updates keep working.

Assignee: nobody → r.majdodin
Status: NEW → ASSIGNED
See Also: → 2060029
See Also: → 2061166
Pushed by jdescottes@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/64d894940229 https://hg.mozilla.org/integration/autoland/rev/b3c15bc9a2a8 Filter cookie change notifications by the host's originAttributes in the storage actor. r=devtools-reviewers,jdescottes
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 155 Branch

Did you want to nominate this for the Fx155 relnotes? If so, set the relnote-firefox flag to "?"
https://wiki.mozilla.org/Release_Management/Release_Notes_Nomination

Possible wording:

Fixed the DevTools Storage panel showing cookies from private windows, containers, and other partitions alongside the inspected page's own cookies.

Flags: needinfo?(r.majdodin)

Thanks Ryan! Nominating with your suggested wording.

Suggested wording: Fixed the DevTools Storage panel showing cookies from private windows, containers, and other partitions alongside the inspected page's own cookies.

Context: long-standing user-visible defect (reported 2023) - the Storage panel live-updated with cookies belonging to other cookie jars (private windows, containers) alongside the inspected page's own, listing rows that vanished on reopen and could not be deleted. The fix ships enabled, not behind any flag. No documentation link needed.

relnote-firefox: --- → ?
Flags: needinfo?(r.majdodin)

Added to the Fx155 relnotes.

Duplicate of this bug: 2056864
QA Whiteboard: [qa-triage-done-c156/b155]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: