fix: accept a negative Set-Cookie Max-Age attribute#5571
Open
arshsmith1 wants to merge 1 commit into
Open
Conversation
Signed-off-by: arshiya tabasum <arshi@bugqore.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5571 +/- ##
==========================================
+ Coverage 93.47% 93.48% +0.01%
==========================================
Files 110 110
Lines 37560 37560
==========================================
+ Hits 35108 35112 +4
+ Misses 2452 2448 -4 ☔ 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.
This relates to...
N/A
Rationale
parseUnparsedAttributesinlib/web/cookies/parse.jsvalidates theMax-Ageattribute-value with/^\d+$/, applied to the whole value rather than to the remainder after the sign. Any negativeMax-Agetherefore fails the check and the attribute is dropped from the parsed cookie:RFC 6265bis section 5.6.2 is explicit that a leading
-is allowed:The step-1 check at line 193 already accepts
-as a first character, and the last step above only has meaning if negative values reach it, so the intent in the surrounding code is the spec behaviour.Max-Age=-1is the usual way a server expires a cookie, and today that signal is silently lost bygetSetCookies().The generation side is deliberately left alone:
validateCookieMaxAgestill rejects negatives, which matches themax-age-av = "Max-Age=" non-zero-digit *DIGITgrammar a server must emit. Parsing is permissive, serialising stays strict.Changes
Relax the digit check to
/^-?\d+$/so a single leading sign is accepted and a non-DIGIT remainder is still ignored.Max-Age=-,--1,-1a,+1and the empty value all stay ignored, and positive values are unchanged.Features
N/A
Bug Fixes
Set-Cookie: ...; Max-Age=-1now parses tomaxAge: -1instead of dropping the attribute.Breaking Changes and Deprecations
N/A
Status