Repository navigation
Conversation
RFC 6265bis applies year clamping (1601–9999) in its own cookie-date algorithm, and user agents clamp dates they cannot represent. Serialize out-of-range but valid dates to the closest bound instead of throwing, so a bad expires value degrades to a long-lived or immediately-expired cookie rather than crashing the caller. Invalid Date objects still throw. Fixes jshttp#293 (released as part of the 2.0.2 reject behavior in jshttp#290; proposed for the next minor).
Member
|
Clamping isn't a desirable fix. Either it's going to remain re RFC compliance or revert back to non-RFC compliance. It seems like it unearthed a bug in your own system so it may be desirable to keep it rather than silently altering inputs. |
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.
Clamp out-of-range
Expiresdates instead of throwingFollow-up to #290 (released in 2.0.2), discussed in #293.
Summary
stringifySetCookienow clamps valid-but-out-of-rangeexpiresdates to the closest representable bound (1601-01-01/9999-12-31) instead of throwing aTypeError.Dateobjects (new Date(NaN)) still throw — that remains a programming error.Why
Throwing turned a previously-silent edge case into a hard crash when it shipped in the 2.0.2 patch. Real-world case from #293: an app multiplied an already-milliseconds timestamp into a year-~58000 date and passed it through
stringifySetCookie; ≤ 2.0.1 serialized it harmlessly (browsers clamp), 2.0.2 threw from inside a login success handler and silently broke the post-login redirect for every user.This also matches the spec's own approach: RFC 6265bis's cookie-date algorithm clamps parsed years to the 1601–9999 range rather than rejecting them, and user agents likewise clamp dates they cannot represent. Serializing with the same semantics keeps
stringifySetCookiesymmetric with what actually happens to the cookie.Behavior
Since this reverts part of 2.0.2's observable behavior, it's intended for the next minor release — with the current
throwkept only for genuinely invalid dates.Test plan
stringify-set-cookie.spec.ts: below-bounds years (−1, 0, 49, 50, 69, 99, 1600) clamp toMon, 01 Jan 1601 00:00:00 GMT; year 10000 clamps toFri, 31 Dec 9999 23:59:59 GMT; in-bounds years (1601, 1970, 9999) unchanged;new Date(NaN)still throws.