Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions litellm/proxy/auth/handle_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,18 @@ 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
):
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
verbose_proxy_logger.debug(
f"JWT team route check: team_id={team_id}, route={route}, is_allowed={is_allowed}"
)
Expand Down
65 changes: 62 additions & 3 deletions litellm/proxy/auth/route_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ 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):
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 +140,15 @@ 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
):
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 +242,11 @@ 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):
RouteChecks._require_auth_pass_through_access(
route=route, valid_token=valid_token
)
elif RouteChecks.is_llm_api_route(route=route):
pass
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
elif RouteChecks.is_info_route(route=route):
# check if user allowed to call an info route
Expand Down Expand Up @@ -624,6 +642,47 @@ def check_route_access(route: str, allowed_routes: List[str]) -> bool:

return False

@staticmethod
def is_auth_enforced_pass_through_route(route: str) -> 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
)
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
162 changes: 139 additions & 23 deletions tests/test_litellm/proxy/auth/test_route_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,24 +686,23 @@ def test_anthropic_count_tokens_route_accessible_to_internal_users():

def test_virtual_key_llm_api_routes_allows_registered_pass_through_endpoints():
"""
Test that virtual keys with llm_api_routes permission can access registered pass-through endpoints.

This tests the scenario where a pass-through endpoint is registered from the DB
(e.g., /azure-assistant) and a virtual key with llm_api_routes permission should be able to access
both the exact path and subpaths (e.g., /azure-assistant/openai/assistants).
Virtual keys with llm_api_routes can access auth=true pass-through endpoints only when
allowed_passthrough_routes is configured on the key or team.
"""

# Mock the registered pass-through routes
mock_dependencies = [object()]
mock_registered_routes = {
"test-uuid-1:exact:/azure-assistant": {
"test-uuid-1:exact:/azure-assistant:DELETE,GET,PATCH,POST,PUT": {
"endpoint_id": "test-uuid-1",
"path": "/azure-assistant",
"type": "exact",
"passthrough_params": {"dependencies": mock_dependencies},
},
"test-uuid-2:subpath:/custom-endpoint": {
"test-uuid-2:subpath:/custom-endpoint:DELETE,GET,PATCH,POST,PUT": {
"endpoint_id": "test-uuid-2",
"path": "/custom-endpoint",
"type": "subpath",
"passthrough_params": {"dependencies": mock_dependencies},
},
}

Expand All @@ -717,32 +716,149 @@ def test_virtual_key_llm_api_routes_allows_registered_pass_through_endpoints():
return_value="/",
),
):
# Create a virtual key with llm_api_routes permission
valid_token = UserAPIKeyAuth(
user_id="test_user",
allowed_routes=["llm_api_routes"],
metadata={
"allowed_passthrough_routes": [
"/azure-assistant",
"/custom-endpoint",
]
},
)

# Test exact match for registered pass-through endpoint
result1 = RouteChecks.is_virtual_key_allowed_to_call_route(
route="/azure-assistant",
valid_token=valid_token,
assert (
RouteChecks.is_virtual_key_allowed_to_call_route(
route="/azure-assistant",
valid_token=valid_token,
)
is True
)
assert (
RouteChecks.is_virtual_key_allowed_to_call_route(
route="/custom-endpoint/openai/assistants",
valid_token=valid_token,
)
is True
)
assert (
RouteChecks.is_virtual_key_allowed_to_call_route(
route="/custom-endpoint",
valid_token=valid_token,
)
is True
)
assert result1 is True

# Test subpath for registered pass-through endpoint with subpath type
result2 = RouteChecks.is_virtual_key_allowed_to_call_route(
route="/custom-endpoint/openai/assistants",
valid_token=valid_token,

def test_virtual_key_llm_api_routes_denies_auth_pass_through_without_allowlist():
"""auth=true pass-through must not be reachable via llm_api_routes alone."""

mock_registered_routes = {
"test-uuid-1:exact:/azure-assistant:GET,POST": {
"endpoint_id": "test-uuid-1",
"path": "/azure-assistant",
"type": "exact",
"passthrough_params": {"dependencies": [object()]},
},
}

with (
patch(
"litellm.proxy.pass_through_endpoints.pass_through_endpoints._registered_pass_through_routes",
mock_registered_routes,
),
patch(
Comment thread
shivamrawat1 marked this conversation as resolved.
Resolved
"litellm.proxy.pass_through_endpoints.pass_through_endpoints.get_server_root_path",
return_value="/",
),
):
valid_token = UserAPIKeyAuth(
user_id="test_user",
allowed_routes=["llm_api_routes"],
)
assert result2 is True

# Test exact match for subpath type
result3 = RouteChecks.is_virtual_key_allowed_to_call_route(
route="/custom-endpoint",
with pytest.raises(HTTPException) as exc_info:
RouteChecks.is_virtual_key_allowed_to_call_route(
route="/azure-assistant",
valid_token=valid_token,
)
assert exc_info.value.status_code == 403


def test_non_proxy_admin_denies_auth_pass_through_without_allowlist():
"""Internal users must not bypass allowed_passthrough_routes via openai_routes."""

mock_registered_routes = {
"test-uuid-1:exact:/my-pass-through:GET,POST": {
"endpoint_id": "test-uuid-1",
"path": "/my-pass-through",
"type": "exact",
"passthrough_params": {"dependencies": [object()]},
},
}

valid_token = UserAPIKeyAuth(
user_id="test_user",
user_role=LitellmUserRoles.INTERNAL_USER.value,
)

with (
patch(
"litellm.proxy.pass_through_endpoints.pass_through_endpoints._registered_pass_through_routes",
mock_registered_routes,
),
patch(
"litellm.proxy.pass_through_endpoints.pass_through_endpoints.get_server_root_path",
return_value="/",
),
):
with pytest.raises(HTTPException) as exc_info:
RouteChecks.non_proxy_admin_allowed_routes_check(
user_obj=None,
_user_role=LitellmUserRoles.INTERNAL_USER.value,
route="/my-pass-through",
request=MagicMock(spec=Request),
valid_token=valid_token,
request_data={},
)
assert exc_info.value.status_code == 403
assert "allowed_passthrough_routes" in exc_info.value.detail


def test_non_proxy_admin_allows_auth_pass_through_with_team_allowlist():
mock_registered_routes = {
"test-uuid-1:exact:/my-pass-through:GET,POST": {
"endpoint_id": "test-uuid-1",
"path": "/my-pass-through",
"type": "exact",
"passthrough_params": {"dependencies": [object()]},
},
}

valid_token = UserAPIKeyAuth(
user_id="test_user",
user_role=LitellmUserRoles.INTERNAL_USER.value,
team_metadata={"allowed_passthrough_routes": ["/my-pass-through"]},
)

with (
patch(
"litellm.proxy.pass_through_endpoints.pass_through_endpoints._registered_pass_through_routes",
mock_registered_routes,
),
patch(
"litellm.proxy.pass_through_endpoints.pass_through_endpoints.get_server_root_path",
return_value="/",
),
):
RouteChecks.non_proxy_admin_allowed_routes_check(
user_obj=None,
_user_role=LitellmUserRoles.INTERNAL_USER.value,
route="/my-pass-through",
request=MagicMock(spec=Request),
valid_token=valid_token,
request_data={},
)
assert result3 is True


def test_virtual_key_without_llm_api_routes_cannot_access_pass_through():
Expand Down
Loading