Skip to content

fix(server): clearCookies({name}) should not transiently delete other cookies#40955

Open
adityasingh2400 wants to merge 1 commit into
microsoft:mainfrom
adityasingh2400:fix-clear-cookies-transient-delete-40953
Open

fix(server): clearCookies({name}) should not transiently delete other cookies#40955
adityasingh2400 wants to merge 1 commit into
microsoft:mainfrom
adityasingh2400:fix-clear-cookies-transient-delete-40953

Conversation

@adityasingh2400
Copy link
Copy Markdown

Fixes #40953.

BrowserContext.clearCookies(options) currently wipes every cookie via doClearCookies() and then re-adds the ones that did not match the filter. Pages that subscribe to the cookieStore.change API observe a transient deletion of the kept cookies during the gap between the wipe and the readd, which is enough to trip route-guards, useSyncExternalStore-style auth state machines, and similar listeners. With cookieStore now Baseline 2025, this race window is observable from user code.

When a filter (name, domain, or path) is set, this PR expires only the matching cookies in place by calling addCookies with expires: 0; the no-filter path still delegates to doClearCookies() as before, so no per-browser code is touched.

Credit to @jasikpark for the full root-cause analysis and the proposed fix shape in the issue.

Added a Chromium-only test in tests/library/browsercontext-clearcookies.spec.ts that adds two cookies, subscribes to cookieStore.change via the page, then calls clearCookies({ name: 'delete_me' }) and asserts the kept cookie never appears in a deletion event.

… cookies

BrowserContext.clearCookies(options) currently wipes every cookie via
doClearCookies() and then re-adds the ones that did not match the
filter. Pages that subscribe to cookieStore.change observe a transient
deletion of the kept cookies during the gap between the wipe and the
readd, which is enough to trip route-guards, useSyncExternalStore-style
auth state machines, and similar.

When a filter (name, domain, or path) is set, expire only the matching
cookies in place by calling addCookies with expires=0; the no-filter
path still delegates to doClearCookies() as before. No per-browser code
is changed.

Reported and diagnosed by @jasikpark in microsoft#40953.
@adityasingh2400
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: context.clearCookies({name}) transiently deletes non-matching cookies (observable via cookieStore.change)

1 participant