Nexus Void Research
IDOR, BOLA, Broken Access Control, Authorization, CWE-639, OWASP API Security, Row-Level Security, How-to
How to Prevent IDOR Vulnerabilities (With Code Examples)
How to prevent IDOR: scope every query by owner or tenant, centralise authorization, deny by default, check writes, and test by swapping IDs.
To prevent IDOR (insecure direct object reference) vulnerabilities, check on the server, for every request, that the logged-in user is allowed to access the specific record they asked for. The simplest reliable pattern is to scope every query by the owner or tenant (WHERE id = ? AND user_id = ?), deny by default, centralise the check instead of repeating it per route, and test by swapping IDs between two accounts.
IDOR happens when an application uses an identifier from the request, such as /invoices/1042, to fetch a record without checking that the caller owns it. Change the number and you see someone else's invoice. MITRE tracks it as CWE-639: Authorization Bypass Through User-Controlled Key, and the OWASP API Security Top 10 ranks the same flaw, Broken Object Level Authorization, as the number one API risk. It is also the bug that scanners miss most often, because the code looks perfectly normal. Authentication and authorization weaknesses are also among the most exploited in the wild: improper authentication (CWE-287) and missing authentication (CWE-306) were two of the most common weakness types in CISA's 2026 Known Exploited Vulnerabilities additions, as our 2026 vulnerability statistics show.
What does an IDOR vulnerability look like?
Here is a typical vulnerable Express route:
The route checks that someone is logged in (authentication) but never checks that this user owns invoice :id (authorization). IDOR shows up anywhere an ID comes from the client:
Path parameters:
/users/58/settingsQuery strings:
?account_id=58Request bodies:
{"orderId": 58, "status": "refunded"}Headers and cookies that carry an account or tenant ID
File names and download links:
/files/report-58.pdfGraphQL arguments and IDs nested inside mutations
Step 1: Scope every query by owner or tenant
The most reliable fix is to make the database query itself impossible to misuse, by including the owner in the lookup:
The same idea in other frameworks:
In multi-tenant apps, scope by organisation as well as user, and apply it to updates and deletes, not just reads. A missing check on PATCH or DELETE is worse than on GET.
Step 2: Enforce it in the database where you can
Row-level security moves the check below the application, so a forgotten WHERE clause cannot leak data. In PostgreSQL (and Supabase, which is built on it):
auth.uid() is Supabase's helper; in plain PostgreSQL you set the current user in a session variable and compare against that. Row-level security is a second layer, not a replacement for application checks.
Step 3: Centralise authorization and deny by default
Checks scattered across hundreds of handlers are how one gets forgotten. Put the decision in one place:
Every handler then calls one function, or a middleware or policy layer does it for them. Authorization libraries and policy engines (CASL, Pundit, Django Guardian, Open Policy Agent) give you the same pattern with less custom code. The OWASP Authorization Cheat Sheet recommends exactly this: deny by default, check on every request, and keep the logic in one place.
Step 4: Do not rely on hard-to-guess IDs
Switching from sequential IDs (1042) to UUIDs makes IDs harder to guess, which slows down enumeration. It is not a fix. IDs leak through URLs, logs, emails, shared links, referrer headers and API responses that list related records. Use random IDs as an extra layer, and still check ownership on every request.
Step 5: Check writes, not just reads
IDOR in a write is often the more damaging version:
Updates: can a user change the
orderIdin a request body to modify someone else's order?Nested objects: can a user attach their comment to another user's private document by changing
documentId?Mass assignment: can a user set
ownerId,roleorpriceby adding the field to the request? Allow-list the fields each endpoint accepts.Bulk endpoints: does
POST /invoices/bulk-deletecheck every ID in the list, or only the first?
Step 6: Return the same response for missing and forbidden
If /invoices/1042 returns 403 Forbidden for someone else's invoice and 404 Not Found for one that does not exist, an attacker can map which IDs are real. Returning 404 in both cases, as the scoped query in step 1 does naturally, avoids leaking that.
Step 7: Test for IDOR on every endpoint
IDOR is easy to test once you build it into your process:
Create two accounts, A and B, in the same and in different organisations.
As A, record the IDs of every object A creates.
As B, request each of A's IDs on every read, update and delete endpoint. Every one should fail.
Automate it with integration tests that log in as one user and request another user's resources.
Manual testing tools can replay every request with a second user's session to spot authorization gaps quickly. Add IDOR checks to your security code review for every new route that takes an ID.
IDOR prevention checklist
Check | Done when |
|---|---|
Every lookup by ID includes the owner or tenant | No query fetches a user-owned record by ID alone |
Writes and deletes are scoped | Update and delete queries include the owner |
Authorization is centralised | One function or policy layer decides access |
Default is deny | Unknown roles or missing data return no access |
Request bodies are allow-listed | Users cannot set owner, role or price fields |
Responses do not reveal existence | Forbidden and missing both return 404 |
Cross-user tests exist | Integration tests try another user's IDs |
IDOR is one form of a wider problem; see how to fix broken access control for function-level and privilege-escalation checks.
How does ARGUS find IDOR vulnerabilities?
Rule-based scanners rarely catch IDOR, because a missing ownership check has no fixed pattern. ARGUS adds AI passes that look for exactly this class of bug.
A business logic pass looks for IDOR, privilege escalation, authentication bypass and broken sequences in Python, JavaScript, TypeScript and Ruby code.
Every AI finding is challenged by independent verifiers that try to refute it, and unsupported findings are dropped, so you are not handed a list of guesses. The finding shows the AI's reasoning and the attack scenario.
API inventory lists the HTTP routes your code defines and marks each one Authenticated, Open or Not determined, so unprotected routes stand out.
Pull request review can run an AI security pass that looks for authorization gaps on the lines that changed, before they merge.
Fix pull requests: click Assign to Agent and ARGUS writes the fix, verifies it with a build and a re-scan, and opens a pull request for you to review and merge.
Limits: the AI passes run when AI scanning is enabled, and the business logic pass covers Python, JavaScript, TypeScript and Ruby. No scanner proves the absence of IDOR, so keep cross-user tests. See ARGUS SAST, or scan a repository free.
Frequently asked questions
What is an IDOR vulnerability?
IDOR, or insecure direct object reference, is a bug where an application uses an ID supplied by the user, such as an invoice number in the URL, to fetch or change a record without checking that the user is allowed to access it. Changing the ID exposes or modifies other users' data.
How do you prevent IDOR?
Check authorization on the server for every request that references an object. Scope database queries by owner or tenant, for example WHERE id = ? AND user_id = ?, centralise the access decision, deny by default, apply the same checks to updates and deletes, and test by requesting one user's IDs as another user.
Does using UUIDs prevent IDOR?
No. Random IDs make guessing harder but do not stop access to an ID that leaks through a URL, email, log or API response. They are a useful extra layer, but every request must still check that the caller is authorized to access that specific object.
What is the difference between IDOR and BOLA?
They describe the same flaw. IDOR is the older web-application term; Broken Object Level Authorization (BOLA) is the name used in the OWASP API Security Top 10, where it ranks first. Both mean a missing check that the caller may access the specific object they requested.
How do you test for IDOR?
Create two user accounts, record the object IDs one user creates, then request those IDs as the other user on every read, update and delete endpoint. Every request should fail. Turn these into automated integration tests so new endpoints are covered as they are added.
Why don't scanners find IDOR vulnerabilities?
Because the vulnerable code looks normal. A query that fetches a record by ID is correct code; the bug is a missing ownership check that depends on business rules a pattern matcher cannot know. Finding IDOR needs logic-aware analysis, manual review or cross-user testing.
Should an unauthorized request return 403 or 404?
For objects owned by other users, returning 404 is usually safer, because a 403 confirms the object exists and lets attackers map valid IDs. A scoped query that simply finds nothing for the wrong user returns 404 naturally.
Can row-level security prevent IDOR?
Yes, as a second layer. PostgreSQL row-level security, used by Supabase, filters rows by the current user at the database level, so a forgotten check in application code cannot return another user's rows. Keep application checks too, and test that the policies cover inserts, updates and deletes.
DATA SOURCES
CWE-639: https://cwe.mitre.org/data/definitions/639.html ; OWASP Authorization Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html ; OWASP API Security Top 10