-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[Client] Double Set-Cookie header management #4486
Comments
|
I have run into this issue where Amazon international servers (.co.uk, .es, .it) are not complying with the referenced RFC . A get request to:
which redirects to
Results in a headers that sets the
Given the RFC is a recommendation I'll see about a local fix for my use case and will see about a PR. However, I may not prioritize upstraming as the component I'm working is a plug-in for HomeAssistant where 3.6.2 and above causes breaking changes #4258. |
After looking at this closer, I think the issue is The top answer in StackOverflow for this question points to this website which states clients should only delete cookies that match the domain, path, and name.
This matches behavior I am seeing on Chrome and Firefox which will process cookies with the same name separately and in this case will keep the |
I have a potential fix but only for my client-side use case. It essentially changes response.cookies from SimpleCookie to [(name, morsel)]. This automatically is handled correctly by cookie_jar.update_cookies(). While I have fixed all tests that assumed it was a SimpleCookie, I have not added a test for the specific issue of receiving multiple cookies and properly updating response.cookies so it's probably not ripe for PR. |
Long story short
In my use case, I have a webserver (on which I have no control) which sends me, in a single request, two
Set-Cookie
headers with the same cookie name. The first one contains an empty value and a expires header in the past, to remove the cookie, and a second one which define a value, but without header, to define it as a session cookie.The problem is that in the response, the two cookies are "mixed" in a single one with the value from the second
Set-Cookie
and the expires from the first one. Which makes the cookie deleted by the cookie jar in the session, asExpires
is in the past.Expected behaviour
Response and session cookie jar should contain the second cookie (at least).
Actual behaviour
Response contains a cookie with the value of the second cookie, but the expires from the first one.
In the session, the cookie is removed.
Steps to reproduce
Your environment
aiohttp==3.6.2
Workaround
From what I found, this seems to be caused by how SimpleCookie loads cookies.
If you load the same cookie name twice, the two cookies are merged in a single one. As I don't know if this is an expected behaviour from
http.cookies.BaseCookie
, I tried to simply remove the cookie before adding the new one:This is not a full fix of this problem, as the problem may occur with something different than the
Expires
header, but it should prevent wrong "mixed" cookies.The text was updated successfully, but these errors were encountered: