BerriAI/litellm · error · SSRFError
URL scheme ' ' is not allowed
Error message
URL scheme '{parsed.scheme}' is not allowed What it means
SSRFError raised by validate_url when a user-supplied URL's scheme is not http or https (_ALLOWED_SCHEMES). validate_url gates every fetch made by safe_get/async_safe_get of user-controlled URLs, so file://, ftp://, gopher://, and scheme-less strings ('example.com/x', whose parsed scheme is '') are refused before any network call is made.
Solutions
- Normalize user URLs before the call: prepend 'https://' when no scheme is present.
- Reject non-http(s) schemes with a clear 400 message at the boundary.
- Catch SSRFError and map it to a client error instead of a 500.
- Only for fully trusted environments: litellm.user_url_validation = False disables the validator (not recommended).
Example fix
# before
url = data["audio_url"] # "example.com/a.mp3"
audio = safe_get(client, url) # SSRFError: URL scheme '' is not allowed
# after
url = data["audio_url"] or ""
if not url.startswith(("http://", "https://")):
url = "https://" + url.lstrip("/")
audio = safe_get(client, url) Defensive patterns
Strategy: validation
Validate before calling
from urllib.parse import urlparse
def is_fetchable_url(url: str) -> bool:
try:
p = urlparse(url)
except ValueError:
return False
return p.scheme in ("http", "https") and bool(p.hostname)
url = data["audio_url"] or ""
if not url.startswith(("http://", "https://")):
url = "https://" + url.lstrip("/")
if not is_fetchable_url(url):
raise HTTPException(status_code=400, detail="Only http(s) URLs are supported")
resp = safe_get(client, url) Type guard
from urllib.parse import urlparse
def is_http_url(value: str) -> bool:
try:
return urlparse(value).scheme in ("http", "https")
except ValueError:
return False Try / catch
from litellm.litellm_core_utils.url_utils import SSRFError
try:
resp = safe_get(client, url)
except SSRFError as e:
raise HTTPException(status_code=400, detail=str(e)) Prevention
- Always scheme-normalize user URLs (prepend https://) before fetching.
- Route every user-supplied URL through safe_get/async_safe_get, never a bare client.get.
- Treat SSRFError as a client-input problem (4xx), not a server failure (5xx).
When it happens
Trigger: Passing 'file:///etc/passwd', 'ftp://mirror/file', or 'example.com/image.png' (no scheme) as a URL that an endpoint fetches via safe_get — e.g. audio_url/file_url/image_url fields or webhook-style fetches.
Common situations: Users pasting scheme-less URLs (common from mobile clients); integrations fed local file paths; SSRF probes testing scheme handling.
Related errors
- URL scheme is not allowed
- Compresr guardrail api_base has no host
- Compresr guardrail api_base
- Compresr guardrail api_base must be http or https, got…
- DNS resolution failed for
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/7dcaa5e975877433.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/url_utils.py:265
validated, not the hostname that could rebind. Callers should also disable
follow_redirects to prevent redirect-based SSRF bypasses.
Args:
url: The user-supplied URL to validate.
Returns:
Tuple of (rewritten_url, host_header).
The rewritten URL has the hostname replaced with the validated IP.
The host_header value should be sent as the Host header.
Raises:
SSRFError: If the URL scheme is invalid or the hostname resolves
to a private/internal IP address.
"""
parsed: Final = urlparse(url)
if parsed.scheme not in _ALLOWED_SCHEMES:
raise SSRFError(f"URL scheme '{parsed.scheme}' is not allowed")
hostname: Final = parsed.hostname
if not hostname:
raise SSRFError("URL has no hostname")
port: Final = parsed.port
default_port: Final = _default_port_for_scheme(parsed.scheme)
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}")
View on GitHub (pinned to 77b7c6c40c)