EXAMPLE REPOSITORY / ORDER SERVICE
Add order details endpoint #42
src/services/orders.ts
TypeScript code excerpt, lines 24 to 30. Line 28 looks up an order by ID without checking user ownership.
export async function getOrder( orderId: string, userId: string) { return db.order.findUnique({ where: { id: orderId }, });}An order ID isn’t an ownership check.
This query filters by orderId alone. If the caller can supply another order ID, this endpoint could expose another customer’s order.
userId is accepted at line 25 but never used in the lookup at line 28. Suggested correction
Scope the lookup to the authenticated owner:
db.order.findFirst({
where: { id: orderId, ownerId: userId },
});Get userId from the server session and handle a missing order before returning a response.