Skip to content
Closed
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)
let parsedLimit = parseInt(searchParams.get('limit') || '50', 10)
if (isNaN(parsedLimit) || parsedLimit < 1) parsedLimit = 50
const limit = Math.min(parsedLimit, 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)
let parsedLimit = parseInt(searchParams.get('limit') || '50', 10)
if (isNaN(parsedLimit) || parsedLimit < 1) parsedLimit = 50
const limit = Math.min(parsedLimit, 100)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let query = (supabase.from('transactions') as any)
Expand Down
8 changes: 6 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,12 @@ 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')
let parsedLimit = parseInt(searchParams.get('limit') || '10', 10)
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: Critical input validation for limit. Without this check, non-numeric or negative values could result in NaN or invalid numbers being passed to the database, potentially causing query errors, unexpected data exposure, or even denial of service if the database layer handles invalid parameters poorly. Always sanitize and validate API inputs.

if (isNaN(parsedLimit) || parsedLimit < 1) parsedLimit = 10
const limit = Math.min(parsedLimit, 100)

let offset = parseInt(searchParams.get('offset') || '0', 10)
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: Essential input validation for offset. Allowing NaN or negative values to reach the database could lead to query failures, incorrect data retrieval, or expose internal errors. Robust validation of all API query parameters is crucial for security and stability.

if (isNaN(offset) || offset < 0) offset = 0

// 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')
let parsedLimit = parseInt(searchParams.get('limit') || '10', 10)
if (isNaN(parsedLimit) || parsedLimit < 1) parsedLimit = 10
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 explicit validation for parsedLimit is a critical improvement. It prevents NaN or values less than 1 from propagating to downstream database queries, significantly enhancing the API's robustness against malformed requests and potential service instability.

Suggestion: For comprehensive and consistent validation across all API routes, consider defining a Zod schema for all incoming query parameters.

const limit = Math.min(parsedLimit, 100)

let offset = parseInt(searchParams.get('offset') || '0', 10)
if (isNaN(offset) || offset < 0) offset = 0
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 explicit validation for offset is a critical improvement. It prevents NaN or negative values from propagating to downstream database queries, significantly enhancing the API's robustness against malformed requests and potential service instability.

Suggestion: For comprehensive and consistent validation across all API routes, consider defining a Zod schema for all incoming query parameters.


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

Expand Down
Loading