Skip to content
IDORIDOR testingBOLA

Insecure Direct Object Reference: How to Test and Fix It

Insecure Direct Object Reference: How to Test and Fix It

You're looking at a client portal the night before a test window, with two accounts in the notes and a developer who already said the identifiers are random so object access is "handled." The last report cleared a single URL. A new export shipped after that, and a SOC 2 assessor will ask whether anyone replayed a foreign record against it. Incrementing one number in a browser doesn't answer that.

That's the usual starting point for an insecure direct object reference on a multi-tenant app. The caller is logged in, the request looks normal, and the only change is which record the server returns. For a penetration testing team, the work is to prove the per-object check on every path in scope, then keep the proof. A clean result covers those paths only.

Table of Contents

What an Insecure Direct Object Reference Is

Say you check into a hotel. The key card in your hand is cut for room 412, and it should open only the room registered to you. If that same card also opens 413, the lock accepted a valid card and skipped the room check. An application does the same thing when it treats a client-supplied identifier as if it were permission.

An insecure direct object reference happens when the server uses an identifier the user supplied, such as an invoice number, an account ID, or a file name, to fetch a record without checking that the logged-in user may see that specific record. Authentication proves who the caller is. Authorization decides what that caller may touch. This flaw is a failure of the second check, not the first.

The identifier is client-controlled, the server skips the per-object check, and the caller reaches someone else's data.

A hand uses a hotel key card to unlock room 412, conceptually demonstrating insecure direct object reference.

How often testers still find it

In 2024, IDOR accounted for 7% of vulnerabilities reported through HackerOne, according to HackerOne's 7th Annual Hacker-Powered Security Report. That figure is bounty volume, not every production estate, and it's still large enough that a provider should expect the pattern on customer portals.

The name moved. The defect didn't. OWASP's API Security Top 10 records insecure direct object reference as A4 in 2007, a standalone category in the 2010 and 2013 editions, then part of Broken Access Control in 2017. That broader category ranked first in 2021 and again in 2025. On APIs the same flaw is Broken Object Level Authorization (BOLA), listed as API1:2019 and kept at API1:2023, and the 2023 assessment calls it widespread, easy to exploit, and easy to detect.

You separate it from an ordinary access-control miss with those three signs. A missing login wall keeps everyone out or lets everyone in. This bug lets a legitimate user touch a record they don't own.

Where Object References Hide in Your Application

The obvious parameter is rarely the only one. Testers miss keys in request bodies and nested routes more often than they miss the number sitting in the address bar. Walk every location before you pick a payload.

Location Example First test
URL path segment /api/invoices/1042 Request invoice 1043 while still authenticated as the owner of 1042
Query parameter ?acct_id=901 Change the account number to a peer's account
JSON or XML body field customerId in the request body Substitute another customer's ID in the body
Hidden form field or cookie hidden field recordKey Edit the stored key and resubmit
GraphQL argument or node ID node(id: '...') Query a node owned by another tenant
Nested route /users/{id}/orders/{id} Keep the outer user valid and change only the inner order ID

A path segment fails when the handler loads whatever id it was given. A query parameter fails the same way, and it's easy to overlook on a page that "only filters." Body fields fail when a profile update trusts customerId from JSON or XML instead of the session. Hidden fields and cookies fail because people assume the browser won't edit them. GraphQL fails when a resolver returns a node by global id with no owner check. Nested routes fail in a sneakier way. The outer user id is valid for the caller, so the code returns early, and the inner order id is never compared to that user.

Sequential, random, or encoded

The identifier can be a counter, a UUID, or a encoded string. The server-side mistake is identical, because the application trusts the reference it was handed. Opaque values slow blind guessing. They don't decide whether this caller may perform this action on this object. You'll still collect them from places the client already received, which is why guessing isn't the test.

Inventory before the first replay

Build the list from the running app, not from a guess about the routes.

  • JSON the UI hides: open a list or search response and note every id the screen never shows.
  • Mail and notification links: copy the object key from an invoice or share message.
  • Error bodies: force a bad update and see whether the message echoes another record's key.
  • Downloads, cookies, and hidden inputs: treat an export URL like a path parameter.

That inventory is what you test, not the whole internet-facing hostname. If the engagement also needs a repeatable way to exercise REST and GraphQL surfaces, pair the list with an API penetration testing pass so body parameters and nested resources aren't skipped. Don't launch a payload runner until the list exists.

A Worked Attack Example From Start to Finish

A customer signs in to a banking app and opens /accountTransactions?acct_id=901. The page shows their own history. A second customer, already signed in on their own session, changes 901 to 902. The app answers 200 OK and returns the first customer's transactions. Nothing looks like an error.

A hand changes the URL ID on a mobile banking app, illustrating an insecure direct object reference vulnerability.

The session check succeeded. The handler then trusted the account number in the query string. OWASP's Authorization Cheat Sheet classifies insecure direct object reference as CWE-639, "Authorization Bypass Through User-Controlled Key." The application accepts a client-controlled account, order, or user id and retrieves the object without establishing that the authenticated caller may access that specific object. Possession of a valid session isn't that check. The server should derive access from the caller's established identity and permissions.

When the same id becomes a write

Leave the parameter in place and change the verb. A PUT that accepts acct_id=902 can rewrite the other customer's shipping address, and the next read by the account owner shows the attacker's value. A DELETE with the same swap can remove an invoice or mark it deleted. The read is how you notice the hole. The write is how it becomes fraud, chargebacks, or a support queue full of missing records.

Horizontal privilege escalation is one customer reaching another customer's records. That's the likely case when both accounts share a role and only the object id changes. Vertical privilege escalation is a customer reaching administrator functions, and OWASP notes it is less common. You see it when a low-privilege session is allowed to supply an admin object id, or to call an admin action that was only hidden in the interface.

One altered parameter can also walk an entire archive, not a single row. In 2019, First American Financial exposed more than 800 million documents and images, including Social Security numbers and bank-account details, after an application let users change a URL parameter and retrieve documents belonging to other users, as described by SentinelOne. Predictable references turned one successful fetch into systematic access.

For the report, keep four artifacts. The original request. The substituted identifier. The authenticated account that sent the replay. The full response, body included, not only the status line.

The clip below shows that same substitution on a request, so the team can see a normal response carrying another person's data.

How to Run a Two-Account Swap Test

Don't send the first swapped request until the paperwork matches the targets. For each engagement on our autonomous platform or Studio, the customer must confirm and attest that they're authorized to test the specified targets and scope. Written authorization and a defined scope come first. The Service is provided "as is" and "as available," and security testing can't identify every vulnerability. A clean run proves the paths you replayed.

Before the steps, draft an authorization matrix. Rows are endpoints and object types. Columns are role, tenant, object state, and HTTP method. You're about to check coverage against that sheet, not against memory.

  1. Create two accounts in separate tenants, each owning an equivalent object such as an invoice or a project. Separate tenants matter because a same-tenant share can look like a bug when the product intends it.
  2. Map every endpoint that accepts an object identifier from captured traffic. The OWASP API Security Testing guide has you find those endpoints in documentation, traffic, or a proxy such as Burp Suite or ZAP, including paths, bodies, and nested routes. If it isn't mapped, it isn't tested.
  3. Record each request while account A reads its own object. You need a known-good baseline, or a later 200 is meaningless.
  4. Replay that request under account B's session and substitute B's object id, then reverse the roles. OWASP's REST Assessment Cheat Sheet calls this a swap test, and it also says to pull identifiers from list responses, errors, and notification links rather than only guessing the next integer. One direction can pass while the other fails.
  5. Repeat for GET, POST, PUT, PATCH, and DELETE, and for list, export, and batch endpoints. A read can be locked while the update route is open.
  6. Compare status codes, response bodies, side effects, and timing. A 404 that arrives faster for foreign ids, or a body that includes another tenant's field, is still a finding.
  7. Confirm each hit with a second request and save the evidence. A single flaky response won't survive a retest argument.

PortSwigger's IDOR workflow is the practical way to scale step 4. Mark the parameter, feed candidate identifiers into an Intruder-style runner, and compare bodies for another user's data instead of trusting the status line. After the horizontal swaps, replay administrator routes with a low-privilege session. That's the vertical check, and it belongs on the same matrix.

An infographic detailing a five-step process for performing a two-account swap test for cybersecurity vulnerability assessments.

What counts as a hit

Method Object action to test Finding if
GET Read another user's object Response returns foreign data instead of 403 or 404
POST Create an object under another user's parent Object is created under the wrong owner
PUT or PATCH Modify another user's object Changed field persists in the other account
DELETE Remove another user's object Object is deleted or marked deleted
List, export, or batch endpoint Return or modify several objects at once Records from the other tenant appear in the output

Practical rule: If account B's bytes show up in account A's body, you have a finding even when the status is 200 and the UI never offered that id.

A passing cell means that pair, that verb, and that object state were denied or absent. It doesn't mean next month's endpoint is safe. Tick the matrix as you go so the report shows what was in scope and what wasn't.

Fixing IDOR and Why Random IDs Are Not Enough

The fix people ship first is a UUID. It reduces guessing. It leaves the authorization gap open, because a leaked identifier works as well as 901. List responses, emails, error text, and shared links hand those values out on purpose. CWE-639 describes the vulnerable pattern as retrieving a record with a user-controlled key and never checking that the requester has sufficient entitlements, which the CWE-639 entry applies to read, update, delete, and export, especially in multi-tenant APIs.

The root question is wrong when the code asks "does this object exist?" The right question is "is this principal entitled to perform this operation on this object?" Remediation is a server-side, deny-by-default check at every object access. Hiding a button in the front end isn't that check. Anyone with a proxy never sees the button.

Pattern How it works Weakness
Ownership check after fetch Load the record by ID, then compare its owner to the caller Easy to skip on new endpoints and bulk routes
Tenant-scoped query WHERE id = :id AND tenant_id = :authenticated_tenant Only as strong as every query that follows the rule
Centralized policy check Each object action calls one authorization service Needs consistent integration across REST, GraphQL, and jobs
Random identifiers (UUID) Makes identifiers hard to guess Doesn't replace authorization; IDs leak through lists and links

Why the scoped query is the stronger default

An ownership check after the fetch can be correct, and it's also easy to forget on the next route. The record was already loaded for a foreign tenant, so a timing gap or a different error can still tell the caller the id exists. A query scoped by tenant or subject never loads that row. There's no object to leak, and no distinct error to compare. It stays only as strong as the queries that include the predicate. One raw findById in a new module undoes it.

A centralized policy service is the right companion when rules aren't a single owner column. Delegates, support agents, and shared projects need one decision point. The weakness is integration. If a GraphQL resolver, a background job, or a bulk endpoint never calls it, the policy is fiction. The same CWE-639 guidance says object-level authorization has to be enforced consistently in REST, GraphQL resolvers, background jobs, and bulk endpoints. Exports belong in that list too. They're often a second code path that reimplements the read.

Random identifiers stay in the table as defense in depth, not as the control. Keep them if you like. Don't close the ticket because you added them.

Make the matrix executable

Turn each denied cross-user and cross-tenant case into a negative test that runs in CI after deploy. Use fixture tenants, assert on body and side effects, and fail the build when foreign data reappears. That is the regression, not a yearly pentest note. For how those checks sit on the route itself, the DevArmor guide to API endpoint security is a useful companion to the query patterns above, and our best practices for API security page is the place to line them up with the rest of the API review.

Mapping IDOR Evidence to SOC 2, PCI DSS and ISO 27001

An object-level finding is control evidence, not only a bug ticket. An assessor will ask whether that evidence is still current after the last release. A report, a fix ticket, and a retest date show remediation over time. They don't, by themselves, certify the program.

A table detailing how IDOR security findings serve as control evidence for SOC 2, PCI DSS, and ISO 27001 compliance standards.

Framework Evidence to keep
SOC 2 CC6.1 Two-account test records and the authorization matrix
ISO/IEC 27001:2022 control 8.3 Denied cross-user request logs and fix tickets
GDPR Article 32 Proof that cross-tenant personal data is protected

Our reports are auto-mapped to HIPAA, SOC 2 Type 2, GLBA, PCI-DSS, CMMC, and GDPR, with specific control references. Treat that mapping as support for the assessor, not as a compliance guarantee. PCI secure-development and penetration-testing expectations still need the same object-level packet. A compliance heat map helps you see which engagements are missing it.

File four things with each test. The two accounts and tenants you used. Each finding tied to a fix and a retest date. The control that finding supports. The scope attestation. When someone asks how the access matrix stays current, the answer is the negative-test suite that reruns after deploy, with denied events you can reproduce.

Confirm Object Authorization Before Your Next Release

Decide this before the branch ships. Run the two-account swap on every endpoint that accepts an object identifier, and start with payments, personal data, and exports. Put each endpoint on a shared sheet with its owner, its object type, and its last test date so a route can't hide during the release window.

Fix each confirmed case with a tenant-scoped query or a central policy check, then add the failing requests to CI as negative tests. Record the result with a retest date in the evidence set so the release isn't a verbal "we looked." For a provider covering several clients, use the same scope rules and the same procedure on every engagement. Client reports stay comparable, and a new tester can pick up the sheet without reinventing the matrix.

This week, pick the three endpoints that return the most sensitive data. Run the swap on those three first, and log the outcome before anything else goes out.


ThreatExploit AI runs automated web and API penetration tests that replay object references across accounts, then package the evidence for the report you hand a client. If your team needs that check on a recurring schedule instead of a single annual pass, visit ThreatExploit AI and scope the next engagement against the endpoints that move customer data.