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(proxy): treat a missing user row as unrestricted in the websocket passthrough gate
mateo-berrif846388bb117
diff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.pyindex 120a0bb29ea..b0e22153401 100644--- a/litellm/proxy/auth/auth_checks.py+++ b/litellm/proxy/auth/auth_checks.py@@ -4155,6 +4155,24 @@ async def _granted_model_lists()+async def _user_object_or_none(+ valid_token: UserAPIKeyAuth,+ prisma_client: PrismaClient,+ user_api_key_cache: UserApiKeyCache,+ proxy_logging_obj: ProxyLogging,+) -> LiteLLM_UserTable | None:+ try:+ return await get_user_object(+ user_id=valid_token.user_id,+ prisma_client=prisma_client,+ user_api_key_cache=user_api_key_cache,+ user_id_upsert=False,+ proxy_logging_obj=proxy_logging_obj,+ )+ except ValueError:+ return None++async def enforced_model_allowlists(valid_token: UserAPIKeyAuth,prisma_client: PrismaClient | None,@@ -4178,11 +4196,10 @@ async def enforced_model_allowlists(user_object: Final = (Noneif team_object is not None- else await get_user_object(- user_id=valid_token.user_id,+ else await _user_object_or_none(+ valid_token=valid_token,prisma_client=prisma_client,user_api_key_cache=user_api_key_cache,- user_id_upsert=False,proxy_logging_obj=proxy_logging_obj,))diff --git a/tests/test_litellm/proxy/auth/test_auth_checks.py b/tests/test_litellm/proxy/auth/test_auth_checks.pyindex 5242a99c54c..7351c981838 100644--- a/tests/test_litellm/proxy/auth/test_auth_checks.py+++ b/tests/test_litellm/proxy/auth/test_auth_checks.py@@ -7336,6 +7336,31 @@ class _UntouchedPrisma:raise AssertionError(f"database reached through {name}")+class _MissingUserPrisma:+ class db:+ class litellm_usertable:+ @staticmethod+ async def find_unique(where: dict[str, str], include: dict[str, bool]) -> None:+ return None+++async def test_enforced_model_allowlists_treats_a_missing_user_row_as_unrestricted():+ from litellm.proxy.auth.auth_checks import enforced_model_allowlists+ from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache+ from litellm.proxy.utils import ProxyLogging++ cache = UserApiKeyCache()+ scopes = await enforced_model_allowlists(+ valid_token=UserAPIKeyAuth(token="hashed-fake", user_id="default_user_id"),+ prisma_client=_MissingUserPrisma(),+ user_api_key_cache=cache,+ proxy_logging_obj=ProxyLogging(user_api_key_cache=cache),+ )++ assert [list(scope) for scope in scopes] == [[], [], [], [], []]++@pytest.mark.asyncioasync def test_enforced_model_allowlists_reads_every_level_from_cache():from litellm.proxy._types import (