Skip to content

Cookie header values should be separated by semi-colon not comma. #42856

@ManickaP

Description

@ManickaP

RFC HTTP State Management Mechanism
Grammar:

   cookie-header = "Cookie:" OWS cookie-string OWS
   cookie-string = cookie-pair *( ";" SP cookie-pair )

We already properly concatenated within SocketsHttpHandler when we merge request headers with cookies from the container: https://github.com/dotnet/runtime/blob/master/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs#L247

We should do the same for all Cookie header values.

Repro:

var client = new HttpClient();
var message = new HttpRequestMessage(HttpMethod.Get, "http://localhost:5001");

// All of the Cookie header bellow will get concatenated with ','.
message.Headers.Add("Cookie", new [] {"test1=1","test2=2"});
message.Headers.Add("Cookie", "test3=3");
message.Headers.TryAddWithoutValidation("Cookie", new [] {"test4=4", "test5=5"});
message.Headers.TryAddWithoutValidation("Cookie", "test6=6");
var response = await client.SendAsync(message);

Wireshark snip:
image

Upon first look, adding a custom HttpHeaderParser overriding the separator and using it for Cookie in known header definitions: https://github.com/dotnet/runtime/blob/master/src/libraries/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs#L43 should do the trick.

Original issue: dotnet/yarp#437

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions