-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: narrow the validation of cookies to match RFC6265 #167
Conversation
fixes jshttp#165. Previously, validation on serialization used the field-content regexp from RFC7230 to perform all checks. However, that is the regexp for the cookie header as a whole, but each individual part of a cookie has a tighter restriction. In the bug report jshttp#165 I demonstrated that whitespace in names and values was invalid but allowed by the field-content pattern. In this code I started by adding tests for those two cases, then added the expressions derived from the RFC; the relevant portions of the RFC have been inlined as comments. Removing the field-content regexp unearthed that as well as those two it was being used to validate domain names and paths. Paths are fairly unrestricted (being any ascii character except control characters and semicolon) but the code was wrong here too - it allowed all 8-bit characters not just 7-bit characters. Domain names have a well recognised pattern, there are only a couple of gotchas: RFC6265 explicitly says RFC1123 applies, so the leading character of a label is allowed to be a digit; and while I wondered for a moment if this should allow things like [::1] the domain matching section of https://datatracker.ietf.org/doc/html/rfc6265#section-5.1.3 teaches that domain values are _not_ ip addresses.
Thanks, this VERY well structured from the comments to the new regular expressions, great work. CI is passing, but I want to wait a bit and see if anyone else on the project as opinions on this. My one review comment is not intended to block, so if you feel strongly about that form of regex please tell me. |
The regexp should be in the same order as the RFC grammar, for ease of checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Hey, can we fix up the lint issues? After that I think we can land this and update in both |
🤦 that's what I get for doing those last two commits in the online editor. Fixed, thanks |
I think that coveralls just glitched out. I can see at https://coveralls.io/builds/68891763 that the coveralls run was successful, but it looks like it never reported back to github. Just needs a kick. |
…C validations These tests are to help illustrate vulnerabilities in the cookie name, domain and path strings. The lack of filtering delimiters like semicolon and comma is the major concern but other characters can present security problems as well. [PR jshttp#167][1] fixes these vulnerabilities and tests should pass with those new validations added. [1]: jshttp#167
…ations These tests better align with the proper RFC rules for the cookie attributes of `name`, `domain`, and `path`. These test are meant to be implemented along with [PR jshttp#167][1] that adds more fine-grained validations based on RFC rules. [1]: jshttp#167
To fix vulnerability jshttp/cookie#167
The version 0.6.0 of the `cookie` package has a security flaw described here (jshttp/cookie#167). This PR does update the library to the closest fixed version. Closes remix-run#10077
The version 0.6.0 of the `cookie` package has a security flaw described here (jshttp/cookie#167). This PR does update the library to the closest fixed version. Closes remix-run#10077
fixes #165. Previously, validation on serialization used the field-content regexp from RFC7230 to perform all checks. However, that is the regexp for the cookie header as a whole, but each individual part of a cookie has a tighter restriction.
In the bug report #165 I demonstrated that whitespace in names and values was invalid but allowed by the field-content pattern. In this code I started by adding tests for those two cases, then added the expressions derived from the RFC; the relevant portions of the RFC have been inlined as comments.
Removing the field-content regexp unearthed that as well as those two it was being used to validate domain names and paths. Paths are fairly unrestricted (being any ascii character except control characters and semicolon) but the code was wrong here too - it allowed all 8-bit characters not just 7-bit characters.
Domain names have a well recognised pattern, there are only a couple of gotchas: RFC6265 explicitly says RFC1123 applies, so the leading character of a label is allowed to be a digit; and while I wondered for a moment if this should allow things like [::1] the domain matching section of https://datatracker.ietf.org/doc/html/rfc6265#section-5.1.3 teaches that domain values are not ip addresses.