{"record":{"id":"c0a70ca672bb5cd5","repo":"JuliusBrussee/caveman","slug":"ssrf-destination-s-for-host-q-is-a-private-ad","errorCode":null,"errorMessage":"ssrf: destination %s (for host %q) is a private address blocked in managed mode","messagePattern":"ssrf: destination (.+?) \\(for host %q\\) is a private address blocked in managed mode","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/ssrf/ssrf.go","lineNumber":360,"sourceCode":"\t\t\tif !cfg.ManagedMode {\n\t\t\t\treturn nil\n\t\t\t}\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\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.","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/ssrf/ssrf.go#L342-L378","documentation":"checkAddr resolved the destination into an RFC1918 private address (10/8, 172.16/12, 192.168/16) while the library is running in managed mode (ManagedMode mirrors CAVE_ENV=prod). In managed mode private destinations are always blocked — the allowlist is ignored — to prevent a compromised/buggy service from pivoting into the internal network.","triggerScenarios":"ValidateURLNoResolve/validateHostPort resolved a hostname (or was given an IP literal) inside 10.0.0.0/8, 172.16.0.0/12, or 192.168.0.0/16 while ManagedMode=true, e.g. calling http://localhost:8080 or http://10.0.0.5 from a production (CAVE_ENV=prod) deployment.","commonSituations":"Code that works locally (self-hosted dev) suddenly fails in production because CAVE_ENV=prod flips managed mode on; pointing a webhook/fetch at an internal service hostname; staging configs copied from dev that reference private IPs.","solutions":["Route the call through an approved public endpoint or egress proxy instead of the private address.","If this is genuinely a self-hosted deployment, run with CAVE_ENV unset/not prod so ManagedMode=false, and add the destination to CAVE_SSRF_ALLOWLIST.","Move the dependency to a publicly reachable address or a gateway that the SSRF policy permits.","Verify which mode you are in: ManagedMode is derived from CAVE_ENV; check the deployment env."],"exampleFix":"// before (prod, managed mode — always fails)\nCAVE_ENV=prod ... http://10.0.0.5:8080/api\n\n// after: go through the public gateway\nCAVE_ENV=prod ... https://api.internal-gw.example.com/api","handlingStrategy":"validation","validationCode":"if inRFC1918(addr) && managedMode {\n    return fmt.Errorf(\"private destination %s unreachable in managed mode; use a public endpoint\", addr)\n}","typeGuard":"func isRFC1918(a netip.Addr) bool {\n    a = a.Unmap()\n    return a.Is4() && (netip.MustParsePrefix(\"10.0.0.0/8\").Contains(a) ||\n        netip.MustParsePrefix(\"172.16.0.0/12\").Contains(a) ||\n        netip.MustParsePrefix(\"192.168.0.0/16\").Contains(a))\n}","tryCatchPattern":"if err := callEndpoint(cfgURL); err != nil {\n    if strings.Contains(err.Error(), \"blocked in managed mode\") {\n        return fmt.Errorf(\"config points at a private address; deploy a public gateway URL: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep per-environment endpoint config: public URLs for prod (CAVE_ENV=prod), private IPs only for self-hosted dev.","Never hardcode 10.x/192.168.x hosts in code that runs in managed environments.","Test prod-mode config in CI with ManagedMode=true to catch private endpoints early."],"tags":["ssrf","security","private-network","managed-mode"],"backgroundTag":"invalid-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"}