fix: trim whitespace from cookie attribute names and values (RFC 6265 5.2)#80
Merged
Merged
Conversation
Owner
|
Oh, good call, thanks for the fix! I'll merge this in and get a release out shortly. |
Owner
|
Published to npm in v3.1.1 |
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.
Attribute parsing does not strip whitespace per RFC 6265 section 5.2 step 3 ("Remove any leading or trailing WSP characters from the attribute-name and the attribute-value"). The attribute loop in
parseStringapplies only.trimLeft()to the attribute name and no trimming at all to the attribute value, so any space after=(or after the attribute name) is kept verbatim.A server may emit OWS around the value, e.g.
Domain= .example.com. Current behavior:A leading space in
domain/pathbreaks domain-match and path-match (RFC 6265 section 5.1.3 / 5.1.4);sameSite: ' Lax'does not equal'Lax'; and a trailing space on a boolean attribute name (Secure,HttpOnly) silently drops the flag because the key no longer matches.Fix
Two-token change in
lib/set-cookie.js, theparseStringattribute loop:.trimLeft()->.trim()(also strips trailing WSP from the name)sides.join("=")->sides.join("=").trim()After:
Max-AgeandExpireswere already tolerant of a leading space (parseInt/new Dateskip leading WSP), so their outputs are unchanged. The existing attribute tests use no space after=and all stay green. Added a test covering leading/trailing WSP on names and values.