fix(security): clamp pagination parameters to prevent negative or overflow values
Replace raw parseInt() with Math.max/min bounds: page >= 1, limit 1-100. Affects public products, admin orders, and admin reviews endpoints.
This commit is contained in:
@@ -13,8 +13,8 @@ export async function GET(request: NextRequest) {
|
||||
if (!user) return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
||||
|
||||
const { searchParams } = new URL(request.url)
|
||||
const page = parseInt(searchParams.get('page') || '1')
|
||||
const limit = parseInt(searchParams.get('limit') || '20')
|
||||
const page = Math.max(1, parseInt(searchParams.get('page') || '1') || 1)
|
||||
const limit = Math.min(100, Math.max(1, parseInt(searchParams.get('limit') || '20') || 20))
|
||||
const status = searchParams.get('status')
|
||||
|
||||
const skip = (page - 1) * limit
|
||||
|
||||
@@ -13,8 +13,8 @@ export async function GET(request: NextRequest) {
|
||||
if (!user) return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
||||
|
||||
const { searchParams } = new URL(request.url)
|
||||
const page = parseInt(searchParams.get('page') || '1')
|
||||
const limit = parseInt(searchParams.get('limit') || '20')
|
||||
const page = Math.max(1, parseInt(searchParams.get('page') || '1') || 1)
|
||||
const limit = Math.min(100, Math.max(1, parseInt(searchParams.get('limit') || '20') || 20))
|
||||
const status = searchParams.get('status')
|
||||
|
||||
const skip = (page - 1) * limit
|
||||
|
||||
@@ -3,8 +3,8 @@ import { prisma } from '@/lib/prisma'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const page = parseInt(searchParams.get('page') || '1')
|
||||
const limit = parseInt(searchParams.get('limit') || '20')
|
||||
const page = Math.max(1, parseInt(searchParams.get('page') || '1') || 1)
|
||||
const limit = Math.min(100, Math.max(1, parseInt(searchParams.get('limit') || '20') || 20))
|
||||
const category = searchParams.get('category')
|
||||
const search = searchParams.get('search')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user