Skip to content

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

Closed
@KimNorgaard

Description

@KimNorgaard
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions