{"record":{"id":"c026b4a4a90fa468","repo":"JuliusBrussee/caveman","slug":"ssrf-invalid-dial-address","errorCode":null,"errorMessage":"ssrf: invalid dial address","messagePattern":"ssrf: invalid dial address","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/ssrf/ssrf.go","lineNumber":450,"sourceCode":"\t}\n\treturn &net.Dialer{\n\t\tTimeout:   connectTimeout,\n\t\tKeepAlive: 30 * time.Second,\n\t}\n}\n\ntype lookupNetIPFunc func(context.Context, string, string) ([]netip.Addr, error)\ntype rawDialContextFunc func(context.Context, string, string) (net.Conn, error)\n\n// dialContextWith resolves each hostname exactly once, validates every returned\n// address, then dials a validated IP literal. net.Transport passes hostnames to\n// DialContext; validating the hostname and handing it to net.Dialer would cause\n// a second DNS lookup and reopen the DNS-rebinding window.\nfunc dialContextWith(cfg Config, lookup lookupNetIPFunc, dial rawDialContextFunc) func(ctx context.Context, network, addr string) (net.Conn, error) {\n\treturn func(ctx context.Context, network, addr string) (net.Conn, error) {\n\t\thost, port, err := net.SplitHostPort(addr)\n\t\tif err != nil {\n\t\t\treturn nil, errors.New(\"ssrf: invalid dial address\")\n\t\t}\n\t\tif err := validateHostInput(host); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif cfg.ManagedMode && port != \"443\" {\n\t\t\treturn nil, errors.New(\"ssrf: managed mode requires port 443\")\n\t\t}\n\n\t\tif parsed, parseErr := netip.ParseAddr(host); parseErr == nil {\n\t\t\tparsed = parsed.WithZone(\"\").Unmap()\n\t\t\tif err := checkAddr(parsed, host, port, cfg); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\treturn dial(ctx, network, net.JoinHostPort(parsed.String(), port))\n\t\t}\n\n\t\tif strings.EqualFold(host, \"localhost\") && !(!cfg.ManagedMode && isInAllowList(host, port, cfg.AllowList)) {\n\t\t\treturn nil, fmt.Errorf(\"ssrf: host %q is blocked (loopback)\", host)","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/ssrf/ssrf.go#L432-L468","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconn, derr := dialer.DialContext(ctx, \"tcp\", host+\":\"+port) // breaks for IPv6\n// after\naddr := net.JoinHostPort(host, port)\nconn, derr := dialer.DialContext(ctx, \"tcp\", addr)","handlingStrategy":"try-catch","validationCode":"if _, _, err := net.SplitHostPort(addr); err != nil {\n    return fmt.Errorf(\"dial address %q is not host:port\", addr)\n}","typeGuard":null,"tryCatchPattern":"conn, err := guardedDial(ctx, network, addr)\nif err != nil && err.Error() == \"ssrf: invalid dial address\" {\n    return nil, fmt.Errorf(\"dialer must receive host:port (use net.JoinHostPort), got %q\", addr)\n}","preventionTips":["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"],"tags":["ssrf","dial","network","go"],"backgroundTag":"invalid-argument-format","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"}