Repository navigation
Conversation
The cookie-date algorithm rejected these values, but they then went to new Date(), which reads 24:00:00 as the next day, drops the seconds from 07:28:60 and keeps the year 1600. rfc6265 5.1.1 says to ignore them.
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.
What is wrong
parseCookieDatereads all the parts of these dates, sees a value out of range, and then passes the string tonew Date()anyway.new Date()does not reject them:Expected: no
expires, same as31 Febtoday. rfc6265 5.1.1 step 5 says to fail when hour > 23, minute > 59, second > 59, day is not 1-31, or year < 1601. tough-cookie'sparseDatereturnsundefinedfor all three.Cause
lib/set-cookie.js,parseCookieDate: the range checks sit in the sameifas the "found all parts" check, so a failed range check falls through toreturn new Date(str). Only the "day doesn't exist in that month" case returnedInvalid Date.Fix
If the time, day, month or year is missing, still fall back to
new Date(str)as before. Once all four are found, any value out of range returnsInvalid Date, so the attribute is ignored with the usual "failed to parse expires time" error.I fuzzed 200k generated dates against tough-cookie's
parseDate. After the fix the only cases where we return a date and tough-cookie does not are ones with a missing part (thenew Date()fallback), and the only cases the other way are days like31 Feb, which tough-cookie rolls over to March.Test
Added "should ignore an Expires with a time or year out of range" with the three dates above. It fails on main and passes with the fix.
npm test(build, lint, mocha, tsd): 83 passing.