Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/parser: add PublicSuffix and RegisteredDomain methods to List #2228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danderson
Copy link
Contributor

These calculate the public suffix or registered/registerable domain of some input domain, according to the strict PSL algorithm. Aside from being useful as a reference implementation of the algorithm, it comes in handy in validations that need to do stuff like figure out what registry to query for domain info.


Please check my work carefully on the PSL algorithm, in particular the handling of wildcard domains. I read the spec very carefully and also the platform.sh wiki page, and I think I've correctly implemented the strict PSL algorithm with no deviation (a public suffix *.foo.com does not imply a public suffix foo.com, and there is an implicit hardcoded * public suffix so that all unknown TLDs are automatically public suffixes).

Later on I could add modifiers to these methods to implement the variants as well, but for now I stuck to the reference algorithm. I ended up needing this logic to implement RDAP support for checking domain expiry, since I have to map a random PSL entry to "which registry RDAP service should I query", and for some suffixes that requires computing the "next" public suffix of the PSL entry :)

These calculate the public suffix or registered/registerable domain of some
input domain, according to the strict PSL algorithm. Aside from being useful
as a reference implementation of the algorithm, it comes in handy in validations
that need to do stuff like figure out what registry to query for domain info.
@wdhdev
Copy link
Contributor

wdhdev commented Oct 18, 2024

To confirm, a *.foo.com entry would indicate all subdomains at the third level (e.g. bar.foo.com) are declared as TLDs.

@danderson
Copy link
Contributor Author

TLD is may be a slight misnomer, in that it might imply the involvement of IANA-level registries. But with an adjusted term, yes: *.foo.com means that all 3-label domains ending foo.com are public suffixes in some registry (public or private), and all 4-label domains ending foo.com are registered/registrable domains.

Said in terms of cookie security, a browser will allow setting cookies on fourth.bar.foo.com (registered domain), but not on bar.foo.com (public suffix).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants