{"record":{"id":"cb276272fe327f79","repo":"JuliusBrussee/caveman","slug":"ssrf-destination-s-for-host-q-is-a-private-ad-cb2762","errorCode":null,"errorMessage":"ssrf: destination %s (for host %q) is a private address; add %s to the SSRF allowlist (CAVE_SSRF_ALLOWLIST) to permit it","messagePattern":"ssrf: destination (.+?) \\(for host %q\\) is a private address; add (.+?) to the SSRF allowlist \\(CAVE_SSRF_ALLOWLIST\\) to permit it","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/ssrf/ssrf.go","lineNumber":365,"sourceCode":"\t}\n\n\tfor _, p := range blockedPrefixes {\n\t\tif p.Contains(addr) {\n\t\t\t// These ranges (link-local/metadata, ULA outside the narrow local-TUN\n\t\t\t// exception, multicast, unspecified, documentation) are absolutely\n\t\t\t// blocked — no allowlist escape in any mode.\n\t\t\treturn fmt.Errorf(\"ssrf: destination %s (for host %q) is in blocked range %s\", addr, host, p)\n\t\t}\n\t}\n\n\tif inRFC1918(addr) {\n\t\tif cfg.ManagedMode {\n\t\t\treturn fmt.Errorf(\"ssrf: destination %s (for host %q) is a private address blocked in managed mode\", addr, host)\n\t\t}\n\t\t// In self-hosted mode, RFC1918 is blocked unless the original hostname\n\t\t// OR the resolved IP literal appears in the allowlist.\n\t\tif !isInAllowList(host, port, cfg.AllowList) && !isInAllowList(addr.String(), port, cfg.AllowList) {\n\t\t\treturn fmt.Errorf(\"ssrf: destination %s (for host %q) is a private address; add %s to the SSRF allowlist (CAVE_SSRF_ALLOWLIST) to permit it\", addr, host, allowListSuggestion(addr, port))\n\t\t}\n\t}\n\treturn nil\n}\n\n// allowListSuggestion renders the allowlist entry to advise for a blocked\n// destination. It must be an entry isInAllowList would actually accept at BOTH\n// stages: ValidateHost pre-flights with an empty port, so JoinHostPort would\n// emit a trailing-colon token like \"127.0.0.1:\" that matches only the\n// port-less stage — an operator following that advice literally relaxes the\n// pre-flight guard, is blocked again at dial time by a second message naming a\n// different token, and leaves a stale weakening entry behind. The bare address\n// form is the one entry that matches every stage.\nfunc allowListSuggestion(addr netip.Addr, port string) string {\n\tif port == \"\" {\n\t\treturn addr.String()\n\t}\n\treturn net.JoinHostPort(addr.String(), port)","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/ssrf/ssrf.go#L347-L383","documentation":"The destination resolved to an RFC1918 private address in self-hosted mode, and neither the original hostname nor the resolved IP:port literal is present in the SSRF allowlist (CAVE_SSRF_ALLOWLIST). The library deliberately fails closed: private-network access requires an explicit allowlist entry, and the error even suggests the exact entry (allowListSuggestion) to add.","triggerScenarios":"ValidateURLNoResolve/validateHostPort resolved a host to 10/8, 172.16/12, or 192.168/16 with ManagedMode=false, and isInAllowList(host) and isInAllowList(addr) both returned false — e.g. CAVE_SSRF_ALLOWLIST is unset or lists only a different host:port.","commonSituations":"Forgetting to set CAVE_SSRF_ALLOWLIST in a self-hosted deployment that must reach local services; allowlist entry not matching on port (host listed without the port the URL uses); allowlist containing the IP but the code checks hostname first, or vice versa (both must miss for this error).","solutions":["Add the suggested entry to CAVE_SSRF_ALLOWLIST exactly as printed in the error message (it includes host/IP and port).","Make sure the allowlist entry includes the port (e.g. 10.0.0.5:8080, not just 10.0.0.5).","Restart/redeploy after changing the env var so the config is re-read.","Alternatively reference the service by a name whose hostname is allowlisted, so isInAllowList(host,...) passes."],"exampleFix":"// before\nexport CAVE_SSRF_ALLOWLIST=\"10.0.0.9:9090\" // wrong host/port -> blocked\n\n// after (matches the suggestion in the error)\nexport CAVE_SSRF_ALLOWLIST=\"10.0.0.5:8080\"","handlingStrategy":"validation","validationCode":"if inRFC1918(addr) && !managedMode {\n    allowed := os.Getenv(\"CAVE_SSRF_ALLOWLIST\")\n    entry := fmt.Sprintf(\"%s:%d\", addr, port)\n    if !strings.Contains(allowed, entry) {\n        return fmt.Errorf(\"precheck: add %s to CAVE_SSRF_ALLOWLIST\", entry)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := fetch(u); err != nil {\n    var suggestion string\n    if m := regexp.MustCompile(`add (\\S+) to the SSRF allowlist`).FindStringSubmatch(err.Error()); m != nil {\n        suggestion = m[1] // surface this to the operator verbatim\n    }\n    return fmt.Errorf(\"ssrf allowlist missing (%s): %w\", suggestion, err)\n}","preventionTips":["Set CAVE_SSRF_ALLOWLIST including the exact host/IP AND port used by requests.","Copy the suggested entry printed in the error message verbatim.","Restart/redeploy after allowlist changes; document required entries in deployment manifests.","Prefer hostname entries you actually use in URLs — both hostname and IP forms are checked, but the port must match."],"tags":["ssrf","security","allowlist","private-network"],"backgroundTag":"missing-config-value","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"}