An IDOR — insecure direct object reference — is when an application takes an identifier straight from the user's request and uses it to fetch a record without checking the user is entitled to it. Change /invoice/1041 to /invoice/1042 and you are reading somebody else's invoice. No exploit, no tooling, no skill required.
Why IDOR still matters
It is the least glamorous bug in web security and routinely the most expensive. There is no payload to craft and no filter to bypass, so there is nothing for a web application firewall to recognise — the request is perfectly well formed and indistinguishable from legitimate traffic. The only difference is who is making it.
That property makes IDOR particularly bad in three ways. It scales: a short script can walk the full ID range and pull every record in the table. It is silent: the application logs a series of ordinary successful requests. And it is total: a single unprotected endpoint on a customer portal can expose every customer, not one.
What an IDOR actually looks like
The classic case is a sequential integer in a path:
GET /api/v1/invoices/1041
Authorization: Bearer <valid token for user A>
The server decodes the token, confirms the session is valid, loads invoice 1041 and returns it. Authentication passed. Authorization never happened. The application confirmed who you are and forgot to ask whether this is yours.
The identifier is not always in the path. In real assessments it turns up in all of these:
- Query strings —
?account=8812&format=pdf - JSON bodies —
{"userId": 400, "newEmail": "..."}on a profile-update endpoint - Hidden form fields — a
team_idthat the UI never lets you change - Cookies — a
tenantcookie read without validation - Headers —
X-Customer-Id, common in internal APIs that were later exposed - Filenames —
/reports/download?file=2026-Q3-acme.pdf - Batch parameters — an export endpoint that accepts
ids=[1,2,3]and validates only the first
The four variants worth knowing
Horizontal. You access another user's data at your own privilege level. Reading their invoice, their messages, their uploaded documents. The most common form.
Vertical. The reference reaches an object that belongs to a higher privilege level — opening an admin-only report by its ID even though the admin menu is hidden from you.
Write-side. Far more damaging than read-side and tested far less. The same missing check on PUT, PATCH or DELETE lets you modify or destroy records you do not own. A read-only IDOR is a breach; a write IDOR is a breach plus data integrity loss, and the victim usually finds out first.
Blind. The response gives nothing away — a generic 200 OK or an empty body — but the action still happened. Confirm it through a side channel: response timing, a record count elsewhere, an email the application sends, or simply logging in as the victim and looking.
How to test for it properly
IDOR testing needs two accounts and discipline. Automated scanners miss it almost entirely, because a scanner has no concept of ownership — it cannot know that order 1041 belongs to a different tenant. This is why IDOR dominates the findings list in manual testing and barely appears in scan reports. We cover the wider method in how to write a penetration test report.
- Register two accounts in the same role, A and B. If the application is multi-tenant, put them in different tenants.
- Exercise the whole application as A with an intercepting proxy recording. Create records, upload files, generate reports, invite colleagues.
- Catalogue every identifier that appears anywhere in a request. Build a list.
- Replay each request with B's session and A's identifiers. Swap only the session; change nothing else.
- Check all methods. An endpoint that correctly refuses
GETmay happily acceptDELETE. Teams implement the check in a controller action, not a policy, and only remember the one they were thinking about. - Try the unauthenticated case. Drop the session entirely. Export and print endpoints are regular offenders.
Then look past the obvious. Older API versions often survive at /api/v1/ after /v2/ gains proper checks. GraphQL nodes can be fetched by global ID while the equivalent REST route is locked down — see GraphQL security testing. Webhooks, CSV exports, PDF renderers and "email me this report" features are built by different people on a different deadline, and the authorization check rarely makes the trip.
The only fix that holds
Every genuine fix is the same sentence: check ownership on the server, on every request, as close to the data as you can get.
// Wrong — authenticated but not authorized
$invoice = Invoice::find($request->id);
// Right — the user's identity is part of the query
$invoice = Invoice::where('id', $request->id)
->where('tenant_id', $user->tenant_id)
->firstOrFail();
Scoping the query to the actor is better than fetching and then comparing, because it fails closed. A developer who forgets the if ships a vulnerability; a developer who forgets the scope gets an empty result and notices in testing.
Beyond that:
- Centralise the decision. Policy objects, middleware or a dedicated authorization service. Checks scattered through controllers are checks that will be missed in the next sprint.
- Default deny. A new endpoint should be unreachable until someone writes a rule for it. Opt-in security survives staff turnover; opt-out does not.
- Do not rely on unguessable IDs alone. UUIDs raise the cost of discovery and nothing else. IDs leak through shared links, browser history, referrer headers, support tickets and log aggregators.
- Write the regression test. For every ownership rule, a test where B requests A's object and expects a 404. This is the single highest-value security test a team can own, and it runs in milliseconds.
- Return 404, not 403. A 403 confirms the record exists, which hands an attacker a working enumeration oracle.
Where teams go wrong
Three patterns account for most of what we find in the field.
Checking in the UI. The button is hidden, so nobody can press it. The endpoint behind the button answers anyone. Browsers are not an access control layer.
Checking once at the edge. A gateway validates the token and every downstream service trusts whatever ID arrives. One service that accepts an internal header without verification undoes the whole design.
Trusting an ID the client supplied about itself. A profile-update endpoint that accepts userId in the body rather than reading it from the session is an account-takeover primitive, not a bug. The user's own identity must never be a request parameter.
Where to go next
IDOR sits inside the wider category covered in broken access control explained, and it is the most frequently found item in the API Security Top 10, where it is listed as Broken Object Level Authorization. If you want the authoritative definitions, the OWASP Top 10 is the reference every tester and auditor works from. For the build-side view, secure code review basics covers how to spot the missing scope during review rather than after release.
If you want this checked properly on your own application, our web application penetration testing engagements use exactly the two-account method described above.
0 comments
Leave a comment