Repository navigation
fix(files)!: scope provider and model file lists to the caller's managed files under require_managed_files - #47682
Conversation
|
@litellm-stampbot |
litellm-stampbot: risk lowApproved at Rules (
Judge: skipped, the rules alone decided. Pushes do not re-run this check. Comment |
kerry-berri
left a comment
There was a problem hiding this comment.
Low risk by rule and by judgement at 03cb854
…under require_managed_files
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Merging this PR will not alter performance1 warning
Comparing Footnotes |
|
@litereview code-review |
|
[Medium impact] The PR appears safe to merge, with the previous alias-listing issue fixed and no new blocking findings. SummaryWith The latest change fixes the previous finding by including storage-backed uploads made through aliases and routing groups. The updated tests cover both cases. No new actionable issues were found.
Reviews (5) · Last reviewed commit: "fix(files): list alias and routing-group..." · Reviewed by Greptile |
…der or model and page with after_id and before_id
|
@litereview code-review |
| or await get_custom_llm_provider_from_request_body(request=request) | ||
| ) | ||
|
|
||
|
|
There was a problem hiding this comment.
Medium · Model-filtered file list returns empty for the owner's own files on wildcard deployments
- The proxy runs with
require_managed_files: trueand has a single wildcard deployment,model_name: anthropic/*. - User A uploads with
target_model_names=anthropic/claude-haiku-4-5. The router resolves the wildcard and storesmodel_mappings = {<wildcard deployment id>: file_...}. - User A then sends
GET /v1/files?target_model_names=anthropic/claude-haiku-4-5, or sets the same model inx-litellm-model.get_authorized_credentials_for_modelaccepts the model._deployment_ids_serving_modelthen callsllm_router.get_model_ids(model_name=...). That call only checks the exactmodel_nameindex, so it returns an empty set. - In
afile_list,deployment_ids.isdisjoint(row.model_mappings)is true for every row. A gets"data": []even though the file is A's own upload on that deployment.
Team public model names have the same gap, because get_model_ids does not consult team_model_to_deployment_indices. To fix it, resolve deployment ids the same way upload routing does: exact name, team public name, then wildcard pattern_router.route(...), collecting model_info.id from each match.
Evidence
Reproducer (executed on the PR checkout, /tmp/wc.py):
r = Router(model_list=[{"model_name":"anthropic/*","litellm_params":{"model":"anthropic/*","api_key":"sk-x"}}])
deps = await r.async_get_healthy_deployments(model="anthropic/claude-haiku-4-5", ...)
add_model_file_id_mappings(deps, [F()])
_deployment_ids_serving_model(r, "anthropic/claude-haiku-4-5")
_deployment_ids_on_provider(r, "anthropic")Output:
upload model_mappings: {'6cd11d07...e84b': 'file_abc'}
list by model: frozenset()
list by provider: frozenset({'6cd11d07...e84b'})
Access check passes for the same model (/tmp/wc2.py): get_authorized_credentials_for_model(..., model_id="anthropic/claude-haiku-4-5") returns provider anthropic, so the request reaches the empty filter. It is not rejected with 403/404.
Router.get_model_ids(model_name=...) (litellm/router.py:12778) reads only model_name_to_deployment_indices. get_credential_deployment (router.py:11851) also checks team public names and wildcard patterns. Upload uses that broader resolution.
New tests (_callers_files_on_every_deployment, integration test_managed_file_listing.py) cover only exact model_name deployments, so they cannot catch this case.
Latest summary by code-review · View this review · Reviewed 2cb4bb5cb563
There was a problem hiding this comment.
Fixed in 6643800, which matches every deployment serving the model, wildcards included. Team public names already answer 400 at the access check on base
There was a problem hiding this comment.
Finding withdrawn
The reply is correct.
- Wildcard case:
_deployment_ids_serving_modelnow usesllm_router.get_model_list(model_name=model), which includes_get_wildcard_deployments, in place ofget_model_ids. A list filtered byanthropic/claude-haiku-4-5now returns the same wildcard deployment id that upload stores inmodel_mappings. The owner sees their own file. - Team public name: this case fails at the access check.
get_credentials_for_modelcallsget_deployment_credentials_with_providerwithout ateam_id, so the lookup finds no deployment and the request fails with a 400. It never reaches thedeployment_idsfilter and never returns a silent"data": []. The original finding's description of this case does not apply.
Evidence
litellm/proxy/openai_files_endpoints/files_endpoints.py:1723-1726:
def _deployment_ids_serving_model(llm_router: Router, model: str) -> frozenset[str]:
if llm_router.has_model_id(model):
return frozenset((model,))
return _deployment_ids(llm_router.get_model_list(model_name=model) or ())Router.get_model_list (litellm/router.py ~13545) also appends _get_wildcard_deployments(model_name=...).
Reproducer /tmp/wc.py on head 66438008:
upload ids ['6cd11d0786de...fe84b']
by model frozenset({'6cd11d0786de...fe84b'})
by provider frozenset({'6cd11d0786de...fe84b'})
Reproducer /tmp/tp.py (team deployment with team_public_model_name=my-claude, key in team1):
serving frozenset()
raised ProxyModelNotFoundError 400 ... 'file list: Invalid model name passed in model=my-claude.'
_listed_deployment_ids calls get_authorized_credentials_for_model before _deployment_ids_serving_model (files_endpoints.py:1776-1782).
tests/unit/proxy/openai_files_endpoint/test_files_endpoint.py::test_require_managed_files_lists_the_callers_files_wherever_the_router_put_them: the wildcard-target-model-names and wildcard-model-header cases assert ["unified-wildcard"]. Run result: 4 passed.
GitHub does not allow this App to resolve this thread. A repository maintainer must do it manually.
Reviewed 66438008a1f0 · View follow-up
…ts that cannot be scoped A model name now matches every deployment that serves it, wildcards and aliases included, and a provider matches deployments by the provider uploads resolve, so anthropic/* and unprefixed Claude models count. The OpenAI and Azure lists also return the caller's pass-through uploads. An unknown provider and different after and after_id cursors answer 400, and a list with no matching deployment skips the database read.
|
@litereview code-review |
…as on main Under require_managed_files, a narrowed list now matches a file's model mappings by deployment id or model name, so files LiteLLM stores in its own database show on their model and provider lists. The Anthropic list defaults to 20 rows when no limit is sent, after_id, before_id and the cursor 400s apply only under the flag, and an admin keeps the provider list when the managed files hook is not loaded. List errors are returned as values and mapped to HTTP errors in one place.
|
@litereview guide |
|
|
@litereview code-review |
Under require_managed_files, an admin keeps the provider list as on main, and only a non-admin list reads the caller's own and team managed files. A stored file now also shows on the provider its model name routes to through a wildcard, with exact model names first, and a list routed to a model takes the default page size of the provider serving it. A new index on created_by and created_at keeps each chunk of the walk an index read, and the model check runs before the file object is parsed.
A non-admin list scoped to a provider or model now asks Postgres only for the caller's rows that map to one of that scope's deployments or models, or that live in file storage, instead of reading every owned row and filtering them in Python. A caller with many files on other providers no longer waits for the whole set to be read. Team members' files are matched in the same query.
|
@litereview code-review |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit e6edd7e. Configure here.
With
require_managed_fileson, a non-admin file list that names a provider or a model now returns only the caller's own and team managed files there. Before, those lists read the shared provider key, so on Anthropic every key saw every file on it, other users' uploads included. Admin lists stay as they are on mainPaging works under the flag now too, with
limit,after, and the Anthropic SDK'safter_idandbefore_idOriginal
Breaking change: with
require_managed_fileson, a non-admin's provider and model lists show only their own and team managed files, newest first, and answer 500 without the managed files hook. Admin lists are unchangedTLDR
Problem this solves:
limitandafterare ignored under the flagHow it solves it:
after,after_idandbefore_idpage newest firstUser Flow
Before: with
require_managed_fileson, user B can list user A's Anthropic filesrequire_managed_fileson, user A uploads with POST https://litellm-domain/anthropic/v1/files andtarget_model_names=claude-filesfile_01...idAfter: B sees only B's own files, and A pages through A's
require_managed_fileson, user A uploads with POST https://litellm-domain/anthropic/v1/files andtarget_model_names=claude-files"data": []on every provider or model list formafter_idorbefore_idpages through themDesign decisions
11 decisions
?provider=, orcustom-llm-providernarrows the list to that provider's deployments, plus pass-through uploads on OpenAI and Azurex-litellm-model, the body, ortarget_model_namesnarrows it to every deployment serving that model, after the access checkmodel_group_aliasor a routing group, on the provider its model resolves toafter_idmeansafterandbefore_idpages toward newer files, as the Anthropic SDK sends them. Conflicting cursors answer 400limit, an Anthropic list returns 20 rows like Anthropic's API, and other lists keep the 10000 capcreated_byandcreated_atindex builtCONCURRENTLY. Filtering 40k owned rows in Python took about 7 sRelevant issues
Related to #45071, which asked for a hook on provider-prefixed file routes. This PR builds that isolation in instead
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Both legs ran the same scripts on real OpenAI, Anthropic and Azure, with a fresh database and 2 uvicorn workers per proxy. U1 to U12 are user A's uploads, listed in the shared setup. Rows other runs left on the shared key show as a count. The timing cases seed 200,000 rows, 40,000 of them B's and none on Anthropic
/anthropic/v1/files/anthropic/v1/fileslimitignored, 20 rowsAll 48 cases
/openai/v1/files/anthropic/v1/files?provider=anthropiccustom-llm-providertarget_model_namesx-litellm-model/azure/v1/files/openai/v1/files/anthropic/v1/filestarget_model_namesx-litellm-modelanthropic/*wildcard model/azure/v1/files?provider=hosted_vllm?provider=antropic/antropic/v1/fileslimit=1page 1afterlimit=1page 1after_idafter=U2withafter_id=U1after=U2withbefore_id=U1limitignored, 20 rowsbefore_id=U3limitignored, 20 rowstarget_model_names/openai/v1/files/anthropic/v1/files/anthropic/v1/filesx-litellm-model/v1/filesShared setup
A uploaded U1 and U2 to OpenAI, U3 to U6 to Anthropic (U5 through
anthropic/*, U6 on an unprefixed model), U7 through the OpenAI pass-through, U8 as a batch input LiteLLM stores itself, U9 to Azure, and U10 as a stored batch input for a model only thehosted_vllm/*wildcard serves. After the paging cases A uploaded U11 to Azure Blob Storage throughlitellm-qa-files-claude-alias, amodel_group_aliasof the Claude model, and U12 throughlitellm-qa-files-claude-group, a routing group over it. D uploaded 21 Anthropic files. A flag-off proxy and a no-database proxy share the scriptsU11 and U12 need
AZURE_STORAGE_ACCOUNT_NAME,AZURE_STORAGE_FILE_SYSTEMandAZURE_STORAGE_ACCOUNT_KEYon the proxy. The flag-off proxy setsrequire_managed_files: false, and the no-database proxy dropsdatabase_urland boots withenv -u DATABASE_URL LITELLM_MODE=PRODUCTION.litellm-qa-files-vllmandhosted_vllm/*point at a static file server that answers 404 on/v1/files, like a vLLM server with no Files API, so its batch upload is stored by LiteLLMD's uploads run after every A and B case. Every list response goes through this filter. It keeps rows whose id is U1 to U12 or whose file name starts with the run's prefix, and collapses every other row on the shared key into a count
The no-database master key list is every file on the shared OpenAI key, so the gist keeps only its row count
Before (c7c895d)
B on /anthropic/v1/files
Run
Observe the raw output, 54 lines of JSON
Other cases, before
B on /openai/v1/files
Run
Observe
B on /v1/files?provider=anthropic
Run
Observe the raw output, 54 lines of JSON
B on /v1/files with custom-llm-provider: anthropic
Run
Observe the raw output, 54 lines of JSON
B on /v1/files?target_model_names=litellm-qa-files-claude
Run
Observe the raw output, 54 lines of JSON
B on /v1/files with x-litellm-model: litellm-qa-files-claude
Run
Observe the raw output, 54 lines of JSON
B on /azure/v1/files
Run
Observe
B on /v1/files with no provider
Run
Observe
B's gpt-only key asks for the Claude model's list
Run
Observe
B with the OpenAI SDK
Save
openai_list.pyRun
KEY=$KEY_B python3 openai_list.pyObserve
B with the Anthropic SDK
Save
anthropic_list.pyRun
KEY=$KEY_B python3 anthropic_list.pyObserve the raw output, 66 lines of JSON
A on /openai/v1/files
Run
Observe the raw output, 42 lines of JSON
A on /anthropic/v1/files
Run
Observe the raw output, 54 lines of JSON
A on /v1/files?target_model_names=litellm-qa-files-gpt
Run
Observe the raw output, 42 lines of JSON
A on /v1/files with x-litellm-model: litellm-qa-files-claude
Run
Observe the raw output, 54 lines of JSON
A on /v1/files with no provider
Run
Observe the raw output, 119 lines of JSON
A on /v1/files?target_model_names=anthropic/claude-haiku-5-5, served by the anthropic/* wildcard
Run
Observe the raw output, 54 lines of JSON
A on /azure/v1/files
Run
Observe the raw output, 20 lines of JSON
A on /v1/files?target_model_names=litellm-qa-files-vllm, the model whose batch input LiteLLM stored
Run
Observe
A on /v1/files?target_model_names=hosted_vllm/qwen-wild, the stored file's wildcard model
Run
Observe
A on /v1/files?provider=hosted_vllm, those models' provider
Run
Observe
A on /v1/files?provider=antropic, a misspelled provider in the query
Run
Observe
A on /antropic/v1/files, a misspelled provider
Run
Observe
A pages /openai/v1/files, page 1
Run
Observe the raw output, 42 lines of JSON
A pages /openai/v1/files, page 2 with after=<page 1 last_id>
Run
Observe the raw output, 42 lines of JSON
A pages /anthropic/v1/files, page 1
Run
Observe the raw output, 54 lines of JSON
A pages /anthropic/v1/files, page 2 with after_id=<page 1 last_id>
Run
Observe the raw output, 54 lines of JSON
A sends two different cursors, after=U2 and after_id=U1
Run
Observe the raw output, 42 lines of JSON
A sends both directions, after=U2 and before_id=U1
Run
Observe the raw output, 20 lines of JSON
A auto-pages with the OpenAI SDK, limit=1
Save
openai_autopage.pyRun
KEY=$KEY_A python3 openai_autopage.pyObserve the raw output, 8 lines of JSON
A auto-pages with the Anthropic SDK, limit=1
Save
anthropic_autopage.pyRun
KEY=$KEY_A python3 anthropic_autopage.pyObserve
A pages backwards with the Anthropic SDK from U3, limit=1
Save
anthropic_before_id.pyRun
KEY=$KEY_A python3 anthropic_before_id.pyObserve
A on /anthropic/v1/files, the alias's provider, after uploading U11
Run
Observe
A on /v1/files?target_model_names=litellm-qa-files-claude-alias
Run
Observe
A on /anthropic/v1/files, the routing group's provider, after uploading U12
Run
Observe
B on /anthropic/v1/files after A's alias and routing-group uploads
Run
Observe
Admin with the master key on /openai/v1/files
Run
Observe the raw output, 42 lines of JSON
Admin with the master key on /anthropic/v1/files
Run
Observe the raw output, 10 lines of JSON
D on /anthropic/v1/files with no limit
Run
Observe
D on /v1/files with x-litellm-model: litellm-qa-files-claude and no limit
Run
Observe
D on /v1/files with no limit
Run
Observe
Flag off, A on /v1/files with no cursor
Run
Observe the raw output, 2 lines of JSON
Flag off, A on /v1/files with after=U2, after_id=U1 and before_id=U3
Run
Observe
No database, Admin uploads with the master key to /openai/v1/files
Run
Observe
No database, Admin with the master key on /openai/v1/files
Run
Observe
Timing, B on /anthropic/v1/files, run 1
Run
Observe
Timing, B on /anthropic/v1/files, run 2
Run
Observe
Timing, B on /anthropic/v1/files, run 3
Run
Observe
After (e6edd7e)
B on /anthropic/v1/files
Run
Observe
Other cases, after
B on /openai/v1/files
Run
Observe
B on /v1/files?provider=anthropic
Run
Observe
B on /v1/files with custom-llm-provider: anthropic
Run
Observe
B on /v1/files?target_model_names=litellm-qa-files-claude
Run
Observe
B on /v1/files with x-litellm-model: litellm-qa-files-claude
Run
Observe
B on /azure/v1/files
Run
Observe
B on /v1/files with no provider
Run
Observe
B's gpt-only key asks for the Claude model's list
Run
Observe
B with the OpenAI SDK
Save
openai_list.pyRun
KEY=$KEY_B python3 openai_list.pyObserve
B with the Anthropic SDK
Save
anthropic_list.pyRun
KEY=$KEY_B python3 anthropic_list.pyObserve
A on /openai/v1/files
Run
Observe the raw output, 42 lines of JSON
A on /anthropic/v1/files
Run
Observe the raw output, 53 lines of JSON
A on /v1/files?target_model_names=litellm-qa-files-gpt
Run
Observe the raw output, 31 lines of JSON
A on /v1/files with x-litellm-model: litellm-qa-files-claude
Run
Observe the raw output, 31 lines of JSON
A on /v1/files with no provider
Run
Observe the raw output, 119 lines of JSON
A on /v1/files?target_model_names=anthropic/claude-haiku-5-5, served by the anthropic/* wildcard
Run
Observe the raw output, 20 lines of JSON
A on /azure/v1/files
Run
Observe the raw output, 20 lines of JSON
A on /v1/files?target_model_names=litellm-qa-files-vllm, the model whose batch input LiteLLM stored
Run
Observe the raw output, 20 lines of JSON
A on /v1/files?target_model_names=hosted_vllm/qwen-wild, the stored file's wildcard model
Run
Observe the raw output, 20 lines of JSON
A on /v1/files?provider=hosted_vllm, those models' provider
Run
Observe the raw output, 31 lines of JSON
A on /v1/files?provider=antropic, a misspelled provider in the query
Run
Observe
A on /antropic/v1/files, a misspelled provider
Run
Observe
A pages /openai/v1/files, page 1
Run
Observe
A pages /openai/v1/files, page 2 with after=<page 1 last_id>
Run
Observe the raw output, 20 lines of JSON
A pages /anthropic/v1/files, page 1
Run
Observe the raw output, 20 lines of JSON
A pages /anthropic/v1/files, page 2 with after_id=<page 1 last_id>
Run
Observe the raw output, 20 lines of JSON
A sends two different cursors, after=U2 and after_id=U1
Run
Observe
A sends both directions, after=U2 and before_id=U1
Run
Observe
A auto-pages with the OpenAI SDK, limit=1
Save
openai_autopage.pyRun
KEY=$KEY_A python3 openai_autopage.pyObserve the raw output, 8 lines of JSON
A auto-pages with the Anthropic SDK, limit=1
Save
anthropic_autopage.pyRun
KEY=$KEY_A python3 anthropic_autopage.pyObserve the raw output, 9 lines of JSON
A pages backwards with the Anthropic SDK from U3, limit=1
Save
anthropic_before_id.pyRun
KEY=$KEY_A python3 anthropic_before_id.pyObserve the raw output, 8 lines of JSON
A on /anthropic/v1/files, the alias's provider, after uploading U11
Run
Observe the raw output, 64 lines of JSON
A on /v1/files?target_model_names=litellm-qa-files-claude-alias
Run
Observe
A on /anthropic/v1/files, the routing group's provider, after uploading U12
Run
Observe the raw output, 75 lines of JSON
B on /anthropic/v1/files after A's alias and routing-group uploads
Run
Observe
Admin with the master key on /openai/v1/files
Run
Observe the raw output, 42 lines of JSON
Admin with the master key on /anthropic/v1/files
Run
Observe the raw output, 54 lines of JSON
D on /anthropic/v1/files with no limit
Run
Observe
D on /v1/files with x-litellm-model: litellm-qa-files-claude and no limit
Run
Observe
D on /v1/files with no limit
Run
Observe
Flag off, A on /v1/files with no cursor
Run
Observe the raw output, 2 lines of JSON
Flag off, A on /v1/files with after=U2, after_id=U1 and before_id=U3
Run
Observe
No database, Admin uploads with the master key to /openai/v1/files
Run
Observe
No database, Admin with the master key on /openai/v1/files
Run
Observe
Timing, B on /anthropic/v1/files, run 1
Run
Observe
Timing, B on /anthropic/v1/files, run 2
Run
Observe
Timing, B on /anthropic/v1/files, run 3
Run
Observe
Observations from the runs
has_morefalsetarget_model_namesanswers 400 on main too/live-pr-risk at e6edd7e
I ran /live-pr-risk on the GCE box with real Postgres, two uvicorn workers per proxy, and real Anthropic, OpenAI and Azure calls, comparing the merge base c7c895d with the head. The same 40 cells gave the same results on GitHub's merge ref 5ed6242. The full report has every caller row, the dependency graph and the integration suites
No dependent path that answered correctly on base fails on head, and every backward-incompatible change below was in the code kerry-berri approved
Paths covered, backward-incompatible changes, and risks
It covered the paths the /qa cases and unit tests do not reach. These are team members, team service-account keys, keys with no user or team, both viewer roles, DB-stored deployments over two workers, a routing group over OpenAI and Azure, a deployment deleted after an upload, a
github_copilotdeployment, hostile cursors, and the index migration throughprisma migrate deploywith a rollback to baseBackward incompatible
All of these apply only with
require_managed_fileson, and only to callers without an admin role. Provider and model lists hold only the caller's own and team managed files,internal_user_viewergets an empty list there, and the lists come back newest first.purpose=boguson/anthropic/v1/filesanswers 400 where Anthropic used to ignore it, and an unknownafter,after_idorbefore_idanswers 400 "no file found with id". Another user's id as a cursor gets that same 400, so it does not reveal whether a file exists. A file whose deployment was deleted drops out of the provider list but stays on/v1/files, and its content already answered 400 on both legs. The purpose and cursor checks already run on/v1/fileson main, and this PR applies them to provider lists too. Every change in this paragraph was already in the code kerry-berri approved at 03cb854 in his reviewRegression risk
The provider scope looks up each deployment's provider on every scoped list call. For a
github_copilotorchatgptdeployment that reads the token file, and an expired token would be refreshed over the network inside the request, which the router avoids throughdeclared_authenticating_provider. A storedmodel_mappingsvalue that is not a JSON object would 500 the page, though no writer stores oneNot verified
Batch output files from a real finished batch, files written by fine-tuning or container flows,
/azure_aipass-through uploads, Azure deployments of non-OpenAI models, an expiredgithub_copilottoken, andrequire_managed_fileswithout the managed files hookType
🐛 Bug Fix
✅ Test
Caveats (if any)
Medium
Low
osv-scanandimage-scanare red on main too, from dependency advisories in files this PR does not touchgithub_copilotorchatgpttoken could refresh over the network inside a scoped list callrequire_managed_filesreach itFinal Attestation
Bugbot summary