mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
plugin/rewrite: prevent illegal names (#1972)
Log and returns an error when the name rewrite creates a name that is illegal. Add test in name_test.go to see if an error is returned. Possible followup could be the only check this if a name-rewrite is done. Fixes: #1638 Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
committed by
Paul Greenberg
parent
8d9cf95ee8
commit
d9b9a955ba
@@ -9,6 +9,8 @@ import (
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/request"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
type nameRule struct {
|
||||
@@ -194,3 +196,16 @@ func (rule *substringNameRule) GetResponseRule() ResponseRule { return ResponseR
|
||||
|
||||
// GetResponseRule return a rule to rewrite the response with.
|
||||
func (rule *regexNameRule) GetResponseRule() ResponseRule { return rule.ResponseRule }
|
||||
|
||||
// validName returns true if s is valid domain name and shortern than 256 characters.
|
||||
func validName(s string) bool {
|
||||
_, ok := dns.IsDomainName(s)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if len(dns.Name(s).String()) > 255 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user