{"record":{"id":"5856e8b1cbf6ee63","repo":"JuliusBrussee/caveman","slug":"ssrf-dns-resolution-failed-for-q-w","errorCode":null,"errorMessage":"ssrf: DNS resolution failed for %q: %w","messagePattern":"ssrf: DNS resolution failed for %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/ssrf/ssrf.go","lineNumber":269,"sourceCode":"\t// If host is an IP literal, check it directly without a DNS round-trip.\n\tif addr, err := netip.ParseAddr(host); err == nil {\n\t\treturn checkAddr(addr, host, port, cfg)\n\t}\n\n\t// \"localhost\" is explicitly blocked regardless of what DNS says — unless a\n\t// self-hosted operator allowlisted it (resolution still runs, so every\n\t// resolved address is range-checked below like any other).\n\tif strings.EqualFold(host, \"localhost\") && !(!cfg.ManagedMode && isInAllowList(host, port, cfg.AllowList)) {\n\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","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/ssrf/ssrf.go#L251-L287","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nerr := ssrf.ValidateURL(ctx, \"https://internal.corp.example/api\", cfg) // no VPN DNS\n\n// after\n// connect VPN / fix resolver first, or go through the proxy path:\nerr := ssrf.ValidateURLNoResolve(\"https://internal.corp.example/api\", cfg)","handlingStrategy":"retry","validationCode":"ips, err := net.LookupHost(host)\nif err != nil {\n    return fmt.Errorf(\"pre-flight: %s is not resolvable from this environment: %v\", host, err)\n}","typeGuard":null,"tryCatchPattern":"if err := ssrf.ValidateURL(ctx, endpoint, cfg); err != nil {\n    var dnsErr *net.DNSError\n    if errors.As(err, &dnsErr) { // the ssrf error wraps it with %w\n        if dnsErr.Temporary() {\n            time.Sleep(backoff); retry()\n        }\n        return fmt.Errorf(\"cannot resolve %s: check DNS/VPN\", host(endpoint))\n    }\n    return err\n}","preventionTips":["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"],"tags":["ssrf","dns","network","resolution-failed"],"backgroundTag":"dns-resolution-failed","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"}