Repository navigation
fix: ignore malformed Max-Age values (RFC 6265 5.2.2) - #90
Merged
Merged
Conversation
Owner
|
Hey, thanks! Do you have any real-world examples of malformed max-age values, or is this more of a theoretical concern? Oh, and it looks like #91 addresses the invalid date |
Contributor
Author
|
Fair question. I have no real-world example. #89 used made-up values, so this is mainly a conformance fix. The practical point is consistency: tough-cookie and undici (behind Node's |
Owner
|
This will be published shortly in v3.1.4 |
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.
Ignore a
Max-Ageattribute whose value is not an integer, as RFC 6265 section 5.2.2 requires. Fixes #89.Before this change,
Max-Age=12junk,Max-Age=12.5andMax-Age=+12all parsed asmaxAge: 12, becauseparseIntaccepts any leading integer prefix.lib/set-cookie.jsnow checks the trimmed value against/^-?\d+$/before it converts it. A malformed value is dropped, and the cookie and its other attributes stay. Valid values, including negative values such as-1, parse as before.I used a regex instead of
Number(value), becauseNumberaccepts12.5and turns""into0. I can change it toparseIntplus a leftover-character check if you prefer that style.The new
max-age attribute (rfc 6265 5.2.2)tests intest/set-cookie-parser.jsfail for the malformed values without the change and pass with it.Out of scope:
Expireswith an unparseable date still givesInvalid Date.