The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(passthrough): cover virtual key echoed in api-key and x-api-key
mateo-berri088a700933cf
diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.pyindex fe0d1a65c70..52ff6e709c5 100644--- a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py+++ b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py@@ -3450,14 +3450,16 @@ class TestVertexCredentiallessPassthroughVirtualKeyLeak:With no Vertex credential configured, the passthrough took thebring-your-own-credentials branch and forwarded the whole incoming header set- to Google, including whichever header carried the caller's LiteLLM virtual key- (``Authorization: Bearer <vkey>`` or ``x-litellm-api-key: <vkey>``). That leaked- the proxy's own secret to an upstream provider.+ to Google, including whichever header carried the caller's LiteLLM virtual key.+ LiteLLM accepts that key from several headers (``Authorization``,+ ``x-litellm-api-key``, ``x-goog-api-key``, ``api-key``, ``x-api-key``), and+ ``x-goog-api-key`` doubles as a genuine Google credential, so any of them could+ leak the proxy's own secret to an upstream provider.A credential-less request that carries no upstream Google credential must nowfail with a clean 401 and never reach ``create_pass_through_route``; a genuinebring-your-own Google credential must still pass through, with the virtual key- stripped from what is forwarded.+ stripped by value from every forwarded header."""VKEY = "sk-litellm-victim-key"@@ -3579,6 +3581,26 @@ class TestVertexCredentiallessPassthroughVirtualKeyLeak:assert "x-litellm-api-key" not in forwardedassert self.VKEY not in " ".join(f"{name}:{value}" for name, value in forwarded.items())+ @pytest.mark.asyncio+ async def test_virtual_key_echoed_in_alternate_auth_headers_is_stripped_by_value(self, monkeypatch):+ raised, forwarded = await self._run(+ monkeypatch,+ [+ (b"x-litellm-api-key", self.VKEY.encode()),+ (b"authorization", b"Bearer ya29.google-oauth-token"),+ (b"api-key", self.VKEY.encode()),+ (b"x-api-key", self.VKEY.encode()),+ (b"content-type", b"application/json"),+ ],+ )+ assert raised is None+ assert forwarded is not None+ assert forwarded.get("authorization") == "Bearer ya29.google-oauth-token"+ assert "api-key" not in forwarded+ assert "x-api-key" not in forwarded+ assert "x-litellm-api-key" not in forwarded+ assert self.VKEY not in " ".join(f"{name}:{value}" for name, value in forwarded.items())+class TestGetAzureAISearchIndexFromEndpoint:"""The operable index is only the segment right after ``indexes``.