rushmorem / publicsuffix

An implementation of Mozilla's Public Suffix List in Rust
MIT License
97 stars 17 forks source link

Support for invalid hostnames, e.g., in DNS #6

Closed jonasbb closed 7 years ago

jonasbb commented 7 years ago

This crate currently seems to be the only project implementing the PSL algorithm for rust unfortunately, it requires the input to be a valid domain.

This requirement is too strict for my use case. I want to analyze DNS data, however DNS is much more generous what it allows in its labels. RFC 2181 specifies:

The DNS itself places only one restriction on the particular labels that can be used to identify resource records. That one restriction relates to the length of the label and the full name. The length of any one label is limited to between 1 and 63 octets. A full domain name is limited to 255 octets (including the separators).

For my use cases supporting the printable ASCII subset is plenty as I am mostly interested in the effective second level domain. A concrete example of what does not work currently is _tcp.example.com., which is often found for SRV resource records.

  1. Is this a use case this crate/their maintainers want to support?
  2. What would be the best way to implement support for this? Removing this line would remove the validity check. However, this check is deep down in the code such that I don't see a good way to change the API in this unfamiliar code.
rushmorem commented 7 years ago

Thank you for opening this issue!

As you have noticed, this library currently has support for only TLDs and email addresses.

  1. Is this a use case this crate/their maintainers want to support?

Yes, absolutely.

  1. What would be the best way to implement support for this?

To be consistent with the rest of the library, we will probably need to add the following method to List:

pub fn parse_dns_name(&self, name: &str) -> Result<DnsName>

We should also be able to extract Domain from DnsName where possible by implementing:

pub fn domain(&self) -> Option<Domain>

I will try to find time to implement this by tomorrow if you don't beat me to it.