JuliusBrussee/caveman · error
ssrf: DNS resolution failed for
Error message
ssrf: DNS resolution failed for %q: %w
What it means
The guard resolves the hostname with net.DefaultResolver.LookupIPAddr as part of pre-flight validation. If that lookup fails (resolver error, NXDOMAIN surfaced as an error, no network, cancelled context), the error is wrapped and returned — the request never proceeds because the library must see every resolved IP to range-check them.
Solutions
- Fix DNS: verify the hostname resolves with `dig`/`nslookup` from the same environment
- Check resolver configuration (/etc/resolv.conf, search domains) and network connectivity
- If dialing through an HTTP proxy because the process has no local DNS, use ssrf.ValidateURLNoResolve instead of ValidateURL
- Inspect the wrapped inner error (the %w cause) — it distinguishes timeout, NXDOMAIN, and server failure
Example fix
// before
err := ssrf.ValidateURL(ctx, "https://internal.corp.example/api", cfg) // no VPN DNS
// after
// connect VPN / fix resolver first, or go through the proxy path:
err := ssrf.ValidateURLNoResolve("https://internal.corp.example/api", cfg) Defensive patterns
Strategy: retry
Validate before calling
ips, err := net.LookupHost(host)
if err != nil {
return fmt.Errorf("pre-flight: %s is not resolvable from this environment: %v", host, err)
} Try / catch
if err := ssrf.ValidateURL(ctx, endpoint, cfg); err != nil {
var dnsErr *net.DNSError
if errors.As(err, &dnsErr) { // the ssrf error wraps it with %w
if dnsErr.Temporary() {
time.Sleep(backoff); retry()
}
return fmt.Errorf("cannot resolve %s: check DNS/VPN", host(endpoint))
}
return err
} Prevention
- Run `dig`/`nslookup` for the target host in the deployment environment before shipping config
- Behind a corporate proxy with no local DNS, call ssrf.ValidateURLNoResolve instead
- Use errors.As with *net.DNSError to distinguish transient vs permanent failures and add bounded retries
When it happens
Trigger: Calling ssrf.ValidateURL / ValidateHost for a hostname when DNS is unreachable, the resolver is misconfigured (/etc/resolv.conf, systemd-resolved down), the context is cancelled or times out mid-lookup, or the process has no outbound DNS (common behind corporate proxies — see ValidateURLNoResolve for that case).
Common situations: Typo in the hostname so DNS returns NXDOMAIN; running in an offline/air-gapped container; DNS outage at the provider; IPv6-only or IPv4-only resolver mismatch; VPN up but split-DNS not routing internal names.
Understand the failure class
- DNS resolution errors: ENOTFOUND and getaddrinfo failures — how hostname lookups fail and how to debug them.
Related errors
- githubapp: request failed
- ssrf: could not parse resolved IP
- ssrf: dial validated addresses for
- ssrf: host resolved to no addresses
- ssrf: invalid dial address
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/5856e8b1cbf6ee63.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/ssrf/ssrf.go:269
// If host is an IP literal, check it directly without a DNS round-trip.
if addr, err := netip.ParseAddr(host); err == nil {
return checkAddr(addr, host, port, cfg)
}
// "localhost" is explicitly blocked regardless of what DNS says — unless a
// self-hosted operator allowlisted it (resolution still runs, so every
// resolved address is range-checked below like any other).
if strings.EqualFold(host, "localhost") && !(!cfg.ManagedMode && isInAllowList(host, port, cfg.AllowList)) {
return fmt.Errorf("ssrf: host %q is blocked (loopback)", host)
}
// Resolve ALL addresses the hostname currently maps to. A hostname that
// returns even one blocked address is rejected (defense-in-depth against
// split-horizon / DNS rebinding scenarios where the pre-flight check and
// the dial see different answers).
addrs, err := net.DefaultResolver.LookupIPAddr(ctx, host)
if err != nil {
return fmt.Errorf("ssrf: DNS resolution failed for %q: %w", host, err)
}
if len(addrs) == 0 {
return fmt.Errorf("ssrf: host %q resolved to no addresses", host)
}
for _, ia := range addrs {
a, ok := netip.AddrFromSlice(ia.IP)
if !ok {
return fmt.Errorf("ssrf: could not parse resolved IP %v for host %q", ia.IP, host)
}
a = a.Unmap() // normalise ::ffff:x.x.x.x → x.x.x.x
if err := checkAddr(a, host, port, cfg); err != nil {
return err
}
}
return nil
}
View on GitHub (pinned to 3ee70a1026)