fix(platform-web): expire a cookie immediately with maxAge: 0 - #248
Merged
Conversation
`CookieStorage.set` tested `maxAge` for truthiness before turning it into `expires`, so `maxAge: 0`, which means immediate expiration in `Set-Cookie` terms, was silently dropped and the cookie was written with the `expires` option instead, usually as a session cookie. The check is now against `undefined`, and `maxAge` keeps its precedence over `expires`. The docs state that `maxAge` is given in seconds.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #248 +/- ##
==========================================
+ Coverage 83.29% 83.33% +0.03%
==========================================
Files 98 98
Lines 2556 2556
Branches 551 551
==========================================
+ Hits 2129 2130 +1
Misses 314 314
+ Partials 113 112 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
CookieStorage.setturnedmaxAgeintoexpiresbehind a truthiness check:maxAge: 0means immediate expiration inSet-Cookieterms, but here it read as "not set", so the cookie was written with theexpiresoption instead, usually as a session cookie. The new specshould expire the cookie immediately with zero max agetimes out onmainwaiting for the cookie to disappear.What
maxAge === undefined, so zero expires the cookie right away.maxAgekeeps its precedence overexpires, as in RFC 6265.maxAge: 60landsexpireswithin a minute from now,maxAge: 0deletes the cookie.maxAgeis given in seconds and takes precedence overexpires.Size
All publicsgrows by 3 B gzipped for theundefinedcomparison, 3419 B against the 3.45 kB limit re-pinned in #247.Checks
oxlint,tsc --noEmit,vitest run(62 tests, browser mode) andsize-limitinpackages/platform-webpass.