Skip to content

Conversation

englehardt
Copy link
Contributor

This PR refactors the cookie retrieval algorithm that formerly lived in The Cookie Header section to a new Retrieval Model section that mirrors the more generic Storage Model section for cookie setting.

This didn't require too much legwork in the end. Of note, I've moved us over from working with a request-target to target URI. A request target may not be a full URI (i.e., the "origin form" is a path + query), but we want a full URI so we can call the retrieval algorithm with a Document's URI for non-HTTP APIs. This was mostly a drop-in replacement in the rest of the doc, but I did remove one section that elaborated on extracting a path from the different forms of a request target.

I'm wondering whether we want to keep the non-HTTP API section at all. This only specifies one type of non-HTTP API (i.e., those with an associated Document); I'm not sure if there are any other non-HTTP APIs that user agents implement? And that functionality is already specified in more detail in HTML here. I wonder whether it's better to just update HTML with a reference to the new Retrieval Algorithm once we release a new version of the draft. cc/ @annevk for input.

Addresses #1233, #769, and #1163.

@englehardt englehardt marked this pull request as draft March 9, 2021 19:07
If a user agent does return cookies for a given call to a "non-HTTP" API with an
associated Document, then the user agent MUST compute the cookie-string following
the algorithm defined in {{retrieval-algorithm}, whereby the retrieval-uri is the
associated Document's URL. The retrieval is same-site if the Document's "site for
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we reference https://dom.spec.whatwg.org/#dom-document-url somewhere (for Document's URL)?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that's accurate. See the open issues against HTML. There's a document cookie URL that browsers use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@annevk you mean whatwg/html#2641 and whatwg/html#332? Are there others?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, those seem the most relevant here. https://github.com/whatwg/html/labels/topic%3A%20cookie is the full list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@annevk it seems like the best thing to do then is to get a cookie URL defined in HTML that captures these nuances. I've updated the reference here to assume that already exists, and can help get those changes into HTML.

Copy link
Contributor

@annevk annevk left a comment

Choose a reason for hiding this comment

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

It seems reasonable to move this lookup to HTML. (I hope we have someone willing to do that work though.) We probably also want to move the cookie store into Fetch eventually so partitioning and such can be defined better.

(There's also a proposal for a cookie API that would offer lower level access than a string and also from workers. That would also need to poke at the store directly.)

If a user agent does return cookies for a given call to a "non-HTTP" API with an
associated Document, then the user agent MUST compute the cookie-string following
the algorithm defined in {{retrieval-algorithm}, whereby the retrieval-uri is the
associated Document's URL. The retrieval is same-site if the Document's "site for
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that's accurate. See the open issues against HTML. There's a document cookie URL that browsers use.

@@ -1629,6 +1649,8 @@ the user agent might wish to try using the UTF-8 character encoding {{RFC3629}}
to decode the octet sequence. This decoding might fail, however, because not
every sequence of octets is valid UTF-8.
Copy link
Contributor

Choose a reason for hiding this comment

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

This also does not match what actually happens. Only Chrome can have such bytes at the moment and Chrome drops the cookies it cannot serialize, but does serialize the others.

@englehardt
Copy link
Contributor Author

englehardt commented Mar 10, 2021

It seems reasonable to move this lookup to HTML.

To be clear, I only meant the Non-HTTP API section. I think the actual retrieval algorithm should continue to live here. Let me know if you meant something different.

(I hope we have someone willing to do that work though.)

I can.

We probably also want to move the cookie store into Fetch eventually so partitioning and such can be defined better.

We'd like to keep this revision scoped to interop. Would you mind to file an issue with a little more detail on what parts you think should move to fetch?

@annevk
Copy link
Contributor

annevk commented Mar 10, 2021

Thanks for clarifying, I misunderstood. I don't really have strong opinions on how it's organized as long as all possible scenarios have clear steps to follow.

I guess there's a couple potential things with the lookup algorithm:

  1. It needs some kind of argument to indicate whether the caller is a "non-HTTP" API (assuming you would remove that definition).
  2. For document.cookie the serialization needs might be a bit more involved than what the current text implies.
  3. Something like https://github.com/WICG/cookie-store probably has even more advanced needs (but also doesn't have broad support yet).

I'll file an issue on Fetch integration later.

@annevk annevk mentioned this pull request Mar 10, 2021
Copy link
Contributor

@chlily1 chlily1 left a comment

Choose a reason for hiding this comment

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

Thanks! This looks pretty good overall.

I think having analogous HTTP/non-HTTP subsections would also be good for the Storage Model section to explicitly spell out what events constitute "receiving a cookie", but that can be a separate change.

@englehardt
Copy link
Contributor Author

I guess there's a couple potential things with the lookup algorithm:

1. It needs some kind of argument to indicate whether the caller is a "non-HTTP" API (assuming you would remove that definition).

Done. I decided to keep that section, but even still it makes sense to include reference to an argument in the algorithm.

2. For `document.cookie` the serialization needs might be a bit more involved than what the current text implies.

I filed #1502 for this. If you have more context to share, please do!

3. Something like https://github.com/WICG/cookie-store probably has even more advanced needs (but also doesn't have broad support yet).

This is out of scope.

@englehardt englehardt marked this pull request as ready for review May 4, 2021 21:21
@englehardt englehardt requested a review from chlily1 May 4, 2021 21:22
Copy link
Contributor

@chlily1 chlily1 left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! Looking really good.

I just had one suggestion for refactoring the algorithm parameters slightly: if you make the URI, same-site status, and HTTP/non-HTTP bit all properties of the retrieval, you can just pass the cookie store and the retrieval into the algorithm, and refer to "the retrieval's URI", "the retrieval's same-site status" etc. I think it makes sense semantically to associate them with the retrieval since every retrieval must have those properties.

Copy link
Contributor

@chlily1 chlily1 left a comment

Choose a reason for hiding this comment

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

Lgtm!

@englehardt englehardt merged commit bc06705 into main May 20, 2021
@englehardt englehardt deleted the 6265-non-http-apis branch May 20, 2021 17:52
@englehardt englehardt restored the 6265-non-http-apis branch May 20, 2021 18:56
miketaylr added a commit to miketaylr/http-extensions that referenced this pull request Jun 2, 2021
(also, adds the changelog for httpwg#1428)
chlily1 pushed a commit that referenced this pull request Jun 2, 2021
Addresses issue #1301 - Consistently use "header field"

(also, adds the changelog for #1428)
@mnot mnot deleted the 6265-non-http-apis branch June 9, 2021 04:55
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jul 26, 2021
These tests were temporarily disabled due to an incompatibility between
Firefox and Chromium. Now that this has been resolved by a spec PR
(httpwg/http-extensions#1428), the tests can be
re-enabled.

Additionally, one of the tests was adjusted to reflect the behavior for
redirects specified in
httpwg/http-extensions#1348, which is enabled as
part of --enable-experimental-web-platform-features.

Bug: 1074441
Change-Id: I7e1deadf0c080927cc328b54d300d5d418fa5c6d
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jul 26, 2021
These tests were temporarily disabled due to an incompatibility between
Firefox and Chromium. Now that this has been resolved by a spec PR
(httpwg/http-extensions#1428), the tests can be
re-enabled.

Additionally, one of the tests was adjusted to reflect the behavior for
redirects specified in
httpwg/http-extensions#1348, which is enabled as
part of --enable-experimental-web-platform-features.

Bug: 1074441
Change-Id: I7e1deadf0c080927cc328b54d300d5d418fa5c6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3054294
Reviewed-by: Steven Bingler <bingler@chromium.org>
Commit-Queue: Lily Chen <chlily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#905421}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jul 26, 2021
These tests were temporarily disabled due to an incompatibility between
Firefox and Chromium. Now that this has been resolved by a spec PR
(httpwg/http-extensions#1428), the tests can be
re-enabled.

Additionally, one of the tests was adjusted to reflect the behavior for
redirects specified in
httpwg/http-extensions#1348, which is enabled as
part of --enable-experimental-web-platform-features.

Bug: 1074441
Change-Id: I7e1deadf0c080927cc328b54d300d5d418fa5c6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3054294
Reviewed-by: Steven Bingler <bingler@chromium.org>
Commit-Queue: Lily Chen <chlily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#905421}
blueboxd pushed a commit to blueboxd/chromium-legacy that referenced this pull request Jul 27, 2021
These tests were temporarily disabled due to an incompatibility between
Firefox and Chromium. Now that this has been resolved by a spec PR
(httpwg/http-extensions#1428), the tests can be
re-enabled.

Additionally, one of the tests was adjusted to reflect the behavior for
redirects specified in
httpwg/http-extensions#1348, which is enabled as
part of --enable-experimental-web-platform-features.

Bug: 1074441
Change-Id: I7e1deadf0c080927cc328b54d300d5d418fa5c6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3054294
Reviewed-by: Steven Bingler <bingler@chromium.org>
Commit-Queue: Lily Chen <chlily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#905421}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jul 30, 2021
…=testonly

Automatic update from web-platform-tests
Re-enable SameSite cookie iframe WPTs

These tests were temporarily disabled due to an incompatibility between
Firefox and Chromium. Now that this has been resolved by a spec PR
(httpwg/http-extensions#1428), the tests can be
re-enabled.

Additionally, one of the tests was adjusted to reflect the behavior for
redirects specified in
httpwg/http-extensions#1348, which is enabled as
part of --enable-experimental-web-platform-features.

Bug: 1074441
Change-Id: I7e1deadf0c080927cc328b54d300d5d418fa5c6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3054294
Reviewed-by: Steven Bingler <bingler@chromium.org>
Commit-Queue: Lily Chen <chlily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#905421}

--

wpt-commits: d4deee9e5303f3c09f65bc0d40783cc18a30606e
wpt-pr: 29792
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jul 31, 2021
…=testonly

Automatic update from web-platform-tests
Re-enable SameSite cookie iframe WPTs

These tests were temporarily disabled due to an incompatibility between
Firefox and Chromium. Now that this has been resolved by a spec PR
(httpwg/http-extensions#1428), the tests can be
re-enabled.

Additionally, one of the tests was adjusted to reflect the behavior for
redirects specified in
httpwg/http-extensions#1348, which is enabled as
part of --enable-experimental-web-platform-features.

Bug: 1074441
Change-Id: I7e1deadf0c080927cc328b54d300d5d418fa5c6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3054294
Reviewed-by: Steven Bingler <bingler@chromium.org>
Commit-Queue: Lily Chen <chlily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#905421}

--

wpt-commits: d4deee9e5303f3c09f65bc0d40783cc18a30606e
wpt-pr: 29792
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request Aug 4, 2021
…=testonly

Automatic update from web-platform-tests
Re-enable SameSite cookie iframe WPTs

These tests were temporarily disabled due to an incompatibility between
Firefox and Chromium. Now that this has been resolved by a spec PR
(httpwg/http-extensions#1428), the tests can be
re-enabled.

Additionally, one of the tests was adjusted to reflect the behavior for
redirects specified in
httpwg/http-extensions#1348, which is enabled as
part of --enable-experimental-web-platform-features.

Bug: 1074441
Change-Id: I7e1deadf0c080927cc328b54d300d5d418fa5c6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3054294
Reviewed-by: Steven Bingler <bingler@chromium.org>
Commit-Queue: Lily Chen <chlily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#905421}

--

wpt-commits: d4deee9e5303f3c09f65bc0d40783cc18a30606e
wpt-pr: 29792
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request Aug 4, 2021
…=testonly

Automatic update from web-platform-tests
Re-enable SameSite cookie iframe WPTs

These tests were temporarily disabled due to an incompatibility between
Firefox and Chromium. Now that this has been resolved by a spec PR
(httpwg/http-extensions#1428), the tests can be
re-enabled.

Additionally, one of the tests was adjusted to reflect the behavior for
redirects specified in
httpwg/http-extensions#1348, which is enabled as
part of --enable-experimental-web-platform-features.

Bug: 1074441
Change-Id: I7e1deadf0c080927cc328b54d300d5d418fa5c6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3054294
Reviewed-by: Steven Bingler <bingler@chromium.org>
Commit-Queue: Lily Chen <chlily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#905421}

--

wpt-commits: d4deee9e5303f3c09f65bc0d40783cc18a30606e
wpt-pr: 29792
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

5 participants