{"record":{"id":"48a89bc9b08026f6","repo":"JuliusBrussee/caveman","slug":"ssrf-dial-validated-addresses-for-q-w","errorCode":null,"errorMessage":"ssrf: dial validated addresses for %q: %w","messagePattern":"ssrf: dial validated addresses for %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/ssrf/ssrf.go","lineNumber":494,"sourceCode":"\t\t}\n\t\tchecked := make([]netip.Addr, 0, len(addrs))\n\t\tfor _, resolved := range addrs {\n\t\t\tresolved = resolved.WithZone(\"\").Unmap()\n\t\t\tif err := checkAddr(resolved, host, port, cfg); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tchecked = append(checked, resolved)\n\t\t}\n\n\t\tvar lastErr error\n\t\tfor _, resolved := range checked {\n\t\t\tconn, err := dial(ctx, network, net.JoinHostPort(resolved.String(), port))\n\t\t\tif err == nil {\n\t\t\t\treturn conn, nil\n\t\t\t}\n\t\t\tlastErr = err\n\t\t}\n\t\treturn nil, fmt.Errorf(\"ssrf: dial validated addresses for %q: %w\", host, lastErr)\n\t}\n}\n\n// NewHTTPClient returns an *http.Client whose Transport enforces the SSRF\n// policy at dial time.  The caller may set additional fields (Timeout, etc.)\n// on the returned client.\n//\n// Use this to create the gateway's upstream client so all outbound provider\n// requests are guarded even against DNS-rebinding attacks.\nfunc NewHTTPClient(cfg Config) *http.Client {\n\tt := http.DefaultTransport.(*http.Transport).Clone()\n\t// SSRF enforcement observes the address passed to DialContext. Go's\n\t// default transport may instead dial an HTTP(S)_PROXY address and leave the\n\t// proxy to connect to the request destination, which would move the guarded\n\t// boundary away from the host this client was built to protect. Protected\n\t// clients are therefore direct unless the caller opts in through cfg.Proxy,\n\t// which wraps the proxy selection in a destination check (see proxiedHooks).\n\tt.Proxy = nil","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/ssrf/ssrf.go#L476-L512","documentation":"Every address that passed SSRF validation was attempted, and all dial attempts failed; the last dial error is wrapped and returned as one aggregate error. This means the policy checks succeeded — the destination is allowed — but the network itself refused/timed out on each validated IP.","triggerScenarios":"The guarded dialer loops over the checked addresses calling dial(ctx, network, host:port); each attempt returns an error (connection refused, unreachable, timeout, TLS failure at dial stage) and lastErr is non-nil at the end of the loop.","commonSituations":"Service not listening on the target port (connection refused); firewall dropping traffic to private ranges; the resolved IPs are stale after a service redeploy; IPv6 address tried where only IPv4 is reachable (or vice versa).","solutions":["Read the wrapped cause (%w) to distinguish refused vs timeout vs unreachable.","Confirm the service is up and listening on the port: `nc -zv <host> <port>` from the same host.","Check firewall/security-group rules for the validated address.","Flush/re-check DNS if records are stale, or pin a correct IP via the allowlist."],"exampleFix":"// before\nurl := \"http://10.0.0.5:8080\" // nothing listening on 8080\n\n// after\nurl := \"http://10.0.0.5:9090\" // actual listening port","handlingStrategy":"retry","validationCode":"for _, a := range resolvedAddrs {\n    conn, err := net.DialTimeout(\"tcp\", net.JoinHostPort(a.String(), port), 3*time.Second)\n    if err != nil { lastPrecheckErr = err }\n    if conn != nil { conn.Close(); break }\n}\n// fail fast if all precheck dials failed","typeGuard":null,"tryCatchPattern":"if err := client.Do(req); err != nil {\n    if strings.Contains(err.Error(), \"dial validated addresses\") {\n        var netErr net.Error\n        if errors.As(err, &netErr) && netErr.Timeout() {\n            // retry with backoff; otherwise (refused/unreachable) surface an ops alert\n        }\n    }\n    return err\n}","preventionTips":["Health-check target host:port before traffic; alert on refused connections.","Keep DNS TTLs low enough that redeploys propagate before clients dial stale IPs.","Check firewall/security-group rules for the validated addresses.","Retry only timeouts/transient errors; connection refused needs a service fix, not retries."],"tags":["network","dial","connection-refused","ssrf"],"backgroundTag":"connection-refused","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"}