Expire the cookie on Set-Cookie Max-Age=0 - #1357
Open
dylanpulver wants to merge 1 commit into
Open
Conversation
`Max-Age=0` is the standard way for a server to delete a cookie, but readsetcookies dropped the attribute instead of recording it. The leading-zero guard rejects any value whose first character is '0', which catches "0" itself, so the parsed Cookie kept `maxage == 0` (attribute absent) and CookieJar stored the cookie rather than deleting it. A logout that clears a session with `Set-Cookie: sid=; Path=/; Max-Age=0` left the stale entry in the jar, to be sent on every later request. Reject a leading zero only on a non-zero value, and map every delta-seconds <= 0 to the `maxage == -1` deletion sentinel (RFC 6265 5.2.2). This also closes a round trip inside the package: `stringify` already serializes a deletion as "Max-Age=0", which the parser could not read back. `Max-Age=01` is still ignored and positive values are unchanged. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1357 +/- ##
=======================================
Coverage 89.41% 89.42%
=======================================
Files 31 31
Lines 12594 12592 -2
=======================================
- Hits 11261 11260 -1
+ Misses 1333 1332 -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.
Max-Age=0is the standard way for a server to delete a cookie, butreadsetcookiesdropped the attribute instead of recording it. Theleading-zero guard rejects any value whose first character is
0, whichcatches
"0"itself, so the parsedCookiekeptmaxage == 0(attributeabsent) and
CookieJarstored the cookie rather than deleting it. A logoutthat clears a session with
Set-Cookie: sid=; Path=/; Max-Age=0left thestale entry in the jar, to be sent on every later request.
Reject a leading zero only on a non-zero value, and map every delta-seconds
<= 0 to the
maxage == -1deletion sentinel (RFC 6265 5.2.2). This alsocloses a round trip inside the package:
stringifyalready serializes adeletion as
Max-Age=0, which the parser could not read back.Max-Age=01is still ignored and positive values are unchanged.
Cross-checked against Go's
net/http, which this parser follows: thereMax-Age=0andMax-Age=-0both giveMaxAge=-1and the jar drops thecookie, while
Max-Age=01is ignored in both. FullPkg.test()is green onJulia 1.12.7 (macOS aarch64).