Repository navigation
chore(proxy): contain UI_LOGO_PATH / LITELLM_FAVICON_URL on unauthenticated asset endpoints #26815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yuneng-berri
merged 12 commits into
BerriAI:litellm_internal_staging
from
stuxf:fix/get-image-lfi-ssrf
May 1, 2026
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0166992
fix(proxy): contain UI_LOGO_PATH and LITELLM_FAVICON_URL to allowed aβ¦
stuxf 9ef8572
fix(proxy): /get_logo_url no longer discloses local UI_LOGO_PATH
stuxf 4f751fd
fix(proxy): also accept LITELLM_ASSETS_PATH for /get_favicon local path
stuxf 55d393d
fix(static-assets): unblock CI β pass headers explicitly + harden + uβ¦
stuxf 75d1a01
fix(static-assets): use async_safe_get; drop SVG; serve bytes inline β¦
stuxf c112bdf
chore(static-assets): /simplify pass β top-level Response import + clβ¦
stuxf 89aa13f
fix(static-assets): also wrap admin-only Vault token verification in β¦
stuxf 14473ed
fix(static-assets): ruff F811 β drop duplicate Response import
stuxf 2c11fa0
chore(static-assets): keep vault tester out of asset hardening
stuxf 215f538
fix(static-assets): browser-load remote branding assets
stuxf b8a141c
fix(static-assets): stop serving stale logo cache
stuxf b67a81d
test(proxy): align favicon remote asset expectations
stuxf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| """ | ||
| Helpers for the unauthenticated logo / favicon endpoints (``/get_image`` and | ||
| ``/get_favicon``). Both read an admin-set environment variable that may be a | ||
| local filesystem path or an HTTP URL, fetch the resource, and return the | ||
| bytes verbatim to any unauthenticated caller. | ||
|
|
||
| Without these helpers: | ||
|
|
||
| * a misconfigured / hostile env var like ``UI_LOGO_PATH=/etc/passwd`` lets | ||
| any unauthenticated caller exfiltrate the file (LFI β GHSA-3pcp-536p-ghjc). | ||
| * a legitimate-looking ``UI_LOGO_PATH=http://internal-service/branding.png`` | ||
| pointing at a private host lets any unauthenticated caller exfiltrate | ||
| whatever that host returns (SSRF β GHSA-pjc9-2hw6-78rr), regardless of | ||
| whether the body is actually an image. | ||
| """ | ||
|
|
||
| import os | ||
| from typing import List, Optional | ||
|
|
||
| from litellm._logging import verbose_proxy_logger | ||
| from litellm.litellm_core_utils.url_utils import SSRFError, validate_url | ||
| from litellm.llms.custom_httpx.http_handler import get_async_httpx_client | ||
| from litellm.types.llms.custom_http import httpxSpecialProvider | ||
|
|
||
| # Conservative allowlist of image MIME types. Anything else is refused β | ||
| # without this, an admin-configured URL whose upstream returns | ||
| # ``application/json`` (e.g. cloud metadata, internal API) would still be | ||
| # served back to the caller verbatim. | ||
| ALLOWED_IMAGE_CONTENT_TYPES = frozenset( | ||
| { | ||
| "image/jpeg", | ||
| "image/jpg", | ||
| "image/png", | ||
| "image/gif", | ||
| "image/svg+xml", | ||
| "image/webp", | ||
| "image/x-icon", | ||
| "image/vnd.microsoft.icon", | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| def resolve_local_asset_path(candidate: str, allowed_roots: List[str]) -> Optional[str]: | ||
| """ | ||
| Resolve ``candidate`` and return its absolute path only if it lives | ||
| within one of ``allowed_roots``. Returns None on any miss (caller | ||
| falls back to the bundled default asset). | ||
|
|
||
| Resolution uses ``realpath`` to follow symlinks, so a symlink inside | ||
| ``allowed_roots`` pointing at ``/etc/passwd`` is rejected the same as | ||
| a direct ``/etc/passwd`` config. | ||
| """ | ||
| if not candidate: | ||
| return None | ||
| try: | ||
| resolved = os.path.realpath(os.path.expanduser(candidate)) | ||
| except (OSError, ValueError): | ||
| return None | ||
| if not os.path.isfile(resolved): | ||
| return None | ||
| for root in allowed_roots: | ||
| if not root: | ||
| continue | ||
| try: | ||
| root_resolved = os.path.realpath(root) | ||
| except (OSError, ValueError): | ||
| continue | ||
| if resolved == root_resolved: | ||
| return resolved | ||
| if resolved.startswith(root_resolved + os.sep): | ||
| return resolved | ||
| return None | ||
|
|
||
|
|
||
| async def fetch_validated_image_bytes( | ||
| url: str, *, timeout_s: float = 5.0 | ||
| ) -> Optional[bytes]: | ||
| """ | ||
| Fetch ``url`` with SSRF protection (always-on) and Content-Type | ||
| validation. Returns the raw bytes on success, ``None`` on any | ||
| failure (blocked target, non-200, or non-image response). | ||
|
|
||
| The SSRF guard is enforced unconditionally β these endpoints are | ||
| unauthenticated, so the admin-facing ``litellm.user_url_validation`` | ||
| toggle does not apply. An admin who opted out of URL validation for | ||
| LLM provider paths should not also expose ``/get_image`` to SSRF. | ||
| """ | ||
| if not url: | ||
| return None | ||
| try: | ||
| rewritten_url, host_header = validate_url(url) | ||
| except SSRFError as exc: | ||
| verbose_proxy_logger.warning( | ||
| "Blocked unauthenticated asset fetch β SSRF guard rejected %r: %s", | ||
| url, | ||
| exc, | ||
| ) | ||
| return None | ||
|
|
||
| # ``validate_url`` rewrites HTTP URLs to point at a validated IP and | ||
| # returns the original hostname for the Host header. For HTTPS with | ||
| # ssl_verify enabled, it returns the URL unchanged (TLS hostname | ||
| # validation handles DNS rebinding). | ||
| request_kwargs = {} | ||
| if rewritten_url != url: | ||
| request_kwargs["headers"] = {"host": host_header} | ||
|
|
||
| async_client = get_async_httpx_client( | ||
| llm_provider=httpxSpecialProvider.UI, | ||
| params={"timeout": timeout_s}, | ||
| ) | ||
| try: | ||
| response = await async_client.get(rewritten_url, **request_kwargs) | ||
|
stuxf marked this conversation as resolved.
Resolved
|
||
| except Exception as exc: | ||
| verbose_proxy_logger.debug("Asset fetch failed for %r: %s", url, exc) | ||
| return None | ||
|
|
||
| if response.status_code != 200: | ||
| return None | ||
|
|
||
| content_type = ( | ||
| (response.headers.get("content-type") or "").split(";")[0].strip().lower() | ||
| ) | ||
| if content_type not in ALLOWED_IMAGE_CONTENT_TYPES: | ||
| verbose_proxy_logger.warning( | ||
| "Asset fetch from %r returned non-image content-type %r β refusing to serve.", | ||
| url, | ||
| content_type, | ||
| ) | ||
| return None | ||
|
|
||
| return response.content | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.