From d0e1bebce0e0ff502e5743cdac7a60b82bc59e07 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2026 02:51:32 +0000 Subject: [PATCH] fix(proxy): reject incompatible forwarding trust configuration --- litellm/proxy/rust_gateway.py | 6 ++++++ tests/unit/proxy/test_rust_gateway.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/litellm/proxy/rust_gateway.py b/litellm/proxy/rust_gateway.py index 9b7ba98c161..cd02be26c77 100644 --- a/litellm/proxy/rust_gateway.py +++ b/litellm/proxy/rust_gateway.py @@ -18,6 +18,10 @@ def gateway_binary() -> str | None: return shutil.which(name, path=sysconfig.get_path("scripts")) or shutil.which(name) +def unsupported_proxy_trust(value: str | None) -> bool: + return any(host.strip() not in ("", "127.0.0.1") for host in (value or "").split(",")) + + def startup_error(binary: str | None, unsupported: Mapping[str, object]) -> str | None: flag: Final = next((name for name, value in unsupported.items() if value), None) if flag is not None: @@ -26,6 +30,8 @@ def startup_error(binary: str | None, unsupported: Mapping[str, object]) -> str return "--rust_gateway requires POSIX inherited sockets and process signals" if binary is None: return "--rust_gateway requires the litellm-gateway binary. Install litellm[proxy] in this environment" + if unsupported_proxy_trust(os.environ.get("FORWARDED_ALLOW_IPS")): + return "--rust_gateway does not support non-loopback FORWARDED_ALLOW_IPS; disable Rust forwarding for this deployment" return None diff --git a/tests/unit/proxy/test_rust_gateway.py b/tests/unit/proxy/test_rust_gateway.py index 969cfd12da4..27b2e9b54e9 100644 --- a/tests/unit/proxy/test_rust_gateway.py +++ b/tests/unit/proxy/test_rust_gateway.py @@ -53,6 +53,20 @@ def test_missing_binary_gives_install_instruction() -> None: ) +@pytest.mark.parametrize("trusted", [None, "", "127.0.0.1", "192.0.2.1", "*", "127.0.0.1,192.0.2.1"]) +def test_configured_proxy_trust_is_not_silently_discarded(trusted: str | None, monkeypatch: pytest.MonkeyPatch) -> None: + if trusted is None: + monkeypatch.delenv("FORWARDED_ALLOW_IPS", raising=False) + else: + monkeypatch.setenv("FORWARDED_ALLOW_IPS", trusted) + expected: Final = ( + None + if trusted in (None, "", "127.0.0.1") + else "--rust_gateway does not support non-loopback FORWARDED_ALLOW_IPS; disable Rust forwarding for this deployment" + ) + assert startup_error("gateway", {}) == expected + + @pytest.mark.parametrize("supervised", [False, True]) @pytest.mark.parametrize("host", ["0.0.0.0", "192.0.2.1", "::"]) def test_metrics_keep_configured_host_separate_from_private_listener( @@ -158,6 +172,7 @@ def test_supervisor_drains_before_stopping_python_and_reaps_both_children( patch("asyncio.create_subprocess_exec", side_effect=spawn) as launch, patch("socket.socket", return_value=listener), patch("os.killpg", side_effect=kill_group) as kill, + patch.dict("os.environ", {"FORWARDED_ALLOW_IPS": "*"}), ): assert supervise("gateway", ("python", "--rust_gateway"), "0.0.0.0", 4000) == expected