FRE-5398: Fix invoice endpoint customer IDOR (M-3)

- Make verifyCustomerOwnership public in BillingService
- Add ownership verification before fetching invoice history
- Returns 403 if customerId does not belong to authenticated user

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-05-16 09:57:57 -04:00
parent d6f574ff8e
commit 9f65ebce5d
2 changed files with 11 additions and 1 deletions

View File

@@ -341,6 +341,16 @@ export async function subscriptionRoutes(fastify: FastifyInstance) {
});
}
// Verify the customer belongs to the authenticated user (IDOR prevention)
try {
await billingService.verifyCustomerOwnership(customerId, authReq.user.id);
} catch {
return reply.status(403).send({
error: 'Forbidden',
message: 'You do not have access to this customer',
});
}
try {
const invoices = await billingService.getInvoiceHistory(customerId);

View File

@@ -37,7 +37,7 @@ export class BillingService {
}
}
private async verifyCustomerOwnership(
async verifyCustomerOwnership(
customerId: string,
userId: string
): Promise<void> {