chmike / domain

Go function to check domain name validity
BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

The maximum length of a domain is 255 including the final dot. #1

Open drahoslavzan opened 1 month ago

drahoslavzan commented 1 month ago

Thanks for the useful library.

I think there should be a check if the domain name has a dot at the end, if not then the length should not go over 254.

https://github.com/chmike/domain/blob/f6a50c133799ad801336e9049a55bc9b90ce7d7e/check.go#L16

chmike commented 1 month ago

Thank you very much for your interest and contribution to this package.

According to domain name specifications RFC 1035:

2.3.4. Size limits

names 255 octets or less

According to the SMTP RFC 5321:

4.5.3.1.2. Domain

The maximum total length of a domain name or number is 255 octets.

I’m not sure if a domain with a final dot is a valid domain. It doesn’t seam so considering the "preferred syntax" described in section 2.3.1 of RFC 1035. It might be a DNS internal specific thing.

Do you have any references to share to help clarify this ?

drahoslavzan commented 1 month ago

domain name ending with a dot is a valid domain, absolute domain name I think it is even mentioned in the RFC you are referring to.

but I just found an article that explains domain name length constraints with references. There is also a leading byte for each label, thus the maximum name is only 253 octets (hidden leading byte for the first label and null label or the dot at the end).

https://www.directedignorance.com/blog/maximum-length-of-domain-name

chmike commented 1 month ago

For now I will stick to the 255 octet upper limit. The reason to do so are

I leave the issue open as further inputs are welcome.

chmike commented 1 month ago

Here is a new relevant input on this matter. It is a superuser answer. In summary: