mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
Internal User Endpoint - vulnerability fix + response type fix (#8228)
* fix(key_management_endpoints.py): fix vulnerability where a user could update another user's keys Resolves https://github.com/BerriAI/litellm/issues/8031 * test(key_management_endpoints.py): return consistent 403 forbidden error when modifying key that doesn't belong to user * fix(internal_user_endpoints.py): return model max budget in internal user create response Fixes https://github.com/BerriAI/litellm/issues/7047 * test: fix test * test: update test to handle gemini token counter change * fix(factory.py): fix bedrock http:// handling * docs: fix typo in lm_studio.md (#8222) * test: fix testing * test: fix test --------- Co-authored-by: foreign-sub <51928805+foreign-sub@users.noreply.github.com>
This commit is contained in:
parent
f6bd48a1c5
commit
df93debbc7
7 changed files with 240 additions and 28 deletions
|
@ -1314,6 +1314,11 @@ def test_generate_and_update_key(prisma_client):
|
|||
budget_duration="1mo",
|
||||
max_budget=100,
|
||||
),
|
||||
user_api_key_dict=UserAPIKeyAuth(
|
||||
user_role=LitellmUserRoles.PROXY_ADMIN,
|
||||
api_key="sk-1234",
|
||||
user_id="1234",
|
||||
),
|
||||
)
|
||||
|
||||
print("response1=", response1)
|
||||
|
@ -1322,6 +1327,11 @@ def test_generate_and_update_key(prisma_client):
|
|||
response2 = await update_key_fn(
|
||||
request=Request,
|
||||
data=UpdateKeyRequest(key=generated_key, team_id=_team_2),
|
||||
user_api_key_dict=UserAPIKeyAuth(
|
||||
user_role=LitellmUserRoles.PROXY_ADMIN,
|
||||
api_key="sk-1234",
|
||||
user_id="1234",
|
||||
),
|
||||
)
|
||||
print("response2=", response2)
|
||||
|
||||
|
@ -2956,7 +2966,11 @@ async def test_generate_key_with_model_tpm_limit(prisma_client):
|
|||
_request = Request(scope={"type": "http"})
|
||||
_request._url = URL(url="/update/key")
|
||||
|
||||
await update_key_fn(data=request, request=_request)
|
||||
await update_key_fn(
|
||||
data=request,
|
||||
request=_request,
|
||||
user_api_key_dict=UserAPIKeyAuth(user_role=LitellmUserRoles.PROXY_ADMIN),
|
||||
)
|
||||
result = await info_key_fn(
|
||||
key=generated_key,
|
||||
user_api_key_dict=UserAPIKeyAuth(user_role=LitellmUserRoles.PROXY_ADMIN),
|
||||
|
@ -3017,7 +3031,11 @@ async def test_generate_key_with_guardrails(prisma_client):
|
|||
_request = Request(scope={"type": "http"})
|
||||
_request._url = URL(url="/update/key")
|
||||
|
||||
await update_key_fn(data=request, request=_request)
|
||||
await update_key_fn(
|
||||
data=request,
|
||||
request=_request,
|
||||
user_api_key_dict=UserAPIKeyAuth(user_role=LitellmUserRoles.PROXY_ADMIN),
|
||||
)
|
||||
result = await info_key_fn(
|
||||
key=generated_key,
|
||||
user_api_key_dict=UserAPIKeyAuth(user_role=LitellmUserRoles.PROXY_ADMIN),
|
||||
|
@ -3710,6 +3728,11 @@ async def test_key_alias_uniqueness(prisma_client):
|
|||
await update_key_fn(
|
||||
data=UpdateKeyRequest(key=key3.key, key_alias=unique_alias),
|
||||
request=Request(scope={"type": "http"}),
|
||||
user_api_key_dict=UserAPIKeyAuth(
|
||||
user_role=LitellmUserRoles.PROXY_ADMIN,
|
||||
api_key="sk-1234",
|
||||
user_id="1234",
|
||||
),
|
||||
)
|
||||
pytest.fail("Should not be able to update a key to use an existing alias")
|
||||
except Exception as e:
|
||||
|
@ -3719,6 +3742,11 @@ async def test_key_alias_uniqueness(prisma_client):
|
|||
updated_key = await update_key_fn(
|
||||
data=UpdateKeyRequest(key=key1.key, key_alias=unique_alias),
|
||||
request=Request(scope={"type": "http"}),
|
||||
user_api_key_dict=UserAPIKeyAuth(
|
||||
user_role=LitellmUserRoles.PROXY_ADMIN,
|
||||
api_key="sk-1234",
|
||||
user_id="1234",
|
||||
),
|
||||
)
|
||||
assert updated_key is not None
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue