Cookie Path attribute is not always explicitly required for __Host- cookies, contrary to RFC6265bis-20 and Chromium's behavior
Categories
(Core :: Networking: Cookies, defect, P2)
Tracking
()
People
(Reporter: sormus.uku, Unassigned)
References
Details
(Whiteboard: [necko-triaged][necko-priority-next])
Steps to reproduce:
- Go to https://example.com/ (important: the URL path must be
/) and open the devtools Console tab - Execute
document.cookie = "__Host-X=Y; Secure"
console.log(document.cookie)
Actual results:
Observe that the cookie is set (Path=/ is implied)
Expected results:
The __Host- name prefixed cookie should not be set without explicit Path attribute, according to RFC6265bis-20 and following the same steps in Chromium.
https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-20#section-4.1.3.2-4:
For example, the following cookies would always be rejected:
...
Set-Cookie: __Host-SID=12345; Secure
https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-20#section-5.7-3.11.1
- If the cookie-attribute-list contains an attribute with an attribute-name of "Path", ... Otherwise, set the cookie's path to the default-path of the request-uri.
https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-20#section-5.7-3.21.1:
- If the cookie-name begins with a case-insensitive match for the string "__Host-", abort these steps and ignore the cookie entirely unless the cookie meets all the following criteria:
...- The cookie-attribute-list contains an attribute with an attribute-name of "Path", and the cookie's path is /.
Firefox Nightly 140.0a1 (2025-05-02) (64-bit)
Comment 1•1 year ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::Privacy: Anti-Tracking' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Updated•1 year ago
|
I don't quite get what you're trying to report here.
Your citations describe the fact that the spec tells us to infer an omitted path as the default-path, which is also described here: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-20#section-5.1.4-1
Once we've inferred the Path as /, then this now satisfies the requirements for a valid __Host- cookie.
You can follow the algorithm outlined in my link to find a case where we indeed fail to set an invalid prefix cookie (as expected)
For example, visit https://example.com/dir/
Attempt to: document.cookie = "__Host-dir-slash=a; Secure;"
Result: dev tools error, cookie not added.
I think this can be closed.
| Reporter | ||
Comment 3•1 year ago
|
||
What I'm trying to report is different behaviors in browsers, where Firefox doesn't follow this version of the spec to the word (AFAICS), which could potentially waste people's time. If a developer uses Firefox and setting or deleting a __Host- prefixed cookie works without / on the root path of the application, the dev may omit setting Path=/ and go on with their day. But the same code won't then have an effect on Chromium-based browsers.
From what I can see, the spec explicitly calls out that the Path should be explicitly set, not inferred:
- from the before referenced examples section, the wording "always be rejected" is used for the example
Set-Cookie: __Host-SID=12345; Secure, not "always, unless the corresponding HTTP request was to path /, in which case we imply" - from the before referenced
__Host-step, "cookie-attribute-list" is used inThe cookie-attribute-list contains an attribute with an attribute-name of "Path"; AFAICS,cookie-attributes-listis only updated when thePathattribute is explicitly used in the setter string https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-20#section-5.6.4 but I might be wrong here
I don't think this is a high-priority issue and I won't be bikeshedding this one, just wanted to let you know that this difference exists :-)
Maybe spec needs clarification then?
| Reporter | ||
Updated•1 year ago
|
My mistake. I've reviewed the spec and we seem to have a bug somewhere in our implementation. Relevant spec notes follow.
In 5.6, the Set-Cookie header field
- We parse the path attribute like so:
- if the attribute name is Path, we infer an empty or non-rooted value to be /
- then the attribute-name (path) and attribute-value (/ or other) is added to the attribute-list.
- Note that none of this occurs if the Path attribute was omitted altogether. (this is where my mistake was on my first pass)
In Storage Model:
- In step 11, we if there is no Path in attribute list: set the cookie's path to default-path. Note that we are modifying the cookie's path, and not the attribute-list.
- In step 21, we ignore the cookie unless the attribute list contains Path=/. The attribute-list is still empty wrt Path, so we should ignore the cookie at this stage in the algorithm.
| Reporter | ||
Comment 5•2 months ago
|
||
"Host cookie-prefix requires Path attribute" https://github.com/httpwg/http-extensions/issues/222
Comment 6•1 month ago
|
||
Looks like this got fixed in bug 2066910.
Description
•