Skip to content

QuizNot attempted

Spot the IDOR

A logged-in user calls GET /api/orders/124, but order 124 belongs to someone else. Which handler is safe?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • const order = await db.getOrder(req.params.id); if (order.userId !== req.user.id) return res.status(403).end();
  • Only the first handler compares the record's owner with req.user.id, the identity from the verified session or token, which the attacker can't forge.
  • Not returning the order because the UI hides others: anyone can call the API directly with any id.
  • Not comparing to req.body.userId: the attacker controls the body and can put the victim's id in it.
  • Not hiding the id or using POST: obscurity and HTTP method aren't access control.