validateDomain() is too strict #1967

Open
opened 2025-11-20 06:10:21 -05:00 by saavagebueno · 1 comment
Owner

Originally created by @zvpunry on GitHub (Jun 17, 2025).

The domainPattern regex in management/server/nameserver.go is too strict, it doesn't allow labels that are completely valid according to rfc1035. As an example, it forbids labels like "x", "x1, "x--x" as tld and possibly some more.

The validateDomain() function must allow rfc1035 labels. The easiest fix is to remove the regex and just depend on dns.IsDomainName() which is not very strict.

If some additional validation is needed, it must allow rfc1035 labels. But maybe even rfc1035 is too strict: See https://www.rfc-editor.org/rfc/rfc2181#section-11

Originally created by @zvpunry on GitHub (Jun 17, 2025). The domainPattern regex in management/server/nameserver.go is too strict, it doesn't allow labels that are completely valid according to rfc1035. As an example, it forbids labels like "x", "x1, "x--x" as tld and possibly some more. The validateDomain() function must allow rfc1035 labels. The easiest fix is to remove the regex and just depend on dns.IsDomainName() which is not very strict. If some additional validation is needed, it must allow rfc1035 labels. But maybe even rfc1035 is too strict: See https://www.rfc-editor.org/rfc/rfc2181#section-11
saavagebueno added the feature-requestdns labels 2025-11-20 06:10:21 -05:00
Author
Owner

@zvpunry commented on GitHub (Jun 17, 2025):

There is also https://www.rfc-editor.org/rfc/rfc1123#section-2 which references the syntax from rfc952 (which is the same as rfc1035) but also allows a label to start with a digit. A regex to validate such a name would be ^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.?)+$ https://regex101.com/r/GXfv3m/1

I mentioned rfc2181 earlier, it basically says everything can be used as a label but it must be limited to 63 bytes and the whole domainname must fit into 255 bytes, which is enforced by dns.IsDomainName().

@zvpunry commented on GitHub (Jun 17, 2025): There is also https://www.rfc-editor.org/rfc/rfc1123#section-2 which references the syntax from rfc952 (which is the same as rfc1035) but also allows a label to start with a digit. A regex to validate such a name would be `^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.?)+$` https://regex101.com/r/GXfv3m/1 I mentioned [rfc2181](https://www.rfc-editor.org/rfc/rfc2181#section-11) earlier, it basically says everything can be used as a label but it must be limited to 63 bytes and the whole domainname must fit into 255 bytes, which is enforced by dns.IsDomainName().
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SVI/netbird#1967