{"record":{"id":"635c78eb5a94eb19","repo":"JuliusBrussee/caveman","slug":"ssrf-could-not-parse-resolved-ip-v-for-host-q","errorCode":null,"errorMessage":"ssrf: could not parse resolved IP %v for host %q","messagePattern":"ssrf: could not parse resolved IP (.+?) for host %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/ssrf/ssrf.go","lineNumber":278,"sourceCode":"\t\treturn fmt.Errorf(\"ssrf: host %q is blocked (loopback)\", host)\n\t}\n\n\t// Resolve ALL addresses the hostname currently maps to.  A hostname that\n\t// returns even one blocked address is rejected (defense-in-depth against\n\t// split-horizon / DNS rebinding scenarios where the pre-flight check and\n\t// the dial see different answers).\n\taddrs, err := net.DefaultResolver.LookupIPAddr(ctx, host)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"ssrf: DNS resolution failed for %q: %w\", host, err)\n\t}\n\tif len(addrs) == 0 {\n\t\treturn fmt.Errorf(\"ssrf: host %q resolved to no addresses\", host)\n\t}\n\n\tfor _, ia := range addrs {\n\t\ta, ok := netip.AddrFromSlice(ia.IP)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"ssrf: could not parse resolved IP %v for host %q\", ia.IP, host)\n\t\t}\n\t\ta = a.Unmap() // normalise ::ffff:x.x.x.x → x.x.x.x\n\t\tif err := checkAddr(a, host, port, cfg); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\n// validateHostInput rejects URL/userinfo-shaped values before they reach DNS\n// or an error formatter. IP literals (including zoned IPv6) are handled by\n// netip.ParseAddr and may contain colons or a zone identifier.\nfunc validateHostInput(host string) error {\n\tif host == \"\" {\n\t\treturn errors.New(\"ssrf: invalid host\")\n\t}\n\tif _, err := netip.ParseAddr(host); err == nil {\n\t\treturn nil","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/ssrf/ssrf.go#L260-L296","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\naddrs, _ := resolver.LookupIPAddr(ctx, host) // custom NSS plugin returns bad data\n\n// after\n// use a standard resolver backend\naddrs, _ := (&net.Resolver{PreferGo: true}).LookupIPAddr(ctx, host)","handlingStrategy":"fallback","validationCode":"// pre-flight sanity: resolve and ensure each answer parses\nfor _, s := range mustResolve(host) {\n    if net.ParseIP(s) == nil {\n        return fmt.Errorf(\"resolver returned non-IP %q for %s\", s, host)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := ssrf.ValidateURL(ctx, endpoint, cfg); err != nil {\n    if strings.Contains(err.Error(), \"could not parse resolved IP\") {\n        log.Warn(\"malformed resolver answer; falling back to IP-literal endpoint\")\n        endpoint = ipLiteralEndpoint\n    }\n    return err\n}","preventionTips":["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"],"tags":["ssrf","dns","netip","fail-closed"],"backgroundTag":"unexpected-response-shape","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}