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:
pommee
2025-11-13 17:43:04 +01:00
parent 8f0aa7e965
commit e4f2387c11

View File

@@ -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
}