analyzer: strip resolver address from DNS lookup error messages
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:
nemunaire 2026-06-03 23:06:10 +09:00
commit 7953dfc3ed
6 changed files with 18 additions and 5 deletions

View file

@ -23,9 +23,22 @@ package analyzer
import (
"context"
"errors"
"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.
// This interface abstracts DNS lookups to allow for custom implementations,
// such as mock resolvers for testing or caching resolvers for performance.