-
Notifications
You must be signed in to change notification settings - Fork 1
fix(security): sanitize API pagination parameters #31
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 |
|---|---|---|
|
|
@@ -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') | ||
|
|
||
| const rawLimit = parseInt(searchParams.get('limit') || '10') | ||
| const limit = isNaN(rawLimit) || rawLimit < 1 ? 10 : Math.min(rawLimit, 100) | ||
|
|
||
| const rawOffset = parseInt(searchParams.get('offset') || '0') | ||
| const offset = isNaN(rawOffset) || rawOffset < 0 ? 0 : rawOffset | ||
|
|
||
|
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 added validation for the |
||
| 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: While the manual parsing and clamping of the
limitparameter is an improvement, for critical API routes handling real money, all user-provided query parameters should be validated using a robust schema library like Zod. This ensures comprehensive type safety, consistency, and better error handling for invalid inputs, preventing potential edge-case vulnerabilities.Fix: Define a Zod schema for the query parameters and parse them, e.g.,
z.object({ limit: z.coerce.number().int().min(1).max(100).default(50) }).