Closed Bug 1964920 Opened 1 year ago Closed 1 month ago

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)

Firefox 140
defect
Points:
3

Tracking

()

RESOLVED FIXED

People

(Reporter: sormus.uku, Unassigned)

References

Details

(Whiteboard: [necko-triaged][necko-priority-next])

Steps to reproduce:

  1. Go to https://example.com/ (important: the URL path must be /) and open the devtools Console tab
  2. 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

  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:

  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:
    ...
  2. 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)

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.

Component: Untriaged → Privacy: Anti-Tracking
Product: Firefox → Core
Component: Privacy: Anti-Tracking → Networking: Cookies

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.

Status: UNCONFIRMED → RESOLVED
Closed: 1 year ago
Resolution: --- → INVALID

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 in The cookie-attribute-list contains an attribute with an attribute-name of "Path"; AFAICS, cookie-attributes-list is only updated when the Path attribute 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?

Flags: needinfo?(edgul)

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

In Storage Model:

Status: RESOLVED → REOPENED
Ever confirmed: true
Flags: needinfo?(edgul)
Resolution: INVALID → ---
Severity: -- → S3
Points: --- → 3
Rank: 3
Priority: -- → P2
Whiteboard: [necko-triaged][necko-priority-next]

"Host cookie-prefix requires Path attribute" https://github.com/httpwg/http-extensions/issues/222

Looks like this got fixed in bug 2066910.

Status: REOPENED → RESOLVED
Closed: 1 year ago → 1 month ago
Depends on: 2066910
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.