-
Notifications
You must be signed in to change notification settings - Fork 1
fix(security): prevent NaN and negative pagination values in API routes #32
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,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 rawLimit = parseInt(searchParams.get('limit') || '10') | ||
| const limit = isNaN(rawLimit) || rawLimit < 1 ? 10 : Math.min(rawLimit, 100) | ||
|
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 🐛 Bug: The previous Fix: Explicitly checking |
||
| const rawOffset = parseInt(searchParams.get('offset') || '0') | ||
| const offset = isNaN(rawOffset) || rawOffset < 0 ? 0 : rawOffset | ||
| 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
🐛 Bugs: The previous
parseIntcould result inNaNif thelimitparameter was not a valid number (e.g.,limit=abc), which would then propagate toMath.min(NaN, 100)resulting inNaN. This change correctly handlesNaNvalues and enforces a minimum limit of 1, improving robustness and preventing invalid database queries. This is a good improvement.