RFC 6265 states that a user-agent should proceed in the following way when receiving a Set-Cookie header:
If the Domain attribute is set:
- Set the cookie's domain to the domain-attribute.
- Set the cookie's host-only-flag to
false
.
If the Domain attribute is not set:
- Set the cookie's domain to the canonicalized request-host.
- Set the cookie's host-only-flag to
true
.
This is all clear. The confusion comes with this paragraph:
If the user agent receives a new cookie with the same cookie-name, domain-value, and path-value as a cookie that it has already stored, the existing cookie is evicted and replaced with the new cookie.
Let's take an example, with two cookies received on the domain www.example.com
:
Set-cookie: name=value
Set-Cookie: name=value; Domain=www.example.com
The domain (and path) will be the same for both cookies, but the first one will have the host-only-flag set to true
, and the second one to false
.
Reading the RFC, it looks like it doesn't matter when comparing the two cookies, and they should be considered equivalent anyway, but I'm not sure my interpretation is correct.
Should the user-agent replace the first cookie with the second one, or should it store both of them?