Fix: Validate CNAME targets (check for "/") #37

This commit is contained in:
Tom Limoncelli 2017-06-11 09:30:12 -04:00
parent adf2f5e165
commit 46707722f6
2 changed files with 8 additions and 0 deletions

View file

@ -10,6 +10,7 @@ import (
"github.com/StackExchange/dnscontrol/providers"
"github.com/miekg/dns"
"github.com/miekg/dns/dnsutil"
"github.com/pkg/errors"
)
// Returns false if target does not validate.
@ -36,6 +37,9 @@ func checkTarget(target string) error {
if len(target) < 1 {
return fmt.Errorf("empty target")
}
if strings.ContainsAny(target, `'" +,|!£$%&/()=?^*ç°§;:_<>[]()@`) {
return errors.Errorf("target (%v) includes invalid char", target)
}
// If it containts a ".", it must end in a ".".
if strings.ContainsRune(target, '.') && target[len(target)-1] != '.' {
return fmt.Errorf("target (%v) must end with a (.) [Required if target is not single label]", target)

View file

@ -64,6 +64,10 @@ func Test_assert_valid_target(t *testing.T) {
{"foo.bar.", false},
{"foo.", false},
{"foo.bar", true},
{"foo&bar", true},
{"foo bar", true},
{"elb21.freshdesk.com/", true},
{"elb21.freshdesk.com/.", true},
}
for _, test := range tests {