Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9ec4e28
fix(proxy): enforce allowed_passthrough_routes for auth=true pass-thr…
shivamrawat1 May 29, 2026
9105fd9
fix(proxy): clarify JWT passthrough denial
shivamrawat1 May 30, 2026
980deee
fix(proxy): make pass-through auth checks method-aware
shivamrawat1 May 30, 2026
bf95c60
Fix passthrough route auth checks
cursoragent May 30, 2026
7a14569
fix(proxy): reject unregistered pass-through HTTP methods
shivamrawat1 May 30, 2026
36f43c0
fix(proxy): remove duplicate request_method in JWT team lookup
shivamrawat1 May 30, 2026
3976521
Fix passthrough route auth enforcement
cursoragent May 30, 2026
4c4c0cb
fix(proxy): raise passthrough-specific 403 directly in virtual-key path
mateo-berri May 30, 2026
ee6b1bb
fix(proxy): load team for RBAC role-claim JWT passthrough gating
mateo-berri May 30, 2026
ca90088
Revert "chore(tests): migrate Bedrock CI to AWS account 941277531214 …
mateo-berri May 30, 2026
59fbb27
fix(proxy): scope pass-through 405 to registry routes; grant rerank p…
mateo-berri May 30, 2026
0069e2b
Merge remote-tracking branch 'origin/litellm_internal_staging' into l…
mateo-berri May 30, 2026
e2fbde5
fix(proxy): guard request method lookup against scopes without a method
mateo-berri May 30, 2026
fe6544b
test(passthrough): pin SERVER_ROOT_PATH in unregistered-method test
mateo-berri May 30, 2026
94f57b4
test(passthrough): restore regression coverage for non-auth-enforced …
mateo-berri May 30, 2026
cb3b9af
fix(proxy): record auth flag in pass-through registry for allowlist e…
mateo-berri May 30, 2026
4fc570c
fix(proxy): include bool in pass-through registry value type for auth…
mateo-berri May 30, 2026
fa52953
fix(proxy): preserve stored auth flag on pass-through endpoint update
mateo-berri May 30, 2026
d0793af
Merge remote-tracking branch 'origin/litellm_internal_staging' into l…
mateo-berri May 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions litellm/proxy/auth/handle_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,8 @@ async def find_team_with_model_access(
"""Find first team with access to the requested model"""
from litellm.proxy.proxy_server import llm_router

denied_auth_enforced_pass_through_route = False

if not team_ids:
if jwt_handler.litellm_jwtauth.enforce_team_based_model_access:
raise HTTPException(
Expand Down Expand Up @@ -1158,6 +1160,22 @@ async def find_team_with_model_access(
user_route=route,
litellm_proxy_roles=jwt_handler.litellm_jwtauth,
)
if (
is_allowed
and RouteChecks.is_auth_enforced_pass_through_route(
route=route
)
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
):
# JWT team selection is team-scoped; key metadata is not
# available here, so passthrough access is granted only by
# the selected team's metadata.
is_allowed = RouteChecks.check_passthrough_route_access(
route=route,
user_api_key_dict=UserAPIKeyAuth(
team_metadata=team_object.metadata or {}
),
)
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
denied_auth_enforced_pass_through_route = not is_allowed
verbose_proxy_logger.debug(
f"JWT team route check: team_id={team_id}, route={route}, is_allowed={is_allowed}"
)
Expand All @@ -1166,6 +1184,15 @@ async def find_team_with_model_access(
except Exception:
continue

if denied_auth_enforced_pass_through_route:
raise HTTPException(
status_code=403,
detail=(
f"Team not allowed to access passthrough route {route}. "
"Configure `allowed_passthrough_routes` on the team."
),
)

if requested_model:
raise HTTPException(
status_code=403,
Expand Down
85 changes: 82 additions & 3 deletions litellm/proxy/auth/route_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,16 @@ def is_virtual_key_allowed_to_call_route(
route=route,
allowed_routes=LiteLLMRoutes._member_map_[allowed_route].value,
):
return True
if RouteChecks.is_auth_enforced_pass_through_route(
route=route,
method=RouteChecks._get_request_method(request=request),
):
if RouteChecks.check_passthrough_route_access(
route=route, user_api_key_dict=valid_token
):
return True
else:
return True
Comment thread
shivamrawat1 marked this conversation as resolved.
Resolved

################################################
# For llm_api_routes, also check registered pass-through endpoints
Expand All @@ -134,7 +143,16 @@ def is_virtual_key_allowed_to_call_route(
if InitPassThroughEndpointHelpers.is_registered_pass_through_route(
route=route
):
return True
if RouteChecks.is_auth_enforced_pass_through_route(
route=route,
method=RouteChecks._get_request_method(request=request),
):
if RouteChecks.check_passthrough_route_access(
route=route, user_api_key_dict=valid_token
):
return True
else:
return True
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

# Method-aware carve-out: allow GET on the two
# read-only MCP-server discovery endpoints
Expand Down Expand Up @@ -228,7 +246,14 @@ def non_proxy_admin_allowed_routes_check(
route=route,
)

if RouteChecks.is_llm_api_route(route=route):
if RouteChecks.is_auth_enforced_pass_through_route(
route=route,
method=RouteChecks._get_request_method(request=request),
):
RouteChecks._require_auth_pass_through_access(
route=route, valid_token=valid_token
)
elif RouteChecks.is_llm_api_route(route=route):
pass
elif RouteChecks.is_info_route(route=route):
# check if user allowed to call an info route
Expand Down Expand Up @@ -624,6 +649,60 @@ def check_route_access(route: str, allowed_routes: List[str]) -> bool:

return False

@staticmethod
def _get_request_method(request: Optional[Request]) -> Optional[str]:
if request is None:
return None

method = getattr(request, "method", None)
if not isinstance(method, str):
return None

return method.upper()

@staticmethod
def is_auth_enforced_pass_through_route(
route: str, method: Optional[str] = None
) -> bool:
"""
True for config/DB pass-through endpoints registered with auth=true.

These routes are injected into ``openai_routes`` for spend/budget hooks but
must not inherit blanket ``openai_routes`` RBAC; access is gated by
``allowed_passthrough_routes`` on the key or team.
"""
from litellm.proxy.pass_through_endpoints.pass_through_endpoints import (
InitPassThroughEndpointHelpers,
)

route_info = InitPassThroughEndpointHelpers.get_registered_pass_through_route(
Comment thread
veria-ai[bot] marked this conversation as resolved.
Resolved
route=route, method=method
)
if route_info is None:
return False
dependencies = route_info.get("passthrough_params", {}).get("dependencies")
Comment thread
veria-ai[bot] marked this conversation as resolved.
Resolved
return dependencies is not None

@staticmethod
def _require_auth_pass_through_access(
route: str,
valid_token: UserAPIKeyAuth,
) -> None:
"""
Require an explicit ``allowed_passthrough_routes`` match for auth=true pass-through.
"""
if RouteChecks.check_passthrough_route_access(
route=route, user_api_key_dict=valid_token
):
return
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail=(
f"Key/team not allowed to access passthrough route {route}. "
"Configure `allowed_passthrough_routes` on the team or key."
),
)

@staticmethod
def check_passthrough_route_access(
route: str, user_api_key_dict: UserAPIKeyAuth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2312,8 +2312,12 @@ def get_registered_pass_through_route(
InitPassThroughEndpointHelpers._build_full_path_with_root(parts[2])
)

# Get the methods for this route
# Get the methods for this route. Prefer the registered metadata,
# but keep supporting test fixtures / older registry entries that
# only encoded methods in the route key.
route_methods = _registered_pass_through_routes[key].get("methods", [])
if not route_methods and len(parts) == 4:
route_methods = parts[3].split(",")

# Check if path matches
path_matches = False
Expand Down
56 changes: 56 additions & 0 deletions tests/test_litellm/proxy/auth/test_handle_jwt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional
from unittest.mock import AsyncMock, MagicMock, patch

from fastapi import HTTPException
import pytest

from litellm.proxy._types import (
Expand Down Expand Up @@ -132,6 +133,61 @@ async def test_map_user_to_teams_null_inputs():
await JWTAuthManager.map_user_to_teams(user_object=None, team_object=None)


@pytest.mark.asyncio
async def test_find_team_with_model_access_reports_passthrough_allowlist_denial():
jwt_handler = JWTHandler()
jwt_handler.litellm_jwtauth = LiteLLM_JWTAuth()
team = LiteLLM_TeamTable(
team_id="team-a",
models=["gpt-4"],
metadata={},
)

with (
patch(
"litellm.proxy.auth.handle_jwt.get_team_object",
new_callable=AsyncMock,
return_value=team,
),
patch(
"litellm.proxy.auth.handle_jwt.can_team_access_model",
new_callable=AsyncMock,
return_value=True,
),
patch(
"litellm.proxy.auth.handle_jwt.allowed_routes_check",
return_value=True,
),
patch(
"litellm.proxy.auth.handle_jwt.RouteChecks.is_auth_enforced_pass_through_route",
return_value=True,
),
patch(
"litellm.proxy.auth.handle_jwt.RouteChecks.check_passthrough_route_access",
return_value=False,
) as mock_passthrough_check,
):
with pytest.raises(HTTPException) as exc_info:
await JWTAuthManager.find_team_with_model_access(
team_ids={"team-a"},
requested_model="gpt-4",
route="/my-pass-through",
jwt_handler=jwt_handler,
prisma_client=None,
user_api_key_cache=MagicMock(),
parent_otel_span=None,
proxy_logging_obj=MagicMock(),
)

assert exc_info.value.status_code == 403
assert "allowed_passthrough_routes" in exc_info.value.detail
assert "requested model" not in exc_info.value.detail

user_api_key_dict = mock_passthrough_check.call_args.kwargs["user_api_key_dict"]
assert user_api_key_dict.metadata == {}
assert user_api_key_dict.team_metadata == {}


@pytest.mark.asyncio
async def test_auth_builder_proxy_admin_user_role():
"""Test that is_proxy_admin is True when user_object.user_role is PROXY_ADMIN"""
Expand Down
Loading
Loading