Enforce UTF-8 JSON and accept decimal limits with leading zeros
This commit is contained in:
+5
-2
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user