From c15b55588f87a82db7103cdd47e713296387049a Mon Sep 17 00:00:00 2001 From: D41910 <158550716+D41910@users.noreply.github.com> Date: Tue, 6 Oct 2026 19:37:12 +0800 Subject: [PATCH] fix(proxy): refuse the blocked flag before member write authorization in PATCH /model/{id}/update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A team member (or team/org admin) PATCHing only the blocked flag hit the member auto-router authorization inside can_user_make_model_call first and got 'This team does not allow you to manage your own auto routers.' — a refusal about auto routers for a body that never mentions one. The documented proxy-admin-only refusal for the blocked flag existed but ran later. Raise the blocked-flag refusal before the member write-authorization check so non-admin callers get 'Only proxy admins can change a model's blocked flag.', and pin the refusal message in the team-admin-gate matrix for every non-admin caller. Fixes #44792 --- .../model_management_endpoints.py | 24 +++++++++-------- .../authorization/test_team_admin_gate.py | 27 ++++++++++++++++--- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/litellm/proxy/management_endpoints/model_management_endpoints.py b/litellm/proxy/management_endpoints/model_management_endpoints.py index 42c4a15a4ef..9b7d640b81d 100644 --- a/litellm/proxy/management_endpoints/model_management_endpoints.py +++ b/litellm/proxy/management_endpoints/model_management_endpoints.py @@ -1198,6 +1198,19 @@ async def patch_model( param=None, ) + # Pause/resume (`blocked`) is a proxy-admin-only privilege. Refuse it + # before the member write-authorization check so a team member (or + # team/org admin) patching only the blocked flag gets this documented + # refusal instead of the auto-router membership refusal the member + # write path raises for bodies without auto-router permissions. + if patch_data.blocked is not None and user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN: + raise ProxyException( + message="Only proxy admins can change a model's blocked flag.", + type=ProxyErrorTypes.auth_error.value, + code=status.HTTP_403_FORBIDDEN, + param="blocked", + ) + write_authorization: Final = await ModelManagementAuthChecks.can_user_make_model_call( model_params=db_model, user_api_key_dict=user_api_key_dict, @@ -1234,17 +1247,6 @@ async def patch_model( else patch_data ) - # Pause/resume (`blocked`) is a proxy-admin-only privilege. Team admins - # passed the auth check above for team-scoped models, but they must not - # be able to unblock (or block) a model their proxy admin has paused. - if patch_data.blocked is not None and user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN: - raise ProxyException( - message="Only proxy admins can change a model's blocked flag.", - type=ProxyErrorTypes.auth_error.value, - code=status.HTTP_403_FORBIDDEN, - param="blocked", - ) - ModelManagementAuthChecks.can_user_attach_credential( litellm_params=patch_data.litellm_params, user_api_key_dict=user_api_key_dict, diff --git a/tests/integration/authorization/test_team_admin_gate.py b/tests/integration/authorization/test_team_admin_gate.py index d62a2a1a9a6..382cfb21cf2 100644 --- a/tests/integration/authorization/test_team_admin_gate.py +++ b/tests/integration/authorization/test_team_admin_gate.py @@ -424,8 +424,29 @@ def test_status_code(shared: TeamScenario, org_team: TeamScenario, route: Route, f"{caller} {call.method} {call.path}: {response.status_code} {response.text}" ) if route.name == "team_update_budget_permitted": - assert read_rows( - 'SELECT max_budget FROM "LiteLLM_TeamTable" WHERE team_id = %s', (s.team_id,) - ) == [{"max_budget": 4.0 if response.status_code == 200 else 5.0}] + assert read_rows('SELECT max_budget FROM "LiteLLM_TeamTable" WHERE team_id = %s', (s.team_id,)) == [ + {"max_budget": 4.0 if response.status_code == 200 else 5.0} + ] if response.status_code == 200 and route.cleanup is not None: route.cleanup(s, object_value(response.json())) + + +@pytest.mark.parametrize( + "caller", + [caller for caller in CALLERS if caller != "proxy_admin"], +) +def test_non_team_admin_patching_the_blocked_flag_gets_the_blocked_flag_refusal( + shared: TeamScenario, org_team: TeamScenario, caller: Caller +) -> None: + """PATCHing only the blocked flag is refused with the documented + proxy-admin-only refusal, not the auto-router membership refusal the + member write path raises for bodies without auto-router permissions.""" + team: Final = org_team if caller in ORG_CALLERS else shared + with team.gateway.scenario() as scenario: + s: Final = replace(team, scenario=scenario) + model_id: Final = s.model() + response: Final = s.gateway.request( + "PATCH", f"/model/{model_id}/update", {"blocked": False}, key=s.keys[caller] + ) + assert response.status_code == 403, response.text + assert "Only proxy admins can change a model's blocked flag." in response.text