From 7b085e6e4efabf54a1a131d00ee40a25e5804c38 Mon Sep 17 00:00:00 2001 From: Jean Carlos Nunez Date: Sun, 5 Apr 2026 14:27:38 -0500 Subject: [PATCH] fix: preserve access group restriction when team_id is provided (#23850) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a key has access_group_ids, resetting key_models=[] on a team_id query parameter allowed any caller to bypass the access group restriction via ?team_id=xxx, reverting to full team-level access. Guard the reset so key_models is only cleared when the key has no access_group_ids — the access group restriction now stays in force regardless of the team_id parameter. Co-Authored-By: Claude Sonnet 4.6 --- litellm/proxy/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index a3bbd22e051..28e246713b7 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -5542,9 +5542,13 @@ async def get_available_models_for_user( # Get team models team_models: List[str] = user_api_key_dict.team_models - # If specific team_id is provided, validate and get team models + # If specific team_id is provided, validate and get team models. + # Do NOT reset key_models when the key has access_group_ids — the access + # group restriction must remain in force even when a team_id is specified, + # otherwise any caller can bypass it via ?team_id=xxx (issue #23850). if team_id and prisma_client and proxy_logging_obj and user_api_key_cache: - key_models = [] + if not user_api_key_dict.access_group_ids: + key_models = [] team_object = await get_team_object( team_id=team_id, prisma_client=prisma_client,