Skip to content

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]

fix(proxy-auth): deny provider-wildcard access inferred through an unrecognized model namespace

mateo-berrid0d1c0e346fd
diff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.py
index 230b9b70ff0..93811812901 100644
--- a/litellm/proxy/auth/auth_checks.py
+++ b/litellm/proxy/auth/auth_checks.py
@@ -4383,14 +4383,23 @@ def _model_custom_llm_provider_matches_wildcard_pattern(model: str, allowed_mode
or
- `model=claude-3-5-sonnet-20240620`
- `allowed_model_pattern=anthropic/*`
+
+ A model that already carries a namespace get_llm_provider did not consume
+ (e.g. `bedrockz/anthropic.claude-...`) is never granted here: its provider was
+ inferred from a fragment of the full string, so rebuilding
+ `{provider}/{model}` would produce `bedrock/bedrockz/...` and slip an
+ unrecognized namespace through a `bedrock/*` key.
"""
try:
- model, custom_llm_provider, _, _ = get_llm_provider(model=model)
+ stripped_model, custom_llm_provider, _, _ = get_llm_provider(model=model)
except Exception:
return False
+ if stripped_model == model and "/" in model:
+ return False
+
return is_model_allowed_by_pattern(
- model=f"{custom_llm_provider}/{model}",
+ model=f"{custom_llm_provider}/{stripped_model}",
allowed_model_pattern=allowed_model_pattern,
)
diff --git a/tests/proxy_unit_tests/test_auth_checks.py b/tests/proxy_unit_tests/test_auth_checks.py
index e7136ecb195..e58e6c9694b 100644
--- a/tests/proxy_unit_tests/test_auth_checks.py
+++ b/tests/proxy_unit_tests/test_auth_checks.py
@@ -236,6 +236,8 @@ async def test_can_team_call_model(model, expect_to_work):
(["bedrock/*"], "bedrock/anthropic.claude-3-5-sonnet-20240620", True),
(["bedrock/*"], "bedrockz/anthropic.claude-3-5-sonnet-20240620", False),
(["bedrock/us.*"], "bedrock/us.amazon.nova-micro-v1:0", True),
+ (["openai/*"], "ft:gpt-4-0613", True),
+ (["openai/*"], "bedrockz/ft:gpt-4-0613", False),
],
)
@pytest.mark.asyncio