IDOR and BOLA: A Practical Developer Guide
How changing one ID in a request can expose or edit another user's data, and how to stop it with server-side checks, safe API patterns and Row-Level Security.
Get the PDF
Free. No email or account needed. PDF · 204 KB
The preview only loads when you tap "Read PDF here", which saves mobile data. Download gives you the original PDF file.
Key takeaways
- Being logged in does not mean you may access every object.
- Never trust an ID just because your own app sent it.
- Check access on the server for each object and each action.
- Row-Level Security helps, but privileged roles can bypass it.
- Hiding or encrypting IDs does not fix the missing check.
BOLA is the first item in the OWASP API Security Top 10 (2023). A logged-in user changes one ID in a request, like 1001 to 1002, and the server returns, edits or deletes someone else's data. This guide explains how the bug works and the patterns that prevent it, with code. The full 13-page PDF above adds the complete test plan, the Row-Level Security pitfalls and a 14-point review checklist.
Test only applications you own, or systems you have explicit permission to test.
The 60-second mental model
IDOR and BOLA are authorization failures. The user is allowed to call the endpoint, but the server never checks whether that user may act on the specific object named in the request.
The core rule: never trust an object reference just because it came from your own app. The client can be inspected, modified, automated or replaced with a hand-written HTTP request.
Every IDOR has three ingredients:
- An object: a profile, invoice, order, file, message, API key or project.
- A reference: a numeric ID, UUID, filename, slug, account number, query value, GraphQL variable or JSON field.
- A missing object-level check: the server loads or changes the object without confirming the current user may do that action on it.
| Term | Easy meaning |
|---|---|
| Authentication | Who are you? A verified session or token says this is User 1001. |
| Authorization | What may you do? User 1001 may read Profile 1001, but not Profile 1002. |
| IDOR | An object reference is used without a correct access check. |
| BOLA | The API name for the same thing: broken authorization at the object level. |
A valid login does not make an object safe. Authentication gives you an identity. Authorization has to connect that identity, the action and the exact object.
How an attacker changes 1001 to 1002
The attacker does not edit a button. The button only sends a request. They watch that request, change the object reference and send it again with the same valid token.
GET /api/profiles/1001 HTTP/1.1
Authorization: Bearer <token-for-user-1001>
GET /api/profiles/1002 HTTP/1.1
Authorization: Bearer <same-token-for-user-1001>
The server authenticates User 1001 and loads object 1002. If nothing checks permission on 1002, another user's data comes back.
The reference can sit anywhere in the request: the path (/orders/8421), the query string (?file_id=8421), the JSON body, a header like X-Account-ID, GraphQL variables, or a filename or storage key.
Why "the user is logged in" is not enough
A secure decision needs at least four inputs:
- Subject: who is making the request?
- Action: read, update, delete, export, invite, refund?
- Object: which exact record?
- Context: ownership, team membership, role, tenant, status, time, consent.
Ownership is only one kind of policy. A team document may be readable by members, editable by editors and deletable only by its owner. An order may be cancellable by its owner only before it ships. An administrator should go through a separate, audited path instead of a blanket bypass.
A vulnerable API, line by line
This Node/Express example checks the login but looks up the profile across the whole table:
app.get('/api/profiles/:id', requireAuth, async (req, res) => {
// req.user.id is 1001 because the token is valid
const profile = await db.profile.findUnique({
where: { id: req.params.id }, // attacker controls this ID
});
if (!profile) return res.sendStatus(404);
return res.json(profile); // no object authorization check
});
requireAuth only proves the caller has a valid identity. req.params.id comes from the client. The query searches every profile, and the record goes out before any permission decision. The same bug on PATCH or DELETE lets an attacker edit or destroy data.
A common review mistake is checking that the endpoint needs a token, then never sending the same request with another user's object. A valid-token test is not an authorization test.
Secure patterns that scale
Pattern A: do not accept an ID when the object is always "me".
app.get('/api/me/profile', requireAuth, async (req, res) => {
const profile = await db.profile.findUnique({ where: { ownerId: req.user.id } });
if (!profile) return res.sendStatus(404);
return res.json(selectPublicProfileFields(profile));
});
Identity comes from the verified session, so there is no user ID to tamper with.
Pattern B: scope the query to what the user may see.
const project = await db.project.findFirst({
where: { id: req.params.id, ownerId: req.user.id },
});
if (!project) return res.sendStatus(404);
The ID and the ownership rule are checked together, so a foreign ID behaves like a missing record.
Pattern C: use a policy for shared objects.
const project = await loadProject(req.params.id);
if (!project) return res.sendStatus(404);
if (!(await policy.can(req.user, 'project:edit', project))) return res.sendStatus(403);
await updateProject(project.id, validatedInput);
Safe default: deny unless a policy explicitly allows this subject to do this action on this object. Apply it to read, list, create, update, delete, export, batch and background-job paths.
Beyond simple ownership
Real products need more than currentUser.id == object.userId: role-based rules for support tools, relationship rules for teams and shared folders, attribute rules like "editors can edit unless the object is locked", and narrow signed capabilities for share links.
To avoid the confused-deputy problem:
- Never accept
tenant_id,owner_idorrolefrom the request as trusted identity. - Load memberships and roles on the server from the verified session.
- In batch endpoints, authorize every object, not just the first ID.
- In nested routes like
/teams/T1/projects/P9, check that P9 really belongs to T1. - For high-risk changes, do the permission check and the update atomically, so access cannot change in between.
Where Row-Level Security fits
PostgreSQL Row-Level Security (RLS) restricts which rows a database role can read or change. It is a strong extra layer, especially when many API paths touch the same tables. Proper authorization is still the fix, and RLS is one powerful way to enforce part of it.
RLS has traps: superuser and BYPASSRLS roles skip it, a read policy does not protect writes, several permissive policies combine with OR, and storage, caches, search indexes and exports never pass through it. The PDF covers each pitfall with a safer approach.
Fixes that look useful but do not solve BOLA
- Hiding the ID in the UI: the client controls hidden fields and app screens.
- Using UUIDs: harder to guess, but a leaked or logged UUID can still be replayed.
- Encrypting or encoding IDs: encoding is reversible, and neither proves permission.
- Validating the ID format: a valid ID can still belong to another user.
- Rate limiting: slows enumeration, but one unauthorized request is still a bug.
Returning 404 or 403 are both fine. The security control is the denial itself, not the status code.
How to test it
Create User A and User B in the same tenant, and User C in another tenant. Give each one an object, plus one shared team object. Then repeat every known-good request while changing only the object reference. A must succeed on A's object and fail on B's and C's for read, update, delete, list, export and batch calls.
Check that nothing leaks in the response, that the forbidden change did not happen in the database, and that the denial is logged without secrets. Switching the HTTP method, API version, client or GraphQL alias must not get around the rule.
The one question to ask
Never ask only "is this user logged in?" Ask: may this user perform this action on this exact object right now?
Further reading: OWASP API1:2023 Broken Object Level Authorization, the OWASP IDOR Prevention Cheat Sheet and the PostgreSQL Row Security Policies docs.