Skip to content

Conversation

@wcontayon
Copy link
Contributor

@wcontayon wcontayon commented May 21, 2021

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

PR Title
Fix multiple cookies deletion with same-key when Path is different but Domain is specified

PR Description
Update the cookie reject predicate to add a new condition that take into account the domain and the path.

(https://github.com/wcontayon/AspNetCore/blob/038557748532e6cc0eeff304ab5cbd7f147f7e72/src/Http/Http/src/Internal/ResponseCookies.cs#L162-L168)

Addresses #30579

@ghost ghost added area-runtime community-contribution Indicates that the PR has been added by a community member labels May 21, 2021

var cookieHeaderValues = headers.SetCookie.ToArray();
Assert.True(cookieHeaderValues.Length == testCookies.Length);
Assert.All(cookieHeaderValues, cookie => Assert.Contains("path=/", cookie));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be verifying the full path and domain are set in the response

https://tools.ietf.org/search/rfc6265#section-3.1
Finally, to remove a cookie, the server returns a Set-Cookie header
with an expiration date in the past. The server will be successful
in removing the cookie only if the Path and the Domain attribute in
the Set-Cookie header match the values used when the cookie was
created.

wcontayon and others added 2 commits May 21, 2021 18:52
@wcontayon wcontayon requested a review from BrennanConroy May 21, 2021 20:16
@BrennanConroy BrennanConroy self-assigned this May 21, 2021
Assert.Equal(testCookies.Length, cookieHeaderValues.Length);

var deletedCookies = cookieHeaderValues.ToArray();
Assert.Contains(deletedCookies, cookie => cookie.StartsWith("key1", StringComparison.InvariantCulture) && cookie.Contains("path=/"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't test for just "path=/" because it matches both cookies, so we're not actually testing that both are there 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effectively 🙂.
In this case, we can improve the testing with specific path "/path1/", "path2/",and test the matching.

{
rejectPredicate = (value, encKeyPlusEquals, opts) =>
value.StartsWith(encKeyPlusEquals, StringComparison.OrdinalIgnoreCase) &&
value.IndexOf($"domain={opts.Domain}", StringComparison.OrdinalIgnoreCase) != -1 &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: in the future we can consider removing these string allocs, don't change this PR

@BrennanConroy BrennanConroy merged commit 15fedb4 into dotnet:main May 24, 2021
@ghost ghost added this to the 6.0-preview6 milestone May 24, 2021
@BrennanConroy
Copy link
Member

Thanks @wcontayon !

@wcontayon wcontayon deleted the 30579-delete_multiple_same-key_cookies branch May 24, 2021 16:48
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants