fix(auth): deny wildcard model access for unrecognized provider prefixes - #33031
Conversation
_model_custom_llm_provider_matches_wildcard_pattern re-prefixed the model returned by get_llm_provider with the inferred provider. For a bare name (gpt-4o -> openai/gpt-4o) that is correct, but get_llm_provider loosely resolves an unrecognized prefix like bedrockz/anthropic.claude-3-5-sonnet-20240620 to provider 'bedrock' WITHOUT stripping the prefix, so the re-prefix produced 'bedrock/bedrockz/anthropic...' which spuriously matched the 'bedrock/*' wildcard. A key or team allowed only bedrock/* was therefore granted access to bedrockz/* models. Only infer a provider for a bare model name: if get_llm_provider returns a model that still contains '/', skip the re-prefix and return False. This makes the previously-failing test_can_key_call_model_wildcard_access / test_can_team_access_model bedrockz cases pass while preserving bare-name inference and all valid-prefix matches. Adds a focused offline unit test.
Greptile SummaryThis PR fixes an access-control bypass in the proxy's wildcard model-permission check where
Confidence Score: 4/5Safe to merge — the change is small and isolated to the wildcard provider-matching helper, existing direct-match paths are untouched, and new tests confirm the fixed behavior. The fix correctly guards against the double-prefix construction for unrecognized provider strings. In practice all recognized provider prefixes are stripped by No files require special attention;
|
| Filename | Overview |
|---|---|
| litellm/proxy/auth/auth_checks.py | Fixes spurious wildcard match in _model_custom_llm_provider_matches_wildcard_pattern by returning False when get_llm_provider leaves a / in the resolved model name (indicating an unrecognized provider prefix that it could not strip). |
| tests/test_litellm/proxy/auth/test_auth_checks.py | Adds 6 parametrized offline unit tests covering bare-name inference, valid provider prefix match, and the two unrecognized-prefix denial cases that were the root of the bug. No real network calls; imports are inline to avoid side effects. |
Reviews (1): Last reviewed commit: "fix(auth): deny wildcard model access fo..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Relevant issues
Fixes #33030
Pre-Submission checklist
Screenshots / Proof of Fix
Access-control bug in the proxy's wildcard model-access check, reproducible offline (no keys/network).
Root cause:
_model_custom_llm_provider_matches_wildcard_patternre-prefixes the model returned byget_llm_providerwith the inferred provider. For a bare name (gpt-4o→openai/gpt-4o) that is correct, butget_llm_provider("bedrockz/anthropic.claude-3-5-sonnet-20240620")loosely resolves the provider tobedrockwithout stripping thebedrockz/prefix, so the re-check runs againstbedrock/bedrockz/anthropic..., which matchesbedrock/*and grants access.Before (base
3d63eda) — the repo's own regression tests fail:(This is the
auth-and-jwtjob that is currently red on PRs againstlitellm_oss_daily_2026_07_10.)After (this PR):
New focused, offline unit test (fails on base, passes here):
Matrix verified via the matcher directly:
openai/gpt-4oopenai/*bedrock/anthropic.claude-3-5-sonnet-20240620bedrock/*bedrockz/anthropic.claude-3-5-sonnet-20240620bedrock/*openaiz/gpt-4o-miniopenai/*gpt-4(bare)openai/*bedrock/claude-3-6-sonnet-20240620bedrock/claude-3-5-*Type
🐛 Bug Fix
Changes
Only infer a provider for a bare model name. If
get_llm_providerreturns a model that still contains/(an unrecognized prefix it could not strip), skip the re-prefix and returnFalse, so a wildcard likebedrock/*no longer matches a different prefix such asbedrockz/*. Valid prefixes and bare-name provider inference are unchanged.cc @ishaan-jaff @krrish-berri-2 — this also fixes the
auth-and-jwtregression currently red onlitellm_oss_daily_*(the twobedrockzaccess-check cases). Small and isolated; would appreciate a look. Thanks!