fix: reject non-numeric page/limit with 400 instead of 500 - #1458
fix: reject non-numeric page/limit with 400 instead of 500#1458ionfwsrijan wants to merge 1 commit into
Conversation
parseInt('abc') produced NaN which Math.max silently propagated into
.skip(NaN)/.limit(NaN), throwing a Mongoose validation error that the catch
turned into a 500. The route now validates page/limit via a zod schema (400
with a clear message), and the controller defensively coerces so NaN can never
reach Mongo — falling back to page=1/limit=20 and clamping limit to 100.
Closes Canopus-Labs#1445
|
Warning Review limit reached
Next review available in: 54 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Comment |
Problem
GET /api/questions/my-questionswith a non-numericpageorlimit(e.g.?page=abc) returned a 500.parseInt('abc')producesNaN, whichMath.max(1, NaN)silently propagates into.skip(NaN)/.limit(NaN), throwing a Mongoose validation error that the catch turned into an internal-server-error response.Fix
page/limitthrough a zod query schema (validateGetMyQuestions), returning a clean 400Validation failedfor non-numeric, negative, zero, fractional, or oversized (limit > 100) values.Number()+Number.isFinite, soNaNcan never reach Mongo: invalid values fall back topage=1/limit=20andlimitis clamped to 100.Files changed
backend/Input_validators/ValidateQuestions.js—getMyQuestionsQuerySchema+validateGetMyQuestionsmiddleware.backend/routes/questionRoutes.js— wirevalidateGetMyQuestionsontoGET /my-questions.backend/controllers/questionController.js— defensive page/limit coercion.backend/tests/questionController.pageLimit.unit.test.js— route-layer (400s) and controller-layer (coercion, no NaN, clamp) tests.Testing
npx vitest run tests/questionController.pageLimit.unit.test.js— 17/17 passing. Full suite shows no new failures vs. the origin/main baseline.Closes #1445