#0103
A billing service exposes a GET /invoices/:id endpoint. Clients pass their user ID alongside the invoice ID they wish to retrieve.
The handler fetches the invoice by ID and returns it immediately — no ownership check is performed.
Any authenticated user can download any invoice by guessing or enumerating IDs, leaking order amounts, itemised products, and billing addresses of other customers.
Financial documents are high-value targets. A single missing ownership check on an invoice endpoint can expose transaction history, pricing data, and shipping addresses of every customer.
getInvoice so it checks that the invoice's ownerId matches the requestingUserId.'Forbidden' when the requester does not own the invoice.'Not found' when the invoice does not exist.getInvoice('alice', 'inv-bob-1', db)// inv-bob-1 belongs to bob// → throws Error('Forbidden')
getInvoice('bob', 'inv-bob-1', db)// → returns { id: 'inv-bob-1', ownerId: 'bob', ... }
'Forbidden' and 'Not found'.db is a plain in-memory array.