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

RFC1035 DNS Labels can be more than 63 characters long #1213

Open
2 tasks done
KimNorgaard opened this issue Jan 12, 2024 · 0 comments · May be fixed by #1214
Open
2 tasks done

RFC1035 DNS Labels can be more than 63 characters long #1213

KimNorgaard opened this issue Jan 12, 2024 · 0 comments · May be fixed by #1214

Comments

@KimNorgaard
Copy link

KimNorgaard commented Jan 12, 2024

  • I have looked at the documentation here first?
  • I have looked at the examples provided that may showcase my question here?

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

The current regular expression for evaluating if a DNS label is RFC1035 compliant is:

dnsRegexStringRFC1035Label = "^[a-z]([-a-z0-9]*[a-z0-9]){0,62}$"

The intention is clear (one alpha character followed by 0-62 alphanum-hypen characters followed by one alphanumeric character). However it is flawed since the max and min count accounts for everything within the parentheses. In effect this allows for unlimited length.

Code sample, to showcase or reproduce:

The code at https://go.dev/play/p/N7bXBCE-mvl should return false but returns true.

To test it in the current main branch:

Add the following tests to TestRFC1035LabelFormatValidation in validate_test.go:

{"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk", "dns_rfc1035_label", true},
{"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl", "dns_rfc1035_label", false},

Run the tests. The second one will fail. It should not.

Fix

The fix it to amend the regexp and introduce a length check in isDnsRFC1035LabelFormat(). Kubernetes and other projects does this exact same thing.

The regex should be:

^[a-z]([-a-z0-9]*[a-z0-9])?$

I'll submit a PR.

@KimNorgaard KimNorgaard linked a pull request Jan 12, 2024 that will close this issue
1 task
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 a pull request may close this issue.

1 participant