Skip to content

Correct innards of document.domain - #6510

Merged
annevk merged 5 commits into
mainfrom
annevk/psl
Jul 21, 2021
Merged

annevk merged 5 commits into
mainfrom
annevk/psl

Conversation

@annevk

@annevk annevk commented Mar 19, 2021 •

Copy link
Copy Markdown
Member

This fixes a regression introduced in 326c644.

(Unclear to me at the moment if it also tackles cases not addressed there and if some of these steps are redundant so this needs more investigation.)

Fixes #6509.

(See WHATWG Working Mode: Changes for more details.)


/infrastructure.html ( diff )
/origin.html ( diff )

This fixes a regression introduced in 326c644.

(Unclear to me at the moment if it also tackles cases not addressed there and if some of these steps are redundant so this needs more investigation.)

Fixes #6509.
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
@annevk

annevk commented Jun 21, 2021

Copy link
Copy Markdown
Member Author

@annevk
annevk marked this pull request as ready for review June 21, 2021 13:06
@annevk
annevk requested review from domenic and mikewest June 21, 2021 13:07

@sleevi sleevi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry, I missed the ping. I think I'm going to need to take a deeper look at this tomorrow, but wanted to send some early feedback. Don't go out of your way if my feedback is junk though - I did just want to get some initial impressions shared.

Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source
Comment on lines +80808 to +80810
<li><p>Assert: <var>originalHost</var>'s <span>public suffix</span>, prefixed by U+002E (.),
matches the end of <var>hostSuffix</var>.</p></li>
<!-- It would be cleaner to avoid string manipulation on domains. -->

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So I'm mostly struggling to reason through this one in the event of holes in the PSL, and trying to figure out if this is assertion or should be a distinctly handled branch (i.e. something that returns false)

The Firefox logic previously discussed does have an ASSERT, but that's because it previously did length checks on the inputs (and fast-failed).

That's not to say this is wrong, but it's twinged enough that I'm going to have to spend more time reasoning through and seeing if I can construct counter-examples.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think my contrived example is this, mostly related to potential holes in the PSL.

Let's say the PSL has:

example
bar.foo.example

And we're on baz.bar.foo.example, and the attempt is to document.domain = "foo.example"

My understanding is that:

  • originalHost == baz.bar.foo.example
  • originalHost's public suffix == bar.foo.example (with baz.bar.foo.example being the registrable domain / PSL + 1)
  • hostSuffix == foo.example (Steps 2/3)
  • hostSuffix is a domain (Step 4.1)
  • hostSuffix with a prefix is .foo.example, which matches the end of originalHost (baz.bar.foo.example) - Step 4.2)
  • hostSuffix != hostSuffix's public suffix (hostSuffix = foo.example, public suffix = example - Step 4.3)
  • hostSuffix with a prefix is .foo.example, which matches the end of originalHost's public suffix (.foo.example vs bar.foo.example) - Step 4.3
  • We trigger the assert - Step 4.4 (.bar.foo.example does not match foo.example)

The string length check would reject this once we determine hostSuffix's public suffix (example) is shorter than originalHost's public suffix (bar.foo.example)

Have I screwed up my analysis?

@annevk annevk Jun 25, 2021 •

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.

In your example, in step 4.3, .foo.example matching the end of bar.foo.example is grounds for that step returning false. And therefore it never reaches the assert. (Also, these holes are demonstrated in the examples through *.compute.amazonaws.com.)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks, I clearly can’t read. You’re entirely right that the check would catch any of the length shenanigans. It feels a little weird that the algorithm doesn’t make that obvious; that is, it’s hard to reason existing implementations are correct and satisfy the “equivalent implementation”, but this algorithm does seem to yield the right/intended result.

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.

An equivalent conditional we could use that might make the issue of holes more apparent:

hostSuffix's public suffix is not equal to originalHost's public suffix

I suppose I could also embrace the length check, it just seems so icky.

@sleevi

sleevi commented Jun 25, 2021 via email

Copy link
Copy Markdown

@annevk

annevk commented Jun 25, 2021

Copy link
Copy Markdown
Member Author

Mainly because the logical smaller unit is domain labels and this completely side-passes them. We don't have domain labels as a primitive, but they have come up a few times and at some point we might. I could see the other string comparisons being done in terms of domain labels, but the length-based one won't work, except if you phrase it as done here (or compare their public suffixes).

@annevk

annevk commented Jul 20, 2021

Copy link
Copy Markdown
Member Author

@domenic okay to land this? Not clear this can be tested.

@domenic

domenic commented Jul 20, 2021

Copy link
Copy Markdown
Member

Yep, go ahead and land indeed. And yeah I don't think it's testable using WPTs. We'll have to write our own tests for https://bugs.chromium.org/p/chromium/issues/detail?id=1189861

@annevk
annevk merged commit b205cae into main Jul 21, 2021
@annevk
annevk deleted the annevk/psl branch July 21, 2021 09:22
blueboxd pushed a commit to blueboxd/chromium-legacy that referenced this pull request Nov 26, 2021
The "public suffix" check needs to done in both directions.
This follows a spec clarification linked below.

Also add spec examples to our unit tests.
Also, drive-by fix for PermissiveGetHostRegistryLength
returning string::npos.
This change should not have any effect on extensions behaviour,
or the URL pattern implementation in particular.

Spec: whatwg/html#6510
Bug: 1189861
Change-Id: I5f45464fd7170bfd46ca2c61a0931c7db5e9aabc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3284831
Commit-Queue: Daniel Vogelheim <[email protected]>
Reviewed-by: Takashi Toyoshima <[email protected]>
Cr-Commit-Position: refs/heads/main@{#945434}
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.

"is a registrable domain suffix of or is equal to" seems pretty broken

3 participants