fix: ignore an unparseable Set-Cookie Expires attribute#5488
Merged
Conversation
parseSetCookie assigned an Invalid Date to cookieAttributeList.expires when the Expires attribute failed to parse, instead of ignoring the attribute. RFC 6265bis 5.4.1 step 2 says to ignore the cookie-av when the date does not parse, which the adjacent code comment already stated. Only set expires when the parsed date is valid.
KhafraDev
approved these changes
Jul 2, 2026
metcoder95
approved these changes
Jul 3, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5488 +/- ##
=======================================
Coverage 93.45% 93.45%
=======================================
Files 110 110
Lines 37147 37148 +1
=======================================
+ Hits 34716 34718 +2
+ Misses 2431 2430 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merged
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.
Description
parseSetCookieassigns anInvalid Dateto the parsed cookie'sexpireswhen theSet-CookieExpiresattribute fails to parse, instead of ignoring the attribute.RFC 6265bis section 5.4.1 step 2 says that if the attribute-value fails to parse as a cookie date, the user agent must ignore the cookie-av. The code comment at that spot already states this, but the assignment ran unconditionally, leaking an
Invalid Dateinto the returned object.Fix
Only set
expireswhen the parsed date is valid.// 2. If the attribute-value failed to parse as a cookie date, ignore // the cookie-av. - - cookieAttributeList.expires = expiryTime + if (!Number.isNaN(expiryTime.getTime())) { + cookieAttributeList.expires = expiryTime + }Valid
Expiresvalues are unchanged.Test
Added a case to
test/cookie/cookies.jsfor an unparseableExpires. It fails before the change (expires: Invalid Datepresent) and passes after (attribute omitted). Full cookie suite stays green.