Skip to content

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

Closed

Description

@domenic

Consider a page hosted on https://www.gourmet.com.s3-website-us-east-1.amazonaws.com that does document.domain = "amazonaws.com".

amazonaws.com itself is not in the PSL. s3-website-us-east-1.amazonaws.com is.

Let's walk through the algorithms:

Since com is not equal to amazonaws.com, all the checks succeed, and document.domain setting works. This is not as intended!

@sleevi suggests that the correct algorithm is instead something like this:

  • Let originalSuffix equal originalHost's public suffix.
  • If host is equals originalSuffix, then return false.
  • If host is shorter than originalSuffix, then return false. (this step would catch the above)
  • If host equals host's public suffix, then return false.
  • If originalSuffix, prefixed by a U+002E FULL STOP, exactly matches the end of host, then return true.

Activity

  1. added a commit that references this issue on Mar 19, 2021
    cffbfa3
  2. annevk commented on Mar 19, 2021

    @annevk
    Member

    It seems I regressed this in 326c644, maybe? At least what was there before has been there since forever I think.

    If host is shorter than originalSuffix, then return false.

    I would rephrase this as

    If host, prefixed by U+002E (.), matches the end of originalSuffix, then return false.

    to stick to the same comparison operations.

    It would be really great to have examples for all these conditions. I put something up at #6510, but I'm struggling a bit at the moment with wrapping my head around it.

  3. sleevi commented on Mar 19, 2021

    @sleevi

    Yeah, I think your proposal will address it, but it mostly moves error handling further down the stack. That is, if I have www.gourmet.com.s3-website-us-east-1.amazonaws.com and try to document.domain = example.com, rather than being excluded based on length, it would be excluded based on the fact that originalSuffix doesn't match the end of host.

    I mentioned on the internal bug, it looks like Firefox is already implementing the algorithm I mentioned ( https://searchfox.org/mozilla-central/rev/200bfc652c5128011e7725fc7c201eb125d453e7/dom/base/Document.cpp#8463-8469 ), not the algorithm mentioned in 326c644 or above. That is, it's relying on the length check as a short-circuit.

    That said, since the observable effect is the same, I'm not sure it matters, other than it took a little extra effort to reason though.

  4. annevk commented on Apr 15, 2021

    @annevk
    Member

    I still manage to confuse myself so I started writing down some examples the eventual algorithm will have to account for. If you have more, please add them.

    hostSuffixString originalHost is a registrable domain suffix of or is equal to? notes
    0.0.0.0 0.0.0.0 true hostSuffix equals originalHost
    example.com example.com true hostSuffix equals originalHost
    example.com www.example.com true
    com example.com false hostSuffix is hostSuffix's public suffix
    example example true hostSuffix equals originalHost
    compute.amazonaws.com example.compute.amazonaws.com false hostSuffix matches the end of originalHost's public suffix
    example.compute.amazonaws.com www.example.compute.amazonaws.com false hostSuffix is hostSuffix's public suffix
    amazonaws.com www.example.compute.amazonaws.com false hostSuffix matches the end of originalHost's public suffix

    In the notes hostSuffix is hostParse(hostSuffixString).

  5. added a commit that references this issue on Jul 21, 2021
    b205cae
  6. added a commit that references this issue on Jun 3, 2022
    c616584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions