JuliusBrussee/caveman · error
ssrf: dial validated addresses for
Error message
ssrf: dial validated addresses for %q: %w
What it means
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.
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.
Example fix
// before url := "http://10.0.0.5:8080" // nothing listening on 8080 // after url := "http://10.0.0.5:9090" // actual listening port
Defensive patterns
Strategy: retry
Validate before calling
for _, a := range resolvedAddrs {
conn, err := net.DialTimeout("tcp", net.JoinHostPort(a.String(), port), 3*time.Second)
if err != nil { lastPrecheckErr = err }
if conn != nil { conn.Close(); break }
}
// fail fast if all precheck dials failed Try / catch
if err := client.Do(req); err != nil {
if strings.Contains(err.Error(), "dial validated addresses") {
var netErr net.Error
if errors.As(err, &netErr) && netErr.Timeout() {
// retry with backoff; otherwise (refused/unreachable) surface an ops alert
}
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- ssrf: invalid dial address
- ssrf: DNS resolution failed for
- AbortError
- awscreds: AWS_EC2_METADATA_SERVICE_ENDPOINT is not a valid…
- awscreds: read response
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/48a89bc9b08026f6.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/ssrf/ssrf.go:494
}
checked := make([]netip.Addr, 0, len(addrs))
for _, resolved := range addrs {
resolved = resolved.WithZone("").Unmap()
if err := checkAddr(resolved, host, port, cfg); err != nil {
return nil, err
}
checked = append(checked, resolved)
}
var lastErr error
for _, resolved := range checked {
conn, err := dial(ctx, network, net.JoinHostPort(resolved.String(), port))
if err == nil {
return conn, nil
}
lastErr = err
}
return nil, fmt.Errorf("ssrf: dial validated addresses for %q: %w", host, lastErr)
}
}
// NewHTTPClient returns an *http.Client whose Transport enforces the SSRF
// policy at dial time. The caller may set additional fields (Timeout, etc.)
// on the returned client.
//
// Use this to create the gateway's upstream client so all outbound provider
// requests are guarded even against DNS-rebinding attacks.
func NewHTTPClient(cfg Config) *http.Client {
t := http.DefaultTransport.(*http.Transport).Clone()
// SSRF enforcement observes the address passed to DialContext. Go's
// default transport may instead dial an HTTP(S)_PROXY address and leave the
// proxy to connect to the request destination, which would move the guarded
// boundary away from the host this client was built to protect. Protected
// clients are therefore direct unless the caller opts in through cfg.Proxy,
// which wraps the proxy selection in a destination check (see proxiedHooks).
t.Proxy = nilView on GitHub (pinned to 3ee70a1026)