Course · Applications · 20 / 69
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.
Diagram
Two accounts, one id
Signed in as user A, open invoice 1042.
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
A short map of the pieces. Each piece says what fails, who is affected, what you would notice, and what you change.
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.
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.
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.
- 01IDOR in exports and batch endpointsA list of ids is still a list of objects. Includes the diagram and a defensive fix.
- 02Nested object authorizationA check on the parent record does not authorize every child id inside the request. Includes the diagram and a defensive fix.
- 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.
- 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
- 01Terminal lab: API traceA scoped host. Read the invoice request and name why one account received another tenant’s record.
- 02Tenant deskTwo companies, one API. Turn the ownership check on and off and watch who can open a record.
- 03Control benchOne drill is an invoice id with no ownership check. Choose the control that checks the caller.
- 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.
- 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.
- 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
- 01Insecure direct object referenceChanging an identifier in a request returns or edits another user's object because the server never checks ownership.
- 02Mass assignmentA client sends extra fields, such as a role or price, and the server writes them because it binds the whole object.
- 03Broken function level authorizationAn administrative endpoint is hidden in the UI but still accepts calls from a normal account.