{"record":{"id":"7dcaa5e975877433","repo":"BerriAI/litellm","slug":"url-scheme-parsed-scheme-is-not-allowed","errorCode":null,"errorMessage":"URL scheme '{parsed.scheme}' is not allowed","messagePattern":"URL scheme '(.+?)' is not allowed","errorType":"exception","errorClass":"SSRFError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/url_utils.py","lineNumber":265,"sourceCode":"    validated, not the hostname that could rebind. Callers should also disable\n    follow_redirects to prevent redirect-based SSRF bypasses.\n\n    Args:\n        url: The user-supplied URL to validate.\n\n    Returns:\n        Tuple of (rewritten_url, host_header).\n        The rewritten URL has the hostname replaced with the validated IP.\n        The host_header value should be sent as the Host header.\n\n    Raises:\n        SSRFError: If the URL scheme is invalid or the hostname resolves\n            to a private/internal IP address.\n    \"\"\"\n    parsed: Final = urlparse(url)\n\n    if parsed.scheme not in _ALLOWED_SCHEMES:\n        raise SSRFError(f\"URL scheme '{parsed.scheme}' is not allowed\")\n\n    hostname: Final = parsed.hostname\n    if not hostname:\n        raise SSRFError(\"URL has no hostname\")\n\n    port: Final = parsed.port\n    default_port: Final = _default_port_for_scheme(parsed.scheme)\n    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","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/url_utils.py#L247-L283","documentation":"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.","triggerScenarios":"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.","commonSituations":"Users pasting scheme-less URLs (common from mobile clients); integrations fed local file paths; SSRF probes testing scheme handling.","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)."],"exampleFix":"# before\nurl = data[\"audio_url\"]        # \"example.com/a.mp3\"\naudio = safe_get(client, url)  # SSRFError: URL scheme '' is not allowed\n\n# after\nurl = data[\"audio_url\"] or \"\"\nif not url.startswith((\"http://\", \"https://\")):\n    url = \"https://\" + url.lstrip(\"/\")\naudio = safe_get(client, url)","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse\n\ndef is_fetchable_url(url: str) -> bool:\n    try:\n        p = urlparse(url)\n    except ValueError:\n        return False\n    return p.scheme in (\"http\", \"https\") and bool(p.hostname)\n\nurl = data[\"audio_url\"] or \"\"\nif not url.startswith((\"http://\", \"https://\")):\n    url = \"https://\" + url.lstrip(\"/\")\nif not is_fetchable_url(url):\n    raise HTTPException(status_code=400, detail=\"Only http(s) URLs are supported\")\nresp = safe_get(client, url)","typeGuard":"from urllib.parse import urlparse\n\ndef is_http_url(value: str) -> bool:\n    try:\n        return urlparse(value).scheme in (\"http\", \"https\")\n    except ValueError:\n        return False","tryCatchPattern":"from litellm.litellm_core_utils.url_utils import SSRFError\n\ntry:\n    resp = safe_get(client, url)\nexcept SSRFError as e:\n    raise HTTPException(status_code=400, detail=str(e))","preventionTips":["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)."],"tags":["ssrf","url-validation","scheme","security"],"backgroundTag":"url-scheme-not-allowed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}