analyzer: strip resolver address from DNS lookup error messages
Some checks are pending
continuous-integration/drone/push Build is running
Some checks are pending
continuous-integration/drone/push Build is running
Wrap user-facing lookup errors through a new formatDNSError helper that clears net.DNSError.Server so the " on <addr>" suffix no longer leaks the upstream resolver (e.g. "on 127.0.0.11:53") to end users. Closes: https://framagit.org/happyDomain/happydeliver/-/work_items/2
This commit is contained in:
parent
b3b1a094de
commit
7953dfc3ed
6 changed files with 18 additions and 5 deletions
|
|
@ -45,7 +45,7 @@ func (d *DNSAnalyzer) checkBIMIRecord(domain, selector string) *model.BIMIRecord
|
||||||
Selector: selector,
|
Selector: selector,
|
||||||
Domain: domain,
|
Domain: domain,
|
||||||
Valid: false,
|
Valid: false,
|
||||||
Error: utils.PtrTo(fmt.Sprintf("Failed to lookup BIMI record: %v", err)),
|
Error: utils.PtrTo(fmt.Sprintf("Failed to lookup BIMI record: %s", formatDNSError(err))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ func (d *DNSAnalyzer) checkDKIMRecord(h DKIMHeader) *model.DKIMRecord {
|
||||||
Domain: h.Domain,
|
Domain: h.Domain,
|
||||||
SigningAlgorithm: signingAlgorithmPtr(h.Algorithm),
|
SigningAlgorithm: signingAlgorithmPtr(h.Algorithm),
|
||||||
Valid: false,
|
Valid: false,
|
||||||
Error: utils.PtrTo(fmt.Sprintf("Failed to lookup DKIM record: %v", err)),
|
Error: utils.PtrTo(fmt.Sprintf("Failed to lookup DKIM record: %s", formatDNSError(err))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ func (d *DNSAnalyzer) checkDMARCRecord(domain string) *model.DMARCRecord {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &model.DMARCRecord{
|
return &model.DMARCRecord{
|
||||||
Valid: false,
|
Valid: false,
|
||||||
Error: utils.PtrTo(fmt.Sprintf("Failed to lookup DMARC record: %v", err)),
|
Error: utils.PtrTo(fmt.Sprintf("Failed to lookup DMARC record: %s", formatDNSError(err))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if foundDomain == "" {
|
if foundDomain == "" {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ func (d *DNSAnalyzer) checkMXRecords(domain string) *[]model.MXRecord {
|
||||||
return &[]model.MXRecord{
|
return &[]model.MXRecord{
|
||||||
{
|
{
|
||||||
Valid: false,
|
Valid: false,
|
||||||
Error: utils.PtrTo(fmt.Sprintf("Failed to lookup MX records: %v", err)),
|
Error: utils.PtrTo(fmt.Sprintf("Failed to lookup MX records: %s", formatDNSError(err))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,22 @@ package analyzer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// formatDNSError renders a resolution error without exposing the upstream
|
||||||
|
// resolver address that net.DNSError.Error() normally appends as " on <addr>".
|
||||||
|
func formatDNSError(err error) string {
|
||||||
|
var dnsErr *net.DNSError
|
||||||
|
if errors.As(err, &dnsErr) {
|
||||||
|
sanitized := *dnsErr
|
||||||
|
sanitized.Server = ""
|
||||||
|
return sanitized.Error()
|
||||||
|
}
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
// DNSResolver defines the interface for DNS resolution operations.
|
// DNSResolver defines the interface for DNS resolution operations.
|
||||||
// This interface abstracts DNS lookups to allow for custom implementations,
|
// This interface abstracts DNS lookups to allow for custom implementations,
|
||||||
// such as mock resolvers for testing or caching resolvers for performance.
|
// such as mock resolvers for testing or caching resolvers for performance.
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ func (d *DNSAnalyzer) resolveSPFRecords(domain string, visited map[string]bool,
|
||||||
{
|
{
|
||||||
Domain: &domain,
|
Domain: &domain,
|
||||||
Valid: false,
|
Valid: false,
|
||||||
Error: utils.PtrTo(fmt.Sprintf("Failed to lookup TXT records: %v", err)),
|
Error: utils.PtrTo(fmt.Sprintf("Failed to lookup TXT records: %s", formatDNSError(err))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue