IDOR and broken object-level authorization: ids without an owner check

How changing an id in a URL or API body returns someone else’s record, why it tops the OWASP API list, how to test it with two accounts you own, and the ownership-scoped query that fixes it.

Lesson 20 of 69 · 13 min read · practice only with authorization

Diagram

Two accounts, one id

Follow the path. One example at a time.

Step 1 of 4

Account A

Signed in as user A, open invoice 1042.

Illustration: Account A
GET /api/invoices/1042   (session: A)  -> 200 {"owner":"A", ...}

The example on the open step is one illustration, or the fix you can paste into an application you own.

What this page is made of

3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.

  1. Every object route

    What fails
    Reads, updates, deletes, exports, and nested routes each need the check.
    Who is affected
    Every customer whose ids can be guessed or enumerated.
    What you would notice
    Routes that take an id and never mention the current user.
    What you change
    Scope queries by owner or tenant in one shared data-access layer.
  2. Unguessable is not authorized

    What fails
    UUIDs make guessing harder but ids leak through links, logs, and shares.
    Who is affected
    The same customers, once an id leaks.
    What you would notice
    Relying on UUIDs as the access control.
    What you change
    Keep the ownership check even with random ids.
  3. Test with two accounts

    What fails
    You need two identities you control to prove cross-account access.
    Who is affected
    Test accounts only, during the test.
    What you would notice
    Findings reported from one account guessing ids.
    What you change
    Create two test accounts and swap ids between them.

A two-account test

In your proxy, record every request user A makes that carries an id. Replay each with user B’s session. Any response other than 404 or 403 containing A’s data is a finding. Burp extensions such as Autorize and ZAP’s access control testing automate this swap within scope.

  • Path ids: /invoices/1042
  • Query and body ids: ?account=, {"user_id":}
  • Nested: /projects/7/files/33
  • Batch: ?ids=1,2,3
  • Exports and downloads

Review walkthrough

For each handler, find the query that loads the object and check whether the current user or tenant is part of it. A check after loading is fragile; a scoped query is not. Look for admin helpers reused in customer routes.

$ rg -n "objects.get\(id=|findById\(|WHERE id = \$1\b" src/api | head
src/api/invoices.py:41:  inv = Invoice.objects.get(id=pk)        <- no tenant
src/api/files.py:18:     f = File.objects.get(id=pk, project__members=request.user)  ok

Related pages

IDOR in exports and batches, and IDOR on nested objects, cover the two variants reviewers miss most.

Check yourself

Recognition and the fix. Nothing here is a procedure.

1 / 3

User B’s session retrieves user A’s invoice by id. What is missing?

Go deeper

Specific techniques, exercises, and glossary cards for this topic.

  1. 01IDOR in exports and batch endpointsA list of ids is still a list of objects. Includes the diagram and a defensive fix.
  2. 02Nested object authorizationA check on the parent record does not authorize every child id inside the request. Includes the diagram and a defensive fix.
  3. 03Broken function-level authorization: admin actions any user can callWhy hiding an admin menu does not protect the admin endpoint, how to map routes against roles from an OpenAPI file, and how central authorization policies with deny-by-default tests close the gap. Includes the diagram and a defensive fix.
  4. 04Mass assignment: when request bodies write fields they should notHow binding a whole JSON body to a model lets callers set roles, prices, or owners, how to spot it in Rails, Django, Express, and Spring code, and why explicit write schemas are the fix. Includes the diagram and a defensive fix.

Exercises

  1. 01Terminal lab: API traceA scoped host. Read the invoice request and name why one account received another tenant’s record.
  2. 02Tenant deskTwo companies, one API. Turn the ownership check on and off and watch who can open a record.
  3. 03Control benchOne drill is an invoice id with no ownership check. Choose the control that checks the caller.
  4. 04Request replay authorization diffReplay each API request with a second user’s session and compare the responses line by line to find the endpoints that skip an ownership or role check.
  5. 05STRIDE threat model boardSort twelve threat cards for a clinic booking system into STRIDE categories, then map them to fixes and decide which one gets fixed first.
  6. 06Terminal mission: A session cookie anyone can editThe admin export was downloaded by an account that is not an admin. Decode the session cookies the proxy logged and find who changed their role and how.

Glossary

  1. 01Insecure direct object referenceChanging an identifier in a request returns or edits another user's object because the server never checks ownership.
  2. 02Mass assignmentA client sends extra fields, such as a role or price, and the server writes them because it binds the whole object.
  3. 03Broken function level authorizationAn administrative endpoint is hidden in the UI but still accepts calls from a normal account.