feat: Add request validation middleware to enforce security and data integrity checks on items_per_page limitation

main^2
MrWaradana 2 weeks ago
parent 18df242c6b
commit 7a4050ee4a

@ -158,11 +158,20 @@ class RequestValidationMiddleware(BaseHTTPMiddleware):
try:
size_val = int(value)
if size_val > 50:
raise HTTPException(status_code=400, detail=f"Pagination size '{key}' cannot exceed 50")
raise HTTPException(
status_code=400,
detail=f"Pagination size '{key}' cannot exceed 50",
)
if size_val % 5 != 0:
raise HTTPException(status_code=400, detail=f"Pagination size '{key}' must be a multiple of 5")
raise HTTPException(
status_code=400,
detail=f"Pagination size '{key}' must be a multiple of 5",
)
except ValueError:
raise HTTPException(status_code=400, detail=f"Pagination size '{key}' must be an integer")
raise HTTPException(
status_code=400,
detail=f"Pagination size '{key}' must be an integer",
)
# -------------------------
# 4. Content-Type sanity

Loading…
Cancel
Save