fix(security): sanitize error logging and remove Zod schema details from responses

- Stripe webhook: log only error.message instead of full error objects
  to avoid exposing stack traces in aggregated logs
- Admin products POST: return only first Zod error message instead of
  the full error array which reveals internal schema structure
This commit is contained in:
2026-05-19 10:11:40 +02:00
parent 8cf038443f
commit 5654964d09
2 changed files with 6 additions and 6 deletions
+3 -3
View File
@@ -16,8 +16,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 search = searchParams.get('search')
const status = searchParams.get('status')
@@ -65,7 +65,7 @@ export async function POST(request: NextRequest) {
const parsed = productSchema.safeParse(body)
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.errors[0]?.message || 'Invalid input', details: parsed.error.errors },
{ error: parsed.error.errors[0]?.message ?? 'Invalid input' },
{ status: 400 }
)
}
+3 -3
View File
@@ -16,7 +16,7 @@ export async function POST(request: NextRequest) {
try {
event = constructWebhookEvent(body, signature, process.env.STRIPE_WEBHOOK_SECRET!)
} catch (err) {
console.error('Webhook signature verification failed:', err)
console.error('Webhook signature verification failed:', err instanceof Error ? err.message : String(err))
return NextResponse.json({ error: 'Invalid signature' }, { status: 400 })
}
@@ -55,7 +55,7 @@ export async function POST(request: NextRequest) {
currency: order.currency,
})
} catch (emailErr) {
console.error('Failed to send confirmation email:', emailErr)
console.error('Failed to send confirmation email:', emailErr instanceof Error ? emailErr.message : String(emailErr))
}
}
@@ -116,7 +116,7 @@ export async function POST(request: NextRequest) {
console.log(`Unhandled event type: ${event.type}`)
}
} catch (err) {
console.error('Error processing webhook:', err)
console.error('Error processing webhook:', err instanceof Error ? err.message : String(err))
return NextResponse.json({ error: 'Webhook processing failed' }, { status: 500 })
}