Skip to content

Cookie doesn't get replaced in CookieContainer #60628

Description

@radischevo

Recently I ran into an issue communicating with a remote website that sets cookies with inconsistent Domain attributes.
Consider the following repro:

var uri = new Uri("https://example.com/", UriKind.Absolute);
var container = new CookieContainer();

// First HTTP response...
container.SetCookies(uri, "foo=bar; Path=/; Domain=example.com");

// Second HTTP response...
container.SetCookies(uri, "foo=baz; Path=/; Domain=.example.com");

Console.WriteLine("Got {0} cookies, expected 1. ", container.GetCookies(uri).Count);

I expected that the second cookie would overwrite the first one, but there are now two cookies in the container instead. When using curl, the cookie gets replaced though, the same way browsers behave.

The issue reproduces on both .NET Core 5.0.402 (Mac) and .NET Framework 4.8 (Win).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions