Security Playbook
by Federico Tejedor Llorente
Learn
Learning path
Concepts
Breaches
Practice
Labs
Playground
Quiz
Work with me
🔥 0
⚡ 0
Playbooks
Playbooks
System Design
Security
●
Algorithms
Portfolio
↗
en
English
✓
Español
← All code reviews
Find the bug · 03/10
Easy
Download your invoice
Only logged-in customers can call this endpoint.
app/api/invoices/[id]/route.ts
01 · Tap the vulnerable line
1
export async function GET(req: Request, { params }: RouteContext<"/api/invoices/[id]">) {
2
const session = await auth();
3
if (!session) return new Response("Unauthorized", { status: 401 });
4
const { id } = await params;
5
const invoice = await db.invoice.findUnique({ where: { id } });
6
if (!invoice) return new Response("Not found", { status: 404 });
7
return new Response(await renderPdf(invoice), { headers: { "content-type": "application/pdf" } });
8
}
02 · What's the problem?
SQL injection
Missing ownership check (IDOR)
Path traversal
Token not verified
03 · How do you fix it?
Query with { id, customerId: session.user.id } so other customers' invoices are not found
Switch invoice IDs to UUIDs so they can't be guessed
Hide the download button for invoices that aren't yours
Check answer