We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Insecure Direct Object References

Putting database identifiers in URLs is normal. It becomes unsafe when the server uses a client-controlled identifier to load an object without checking whether the requester is allowed to access it.

When broken access control involves an object identifier, it's called an Insecure Direct Object Reference (IDOR).

The fix is the same: check permissions on the server before returning any object data. Database IDs are not secrets, so just because an incoming request knows a user's order ID does not mean that user is allowed to see it.

order, found, err := store.FindByID(request.Context(), orderID)
if err != nil {
  return err
}
if !found || order.UserID != current.User.ID {
  respondNotFound(responseWriter)
  return nil
}
respondWithJSON(responseWriter, order)

Another strong pattern is to include ownership directly in the database lookup. You still need to handle a missing result, but an unauthorized order never leaves the database:

SELECT *
FROM orders
WHERE id = ? AND user_id = ?

Assignment

Bearly Secure's order-detail API returns any order to any authenticated user. Fix the IDOR so account users can retrieve only their own orders.

With Bearly Secure still running, run and submit the CLI tests from the project root.