{"record":{"id":"58ab6681c8c9465a","repo":"JuliusBrussee/caveman","slug":"ssrf-invalid-url","errorCode":null,"errorMessage":"ssrf: invalid URL","messagePattern":"ssrf: invalid URL","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/ssrf/ssrf.go","lineNumber":213,"sourceCode":"\t\treturn err\n\t}\n\tif addr, parseErr := netip.ParseAddr(host); parseErr == nil {\n\t\treturn checkAddr(addr, host, port, cfg)\n\t}\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\treturn nil\n}\n\n// parseValidatedURL applies the URL-shape policy — scheme, embedded\n// credentials, managed-mode port — and returns the host/port to check.\nfunc parseValidatedURL(raw string, cfg Config) (host, port string, err error) {\n\tu, parseErr := url.Parse(raw)\n\tif parseErr != nil {\n\t\t// net/url.Error includes the raw URL (and may therefore include\n\t\t// credentials or query secrets). Keep this error field-only and stable.\n\t\treturn \"\", \"\", errors.New(\"ssrf: invalid URL\")\n\t}\n\tif u.Scheme != \"https\" && !(u.Scheme == \"http\" && !cfg.ManagedMode) {\n\t\treturn \"\", \"\", fmt.Errorf(\"ssrf: scheme %q not permitted (managed mode requires https)\", u.Scheme)\n\t}\n\tif u.User != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"ssrf: credentials embedded in URL are forbidden\")\n\t}\n\thost = u.Hostname()\n\tif host == \"\" {\n\t\treturn \"\", \"\", fmt.Errorf(\"ssrf: URL must contain a host\")\n\t}\n\tport = u.Port()\n\tif cfg.ManagedMode && port != \"\" && port != \"443\" {\n\t\treturn \"\", \"\", errors.New(\"ssrf: managed mode requires port 443\")\n\t}\n\tif port == \"\" {\n\t\tif u.Scheme == \"https\" {\n\t\t\tport = \"443\"","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/ssrf/ssrf.go#L195-L231","documentation":"This error means the URL string passed to the ssrf package's URL validation could not be parsed by net/url.Parse at all. Because net/url.Error embeds the raw URL (which may contain credentials or query secrets), the library deliberately returns a stable, field-only message with no URL content. It guards callers from feeding malformed or attacker-controlled URLs into SSRF-protected fetches.","triggerScenarios":"Calling ValidateURL or ValidateURLNoResolve with a raw string that net/url.Parse rejects — e.g. \"https://exa mple.com\" (space), \"http://%zz\", \"ht tp://host\", or any string with a malformed control character or bad percent-escape.","commonSituations":"Building a URL by string concatenation with unescaped user input or env vars; passing a proxy or webhook URL from config that contains a trailing space or stray characters; copying a URL with a hidden non-ASCII character; handing attacker-supplied input directly to ValidateURL.","solutions":["Run url.Parse(raw) on the input before calling ValidateURL and fix the parse error at the source (trim whitespace, percent-encode the query/path).","If the URL comes from config/env, validate and trim it at load time (strings.TrimSpace, url.QueryEscape on interpolated values).","If the input is user-supplied, reject it with a 400-style validation error before it reaches the ssrf layer — the library intentionally hides the URL from the error message."],"exampleFix":"// before\nclient, err := ssrf.ValidateURL(cfg.WebhookBase + \"/v1/notify?msg=\" + msg)\n// after\nu := cfg.WebhookBase + \"/v1/notify?msg=\" + url.QueryEscape(msg)\nu = strings.TrimSpace(u)\nif _, perr := url.Parse(u); perr != nil {\n    return fmt.Errorf(\"invalid webhook URL: %w\", perr)\n}\nclient, err := ssrf.ValidateURL(u)","handlingStrategy":"validation","validationCode":"func isParseableURL(raw string) bool {\n    u, err := url.Parse(strings.TrimSpace(raw))\n    return err == nil && u.Scheme != \"\" && u.Host != \"\"\n}","typeGuard":null,"tryCatchPattern":"client, err := ssrf.ValidateURL(raw)\nif err != nil {\n    if err.Error() == \"ssrf: invalid URL\" {\n        return fmt.Errorf(\"malformed URL rejected by ssrf guard: %w\", err)\n    }\n    return err\n}","preventionTips":["Trim and percent-encode user-supplied URL parts before validating","Never build URLs by naive string concatenation of unescaped values","Parse URLs at config-load time to fail fast"],"tags":["ssrf","url-parsing","input-validation","go"],"backgroundTag":"invalid-url-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"}