-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: (*http.Response).Cookies
have different behaviour compared with web browser
#66118
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
Comments
(attn @neild) |
Just adding an extra context here of what Chromium did, is basically allowing Expand // IsValidCookieValue() returns whether a string matches the following
// grammar:
//
// cookie-value = *cookie-value-octet
// cookie-value-octet = %x20-3A / %x3C-7E / %x80-FF
// ; octets excluding CTLs and ";"
//
// This can be used to determine whether cookie values contain any invalid
// characters.
//
// Note that RFC6265bis section 4.1.1 suggests a stricter grammar for
// parsing cookie values, but we choose to allow a wider range of characters
// than what's allowed by that grammar (while still conforming to the
// requirements of the parsing algorithm defined in section 5.2).
//
// For reference, see:
// - https://crbug.com/238041 Effectivly changing the grammar to:
|
https://chromium.googlesource.com/chromium/src/+/refs/heads/main/net/cookies/parsed_cookie.cc a reference to the chromium implementation |
Is this a duplicate of #46443 ? |
No, this one is expecting an interface for cookie validation for |
If I understand correctly this issue, Go also doesn't support any non-ascii values in the cookie value. E.g:
will print only the second cookie. |
I have experienced a similar problem with backslashes. Backslashes are not allowed in cookie-value but web browsers has no problem with it. You can check this behavior accessing the url httpbin-url-test which sets a cookie value using backslashes to scape unicode characters. It will be nice if a custom validator for cookie values could be implemented. Related code: Line 472 in 30b6fd6
|
Go version
go version go1.22.0 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I was trying to get any valid cookies given in HTTP response header specifically via
Set-Cookie
header entry. https://go.dev/play/p/M8hiEzF_n97What did you see happen?
In the example code, the
Cookies
method excludeutid
because it has quotation mark chars inside cookie-value. Looking at the RFC in the comment, https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1Quotation mark
"
OR in hex 0x22 is excluded, which is already expected behaviour:However, for web browsers that behaviour is totally fine.
What did you expect to see?
Interface for custom validation for valid cookies
The text was updated successfully, but these errors were encountered: