Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/app/api/transactions/history/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export async function GET(req: NextRequest) {

const supabase = createServerClient()
const { searchParams } = new URL(req.url)
const limit = Math.min(parseInt(searchParams.get('limit') || '50'), 100)

const rawLimit = parseInt(searchParams.get('limit') || '50')
Copy link
Copy Markdown

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 limit parameter 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) }).

const limit = isNaN(rawLimit) || rawLimit < 1 ? 50 : Math.min(rawLimit, 100)

// 1. Fetch Sent Transactions (where customer_wallet = walletAddress)
const { data: sentTransactions, error: sentError } = await supabase
Expand Down
4 changes: 3 additions & 1 deletion src/app/api/transactions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export async function GET(req: NextRequest) {
const supabase = createServerClient()
const { searchParams } = new URL(req.url)
const paymentLinkId = searchParams.get('payment_link_id')
const limit = Math.min(parseInt(searchParams.get('limit') || '50'), 100)

const rawLimit = parseInt(searchParams.get('limit') || '50')
const limit = isNaN(rawLimit) || rawLimit < 1 ? 50 : Math.min(rawLimit, 100)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let query = (supabase.from('transactions') as any)
Expand Down
9 changes: 7 additions & 2 deletions src/app/api/v1/payment-links/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,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')

// Parse pagination parameters securely to avoid NaN or negative values
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

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const supabase = createServerClient() as any
Expand Down
9 changes: 7 additions & 2 deletions src/app/api/v1/transactions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flash Review

🚨 Security: This added validation for the limit parameter is crucial. Previously, malformed input (e.g., limit=abc) would result in NaN being passed to downstream logic, potentially leading to unexpected database query behavior or errors. The explicit isNaN and bounds checks now ensure limit is always a valid, positive integer, significantly hardening the API against invalid requests and preventing potential service disruption.

const status = searchParams.get('status')
const paymentLinkId = searchParams.get('payment_link_id')

Expand Down
Loading