{"record":{"id":"ebb56e376edace00","repo":"JuliusBrussee/caveman","slug":"ssrf-url-must-contain-a-host","errorCode":null,"errorMessage":"ssrf: URL must contain a host","messagePattern":"ssrf: URL must contain a host","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/ssrf/ssrf.go","lineNumber":223,"sourceCode":"\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\"\n\t\t} else {\n\t\t\tport = \"80\"\n\t\t}\n\t}\n\treturn host, port, nil\n}\n\n// ValidateHost resolves host (bare hostname or IP literal) and checks all\n// resolved addresses.  Use when you have a host/port pair rather than a full\n// URL.","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/ssrf/ssrf.go#L205-L241","documentation":"Error from parseValidatedURL in the SSRF guard: the URL parsed and passed scheme checks, but contains no host component. There is nothing to resolve or port-check, and a hostless URL (e.g. a scheme-only or malformed value) is treated as invalid rather than passed through.","triggerScenarios":"Calling ssrf.ValidateURL / ValidateURLNoResolve with a URL string that parses but has no authority component: \"https://\", \"https:///api\", \"http://#frag\", or a base URL joined onto an empty variable.","commonSituations":"An unset or empty environment variable interpolated into a base URL (BASE_URL=\"\" yields \"https:///path\"); string concatenation like \"https://\"+host where host is empty; a template placeholder never filled in.","solutions":["Fix the source of the empty host — check the env var / config value feeding the URL","Validate the URL with url.Parse and assert u.Hostname() != \"\" before calling the library","Add a startup-time check that required base-URL config values are non-empty"],"exampleFix":"// before\nraw := \"https://\" + os.Getenv(\"PROVIDER_HOST\") // empty\nerr := ssrf.ValidateURL(ctx, raw, cfg)\n\n// after\nhost := os.Getenv(\"PROVIDER_HOST\")\nif host == \"\" {\n    return fmt.Errorf(\"PROVIDER_HOST is required\")\n}\nerr := ssrf.ValidateURL(ctx, \"https://\"+host, cfg)","handlingStrategy":"validation","validationCode":"u, err := url.Parse(raw)\nif err != nil || u.Hostname() == \"\" {\n    return errors.New(\"endpoint URL must include a host\")\n}","typeGuard":"func hasHost(raw string) bool {\n    u, err := url.Parse(raw)\n    return err == nil && u.Hostname() != \"\"\n}","tryCatchPattern":"if err := ssrf.ValidateURL(ctx, endpoint, cfg); err != nil {\n    if strings.Contains(err.Error(), \"must contain a host\") {\n        return fmt.Errorf(\"endpoint config is empty or malformed: %q\", endpoint)\n    }\n    return err\n}","preventionTips":["Check required URL env vars at process startup and fail fast when empty","Use url.JoinPath/base-URL joining instead of string concatenation","Never build URLs from possibly-empty string variables without a check"],"tags":["ssrf","url-validation","config","empty-value"],"backgroundTag":"empty-required-field","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"}