JuliusBrussee/caveman · error
ssrf: could not parse resolved IP
Error message
ssrf: could not parse resolved IP %v for host %q
What it means
Each IP returned by the resolver is converted to a netip.Addr with netip.AddrFromSlice before range-checking. If conversion fails — an IP length the parser does not accept — the library treats the resolver answer as corrupt and fails closed rather than skipping the check for that address.
Solutions
- Report/inspect the resolver answer (dig shows the raw records) and fix the resolver or NSS plugin producing malformed data
- Switch to a known-good resolver (e.g. run a local caching resolver like dnsmasq/Unbound in front)
- As a workaround, configure the destination by IP literal so LookupIPAddr is bypassed
- Retry after restarting the affected resolver daemon
Example fix
// before
addrs, _ := resolver.LookupIPAddr(ctx, host) // custom NSS plugin returns bad data
// after
// use a standard resolver backend
addrs, _ := (&net.Resolver{PreferGo: true}).LookupIPAddr(ctx, host) Defensive patterns
Strategy: fallback
Validate before calling
// pre-flight sanity: resolve and ensure each answer parses
for _, s := range mustResolve(host) {
if net.ParseIP(s) == nil {
return fmt.Errorf("resolver returned non-IP %q for %s", s, host)
}
} Try / catch
if err := ssrf.ValidateURL(ctx, endpoint, cfg); err != nil {
if strings.Contains(err.Error(), "could not parse resolved IP") {
log.Warn("malformed resolver answer; falling back to IP-literal endpoint")
endpoint = ipLiteralEndpoint
}
return err
} Prevention
- Use a standard resolver backend (PreferGo: true or plain libc) — custom NSS plugins are the usual culprit
- Restart/replace misbehaving local resolver daemons
- Pin critical endpoints to IP literals (with allowlist entries) if your DNS path is unreliable
When it happens
Trigger: Calling ssrf.ValidateURL / ValidateHost when the system resolver returns an address whose byte representation is neither 4 nor 16 bytes (malformed resolver response, unusual nsswitch/backend output).
Common situations: Buggy third-party NSS plugins or custom resolver daemons returning non-standard answers; corrupted libc resolver state; exotic DNS-to-IP translation layers (NAT64 gateways with malformed answers). This is rare in normal environments.
Related errors
- ssrf: DNS resolution failed for
- ssrf: host resolved to no addresses
- awscreds: AWS_EC2_METADATA_SERVICE_ENDPOINT is not a valid…
- awscreds: refusing plaintext container credentials endpoint…
- awscreds: refusing plaintext IMDS endpoint at host
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/635c78eb5a94eb19.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/ssrf/ssrf.go:278
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
}
// validateHostInput rejects URL/userinfo-shaped values before they reach DNS
// or an error formatter. IP literals (including zoned IPv6) are handled by
// netip.ParseAddr and may contain colons or a zone identifier.
func validateHostInput(host string) error {
if host == "" {
return errors.New("ssrf: invalid host")
}
if _, err := netip.ParseAddr(host); err == nil {
return nilView on GitHub (pinned to 3ee70a1026)