Security Playbook
09 · Web vulnerabilitiesOWASP A01:20257 min read

Broken access control and IDOR: the #1 web risk

Insecure direct object references let users read or change other people's data just by changing an ID. Why it's the most common serious bug in web apps, how to find it and how to fix it for good.

In one sentence

If /api/orders/1042 works for a user who doesn't own order 1042, that's an IDOR. Every query that loads a record by ID must also filter by who's asking.

The idea

The endpoint checks that you're logged in, loads the order with the ID in the URL and returns it. It never asks whether this order belongs to you. Changing 1041 to 1042 shows a stranger's name and address.

IDOR: just change the number in the URL
shop.test/api/orders/
Logged in as Ana (user 7)HTTP 200 · your order
{
  "id": 1041,
  "owner": 7,
  "name": "Ana López",
  "address": "Calle Mayor 12, Madrid",
  "total": "€48.90"
}
Being logged in isn't enough. The server must check that this specific record belongs to this user, on every request. Random IDs make guessing harder but are not a fix.
You're Ana (user 7). Step through order IDs with and without the ownership check.

Shapes it takes

  • Horizontal: user A reads or edits user B's data (orders, messages, invoices, files).
  • Vertical: a normal user calls an admin endpoint (POST /api/admin/refund) that only hides its button in the UI.
  • Mass assignment: PATCH /api/me with { "role": "admin" } because the server saves the whole body.
  • Indirect IDs: the ID is in a hidden field, a GraphQL argument, a file name or an export URL instead of the path.

Fixing it structurally

Vulnerable

  • db.order.findUnique({ where: { id } })
  • Checks login only; trusts the ID
  • Role check only in the React component

Safe

  • db.order.findFirst({ where: { id, userId: session.userId } })
  • Scope every query by owner or tenant
  • Authorization in a server-side policy, reused everywhere
  • Deny by default: a new endpoint without a policy should fail closed.
  • Scope queries, don't check after: filtering by owner in the query can't be forgotten in one branch.
  • Allowlist writable fields to prevent mass assignment (pick(body, ['name', 'avatar'])).
  • Test it: for every endpoint, an automated test that a second user gets 404.

Key takeaways

  • 01IDOR = loading a record by ID without checking the requester may access it.
  • 02Scope every query by owner or tenant on the server.
  • 03Hiding UI isn't access control; check every endpoint, including admin ones.
  • 04Allowlist writable fields and write a second-user test for each endpoint.

Check your understanding

1 of 3

What is an IDOR?

Related concepts