'What are valid characters for a DNS Zone file and how can I sanitize user input?

I'm working on an interface to allow our clients to update their DNS on their own.

I have 2 questions:

  1. What constitutes valid a valid host and target records? (A, CNAME, MX, TXT) i.e. if the user enters ........ for the host and target the DNS server won't like that.
  2. Is there a regex I can use to sanitize user input?

BTW it is BIND9 DNS and C# web app.

Thanks,

Kyle



Solution 1:[1]

The answer used to be easy, but not anymore.

You can use almost any Unicode characters, but they should go thru a normalization, and encoding process.

See RFC 3490 (IDNA), RFC 3454 (Stringprep), RFC 3491 (Nameprep), RFC 3492 (Punycode)

Or go with Wikipedia for the big picture (http://en.wikipedia.org/wiki/Internationalized_domain_name).

Solution 2:[2]

Do not forget AAAA, the IPv6 addresses (remember, only two years left before we run out of IPv4 addresses...).

For the legal names, read RFC 1123, section 2.1. domain names can be anything, host names have a much stricter syntax (see RFC 1123).

Solution 3:[3]

apart from suggestions above, if anyone still faces issue with importing zone files from godaddy to route53, remove the comments. it took me few hours to figure out that comments written as ;comment line here were causing route 53 system to not parse the zone file properly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mihai Nita
Solution 2 bortzmeyer
Solution 3 Leonardo Alves Machado