fix(cookies): keep domain-scoped deletion in name-keyed cookie stores#258
Conversation
since supabase#240 added the host-only also-clear, removeItem, setItem cleanup and applyServerStorage emit two entries for the same cookie name when a domain is configured: the domain clear first, then the host-only one. next.js backs its cookie store with a map keyed by name only, so the host-only entry (no Domain) overwrites the domain one and only that reaches the browser. browsers match cookies by (name, domain, path), so the domain-scoped session cookie the library set is never actually deleted and signOut leaves the session stuck. this flips the order so the host-only clear comes first and the domain clear last. name-keyed stores keep the domain deletion (the one that matches what we set) and only drop the best-effort host-only cleanup; adapters that emit a Set-Cookie per entry still get both. no change when no domain is configured. added a test that runs removeItem through a name-keyed store and checks the surviving deletion still carries the domain - it fails on the old order. updated the three existing order assertions to match. fixes supabase#256
|
Hi @thribhuvan003, thank you so much for contributing to Supabase! 💚 This is a great catch and a great fix. I went and pulled the actual One thing I would like to see before merging: the new Everything else here looks solid to me, the reorder is applied consistently across all three sites and I did not find any interaction with the dedup logic from #246. Thank you again for digging into this and fixing it properly rather than just papering over the symptom, it makes a real difference for anyone running |
mandarini
left a comment
There was a problem hiding this comment.
Read my comment above please! THank you!
|
thanks for the thorough review @mandarini, and for pulling the edge-runtime source to double check it! 💚 good call on the server path — added a test that runs the same name-keyed map through |
🤖 I have created a release *beep* *boop* --- ## [0.12.3](v0.12.2...v0.12.3) (2026-07-14) ### Bug Fixes * **cookies:** keep domain-scoped deletion in name-keyed cookie stores ([#258](#258)) ([d3a8a98](d3a8a98)), closes [#256](#256) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
since #240 added the host-only also-clear,
removeItem, thesetItemchunk cleanup andapplyServerStorageemit two entries for the same cookie name when a domain is configured — the domain clear first, then the host-only one. next.js backs its cookie store with a map keyed by name only (ResponseCookiesfrom@edge-runtime/cookies), so the second host-only entry (noDomain) overwrites the first and only that reaches the browser. browsers match cookies by (name, domain, path), so the domain-scoped session cookie the library itself set never gets deleted andsignOut()leaves the session stuck for any project that setscookieOptions.domain.this flips the order so the host-only clear comes first and the domain clear last. name-keyed stores keep the domain deletion (the one that matches what we set) and only drop the best-effort host-only cleanup; adapters that emit a Set-Cookie per entry still get both. no behaviour change when no domain is configured.
the tests added in #240 asserted the payload order, so they passed even though the collapse happens one layer down in the cookie store — i added a test that runs
removeItemthrough a name-keyed store and checks the surviving deletion still carries the domain (fails on the old order), and updated the three existing order assertions to match.fixes #256