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: redact db environment variable debug logs
yucheng-berriai89d3f2a7b821
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex e7ccfc883c3..0b09f661ea5 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -5691,7 +5691,7 @@ class ProxyConfig:verbose_proxy_logger.debug("param_name=%s, param_value=%s",param_name,- _redact_secret_values_in_obj(param_value) if isinstance(param_value, (dict, list)) else param_value,+ _redact_config_param_value_for_logging(param_name, param_value),)if param_name is not None and param_value is not None:@@ -14293,6 +14293,14 @@ def _redact_secret_values_in_obj(value: JsonValue, depth: int = 0) -> JsonValue:return value+def _redact_config_param_value_for_logging(param_name: Optional[str], param_value: JsonValue) -> JsonValue:+ if param_name == "environment_variables" and isinstance(param_value, dict):+ return {key: "REDACTED" for key in param_value}+ if isinstance(param_value, (dict, list)):+ return _redact_secret_values_in_obj(param_value)+ return param_value++def _redact_general_setting_value(field_name: str, value: JsonValue, is_full_admin: bool) -> JsonValue:if is_full_admin:return valuediff --git a/tests/test_litellm/proxy/proxy_server/test_proxy_config.py b/tests/test_litellm/proxy/proxy_server/test_proxy_config.pyindex 08b825f41d4..e7c036dd039 100644--- a/tests/test_litellm/proxy/proxy_server/test_proxy_config.py+++ b/tests/test_litellm/proxy/proxy_server/test_proxy_config.py@@ -1639,9 +1639,16 @@ async def test_ProxyConfig__update_config_from_db_does_not_log_general_settings_from litellm._logging import verbose_proxy_loggermonkeypatch.setattr(_logging_module, "_ENABLE_SECRET_REDACTION", False)+ monkeypatch.delenv("DATABASE_URL", raising=False)++ def _fake_decrypt_value_helper(value, key, **_kwargs):+ return value++ monkeypatch.setattr("litellm.proxy.proxy_server.decrypt_value_helper", _fake_decrypt_value_helper)master_key_secret = "sk-lit4152-db-path-master-key-abcdef1234567890"db_url_secret = "postgresql://leak_user:[email protected]:5432/leak_db"+ env_db_url_secret = "postgresql://env_leak_user:[email protected]:5432/env_leak_db"nested_webhook_secret = "https://hooks.slack.com/services/T0/B0/db-path-webhook-secret"responses = {@@ -1655,15 +1662,16 @@ async def test_ProxyConfig__update_config_from_db_does_not_log_general_settings_),"router_settings": None,"litellm_settings": None,- "environment_variables": None,+ "environment_variables": SimpleNamespace(+ param_name="environment_variables",+ param_value={"DATABASE_URL": env_db_url_secret},+ ),}async def _fake_get_config_param(prisma_client, key):return responses[key]- monkeypatch.setattr(- "litellm.proxy.proxy_server.get_config_param", _fake_get_config_param- )+ monkeypatch.setattr("litellm.proxy.proxy_server.get_config_param", _fake_get_config_param)class LogRecordHandler(logging.Handler):def __init__(self) -> None:@@ -1692,12 +1700,15 @@ async def test_ProxyConfig__update_config_from_db_does_not_log_general_settings_for secret in (master_key_secret,db_url_secret,+ env_db_url_secret,nested_webhook_secret,"leak_password_9090",+ "env_leak_password_9090",):assert secret not in rendered, f"leak: {secret} in {rendered!r}"assert merged["general_settings"]["master_key"] == master_key_secretassert merged["general_settings"]["database_url"] == db_url_secret+ assert merged["environment_variables"]["DATABASE_URL"] == env_db_url_secret@pytest.mark.asyncio