mirror of
https://github.com/pommee/goaway.git
synced 2026-01-06 05:49:35 -06:00
chore: validate domain name shorter than 2 characters
Will need to add more validation going forward; but this was something I encountered and it was a smaller fix.
This commit is contained in:
@@ -95,10 +95,7 @@ func NewDNSServer(config *settings.Config, dbconn *gorm.DB, cert tls.Certificate
|
||||
}
|
||||
|
||||
func (s *DNSServer) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
||||
if len(r.Question) != 1 {
|
||||
log.Warning("Query contains more than one question, ignoring!")
|
||||
r.SetRcode(r, dns.RcodeFormatError)
|
||||
_ = w.WriteMsg(r)
|
||||
if !s.validQuery(w, r) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -186,3 +183,23 @@ func (s *DNSServer) WSCom(message communicationMessage) {
|
||||
s.WSCommunication = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DNSServer) validQuery(w dns.ResponseWriter, r *dns.Msg) bool {
|
||||
failedCallback := func() bool {
|
||||
r.SetRcode(r, dns.RcodeFormatError)
|
||||
_ = w.WriteMsg(r)
|
||||
return false
|
||||
}
|
||||
|
||||
if len(r.Question) != 1 {
|
||||
log.Warning("Query contains more than one question, ignoring!")
|
||||
return failedCallback()
|
||||
}
|
||||
|
||||
if len(r.Question[0].Name) <= 1 {
|
||||
log.Warning("Query contains invalid question name '%s', ignoring!", r.Question[0].Name)
|
||||
return failedCallback()
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user