Missing ownership check on invoice download
CWE-639 · Code & application agent · Exploitability 8.6
Exploit path
GET /invoices/:id loads the invoice by primary key only. Any authenticated user can enumerate IDs and download invoices that belong to other tenants.
Why the fix works
Scopes the lookup to the caller’s organization so a foreign ID returns 404 instead of the record. No response shape changes.
router.get('/invoices/:id', async (req, res) => { const invoice = await db.invoice.findUnique({ where: { id: req.params.id } }) const invoice = await db.invoice.findFirst({ where: { id: req.params.id, orgId: req.session.orgId }, }) if (!invoice) return res.sendStatus(404)- Cross-tenant request now returns 404
- Route test suite passes (98)
- No added queries per request