Description
Multiple list endpoints parse pagination with parseInt(...) and guard with value < 1. Because parseInt("abc") is NaN and NaN < 1 is false, invalid values slip past validation and are passed to Prisma skip/take, which throws and returns a generic 500. There is also no upper bound on limit, allowing unbounded page sizes.
More info
- File:
app/app/api/posts/route.ts (GET, approx. lines 218-219)
- File:
app/app/api/posts/[id]/entries/route.ts (approx. lines 306-307)
- File:
app/app/api/posts/[id]/comments/route.ts (approx. lines 15-17)
- Files:
app/app/api/users/[id]/followers/route.ts, app/app/api/users/[id]/following/route.ts
- Parse with
Number(...) || default, guard Number.isNaN, and clamp to [1, MAX].
- Add a test sending
?page=abc&limit=-5 and asserting a sane default response (not 500).
Description
Multiple list endpoints parse pagination with
parseInt(...)and guard withvalue < 1. BecauseparseInt("abc")isNaNandNaN < 1isfalse, invalid values slip past validation and are passed to Prismaskip/take, which throws and returns a generic 500. There is also no upper bound onlimit, allowing unbounded page sizes.More info
app/app/api/posts/route.ts(GET, approx. lines 218-219)app/app/api/posts/[id]/entries/route.ts(approx. lines 306-307)app/app/api/posts/[id]/comments/route.ts(approx. lines 15-17)app/app/api/users/[id]/followers/route.ts,app/app/api/users/[id]/following/route.tsNumber(...) || default, guardNumber.isNaN, and clamp to[1, MAX].?page=abc&limit=-5and asserting a sane default response (not 500).