Skip to content

fix(proxy): validate model credential name only when it changes - #42701

Merged
yuneng-berri merged 1 commit into
mainfrom
litellm_credential_name_validation_scope
Sep 23, 2026
Merged

yuneng-berri merged 1 commit into
mainfrom
litellm_credential_name_validation_scope

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

  • Compare the requested name with the model's stored credential name
  • Skip the existence check when they match, keep it on a real change
  • Empty string still 400, non-admin detach still 403

User Flow

Before: an admin wants to raise a model's rpm from an API client that reads the model, edits one field, and sends the whole object back, but the update is refused because of a field they never touched

  1. They send GET https://litellm-domain/model/info?litellm_model_id=704037ef-... and get the model back with "rpm": 5 and "litellm_credential_name": "dangling-demo-6f227715", a credential that was deleted earlier
  2. They send PATCH https://litellm-domain/model/704037ef-.../update with {"litellm_params": {"litellm_credential_name": "dangling-demo-6f227715", "rpm": 7}}
  3. They get HTTP 400 Credential 'dangling-demo-6f227715' not found. Create it via /credentials before attaching it to a model. and rpm stays at 5

After: the same edit goes through, and the credential checks that #42291 added still fire on a real change

  1. They send GET https://litellm-domain/model/info?litellm_model_id=704037ef-... and get the model back with "rpm": 5 and the same dangling credential name
  2. They send the same PATCH https://litellm-domain/model/704037ef-.../update with the unchanged credential name and "rpm": 7
  3. They get HTTP 200 and GET /model/info now shows "rpm": 7 with the credential name still attached
  4. Sending PATCH with "litellm_credential_name": "does-not-exist-475415cd" still returns HTTP 400 not found, and "" still returns HTTP 400 empty string
  5. A team admin who is not a proxy admin sending "litellm_credential_name": null still gets HTTP 403

Relevant issues

Follow-up to #42291

Affected release

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/test_litellm/<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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Screenshots / Proof of Fix

Shared setup: the tests/integration rig (real proxy on 127.0.0.1:4000 with Postgres and Redis, STORE_MODEL_IN_DB=True, master key sk-integration-master). Each run creates a credential, creates a model that uses it, then deletes the credential so the model holds a dangling name

Before (40ec84c)

  1. curl -s -X POST http://127.0.0.1:4000/credentials -H 'Authorization: Bearer sk-integration-master' -H 'Content-Type: application/json' -d '{"credential_name":"dangling-demo-6f227715","credential_values":{"api_key":"sk-demo"},"credential_info":{}}' -> HTTP 200
  2. curl -s -X POST http://127.0.0.1:4000/model/new ... -d '{"model_name":"demo-55c4639d","litellm_params":{"model":"openai/gpt-4o-mini","api_base":"http://127.0.0.1:8190/v1","litellm_credential_name":"dangling-demo-6f227715","rpm":5},"model_info":{}}' -> HTTP 200, id af3b1260-1cb6-45bb-8c24-1c87e07bd6ba
  3. curl -s -X DELETE http://127.0.0.1:4000/credentials/dangling-demo-6f227715 -H 'Authorization: Bearer sk-integration-master' -> HTTP 200
  4. curl -s 'http://127.0.0.1:4000/model/info?litellm_model_id=af3b1260-1cb6-45bb-8c24-1c87e07bd6ba' -H 'Authorization: Bearer sk-integration-master' -> "litellm_params":{"api_base":"http://127.0.0.1:8190/v1","rpm":5,"litellm_credential_name":"dangling-demo-6f227715",...}
  5. curl -s -i -X PATCH http://127.0.0.1:4000/model/af3b1260-1cb6-45bb-8c24-1c87e07bd6ba/update -H 'Authorization: Bearer sk-integration-master' -H 'Content-Type: application/json' -d '{"litellm_params":{"litellm_credential_name":"dangling-demo-6f227715","rpm":7}}'
HTTP/1.1 400 Bad Request
{"error":{"message":"Credential 'dangling-demo-6f227715' not found. Create it via /credentials before attaching it to a model.","type":"validation_error","param":"litellm_credential_name","code":"400"}}

After (648f475)

  1. curl -s -X POST http://127.0.0.1:4000/credentials ... -d '{"credential_name":"dangling-demo-191012fe","credential_values":{"api_key":"sk-demo"},"credential_info":{}}' -> HTTP 200
  2. curl -s -X POST http://127.0.0.1:4000/model/new ... -d '{"model_name":"demo-6e5ab0d5","litellm_params":{"model":"openai/gpt-4o-mini","api_base":"http://127.0.0.1:8190/v1","litellm_credential_name":"dangling-demo-191012fe","rpm":5},"model_info":{}}' -> HTTP 200, id 704037ef-108c-4daa-b9ea-76b88a1884e0
  3. curl -s -X DELETE http://127.0.0.1:4000/credentials/dangling-demo-191012fe -H 'Authorization: Bearer sk-integration-master' -> HTTP 200
  4. curl -s 'http://127.0.0.1:4000/model/info?litellm_model_id=704037ef-108c-4daa-b9ea-76b88a1884e0' -H 'Authorization: Bearer sk-integration-master' -> "litellm_params":{"api_base":"http://127.0.0.1:8190/v1","rpm":5,"litellm_credential_name":"dangling-demo-191012fe",...}
  5. curl -s -i -X PATCH http://127.0.0.1:4000/model/704037ef-108c-4daa-b9ea-76b88a1884e0/update -H 'Authorization: Bearer sk-integration-master' -H 'Content-Type: application/json' -d '{"litellm_params":{"litellm_credential_name":"dangling-demo-191012fe","rpm":7}}'
HTTP/1.1 200 OK
{"model_id":"704037ef-108c-4daa-b9ea-76b88a1884e0","model_name":"demo-6e5ab0d5","litellm_params":{"rpm":7,...},...}
  1. curl -s 'http://127.0.0.1:4000/model/info?litellm_model_id=704037ef-108c-4daa-b9ea-76b88a1884e0' -H 'Authorization: Bearer sk-integration-master' -> "litellm_params":{"api_base":"http://127.0.0.1:8190/v1","rpm":7,"litellm_credential_name":"dangling-demo-191012fe",...}
  2. curl -s -i -X PATCH .../model/704037ef-108c-4daa-b9ea-76b88a1884e0/update ... -d '{"litellm_params":{"litellm_credential_name":"does-not-exist-475415cd"}}'
HTTP/1.1 400 Bad Request
{"error":{"message":"Credential 'does-not-exist-475415cd' not found. Create it via /credentials before attaching it to a model.","type":"validation_error","param":"litellm_credential_name","code":"400"}}
  1. curl -s -i -X PATCH .../model/704037ef-108c-4daa-b9ea-76b88a1884e0/update ... -d '{"litellm_params":{"litellm_credential_name":""}}'
HTTP/1.1 400 Bad Request
{"error":{"message":"litellm_credential_name cannot be an empty string. Send null to detach the stored credential or omit the field to leave it unchanged.","type":"validation_error","param":"litellm_credential_name","code":"400"}}

Regression test red on unfixed main (40ec84c)

tests/integration/management/test_model_credential_name_updates.py against the same rig, before the fix. The two preservation nodes pass on main as expected, the read-modify-write node fails on its assertion

..F                                                                      [100%]
____ test_unrelated_patch_succeeds_when_resent_credential_name_is_dangling _____
>           assert patched.status_code == 200, patched.text
E           AssertionError: {"error":{"message":"Credential 'credential-a67b437bfe02411094fce2996659edaf' not found. Create it via /credentials before attaching it to a model.","type":"validation_error","param":"litellm_credential_name","code":"400"}}
E           assert 400 == 200
FAILED tests/integration/management/test_model_credential_name_updates.py::test_unrelated_patch_succeeds_when_resent_credential_name_is_dangling
1 failed, 2 passed in 0.86s

Mutation proof

Deleted the two-line early return in _raise_on_invalid_credential_name, restarted the proxy, and ran test_unrelated_patch_succeeds_when_resent_credential_name_is_dangling

-    if credential_name == _stored_credential_name(existing_litellm_params):
-        return
E           AssertionError: {"error":{"message":"Credential 'credential-82a8f71909674c0cae4311d1221b5046' not found. Create it via /credentials before attaching it to a model.","type":"validation_error","param":"litellm_credential_name","code":"400"}}
E           assert 400 == 200
FAILED tests/integration/management/test_model_credential_name_updates.py::test_unrelated_patch_succeeds_when_resent_credential_name_is_dangling

Restored the lines, restarted, same node: 1 passed in 0.29s. Full file at the fixed tip: 3 passed in 0.94s. Mapped unit file tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py: 318 passed

Type

🐛 Bug Fix

Caveats (if any)

Low

  • The stored name is compared after decryption, same as the existing 403 check
  • Before-side curl was captured on the merge-base behavior by running the proxy with the early return removed, which is byte-identical to the 40ec84c code path for this route

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/f5459494023c45dfbab2637ad6119a5b
Open in Devin Desktop: https://app.devin.ai/desktop/session/f5459494023c45dfbab2637ad6119a5b?variant=devin

PATCH /model/{id}/update rejected read-modify-write edits that resent an unchanged but dangling litellm_credential_name. Existence validation now runs only when the requested name differs from the stored one; empty string and non-admin detach rejections are unchanged

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot requested a review from a team September 23, 2026 07:36
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@greptile-apps

greptile-apps Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge because unchanged values bypass only credential existence lookup, while authorization and real-change validation remain enforced

Summary

This PR allows model updates to resend an unchanged credential name without revalidating whether that credential still exists

  • Centralizes stored credential-name decryption for authorization and validation
  • Preserves proxy-admin checks for replacement and detachment
  • Preserves rejection of empty and changed missing credential names
  • Adds unit and integration regression coverage for dangling unchanged credentials

Reviews (1) · Last reviewed commit: "fix(proxy): validate model credential na..."

@codecov

codecov Bot commented Sep 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_credential_name_validation_scope (648f475) with main (40ec84c)

Open in CodSpeed

@yuneng-berri
yuneng-berri merged commit 5028f9e into main Sep 23, 2026
93 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_credential_name_validation_scope branch September 23, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant