BerriAI/litellm · error · SSRFError
URL targets a blocked address
Error message
URL targets a blocked address ({resolved_ip}). If this is a legitimate internal service, add the host to `user_url_allowed_hosts` in general_settings. What it means
SSRFError raised when any address the hostname resolves to is blocked by litellm's default-deny policy: _is_blocked_ip blocks every IP that is not globally routable (loopback, RFC1918, link-local including the 169.254.169.254 cloud-metadata endpoint, multicast, unparseable addresses, plus the Azure Wire Server), and every resolved address is checked. Legitimate internal services can be exempted per host via user_url_allowed_hosts in general_settings (litellm.user_url_allowed_hosts).
Solutions
- If the target is a legitimate internal service, add the host (bare host, host:port, or full origin) to user_url_allowed_hosts under general_settings.
- Expose the service on a globally routable address instead.
- Catch SSRFError and return a 4xx so the caller knows the URL was refused.
- Only for fully trusted environments: litellm.user_url_validation = False disables the whole validator (SSRF risk).
Example fix
# before (config.yaml)
general_settings: {} # fetching http://localhost:11434/... raises SSRFError
# after
general_settings:
user_url_allowed_hosts:
- "localhost:11434"
- "internal-files.corp" Defensive patterns
Strategy: try-catch
Validate before calling
from urllib.parse import urlparse
import litellm
p = urlparse(user_url)
allowed = [str(h) for h in (getattr(litellm, "user_url_allowed_hosts", []) or [])]
normalized = (p.hostname or "").lower()
if not any(normalized in a or a.startswith(normalized + ":") for a in allowed):
# host is not exempted; expect default-deny for private IPs
pass Try / catch
from litellm.litellm_core_utils.url_utils import SSRFError
try:
resp = safe_get(client, user_url)
except SSRFError as e:
if "blocked address" in str(e):
raise HTTPException(status_code=400, detail="URL points to a blocked (internal) address; ask the admin to allowlist it")
raise Prevention
- Pre-configure user_url_allowed_hosts in general_settings for the internal services your users legitimately reference.
- Do not disable user_url_validation merely to reach internal hosts — use the allowlist so protection stays on.
- Document for users which hosts are fetchable; blocked-address errors are policy working as intended.
When it happens
Trigger: Fetching http://localhost:8080/x, http://10.0.0.5/api, an internal-only hostname, or a public-looking name under split-horizon DNS that resolves to a private IP from inside the network.
Common situations: Self-hosted proxy deployments where users reference internal/self-hosted services (Ollama on localhost, internal file servers) through endpoints that fetch user URLs; enterprises with split-horizon DNS; SSRF probes targeting cloud metadata.
Related errors
- Compresr guardrail api_base
- DNS resolution failed for
- only accepts identity headers from configured trusted proxy…
- ip_filtering
- MAVVRIK_API_ENDPOINT host must be a Mavvrik domain
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/25ff484475b51dc4.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/url_utils.py:291
effective_port: Final = port if port is not None else default_port
host_header: Final = _format_host_header(hostname, effective_port, default_port)
is_allowlisted: Final = _is_host_allowlisted(hostname, effective_port)
# Resolve hostname and validate ALL addresses
try:
addrinfo: Final = socket.getaddrinfo(hostname, effective_port, proto=socket.IPPROTO_TCP)
except socket.gaierror as e:
raise SSRFError(f"DNS resolution failed for '{hostname}': {e}")
if not addrinfo:
raise SSRFError(f"No addresses found for '{hostname}'")
if not is_allowlisted:
for family, type_, proto, canonname, sockaddr in addrinfo:
resolved_ip = _sockaddr_host(sockaddr)
if _is_blocked_ip(resolved_ip):
raise SSRFError(
f"URL targets a blocked address ({resolved_ip}). "
"If this is a legitimate internal service, add the host "
"to `user_url_allowed_hosts` in general_settings."
)
# For HTTPS with SSL verification enabled, TLS certificate validation
# binds the connection to the hostname — DNS rebinding can't redirect
# to a different server because the cert wouldn't match.
# When SSL verification is disabled, this defense doesn't apply, so
# we rewrite to the validated IP like HTTP.
ssl_verify: Final = getattr(litellm, "ssl_verify", True)
if parsed.scheme == "https" and ssl_verify is not False:
return url, host_header
# For HTTP, rewrite URL to connect to the validated IP directly
# to prevent DNS rebinding (no TLS to bind the connection).
validated_ip: Final = _sockaddr_host(addrinfo[0][4])
is_ipv6: Final = addrinfo[0][0] == socket.AF_INET6View on GitHub (pinned to 77b7c6c40c)