Skip to content
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

Kestrel should merge HTTP/2 request Cookie headers #26461

Closed
Tratcher opened this issue Sep 30, 2020 · 8 comments · Fixed by #41591
Closed

Kestrel should merge HTTP/2 request Cookie headers #26461

Tratcher opened this issue Sep 30, 2020 · 8 comments · Fixed by #41591
Assignees
Labels
affected-few This issue impacts only small number of customers area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions bug This issue describes a behavior which is not expected - a bug. feature-kestrel HTTP2 HTTP3 severity-minor This label is used by an internal tool
Milestone

Comments

@Tratcher
Copy link
Member

Tratcher commented Sep 30, 2020

microsoft/reverse-proxy#437

https://www.rfc-editor.org/rfc/rfc6265.html#section-5.4 (COOKIE)

When the user agent generates an HTTP request, the user agent MUST
NOT attach more than one Cookie header field.

https://tools.ietf.org/html/rfc7540#section-8.1.2.5 (HTTP/2)

To allow for better compression efficiency, the Cookie header field
MAY be split into separate header fields, each with one or more
cookie-pairs. If there are multiple Cookie header fields after
decompression, these MUST be concatenated into a single octet string
using the two-octet delimiter of 0x3B, 0x20 (the ASCII string "; ")
before being passed into a non-HTTP/2 context, such as an HTTP/1.1
connection, or a generic HTTP server application.

I don't know if Kestrel properly accounts for this, we'd have to check. I don't see anything in the HPACK decoder or Kestrel to special case Cookies.

Edit: The client in the reported YARP scenario is Chrome using HTTP/2, so this is almost certainly something we should then a fix in Kestrel.

This hasn't come up before in common AspNetCore scenarios because the cookie parser is tolerant of multiple cookie headers and people don't usually look at the cookie header directly.

@halter73
Copy link
Member

So if I'm reading this correctly, RFC 6265 simply says clients MUST NOT send more than one Cookie header. And then the HTTP/2 RFC supersedes that and says multiple Cookie headers are allowed if they are sent separately for better compression efficiency.

The HTTP/2 RFC then goes on to say that the Cookie header needs to be merged before being proxied over an HTTP/1.1 connection or passed to "a generic HTTP server application" which in the case of ASP.NET Core would mean any middleware.

So my question is, what do you think Kestrel should do when it receives multiple Cookie headers in an HTTP/1.1 request? Reject the request? Leave multiple Cookie header values in the StringValues like it does today? Or merge the Cookie header values like it will for HTTP/2 requests? Personally, I'm leaning towards the last option.

@Tratcher
Copy link
Member Author

I'd leave HTTP/1.1 alone, we don't know of any client's that actually violate the spec like that, and it would still work with the current cookie parser so there's little reason to change it. There are plans to fix how HttpClient handles sending the cookie header that would avoid this on the outgoing side.

In the HTTP/2 scenario the client is within spec and the server is not.

No rush for a 5.0 fix, the mitigation is easy.

@halter73 halter73 added this to the 6.0.0-alpha1 milestone Oct 2, 2020
@Tratcher Tratcher added affected-few This issue impacts only small number of customers severity-minor This label is used by an internal tool labels Oct 6, 2020 — with ASP.NET Core Issue Ranking
@BrennanConroy
Copy link
Member

@captainsafia do you have capacity to get to this in preview1?

@captainsafia
Copy link
Member

@BrennanConroy Unfortunately, no. :/

@ghost
Copy link

ghost commented Jan 15, 2021

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@Tratcher
Copy link
Member Author

@captainsafia no worries, we'll re-asses for the next milestone.

@Tratcher
Copy link
Member Author

Tratcher commented Jul 6, 2021

Note the HTTP/3 spec has the same requirement as HTTP/2.
https://quicwg.org/base-drafts/draft-ietf-quic-http.html#section-4.1.1.2

@ghost
Copy link

ghost commented Aug 2, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@Tratcher Tratcher modified the milestones: Backlog, .NET 7 Planning Oct 28, 2021
Daniel-Genkin-MS-2 added a commit to Daniel-Genkin-MS-2/aspnetcore that referenced this issue May 10, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jun 13, 2022
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-few This issue impacts only small number of customers area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions bug This issue describes a behavior which is not expected - a bug. feature-kestrel HTTP2 HTTP3 severity-minor This label is used by an internal tool
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants