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
fix(vector_stores): stop leaking stored credentials in direct search debug logs (#37373)
ryan-crabbe-berri869a8cd984fe
diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.pyindex 7998a967344..3ee803646a9 100644--- a/litellm/llms/custom_httpx/llm_http_handler.py+++ b/litellm/llms/custom_httpx/llm_http_handler.py@@ -9433,6 +9433,27 @@ class BaseLLMHTTPHandler:)###### VECTOR STORE HANDLER ######+ @staticmethod+ def _pre_call_direct_vector_store_search(+ logging_obj: LiteLLMLoggingObj,+ custom_llm_provider: str,+ vector_store_id: str,+ query: str | Sequence[str],+ ) -> None:+ """Direct providers have no HTTP request to echo, and an empty api_base makes the debug+ logger fall back to dumping model_call_details, which holds stored provider credentials."""+ endpoint: Final = f"{custom_llm_provider}://{vector_store_id}"+ logging_obj.pre_call(+ input="",+ api_key="",+ additional_args={ # mutable-ok: pre_call's additional_args contract is a dict+ "query": query,+ "vector_store_id": vector_store_id,+ "api_base": endpoint,+ "request_str": f"direct vector store search: {endpoint}",+ },+ )+async def async_vector_store_search_handler(self,vector_store_id: str,@@ -9449,13 +9470,11 @@ class BaseLLMHTTPHandler:_is_async: bool = False,) -> VectorStoreSearchResponse:if isinstance(vector_store_provider_config, BaseDirectVectorStoreConfig):- logging_obj.pre_call(- input="",- api_key="",- additional_args={ # mutable-ok: pre_call's additional_args contract is a dict- "query": query,- "vector_store_id": vector_store_id,- },+ self._pre_call_direct_vector_store_search(+ logging_obj=logging_obj,+ custom_llm_provider=custom_llm_provider,+ vector_store_id=vector_store_id,+ query=query,)return await vector_store_provider_config.aexecute_search_vector_store_request(vector_store_id=vector_store_id,@@ -9580,13 +9599,11 @@ class BaseLLMHTTPHandler:)if isinstance(vector_store_provider_config, BaseDirectVectorStoreConfig):- logging_obj.pre_call(- input="",- api_key="",- additional_args={ # mutable-ok: pre_call's additional_args contract is a dict- "query": query,- "vector_store_id": vector_store_id,- },+ self._pre_call_direct_vector_store_search(+ logging_obj=logging_obj,+ custom_llm_provider=custom_llm_provider,+ vector_store_id=vector_store_id,+ query=query,)return vector_store_provider_config.execute_search_vector_store_request(vector_store_id=vector_store_id,diff --git a/tests/test_litellm/llms/custom_httpx/test_llm_http_handler.py b/tests/test_litellm/llms/custom_httpx/test_llm_http_handler.pyindex 2dda8bf722a..69f2312f203 100644--- a/tests/test_litellm/llms/custom_httpx/test_llm_http_handler.py+++ b/tests/test_litellm/llms/custom_httpx/test_llm_http_handler.py@@ -1,7 +1,9 @@import asyncioimport json+import loggingimport osimport sys+import timefrom unittest.mock import AsyncMock, Mock, patchimport httpx@@ -9,6 +11,7 @@ import pytestsys.path.insert(0, os.path.abspath("../../../..")) # Adds the parent directory to the system pathimport litellm+from litellm._logging import verbose_loggerfrom litellm.integrations.code_interpreter_interception.handler import (CodeInterpreterInterceptionLogger,LITELLM_CODE_EXECUTION_TOOL_NAME,@@ -2158,3 +2161,68 @@ async def test_vector_store_search_handler_direct_config_async_skips_http():pre_call_args = logging_obj.pre_call.call_args.kwargs["additional_args"]assert pre_call_args["query"] == ["q1", "q2"]assert pre_call_args["vector_store_id"] == "vs_direct"+++def _direct_vector_store_debug_logging_obj():+ from litellm.litellm_core_utils.litellm_logging import Logging as LitellmLogging++ logging_obj = LitellmLogging(+ model="valkey",+ messages=[{"role": "user", "content": "q"}],+ stream=False,+ call_type="vector_store_search",+ start_time=time.time(),+ litellm_call_id="vs-debug-call-id",+ function_id="vs-debug-function-id",+ log_raw_request_response=True,+ )+ logging_obj.update_environment_variables(+ model="valkey",+ optional_params={"vector_store_id": "vs_direct", "query": "q"},+ litellm_params={+ "litellm_call_id": "vs-debug-call-id",+ "vector_store_id": "vs_direct",+ "litellm_request_debug": True,+ "metadata": {"user_api_key_alias": "vs-test-key"},+ "valkey_host": "valkey.internal",+ "valkey_password": "sup3r-s3cret-valkey-pw",+ "litellm_embedding_config": {"api_key": "sk-embedding-s3cret"},+ },+ )+ return logging_obj++[email protected]("is_async", [False, True])+def test_direct_vector_store_search_debug_log_omits_stored_credentials(caplog, is_async):+ """Regression: an empty api_base made pre_call dump the whole model_call_details, so every+ search shipped the stored valkey_password / embedding api_key into the raw_request metadata."""+ handler = BaseLLMHTTPHandler()+ stub_response = {"object": "vector_store.search_results.page", "search_query": "q", "data": []}+ config = _make_stub_direct_vector_store_config(stub_response)+ logging_obj = _direct_vector_store_debug_logging_obj()++ with caplog.at_level(logging.DEBUG, logger=verbose_logger.name):+ result = handler.vector_store_search_handler(+ vector_store_id="vs_direct",+ query="q",+ vector_store_search_optional_params={"max_num_results": 4},+ vector_store_provider_config=config,+ custom_llm_provider="valkey",+ litellm_params=GenericLiteLLMParams(+ valkey_host="valkey.internal",+ valkey_password="sup3r-s3cret-valkey-pw",+ ),+ logging_obj=logging_obj,+ _is_async=is_async,+ )+ if is_async:+ result = asyncio.run(result)++ assert result is stub_response+ raw_request = logging_obj.model_call_details["litellm_params"]["metadata"]["raw_request"]+ assert "sup3r-s3cret-valkey-pw" not in raw_request+ assert "sk-embedding-s3cret" not in raw_request+ assert "valkey://vs_direct" in raw_request+ logged = "\n".join(record.getMessage() for record in caplog.records)+ assert "sup3r-s3cret-valkey-pw" not in logged+ assert "sk-embedding-s3cret" not in logged