-
Notifications
You must be signed in to change notification settings - Fork 1
fix(security): sanitize api pagination parameters #36
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,10 @@ 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 parsedLimit = parseInt(searchParams.get('limit') || '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: The previous logic for Fix: No further fix needed, this change correctly addresses the potential issue. |
||
| const limit = isNaN(parsedLimit) || parsedLimit < 1 ? 10 : Math.min(parsedLimit, 100) | ||
| const parsedOffset = parseInt(searchParams.get('offset') || '0') | ||
| const offset = isNaN(parsedOffset) || parsedOffset < 0 ? 0 : parsedOffset | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const supabase = createServerClient() as any | ||
|
|
||
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
limitparsing logic is improved to handleNaNand negative values, relying on manualparseIntandisNaNchecks for API query parameters can be less robust and consistent than using a dedicated validation library.Fix: Implement a Zod schema to validate all incoming query parameters for this API route, including
payment_link_idandlimit. This ensures consistent, declarative validation, better type safety, and prevents unexpected values from reaching the database.