JuliusBrussee/caveman · error
ssrf: invalid dial address
Error message
ssrf: invalid dial address
What it means
The DialContext control hook installed by the ssrf transport received a dial address without a host:port split (net.SplitHostPort failed). Because the package must validate the hostname itself (to close the DNS-rebinding window, it cannot let net.Dialer re-resolve), an unparseable address is rejected outright.
Solutions
- Always dial with net.JoinHostPort(host, port) so IPv6 hosts are bracketed and the address always splits cleanly.
- When wrapping the transport, call the ssrf control DialContext last (or pass through the original addr unmodified) so it receives canonical addresses.
- For IPv6, pre-bracket the host: net.JoinHostPort("::1", "443") produces "[::1]:443" which SplitHostPort accepts.
Example fix
// before conn, derr := dialer.DialContext(ctx, "tcp", host+":"+port) // breaks for IPv6 // after addr := net.JoinHostPort(host, port) conn, derr := dialer.DialContext(ctx, "tcp", addr)
Defensive patterns
Strategy: try-catch
Validate before calling
if _, _, err := net.SplitHostPort(addr); err != nil {
return fmt.Errorf("dial address %q is not host:port", addr)
} Try / catch
conn, err := guardedDial(ctx, network, addr)
if err != nil && err.Error() == "ssrf: invalid dial address" {
return nil, fmt.Errorf("dialer must receive host:port (use net.JoinHostPort), got %q", addr)
} Prevention
- Always build dial addresses with net.JoinHostPort
- Bracket IPv6 literals (JoinHostPort does this automatically)
- Do not rewrite addr strings in middleware wrapping the ssrf transport
When it happens
Trigger: A custom or wrapped transport/dialer hands the ssrf control DialContext an address like "example.com" (no port), "[::1]" (no port), "host:1:2:3" (too many colons), or an empty string instead of the canonical "host:port" form.
Common situations: Composing the ssrf transport with third-party middleware that rewrites addresses; IPv6 literals not bracketed before dialing; custom proxy dialers joining host and port incorrectly; tests injecting hand-built addr strings.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- ssrf: dial validated addresses for
- githubapp: base_url rejected by SSRF guard
- kms: read response
- kms: request failed
- secretbox: KMS encrypt
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/c026b4a4a90fa468.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/ssrf/ssrf.go:450
}
return &net.Dialer{
Timeout: connectTimeout,
KeepAlive: 30 * time.Second,
}
}
type lookupNetIPFunc func(context.Context, string, string) ([]netip.Addr, error)
type rawDialContextFunc func(context.Context, string, string) (net.Conn, error)
// dialContextWith resolves each hostname exactly once, validates every returned
// address, then dials a validated IP literal. net.Transport passes hostnames to
// DialContext; validating the hostname and handing it to net.Dialer would cause
// a second DNS lookup and reopen the DNS-rebinding window.
func dialContextWith(cfg Config, lookup lookupNetIPFunc, dial rawDialContextFunc) func(ctx context.Context, network, addr string) (net.Conn, error) {
return func(ctx context.Context, network, addr string) (net.Conn, error) {
host, port, err := net.SplitHostPort(addr)
if err != nil {
return nil, errors.New("ssrf: invalid dial address")
}
if err := validateHostInput(host); err != nil {
return nil, err
}
if cfg.ManagedMode && port != "443" {
return nil, errors.New("ssrf: managed mode requires port 443")
}
if parsed, parseErr := netip.ParseAddr(host); parseErr == nil {
parsed = parsed.WithZone("").Unmap()
if err := checkAddr(parsed, host, port, cfg); err != nil {
return nil, err
}
return dial(ctx, network, net.JoinHostPort(parsed.String(), port))
}
if strings.EqualFold(host, "localhost") && !(!cfg.ManagedMode && isInAllowList(host, port, cfg.AllowList)) {
return nil, fmt.Errorf("ssrf: host %q is blocked (loopback)", host)View on GitHub (pinned to 3ee70a1026)