Repository navigation
fix(browser): fail-closed cookie clear after a partial import wipe (STA-4090) - #14191
Conversation
…TA-4090) A rejected bulk clear plus a later per-cookie removal could permanently delete cookies that were already gone. Snapshot partition-complete identities before mutating, keep the bulk clear, and restore through CDP so a failed import never silently drops existing cookies.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe PR separates cookie clearing from policy logic. It adds serialized clear operations, cookie identity capture, rollback handling, and CDP-based restoration with partition-key support. Cookie imports create and dispose a clear store around cleanup. Tests cover snapshot failures, removal failures, partial restoration, concurrent clears, Google exclusions, and Electron partitioned-cookie rollback. Mergeability Score: ⚪ Minimal · up to The PR adds fail-closed cookie clearing with rollback for partial failures; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (4)
src/main/browser/browser-cookie-clear-store.ts (1)
110-149: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value
Network.enablestays on for a reused tab.When
findPartitionWebContentsreturns an existing tab,dispose()releases the debugger lease but does not sendNetwork.disable. If another owner holds the lease, or if DevTools is attached, the Network domain remains enabled on a user-visible tab after the import. That changes network instrumentation for that tab for the rest of its life.Consider sending
Network.disableindispose()when the store enabled the domain on a pre-existing tab.src/main/browser/browser-cookie-import-google-exclusion.test.ts (1)
88-100: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueThe mock reverses an already reversed list.
removeTransplantableCookiescallsrestoreClearIdentities(identities.toReversed())insrc/main/browser/browser-cookie-import-clear.ts(Line 134). This mock then appliestoReversed()again, so it writes cookies back in the original snapshot order. The real store insrc/main/browser/browser-cookie-clear-store.tsrestores in the order it receives. DroptoReversed()here so the mock matches the production contract.♻️ Proposed fix
- for (const identity of identities.toReversed()) { + for (const identity of identities) {src/main/browser/browser-cookie-import-policy.test.ts (1)
4-7: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMove the clear-module cases out of the policy test file.
removeTransplantableCookiesnow lives insrc/main/browser/browser-cookie-import-clear.ts. This file is named for the policy module, andsrc/main/browser/browser-cookie-import-clear-atomicity.test.tsalready covers the clear workflow. Move theclearSessionfixture and the clear tests into a clear-module test file so each test file matches its subject.Also applies to: 357-384
src/main/browser/browser-cookie-import.test.ts (1)
47-61: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueThree copies of the
openCookieClearStoremock. Each import test file redeclares the same fake clear store with its own inline types. A contract change inCookieClearStorerequires three edits.
src/main/browser/browser-cookie-import.test.ts#L47-L61: replace the inline factory with a shared factory imported from a new module such asbrowser-cookie-clear-store-test-double.ts, typed againstCookieClearStore.src/main/browser/browser-cookie-import-replacement.test.ts#L29-L43: use the same shared factory.src/main/browser/browser-cookie-import-google-exclusion.test.ts#L33-L104: use the shared factory with a restore callback option so this file keeps itscookies.setbehavior. Do not name the new modulehelpers,utils,common, orshared. As per coding guidelines: "Do not use vague names such ashelpers,utils,common,misc, orshared-stufffor files, folders, or modules; use concrete domain-oriented names instead."Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c25cbb93-c3c2-4196-a85f-6c9dc33cd69a
📒 Files selected for processing (11)
src/main/browser/browser-cookie-clear-store.test.tssrc/main/browser/browser-cookie-clear-store.tssrc/main/browser/browser-cookie-import-clear-atomicity.test.tssrc/main/browser/browser-cookie-import-clear.tssrc/main/browser/browser-cookie-import-google-exclusion.test.tssrc/main/browser/browser-cookie-import-partition-rollback.electron.test.tssrc/main/browser/browser-cookie-import-policy.test.tssrc/main/browser/browser-cookie-import-policy.tssrc/main/browser/browser-cookie-import-replacement.test.tssrc/main/browser/browser-cookie-import.test.tssrc/main/browser/browser-cookie-import.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/browser/browser-cookie-import-partition-rollback.electron.test.ts (1)
90-94: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAssert that a cookie removal succeeds before testing rollback.
mapSettledWithConcurrencystarts all groups concurrently, so cookie enumeration order does not guarantee thatvictimfails after another removal. Record successfulcookies.removecalls and assert that at least one succeeds before asserting restored cookies.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c6659275-5a23-456e-b2a2-4f3a2fc1530a
📒 Files selected for processing (5)
src/main/browser/browser-cookie-clear-store-lifecycle.test.tssrc/main/browser/browser-cookie-clear-store.test.tssrc/main/browser/browser-cookie-clear-store.tssrc/main/browser/browser-cookie-import-clear-atomicity.test.tssrc/main/browser/browser-cookie-import-partition-rollback.electron.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/browser/browser-cookie-import-clear-atomicity.test.ts
STA-4090 visual proof @
|
…TA-4090) (stablyai#14191) * fix(browser): fail-closed cookie clear after a partial import wipe (STA-4090) A rejected bulk clear plus a later per-cookie removal could permanently delete cookies that were already gone. Snapshot partition-complete identities before mutating, keep the bulk clear, and restore through CDP so a failed import never silently drops existing cookies. * fix(browser): preserve exact cookie clear identities * fix(browser): abort unrepresentable cookie clears * fix(browser): skip excluded-only cookie clears (cherry picked from commit 93334dc)
…TA-4090) (stablyai#14191) * fix(browser): fail-closed cookie clear after a partial import wipe (STA-4090) A rejected bulk clear plus a later per-cookie removal could permanently delete cookies that were already gone. Snapshot partition-complete identities before mutating, keep the bulk clear, and restore through CDP so a failed import never silently drops existing cookies. * fix(browser): preserve exact cookie clear identities * fix(browser): abort unrepresentable cookie clears * fix(browser): skip excluded-only cookie clears





Summary
Failed native cookie import could permanently delete cookies that were already removed during a concurrent/partial full clear (STA-4090, follow-up to #14132). The import reported failure, but existing non-Google session cookies stayed gone.
This keeps the STA-4065 bulk
clearDatapath, but snapshots partition-complete cookie identities before any mutation. If the bulk clear rejects and a later per-cookie removal also rejects, the clear restores from that snapshot through CDPNetwork.setCookie(including CHIPSpartitionKey). Electroncookies.set()is never used for restore. If identities cannot be snapshotted, the import fails closed and leaves the jar unchanged.Fixes STA-4090. Follow-up to #14132.
Reproduction (current main)
A deterministic unit regression and a real Electron fixture both failed on origin/main:
removed-firstwas deleted,stalethen rejected, andremoved-firststayed gone.Design
clearData.No remote-wire shape change.
Tests
cookies.set(); concurrent clears serialize.victimremoval rejection,chips-authis still partitioned andplainis still present. GoogleSIDstays excluded.Validation
browser-cookie-import-partition-rollback.electron.test.ts: passbrowser-cookie-import-partition.electron.test.ts: passpnpm tc:node: passResidual risk
If restore itself fails after a partial clear, the session can still be left partial and the error says so. Headless hosts without an existing partition
webContentscreate a hidden window to attach CDP; if that attach fails, the import fails closed without deleting cookies.