All writing
10 min read

BOLA and IDOR testing with two accounts

Test BOLA and IDOR with two accounts: as B, replay A's requests with A's IDs and compare. Where it hides, the fix in one place, and a test per resource.

Asghar Ali · Chief Technology Officer, Kakushin.io LTD

BOLA (broken object-level authorisation) and IDOR (insecure direct object reference) are the same flaw: the server reads, changes or deletes a record because the caller supplied its ID, without checking that this caller may touch it. The most useful manual test is also the simplest. Create two ordinary accounts that each own their own records, sign in as account B, replay every request account A makes with A's IDs, and compare what comes back with what B should get. Any success is the finding. The fix is one ownership check that every data access passes through, denying by default, and the test stays in CI as a regression test for each resource.

This is for teams shipping an API, a SaaS product or an app built with AI assistants, and for whoever commissions the testing. It covers the method, where the check hides (nested routes, bulk endpoints, export links, GraphQL), the fix and how to keep it fixed. For a single endpoint broken and fixed end to end, see the ID in the URL. For where this sits in the wider order of work, see application security best practices.

What is the difference between BOLA and IDOR?

There is none in practice. IDOR is the older web name; it was a category of its own (A4) in the 2013 OWASP Top 10. BOLA is the name used by the OWASP API Security Top 10, where it is API1:2023, still the latest edition as of 17 November 2026. OWASP puts the rule in one sentence: every endpoint that receives an object ID and acts on it "should implement object-level authorization checks". Both names map to CWE-639, authorisation bypass through a user-controlled key.

It is common. In the OWASP Top 10:2025, broken access control is A01, and OWASP reports that "100% of the applications tested were found to have some form of broken access control" (read on 17 November 2026).

One distinction matters in the write-up. If B can call an endpoint B should never use at all, such as an admin route, that is broken function-level authorisation (API5:2023). BOLA is B using a normal endpoint on A's record.

Why do scanners and AI-built code miss it?

Because nothing about the request looks wrong: a valid ID, a valid session, a normal 200. Only someone who knows the invoice belongs to A, not B, sees the problem. A scanner is good at known, version-shaped issues, the kind the PHP2Shell checker looks for. Ownership is business logic, and it lives in your data model.

AI assistants widen the gap. Ask for "an endpoint that returns an invoice" and you get a lookup by ID behind a login check. The ownership check has to be asked for, and a missing line does not show up in a diff.

How do you test for BOLA with two accounts?

Run this on your own app, in staging, with your own test accounts. The OWASP Web Security Testing Guide (WSTG-ATHZ-04, stable v4.2, read on 17 November 2026) says the best way is "having at least two (often more) users". The development version adds an API-specific test, WSTG-APIT-02, which runs through each HTTP method.

  1. Set up a real ownership boundary. Put A and B in different organisations or tenants. Two members of one team may legitimately share records. Add an admin account for function-level checks.
  2. Seed one of everything. As each account, create one record of every type: project, task, invoice, file, comment, export, API key. Write the IDs down in an ownership sheet. Without it you cannot tell a leak from a shared record.
  3. Map every place an ID enters. WSTG asks the tester to "map out all locations in the application where user input is used to reference objects directly". That means path segments, query strings, JSON bodies, headers, cookies, GraphQL variables, file names and download links. Include the mobile app's calls.
  4. Replay A's requests as B. Record A using every feature, then send the same requests with B's session and A's IDs: read, update, delete, and create where the body names a parent ("add a comment to project 7").
  5. Compare, then check A's record. Do not judge by the status code alone: a 200 can carry an empty body, and a 403 can hide a write that went through. Read the body, then reload A's record as A.
  6. Reverse it. Run A against B's IDs, then each request with no session at all. A check can exist in one direction and not the other.
Diagram of the two-account BOLA test in five steps. One, seed: account A in one tenant and account B in another each create one record of every type, and every ID goes in an ownership sheet. Two, map every ID: path, query string, JSON body, headers, cookies, GraphQL variables, file and export links, for web and mobile calls. Three, replay as B: B's session with A's IDs for read, update, delete and create under A's parent, then A on B's IDs, then with no session. Four, compare: read the body, not only the status code, and reload A's record as A. Five, keep it: one regression test per resource and action from an authorisation matrix, and a route with no matrix row fails the build. A band at the bottom states the pass: B gets the same answer as for an ID that does not exist, and A's record is unchanged.
The two-account test. The pass condition at the bottom is the one to write into every regression test.
SwapWhat to send as BPass
ReadA request for A's record by its IDThe same 404 or 403 as for an ID that does not exist; no fields of A's record
UpdateA change to A's recordRefused, and A's record unchanged when A reloads it
DeleteA delete of A's recordRefused, and the record still there for A
Create under a parentA new child (comment, task, file) under A's projectRefused; nothing new appears in A's project
Owner field in the bodyB's own record with A's tenant or owner ID in the bodyIgnored or refused; the record does not move to A
No sessionEach request above with no login401, with no data

Where does BOLA hide beyond the obvious routes?

Teams check /invoices/{id}. The misses are routes with two IDs, many records or no visible ID.

PlaceWhy it is missedWhat to check
Nested routesThe handler checks the parent and trusts the childB's own project with A's task ID: /projects/{B}/tasks/{A} must fail
Bulk and batch endpointsThe check runs on the first ID or on noneA list of B's IDs with one of A's in it: A's must not come back or change
Export, report and download linksFiles are generated and served outside the main APIEvery export and file URL as B, and as nobody; links should expire
Files in cloud storageStatic files skip the app's checksOWASP's Authorization Cheat Sheet asks that "static resources are incorporated into access control policies"
GraphQLResolvers check the top-level query but not nested fields or node lookupsThe GraphQL Cheat Sheet says "Enforce authorization checks on both edges and nodes"
Search, filters and countsA tenant or owner ID in the query string widens the resultChanging owner or tenant parameters changes nothing; counts do not reveal A's records
Realtime and webhooksSubscriptions to a channel by ID skip the checkB cannot subscribe to A's channel or register a webhook for A's resources
AI featuresA tool call or retrieval step takes an ID from the modelThe tool loads records for the signed-in user only; see AI agent tool permissions and RAG data leakage

GraphQL deserves its own pass: OWASP's API1 entry describes a mutation that deletes another user's document by ID with no permission check.

What does the fix look like?

One policy check, in one place, that every read and write goes through. OWASP's API1 entry asks you to check "if the logged-in user has access to perform the requested action on the record" in every function that takes client input to reach a record. The Authorization Cheat Sheet adds that the mechanism should allow "global, application-wide configuration" rather than being repeated per method, and that an application should "deny access by default".

In practice:

  • Scope the lookup, do not check afterwards. Load records by ID and tenant together, with the tenant taken from the server-side session, never from the request. If the record is not theirs, it is not found.
  • Ask a policy function, not each handler. Something like can(user, action, record) sits in front of the data layer. Handlers cannot reach a record without it. The cheat sheet notes that plain role checks do "a poor job of supporting object-level or horizontal access control decisions", so the policy looks at the record's owner and tenant, not only the user's role.
  • Same answer for "not yours" and "not there". Returning 404 for both stops B learning which IDs exist.
  • Treat random IDs as a seatbelt, not the brakes. OWASP recommends random, unpredictable IDs, and the cheat sheet says such an approach "is generally not sufficient by itself". IDs leak through links, logs and shared screens. The check is the control.

Comparing the user ID in the session token with the ID parameter is not enough either; OWASP says it "isn't a sufficient solution". Most records are not users.

In a source-code audit, the first thing I list is every query that takes an ID from the request, then how many of them go through the shared check. The ones that do not are the test plan.

How do you stop BOLA coming back?

Turn the manual test into a regression test for every resource. OWASP's API1 prevention list ends with "Write tests to evaluate the vulnerability of the authorization mechanism. Do not deploy changes that make the tests fail." The Authorization Testing Automation Cheat Sheet describes the shape: write the authorisation matrix down in a file, then drive integration tests from it, one point of view (role) at a time.

An illustrative matrix for a small project tool:

Resource and actionOwnerSame-tenant memberOther tenantNo session
Project: readAllowAllowDeny (404)Deny (401)
Project: deleteAllowDenyDeny (404)Deny (401)
Task under project: updateAllowAllowDeny (404)Deny (401)
Invoice: readAllowDenyDeny (404)Deny (401)
Export file: downloadAllowDenyDeny (404)Deny (401)

Three rules keep it honest. Each deny test has a matching allow test for the owner, so a broken endpoint cannot pass by failing for everyone. Each write test reloads the record afterwards. And a new route with no row in the matrix fails the build, which makes "deny by default" true for the test suite as well as the app.

Driving penetration-test remediation that gated production acceptance on the customer apps of a European national electricity utility taught me to treat a fix as done only when a retest proves it. A regression test is a retest that runs on every release.

A worked example (illustrative)

An invented example, not a client case: a project tool. Two test tenants, Alder and Birch, each get a user, a project, three tasks, an invoice and a CSV export. The ownership sheet lists 14 IDs.

Replaying Alder's requests as Birch: /projects/{id} and /invoices/{id} refuse correctly. /projects/{Birch}/tasks/{Alder} returns Alder's task, because the handler checked the project in the path and loaded the task by ID alone. The export link opens without a session, because files are served straight from storage. The GraphQL node query returns Alder's invoice, because the check lives in the REST controller.

Three local fixes would close today's holes. The better fix is one: move every lookup behind a shared loadFor(user, action, type, id) that scopes by tenant, serve exports through the app with a short-lived signed link, and point the GraphQL resolvers at the same function. Then the 14 IDs become a test fixture, and the matrix above runs in CI.

What this cannot tell you

  • Only the boundaries you seeded. Two tenants test tenant isolation. Roles inside a tenant (viewer, editor, billing) need their own pairs.
  • Not field-level problems. A user changing a field they should not, or seeing a hidden property, is broken object property level authorisation (API3:2023). It needs its own test.
  • Not function-level access. Admin routes reachable by ordinary users (API5:2023) need a role-by-route matrix.
  • Not a penetration test. It does not cover authentication, injection, configuration or infrastructure.
  • Only systems you own. Run it on your own app or with written permission, against test accounts, never against other people's data.

Frequently asked questions

Do UUIDs fix IDOR?

No. OWASP recommends random, unpredictable IDs, but they end up in links, logs and exports. Use them as defence in depth and keep the ownership check.

Should "not yours" return 403 or 404?

The same response as for a record that does not exist, usually 404. A different answer tells the caller the ID is real. Keep the detail in your logs.

Can an automated scanner find BOLA?

Rarely on its own, because it does not know who owns what. Tools can replay requests across two sessions, but someone still has to seed the accounts and keep the ownership sheet.

How many test accounts do I need?

WSTG asks for at least two users. Put them in different tenants, then add one per role you want to test inside a tenant, and an admin. Keep them as permanent fixtures so the regression tests can use them.

If you want this checked

I review APIs and AI-built apps for this: the ownership sheet, the ID map across REST, GraphQL, exports and files, the two-account replay, a review of where the policy check lives in the code, and a written fix list with the regression tests to add. The scope is on my hire page.