[Fix] /key/list user_id Empty String Edge Case#20623
Merged
yuneng-jiang merged 1 commit intomainfrom Feb 7, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile OverviewGreptile SummaryFixed a security vulnerability where non-admin users could list all keys by passing an empty Key Changes
Issues Found
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/proxy/management_endpoints/key_management_endpoints.py | Fixed security issue where empty user_id query parameter could bypass authorization checks and return all keys instead of user-specific keys |
| tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py | Added test for auto-setting user_id when None, but doesn't test the empty string case which was the actual security vulnerability |
Sequence Diagram
sequenceDiagram
participant Client as Non-Admin User
participant API as list_keys Endpoint
participant Auth as Authorization Check
participant Helper as _list_key_helper
participant DB as Database
Note over Client,DB: Before Fix (Vulnerability)
Client->>API: GET /key/list?user_id=
API->>Auth: Check if user_id is None
Auth-->>API: False (empty string != None)
API->>Helper: _list_key_helper(user_id="")
Helper->>DB: Query with empty user_id filter
DB-->>Helper: Returns ALL keys
Helper-->>Client: Unauthorized access to all keys
Note over Client,DB: After Fix (Secure)
Client->>API: GET /key/list?user_id=
API->>Auth: Check if not user_id
Auth-->>API: True (empty string is falsy)
API->>API: Set user_id = authenticated_user_id
API->>Helper: _list_key_helper(user_id="test-user-123")
Helper->>DB: Query filtered by user_id
DB-->>Helper: Returns only user's keys
Helper-->>Client: Authorized access to own keys only
| await list_keys( | ||
| request=mock_request, | ||
| user_api_key_dict=mock_user_api_key_dict, | ||
| user_id=None, # This should be auto-set to test_user_id |
Contributor
There was a problem hiding this comment.
Test should also include user_id="" (empty string) case, which is the actual security vulnerability being fixed. Query parameters like ?user_id= result in empty strings, not None.
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🐛 Bug Fix
✅ Test
Changes
Fixes an issue where an empty user_id will return the entire list of keys
Screenshot