Skip to content

Lesson 8 of 19 · 20m

IDOR and BOLA: Authorization Is a Query, Not a Convention

Object IDs in URLs are guesses that work — why broken object-level authorization tops the OWASP API list, what UUIDs and 403s don't fix, and the scoped-predicate pattern that actually holds.

Your middleware ran, the JWT verified, req.user is set. Then the handler executes SELECT * FROM invoices WHERE id = $1 with req.params.id, and returns whatever comes back. Nothing in that query asked whether the invoice belongs to req.user. That's IDOR — insecure direct object reference — and in the OWASP API Security Top 10 it sits at number one as Broken Object Level Authorization, because it is how real APIs lose real data.

The wrong mental model is that authentication implies authorization. Authentication answered "who is this caller." Nobody yet answered "may this caller touch this object." Those are different questions. The second one has to be asked per object, per request, per code path — including the paths nobody calls from the UI.

UUIDs are unguessable, not unauthorized

The standard response to IDOR is "use UUIDs." It doesn't hold. A UUIDv4 is unguessable — but a UUID that has appeared anywhere is a working key forever. It rides Referer headers to third-party trackers, lands in access logs, sits in screenshots and support tickets, gets pasted into Slack, ships inside "copy this link to share" features. Unguessable is a property of the string. Authorized is a property of a check that either runs or doesn't.

Random IDs are fine — enumerate-resistance is useful defense-in-depth — but the day a link leaks, you learn whether the authorization check existed.

The same trap hides in GraphQL and RPC-style APIs: a global node(id) resolver that decodes a base64 ID and fetches whatever it names is a BOLA dispenser. Relay-style node IDs feel opaque; they're still direct references, and the resolver must authorize before it resolves, not after.

Two axes: horizontal and vertical

Horizontal IDOR is the famous one: same role, someone else's row. /api/tickets/881 → /api/tickets/880. Vertical is quieter: mass assignment and parameter pollution that change what you are. User.update(req.body) is how {"role": "admin"} or {"org_id": 7} lands in a user row. Rails learned this the hard way — attr_accessible, then strong_parameters, exist because frameworks kept trusting request bodies. The fix everywhere is the same: an explicit allowlist of writable fields, and the request body never reaches the persistence layer raw.

The receipts

  • First American Financial, May 2019: roughly 885 million title and escrow documents reachable by incrementing a document ID in the URL — no authentication on the endpoint at all.
  • Parler, January 2021: a public API with sequential post IDs and no object-level checks. Scrapers pulled about 70TB, including posts the platform had flagged as deleted but never actually removed.
  • USPS Informed Delivery, 2018: the API honored arbitrary account lookups; around 60 million users' data was exposed before the fix shipped.

None of these were exotic. An integer and a missing WHERE clause.

The check that actually holds

Put the authorization question in one place, then make it impossible to skip. A shared requireAuthorizedObject('invoice', req.params.id, req.user) that loads the row scoped to the caller: WHERE id = $1 AND org_id = $2. Authorization inside the predicate means a forgotten check returns nothing instead of something. In Postgres you can go lower — row-level security with CREATE POLICY ... USING (org_id = current_setting('app.org_id')) enforces it beneath the ORM, where a buggy handler can't bypass it.

On 404 versus 403: return 404 when existence itself is sensitive (don't confirm the row exists), 403 when the UI needs to render a useful denial. Either beats 200.

The test that can't regress is mechanical: seed two users in CI, and for every route that takes an ID, assert GET /thing/<other-user's-id> does not return the row. Write it once per route, forever. Every future IDOR becomes a failed build instead of a breach report.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.