-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
net/http: add field Cookie.Quoted bool #46443
Comments
This is wrong. The optional double-quotes around a cookie are not part of the value. The standard library is correct. |
What version of Go are you using (
|
I believe there is some confusion over what the Cookie.Value represents. My reading is that its the |
RFC 6265 is quite clear that double-quotes are part of the Empirically, |
After some investigation, with this message I will explain the source of the problem
and its consequences
Also, I will propose some solutions. Source of the problemThe ConsequencesConsequently, a A type that implements the
So, if a Set-Cookie: name="value" is sent to the server as Cookie: name=value instead of Cookie: name="value" Note that all the major browsers, latest and older versions, do not alter the cookie value sent to the server. SolutionsI propose three alternative solutions a) Standard compliant cookies received with a b) Add a c) Change the meaning of the |
This issue is about a simple question: Does net/http.Cookie.Value represent the "semantic value" of a cookie or does it represent the raw data that RFC 6265 calls the "cookie-value". RFC 6265 is not clear here (as it make much statements about how values should be interpreted) but common interpretation has been that the semantic value of a cookie can be optionally enclosed in double quotes or not enclosed. See e.g. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie stating "A cookie-value can optionally be wrapped in double quotes". This interpretation is shared by net/http which treats the double quotes as not being part of the value. Unfortunately net/http.Cookie mentions RFC 6265 and maybe this lead to this confusion here. I still think that |
This is obviously not something we can or should do.
This seems like the simplest way to preserve double-quoted
We could safely change Preserving the ability to round-trip a |
@neild I agree, the only viable option is b. Even if we could break existing users, this option does not force you to manage surrounding DQUOTE characters if you don't want to, and also allows you to adds surrounding DQUOTE characters if you need to.
It's a good question. I honestly think no one knows. I also found this similar old issue #10195, closed but not solved. |
This proposal has been added to the active column of the proposals project |
By analogy with url.URL.ForceQuery it seems like this should be Cookie.ForceQuote. |
We automatically quote when the value contains space or comma, which is weird because spaces and commas are never valid in cookie values. I don't know if automatic quoting is correct or incorrect, but it doesn't seem useful, and it is confusing.
|
While spaces and commas are never valid in cookie values according to RFC 6265 all browsers (and even curl) support spaces and commas (if quoted) and people rely on this behaviour because a lot of systems, libraries and frameworks use them and they do work irl. (Firefox allows (almost) arbitrary UTF-8 strings as cookie values, at least when I tested it some years ago.) I'm unsure about |
We can also just call it "Quoted". No need for Force. |
Have all remaining concerns about this proposal been addressed? The proposal is to add a new field ‘Quoted bool’ in http.Cookie. |
The |
Thanks for pointing that out @gazerro. We should definitely update the cookiejar implementation to preserve Quoted. I'm surprised it doesn't just use the Cookie type directly. Maybe that would make more sense. But yes, please consider updating cookiejar part of this proposal. |
Have all remaining concerns about this proposal been addressed? The proposal is to add a new field ‘Quoted bool’ in http.Cookie. The net/http/cookiejar implementation also has to be updated to preserve the Quoted field. |
Since all the concerns seem to have been addressed, can I take on this proposal? |
@nunogoncalves03 The proposal has not been formally accepted yet. But, sure, you can send a patch for it that can be submitted when and if it is accepted. Thanks. |
The current implementation of the http package strips double quotes from the cookie-value during parsing, resulting in the serialized cookie not including them. This patch addresses this limitation by introducing a new field to track whether the original value was enclosed in quotes. Additionally, the internal representation of a cookie in the cookiejar package has been adjusted to align with the new representation. The syntax of cookies is outlined in RFC 6265 Section 4.1.1: https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1 Fixes golang#46443 Co-authored-by: Fábio Mata <[email protected]>
Based on the discussion above, this proposal seems like a likely accept. The proposal is to add a new field ‘Quoted bool’ in http.Cookie. The net/http/cookiejar implementation also has to be updated to preserve the Quoted field. |
The current implementation of the http package strips double quotes from the cookie-value during parsing, resulting in the serialized cookie not including them. This patch addresses this limitation by introducing a new field to track whether the original value was enclosed in quotes. Additionally, the internal representation of a cookie in the cookiejar package has been adjusted to align with the new representation. The syntax of cookies is outlined in RFC 6265 Section 4.1.1: https://datatracker.ietf.org/doc/html/rfc6265\#section-4.1.1 Fixes golang#46443 Co-authored-by: Fábio Mata <[email protected]>
Change https://go.dev/cl/577755 mentions this issue: |
No change in consensus, so accepted. 🎉 The proposal is to add a new field ‘Quoted bool’ in http.Cookie. The net/http/cookiejar implementation also has to be updated to preserve the Quoted field. |
The current implementation of the http package strips double quotes from the cookie-value during parsing, resulting in the serialized cookie not including them. This patch addresses this limitation by introducing a new field to track whether the original value was enclosed in quotes. Additionally, the internal representation of a cookie in the cookiejar package has been adjusted to align with the new representation. The syntax of cookies is outlined in RFC 6265 Section 4.1.1: https://datatracker.ietf.org/doc/html/rfc6265\#section-4.1.1 Fixes golang#46443 Co-authored-by: Fábio Mata <[email protected]>
The current implementation of the http package strips double quotes from the cookie-value during parsing, resulting in the serialized cookie not including them. This patch addresses this limitation by introducing a new field to track whether the original value was enclosed in quotes. Additionally, the internal representation of a cookie in the cookiejar package has been adjusted to align with the new representation. The syntax of cookies is outlined in RFC 6265 Section 4.1.1: https://datatracker.ietf.org/doc/html/rfc6265\#section-4.1.1 Fixes golang#46443 Co-authored-by: Fábio Mata <[email protected]>
For the RFC 6265, the double-quotes are part of the cookie value but the functions and methods in the standard library that operates on cookies treat them as if they were not part of it.
The
SetCookie
function does not allow to send a cookie, that conforms to the spec, with a double-quoted value and the(*Request).Cookie
method strips the quotes from the value despite the double-quotes are part of it.The syntax in the RFC 6265 is
but it has been implemented in the standard library as
The author of the RFC 6265 has confirmed in https://lists.w3.org/Archives/Public/ietf-http-wg/2017JanMar/0229.html that this was the intent.
The draft https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02 added this note to the spec
and in the appendix reports this discussion https://issues.apache.org/jira/browse/HTTPCLIENT-1006.
The text was updated successfully, but these errors were encountered: