-
Notifications
You must be signed in to change notification settings - Fork 1
fix(security): sanitize pagination parameters to prevent DB errors #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,8 +183,12 @@ export async function GET(req: NextRequest) { | |
| } | ||
|
|
||
| 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) | ||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚡ Flash Review 🚨 Security: Essential input validation for |
||
| if (isNaN(offset) || offset < 0) offset = 0 | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const supabase = createServerClient() as any | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,8 +10,13 @@ export async function GET(req: NextRequest) { | |
| } | ||
|
|
||
| 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) | ||
| if (isNaN(parsedLimit) || parsedLimit < 1) parsedLimit = 10 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚡ Flash Review 🚨 Security: This explicit validation for 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚡ Flash Review 🚨 Security: This explicit validation for Suggestion: For comprehensive and consistent validation across all API routes, consider defining a Zod schema for all incoming query parameters. |
||
|
|
||
| const status = searchParams.get('status') | ||
| const paymentLinkId = searchParams.get('payment_link_id') | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚡ Flash Review
🚨 Security: Critical input validation for
limit. Without this check, non-numeric or negative values could result inNaNor 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.