{"record":{"id":"25ff484475b51dc4","repo":"BerriAI/litellm","slug":"url-targets-a-blocked-address-resolved-ip-if","errorCode":null,"errorMessage":"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.","messagePattern":"URL targets a blocked address \\((.+?)\\)\\. If this is a legitimate internal service, add the host to `user_url_allowed_hosts` in general_settings\\.","errorType":"exception","errorClass":"SSRFError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/url_utils.py","lineNumber":291,"sourceCode":"    effective_port: Final = port if port is not None else default_port\n    host_header: Final = _format_host_header(hostname, effective_port, default_port)\n\n    is_allowlisted: Final = _is_host_allowlisted(hostname, effective_port)\n\n    # Resolve hostname and validate ALL addresses\n    try:\n        addrinfo: Final = socket.getaddrinfo(hostname, effective_port, proto=socket.IPPROTO_TCP)\n    except socket.gaierror as e:\n        raise SSRFError(f\"DNS resolution failed for '{hostname}': {e}\")\n\n    if not addrinfo:\n        raise SSRFError(f\"No addresses found for '{hostname}'\")\n\n    if not is_allowlisted:\n        for family, type_, proto, canonname, sockaddr in addrinfo:\n            resolved_ip = _sockaddr_host(sockaddr)\n            if _is_blocked_ip(resolved_ip):\n                raise SSRFError(\n                    f\"URL targets a blocked address ({resolved_ip}). \"\n                    \"If this is a legitimate internal service, add the host \"\n                    \"to `user_url_allowed_hosts` in general_settings.\"\n                )\n\n    # For HTTPS with SSL verification enabled, TLS certificate validation\n    # binds the connection to the hostname — DNS rebinding can't redirect\n    # to a different server because the cert wouldn't match.\n    # When SSL verification is disabled, this defense doesn't apply, so\n    # we rewrite to the validated IP like HTTP.\n    ssl_verify: Final = getattr(litellm, \"ssl_verify\", True)\n    if parsed.scheme == \"https\" and ssl_verify is not False:\n        return url, host_header\n\n    # For HTTP, rewrite URL to connect to the validated IP directly\n    # to prevent DNS rebinding (no TLS to bind the connection).\n    validated_ip: Final = _sockaddr_host(addrinfo[0][4])\n    is_ipv6: Final = addrinfo[0][0] == socket.AF_INET6","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/url_utils.py#L273-L309","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"# before (config.yaml)\ngeneral_settings: {}  # fetching http://localhost:11434/... raises SSRFError\n\n# after\ngeneral_settings:\n  user_url_allowed_hosts:\n    - \"localhost:11434\"\n    - \"internal-files.corp\"","handlingStrategy":"try-catch","validationCode":"from urllib.parse import urlparse\nimport litellm\n\np = urlparse(user_url)\nallowed = [str(h) for h in (getattr(litellm, \"user_url_allowed_hosts\", []) or [])]\nnormalized = (p.hostname or \"\").lower()\nif not any(normalized in a or a.startswith(normalized + \":\") for a in allowed):\n    # host is not exempted; expect default-deny for private IPs\n    pass","typeGuard":null,"tryCatchPattern":"from litellm.litellm_core_utils.url_utils import SSRFError\n\ntry:\n    resp = safe_get(client, user_url)\nexcept SSRFError as e:\n    if \"blocked address\" in str(e):\n        raise HTTPException(status_code=400, detail=\"URL points to a blocked (internal) address; ask the admin to allowlist it\")\n    raise","preventionTips":["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."],"tags":["ssrf","security","private-ip","allowlist","network"],"backgroundTag":"ssrf-protection-blocked","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}