mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-30 01:52:18 +00:00
fix(usage): reject non-finite spend and empty key in page cursors
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
01a5db4194
commit
650dbf49b4
2 changed files with 8 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ import asyncio
|
|||
import base64
|
||||
import binascii
|
||||
import json
|
||||
import math
|
||||
from collections.abc import Awaitable, Callable, Mapping, Sequence
|
||||
from collections.abc import Set as AbstractSet
|
||||
from dataclasses import dataclass
|
||||
|
|
@ -840,9 +841,12 @@ def decode_key_page_cursor(raw: str) -> KeyPageCursor | None:
|
|||
except (ValueError, binascii.Error):
|
||||
return None
|
||||
try:
|
||||
return _KEY_PAGE_CURSOR_ADAPTER.validate_json(decoded)
|
||||
cursor: Final = _KEY_PAGE_CURSOR_ADAPTER.validate_json(decoded)
|
||||
except ValidationError:
|
||||
return None
|
||||
if not math.isfinite(cursor.spend) or cursor.api_key == "":
|
||||
return None
|
||||
return cursor
|
||||
|
||||
|
||||
def _build_aggregated_sql_query(
|
||||
|
|
|
|||
|
|
@ -2888,6 +2888,9 @@ class TestKeyPageCursorCodec:
|
|||
"aGVsbG8=", # valid base64, not json
|
||||
"eyJmb28iOiAxfQ==", # json object missing both fields
|
||||
"eyJzcGVuZCI6ICIxLjUiLCAiYXBpX2tleSI6IDd9", # wrong types
|
||||
"eyJzcGVuZCI6IE5hTiwgImFwaV9rZXkiOiAiayJ9", # {"spend": NaN, "api_key": "k"}
|
||||
"eyJzcGVuZCI6IEluZmluaXR5LCAiYXBpX2tleSI6ICJrIn0=", # {"spend": Infinity, "api_key": "k"}
|
||||
"eyJzcGVuZCI6IDEuMCwgImFwaV9rZXkiOiAiIn0=", # {"spend": 1.0, "api_key": ""}
|
||||
],
|
||||
)
|
||||
def test_malformed_returns_none(self, raw):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue