JuliusBrussee/caveman · error

ssrf: destination (for host ) is a private address; add to…

Error message

ssrf: destination %s (for host %q) is a private address; add %s to the SSRF allowlist (CAVE_SSRF_ALLOWLIST) to permit it

What it means

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.

Solutions

  1. Add the suggested entry to CAVE_SSRF_ALLOWLIST exactly as printed in the error message (it includes host/IP and port).
  2. Make sure the allowlist entry includes the port (e.g. 10.0.0.5:8080, not just 10.0.0.5).
  3. Restart/redeploy after changing the env var so the config is re-read.
  4. Alternatively reference the service by a name whose hostname is allowlisted, so isInAllowList(host,...) passes.

Example fix

// before
export CAVE_SSRF_ALLOWLIST="10.0.0.9:9090" // wrong host/port -> blocked

// after (matches the suggestion in the error)
export CAVE_SSRF_ALLOWLIST="10.0.0.5:8080"
Defensive patterns

Strategy: validation

Validate before calling

if inRFC1918(addr) && !managedMode {
    allowed := os.Getenv("CAVE_SSRF_ALLOWLIST")
    entry := fmt.Sprintf("%s:%d", addr, port)
    if !strings.Contains(allowed, entry) {
        return fmt.Errorf("precheck: add %s to CAVE_SSRF_ALLOWLIST", entry)
    }
}

Try / catch

if err := fetch(u); err != nil {
    var suggestion string
    if m := regexp.MustCompile(`add (\S+) to the SSRF allowlist`).FindStringSubmatch(err.Error()); m != nil {
        suggestion = m[1] // surface this to the operator verbatim
    }
    return fmt.Errorf("ssrf allowlist missing (%s): %w", suggestion, err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Understand the failure class

Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/cb276272fe327f79. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/ssrf/ssrf.go:365

	}

	for _, p := range blockedPrefixes {
		if p.Contains(addr) {
			// These ranges (link-local/metadata, ULA outside the narrow local-TUN
			// exception, multicast, unspecified, documentation) are absolutely
			// blocked — no allowlist escape in any mode.
			return fmt.Errorf("ssrf: destination %s (for host %q) is in blocked range %s", addr, host, p)
		}
	}

	if inRFC1918(addr) {
		if cfg.ManagedMode {
			return fmt.Errorf("ssrf: destination %s (for host %q) is a private address blocked in managed mode", addr, host)
		}
		// In self-hosted mode, RFC1918 is blocked unless the original hostname
		// OR the resolved IP literal appears in the allowlist.
		if !isInAllowList(host, port, cfg.AllowList) && !isInAllowList(addr.String(), port, cfg.AllowList) {
			return 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))
		}
	}
	return nil
}

// allowListSuggestion renders the allowlist entry to advise for a blocked
// destination. It must be an entry isInAllowList would actually accept at BOTH
// stages: ValidateHost pre-flights with an empty port, so JoinHostPort would
// emit a trailing-colon token like "127.0.0.1:" that matches only the
// port-less stage — an operator following that advice literally relaxes the
// pre-flight guard, is blocked again at dial time by a second message naming a
// different token, and leaves a stale weakening entry behind. The bare address
// form is the one entry that matches every stage.
func allowListSuggestion(addr netip.Addr, port string) string {
	if port == "" {
		return addr.String()
	}
	return net.JoinHostPort(addr.String(), port)

View on GitHub (pinned to 3ee70a1026)