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): allow custom auth routes to bypass route authorization checks
Harshit28j6d535e563957
diff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.pyindex ef6b0ac462c..91ac58215ab 100644--- a/litellm/proxy/auth/auth_checks.py+++ b/litellm/proxy/auth/auth_checks.py@@ -234,6 +234,7 @@ async def common_checks(request: Request,skip_budget_checks: bool = False,project_object: Optional[LiteLLM_ProjectTableCachedObj] = None,+ skip_route_check: bool = False,) -> bool:"""Common checks across jwt + key-based auth.@@ -453,18 +454,21 @@ async def common_checks(user_object=user_object, route=route, request_body=request_body)- token_team = getattr(valid_token, "team_id", None)- token_type: Literal["ui", "api"] = (- "ui" if token_team is not None and token_team == "litellm-dashboard" else "api"- )- _is_route_allowed = _is_allowed_route(- route=route,- token_type=token_type,- user_obj=user_object,- request=request,- request_data=request_body,- valid_token=valid_token,- )+ if not skip_route_check:+ token_team = getattr(valid_token, "team_id", None)+ token_type: Literal["ui", "api"] = (+ "ui"+ if token_team is not None and token_team == "litellm-dashboard"+ else "api"+ )+ _is_route_allowed = _is_allowed_route(+ route=route,+ token_type=token_type,+ user_obj=user_object,+ request=request,+ request_data=request_body,+ valid_token=valid_token,+ )# 11. [OPTIONAL] Vector store checks - is the object allowed to access the vector storeawait vector_store_access_check(diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.pyindex a2705ceb7da..1d575fb5131 100644--- a/litellm/proxy/auth/user_api_key_auth.py+++ b/litellm/proxy/auth/user_api_key_auth.py@@ -1766,6 +1766,7 @@ async def _run_post_custom_auth_checks(valid_token=valid_token,skip_budget_checks=False,project_object=_project_obj,+ skip_route_check=True,)return valid_tokendiff --git a/tests/test_litellm/proxy/auth/test_auth_checks.py b/tests/test_litellm/proxy/auth/test_auth_checks.pyindex 4cdca2d0617..501c2285d1e 100644--- a/tests/test_litellm/proxy/auth/test_auth_checks.py+++ b/tests/test_litellm/proxy/auth/test_auth_checks.py@@ -1519,3 +1519,55 @@ async def test_get_fuzzy_user_object_case_insensitive_email():assert call_args.kwargs["where"]["user_email"]["equals"] == "[email protected]"assert call_args.kwargs["where"]["user_email"]["mode"] == "insensitive"assert call_args.kwargs["include"] == {"organization_memberships": True}+++async def test_common_checks_skip_route_check_for_custom_auth():+ """+ Test that custom routes (e.g. /ldap/ngs/ready) pass common_checks when+ skip_route_check=True, which is the case for custom auth flows.++ Regression test for: custom user-added routes being rejected as admin-only+ after _run_post_custom_auth_checks was introduced.+ """+ from fastapi import Request++ from litellm.proxy.auth.auth_checks import common_checks++ mock_request = MagicMock(spec=Request)+ valid_token = UserAPIKeyAuth(token="test-token")++ # Without skip_route_check, a custom route with unknown user should fail+ with pytest.raises(Exception):+ await common_checks(+ request_body={},+ team_object=None,+ user_object=None,+ end_user_object=None,+ global_proxy_spend=None,+ general_settings={},+ route="/ldap/ngs/ready",+ llm_router=None,+ proxy_logging_obj=MagicMock(),+ valid_token=valid_token,+ request=mock_request,+ skip_route_check=False,+ )++ # With skip_route_check=True (custom auth path), the same route should pass+ result = await common_checks(+ request_body={},+ team_object=None,+ user_object=None,+ end_user_object=None,+ global_proxy_spend=None,+ general_settings={},+ route="/ldap/ngs/ready",+ llm_router=None,+ proxy_logging_obj=MagicMock(),+ valid_token=valid_token,+ request=mock_request,+ skip_route_check=True,+ )++ assert result is True