HIGHBroken authorization on invoice download
routes/invoice.ts:47VULK-1042CWE-639
Nothing scopes the lookup to the caller's organisation, and requireAuth only proves they are signed in. Any signed-in user can read another org's invoice by changing the number in the URL.
Suggested change
| Line before | Line after | Change | Source |
|---|---|---|---|
| @@ -45,7 +45,11 @@ router.get('/invoices/:id/download') | |||
| 45 | 45 | router.get('/invoices/:id/download', requireAuth, async (req, res) => { | |
| 46 | Removed line. const invoice = await db.invoice.findUnique({ | ||
| 47 | Removed line. where: {id: req.params.id}, | ||
| 46 | Added line. const invoice = await db.invoice.findFirst({ | ||
| 47 | Added line. where: {id: req.params.id, orgId: req.org.id}, | ||
| 48 | 48 | }); | |
| 49 | 49 | ||
| 50 | Added line. if (!invoice) { | ||
| 51 | Added line. return res.status(404).send('not found'); | ||
| 52 | Added line. } | ||
| 53 | Added line. | ||
| 50 | 54 | return res.download(invoice.path); | |
| 51 | 55 | }); | |
vulkro scan · exit 1 · 1 high, 0 criticalRan on your runner. The code never left it.
