Skip to content

Add URL path equality and prefix comparison - #929

Merged
annevk merged 2 commits into
mainfrom
url-path-comparison
Sep 10, 2026
Merged

annevk merged 2 commits into
mainfrom
url-path-comparison

Conversation

@annevk

@annevk annevk commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

Cookies need to compare URL paths, both for equality and for whether one path contains another. Comparing serializations is not great: an opaque path can serialize identically to a list of URL path segments, and one path's
serialization can be a prefix of another's without covering whole segments.

Also let the URL path serializer take a URL path and record that the URL path segments in a list never contain U+002F (/), which is what makes the prefix comparison meaningful.

Tests: web-platform-tests/wpt#62165

Closes #814.


💥 AccessDenied: Access Denied 💥

PR Preview failed to build. (Last tried on Sep 7, 2026, 1:12 PM UTC).

More

If you don't have enough information above to solve the error by yourself, please file an issue.

Cookies needs to compare URL paths, both for equality and for whether one path
contains another. Comparing serializations is not right for either: an opaque
path can serialize identically to a list of URL path segments, and one path's
serialization can be a prefix of another's without covering whole segments.

Also let the URL path serializer take a URL path, so that callers holding one no
longer have to inline it, and record that a URL path segment never contains
U+002F (/), which is what makes the prefix comparison meaningful.

Closes #814.

Tests: web-platform-tests/wpt#62165

@johannhof johannhof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@annevk
annevk requested review from domenic and rmisev September 2, 2026 13:49

@domenic domenic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This all feels a little unclean from the pure URL Standard perspective, but I appreciate this is needed for cookies and you're trying to balance.

No really substantial comments, although I think my final comment on the note is worth acting on.

Comment thread url.bs
@@ -3220,15 +3220,18 @@ these steps. They return an <a>ASCII string</a>.

<div algorithm>
<p>The <dfn export lt="URL path serializer|URL path serializing">URL path serializer</dfn> takes a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This feels subjectively icky. I'd rather have two algorithms which take well-defined types, with one delegating to the other. It'd be a bonus if the one that takes a path could stay non-exported.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've decided to keep this as-is. I don't think it's too bad. (I did investigate only having one, but that impacts too many downstream specifications.)

Comment thread url.bs Resolved
Comment thread url.bs
<li><p>If <var>A</var>'s <a for=list>size</a> is not <var>B</var>'s <a for=list>size</a>, then
return false.

<li><p><a for=list>For each</a> <var>index</var> of <var>A</var>'s <a for=list>indices</a>: if

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess whatwg/infra#710 would be useful here, but stalled.

Comment thread url.bs Resolved
Comment thread url.bs Outdated
<p class=note>As <a for=/>URL path segments</a> never contain U+002F (/), this can only be true when
<var>B</var> covers whole segments of <var>A</var>. That makes it suitable for deciding whether one
<a for=/>URL path</a> is contained by another, which comparing serializations is not: the
serialization of « "<code>foo</code>" » is a prefix of that of « "<code>foobar</code>" ».

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This note is helpful, but still a little confusing, in part because of how it moves between "starts with", "is a prefix", and "contains". Suggested, including some notable cross-links:

As URL path segments never contain U+002F (/), A starts with B only when B covers whole segments of A. This makes it suitable for deciding whether one URL path is "contained" by another. Comparing [=URL path serializer|serializations=] is not appropriate: the serialization of « "foobar" » [=string/starts with=] the serialization of « "foo" », but conceptually, a URL with the former path does not contain a URL with the latter path.

This may further benefit from a second note, or maybe warning, explaining that the concept of paths "containing" each other is not really a good precedent, and is only used by legacy APIs like cookies (or service worker?) to impose a kind of path-based authority system that is discordant with the same origin policy used by the rest of the platform.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is great. I've reused a bunch of your suggested words here.

Comment thread url.bs Resolved
Comment thread url.bs Resolved
Comment thread url.bs Resolved
@annevk

annevk commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

@domenic @rmisev thanks for your helpful comments! I've addressed most of them. Hopefully it's good to go now.

@domenic domenic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great!

@annevk
annevk merged commit 8e14777 into main Sep 10, 2026
2 checks passed
@annevk
annevk deleted the url-path-comparison branch September 10, 2026 08:28
annevk added a commit to httpwg/http-extensions that referenced this pull request Sep 10, 2026
Path-Matches compared serialized paths, which made a cookie path of /foo match a request path of /foobar, and passed URL paths to the URL path serializer, which takes a URL. Compare URL path segments instead, using the operations URL now provides.

The Path attribute was split into a list that kept its leading empty segment, which is not how a URL path is represented, so such a path matched nothing and no "__Host-" prefixed cookie could be set. Isomorphic decode the attribute, drop that segment, and return failure if the result is not an ASCII string, rather than storing a path no request could ever carry. That check applies to the Path attribute that wins, so it happens once all attributes have been processed.

Cookie Default Path removed an item from the URL path it was given, or replaced that path's first item, and it is called with a request URL's path. Operate on a clone instead.

Also stop passing a path to Store a Cookie, which takes no such argument.

Tests: web-platform-tests/wpt#62165

Depends on whatwg/url#929.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

URL path comparison

4 participants