fix(security): sanitize pagination parameters to prevent DB errors#34
fix(security): sanitize pagination parameters to prevent DB errors#34Shreyassp002 wants to merge 1 commit into
Conversation
Sanitize `limit` and `offset` in paginated API endpoints using `parseInt` with base 10 and fallback values. This prevents Supabase errors when these parameters evaluate to `NaN` or negative numbers. Addressed endpoints: - `src/app/api/transactions/history/route.ts` - `src/app/api/transactions/route.ts` - `src/app/api/v1/payment-links/route.ts` - `src/app/api/v1/transactions/route.ts` Co-authored-by: Shreyassp002 <96625037+Shreyassp002@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
⚡ Flash Review
🚨 Critical (must fix before merge)
|
| const { searchParams } = new URL(req.url) | ||
| const limit = Math.min(parseInt(searchParams.get('limit') || '10'), 100) | ||
| const offset = parseInt(searchParams.get('offset') || '0') | ||
| let parsedLimit = parseInt(searchParams.get('limit') || '10', 10) |
There was a problem hiding this comment.
⚡ Flash Review
🚨 Security: Critical input validation for limit. Without this check, non-numeric or negative values could result in NaN or invalid numbers being passed to the database, potentially causing query errors, unexpected data exposure, or even denial of service if the database layer handles invalid parameters poorly. Always sanitize and validate API inputs.
| if (isNaN(parsedLimit) || parsedLimit < 1) parsedLimit = 10 | ||
| const limit = Math.min(parsedLimit, 100) | ||
|
|
||
| let offset = parseInt(searchParams.get('offset') || '0', 10) |
There was a problem hiding this comment.
⚡ Flash Review
🚨 Security: Essential input validation for offset. Allowing NaN or negative values to reach the database could lead to query failures, incorrect data retrieval, or expose internal errors. Robust validation of all API query parameters is crucial for security and stability.
| const limit = Math.min(parseInt(searchParams.get('limit') || '10'), 100) | ||
| const offset = parseInt(searchParams.get('offset') || '0') | ||
| let parsedLimit = parseInt(searchParams.get('limit') || '10', 10) | ||
| if (isNaN(parsedLimit) || parsedLimit < 1) parsedLimit = 10 |
There was a problem hiding this comment.
⚡ Flash Review
🚨 Security: This explicit validation for parsedLimit is a critical improvement. It prevents NaN or values less than 1 from propagating to downstream database queries, significantly enhancing the API's robustness against malformed requests and potential service instability.
Suggestion: For comprehensive and consistent validation across all API routes, consider defining a Zod schema for all incoming query parameters.
| const limit = Math.min(parsedLimit, 100) | ||
|
|
||
| let offset = parseInt(searchParams.get('offset') || '0', 10) | ||
| if (isNaN(offset) || offset < 0) offset = 0 |
There was a problem hiding this comment.
⚡ Flash Review
🚨 Security: This explicit validation for offset is a critical improvement. It prevents NaN or negative values from propagating to downstream database queries, significantly enhancing the API's robustness against malformed requests and potential service instability.
Suggestion: For comprehensive and consistent validation across all API routes, consider defining a Zod schema for all incoming query parameters.
|
Closing as duplicate of #31 which has been merged. |
Understood. Acknowledging that this work is now obsolete and stopping work on this task. |
Category: Security
Priority: P1
What: Updated
limitandoffsetparsing logic across 4 transaction and payment-link API routes.parseIntnow explicitly uses base 10 and explicitly handlesNaNand negative values by falling back to safe defaults before applying theMath.min()limit constraint.Why: If an API client queries
?limit=not-a-numberor?offset=-10,parseIntwould returnNaNor a negative value respectively. This gets passed into Supabase.range()or.limit(), causing the database query to fail or throw unhandled promise rejections, resulting in 500 API errors and breaking functionality.Impact: Paginated API endpoints are now robust against malformed input parameters, ensuring they return safe fallback defaults instead of database errors.
Verification:
npm run lintsuccessfully.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=dummy npm run buildsuccessfully.PR created automatically by Jules for task 7051721128769812940 started by @Shreyassp002