mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
Warn when domain names are not in RFC1035 preferred syntax (#5414)
Warn when domain names are not in RFC1035 preferred syntax Signed-off-by: Md Sahil <Mohdssahil1@gmail.com>
This commit is contained in:
@@ -2,9 +2,22 @@ package dnsserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
|
||||
"github.com/coredns/coredns/plugin/pkg/dnsutil"
|
||||
)
|
||||
|
||||
// checkZoneSyntax() checks whether the given string match 1035 Preferred Syntax or not.
|
||||
// The root zone, and all reverse zones always return true even though they technically don't meet 1035 Preferred Syntax
|
||||
func checkZoneSyntax(zone string) bool {
|
||||
if zone == "." || dnsutil.IsReverse(zone) != 0 {
|
||||
return true
|
||||
}
|
||||
regex1035PreferredSyntax, _ := regexp.MatchString(`^(([A-Za-z]([A-Za-z0-9-]*[A-Za-z0-9])?)\.)+$`, zone)
|
||||
return regex1035PreferredSyntax
|
||||
}
|
||||
|
||||
// startUpZones creates the text that we show when starting up:
|
||||
// grpc://example.com.:1055
|
||||
// example.com.:1053 on 127.0.0.1
|
||||
@@ -13,6 +26,7 @@ func startUpZones(protocol, addr string, zones map[string]*Config) string {
|
||||
|
||||
keys := make([]string, len(zones))
|
||||
i := 0
|
||||
|
||||
for k := range zones {
|
||||
keys[i] = k
|
||||
i++
|
||||
@@ -20,6 +34,9 @@ func startUpZones(protocol, addr string, zones map[string]*Config) string {
|
||||
sort.Strings(keys)
|
||||
|
||||
for _, zone := range keys {
|
||||
if !checkZoneSyntax(zone) {
|
||||
s += fmt.Sprintf("Warning: Domain %q does not follow RFC1035 preferred syntax\n", zone)
|
||||
}
|
||||
// split addr into protocol, IP and Port
|
||||
_, ip, port, err := SplitProtocolHostPort(addr)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user