Enforce UTF-8 JSON and accept decimal limits with leading zeros

This commit is contained in:
2026-11-07 08:46:57 +03:00
parent a38c889df2
commit 5e7c93a036
3 changed files with 41 additions and 2 deletions
+5 -2
View File
@@ -42,7 +42,7 @@ async def body(request: Request, model: type[Input]) -> Input:
data = await request.body()
return model.model_validate(
json.loads(
data,
data.decode("utf-8"),
parse_constant=lambda _: (_ for _ in ()).throw(ValueError()),
)
)
@@ -56,7 +56,10 @@ def pagination(request: Request) -> tuple[int, str | None]:
if len(limits) > 1 or len(cursors) > 1:
raise invalid()
raw = limits[0] if limits else "50"
if not raw.isascii() or not raw.isdecimal() or len(raw) > 3:
if not raw.isascii() or not raw.isdecimal():
raise invalid()
raw = raw.lstrip("0") or "0"
if len(raw) > 3:
raise invalid()
limit = int(raw)
if not 1 <= limit <= 100: