API Authorization Patterns
On this page
BOLA: the top API vulnerability
The OWASP API Security Top 10 lists Broken Object Level Authorization (BOLA) first. It's simple: an API checks that a user is logged in, but not that the object they asked for is theirs. Change /expense-reports/9931 to /expense-reports/9932 and you're reading a colleague's expenses.
The vulnerable pattern: checking login but not ownership
// Logged in? Right role? Then return whatever ID was asked for.
app.get('/expense-reports/:id', auth, (req, res) => {
if (req.user.role !== 'employee') return res.sendStatus(403);
res.json(reports.get(Number(req.params.id))); // anyone's report
});Every check passes for every employee, for every report. IDs are often sequential, so an attacker can walk through them all.
The fix: object-level authorization on every request
app.get('/expense-reports/:id', auth, (req, res) => {
if (!req.user.scope.split(' ').includes('reports:read'))
return problem(res, 403, 'insufficient-scope', 'Token lacks reports:read');
const report = reports.get(Number(req.params.id));
// 404, not 403, for other people's objects, so IDs can't be probed
if (!report || report.ownerId !== req.user.sub)
return problem(res, 404, 'not-found', 'Report not found');
res.json(report);
});Tested with a token for user_7:
GET /expense-reports/9931 (owned by user_7) -> 200 {"id":9931,"ownerId":"user_7","total":412.5}
GET /expense-reports/9932 (owned by user_8) -> 404 Report not found
GET /expense-reports/9931 (token scope profile:read) -> 403 Token lacks reports:readBetter still, put the ownership condition in the query, WHERE id = $1 AND owner_id = $2, so it can't be forgotten in one code path. Random, unguessable IDs (UUIDs) make enumeration harder but are not a substitute for the check.
Authorization models: scopes, RBAC, ABAC and ReBAC
Before the table, the same question in plain words: how does the system decide yes or no? By the key the app was given (scopes), by the job title the person holds (roles), by facts about the situation such as amount, department and time (attributes), or by who is connected to what, like "member of the folder that contains this file" (relationships).
| Model | Decides by | Example |
|---|---|---|
| Scopes | What the token was granted | orders:read on an OAuth token |
| RBAC (role-based) | The user's roles | Admins can delete; members can read |
| ABAC (attribute-based) | Attributes of user, object and context | Managers can approve expenses under $5,000 in their own department |
| ReBAC (relationship-based) | Relationships between users and objects | Editors of a document's parent folder can edit it (Google Zanzibar, OpenFGA, SpiceDB) |
Real systems combine them: the token's scopes cap what the app may do, roles cover broad permissions, and object-level rules decide each record.
Other API authorization failures
- Broken function-level authorization: admin endpoints reachable by ordinary users because only the UI hides them. Check the role on the server for every function.
- Property-level problems: returning sensitive fields to everyone, or accepting fields the user shouldn't set (mass assignment, Day 24).
- Tenant isolation: in multi-tenant APIs, every query must be scoped to the caller's tenant.
Making authorization systematic
- Centralize policy in one module or a policy engine (OPA, Cedar, OpenFGA) rather than scattered
ifstatements. - Deny by default: endpoints without an explicit rule refuse access.
- Test it: for each endpoint, a test that user A can't read or change user B's objects. With Node's built-in test runner, against the fixed endpoint:
test("user_7 cannot read user_8's report", async () => {
const res = await get(9932, 'user_7'); // fetch as user_7
assert.equal(res.status, 404);
});ok 1 - owner can read their report
ok 2 - user_7 cannot read user_8's reportA test like this fails the build the day someone removes the ownership check.
- Log denials and alert on spikes; enumeration attempts show up as streams of 404s or 403s.
Check yourself
Broken object-level authorization: the API doesn't verify that the caller may access the specific object requested, so changing an ID exposes other users' data.
With WHERE id = ? AND owner_id = ?, the check can't be forgotten in some code path after loading, and unauthorized objects are never loaded into memory at all. A missing row naturally becomes a 404.
No. They make guessing harder, but IDs leak through logs, links and shared URLs; the ownership check is still required.
Add an automated test that calls the endpoint as one user for another user's object and expects 404 or 403, so the build fails if the ownership check disappears.
RBAC grants permissions by role, such as admin or editor. ABAC decides using attributes of the user, resource and context, like department or time, which is more flexible but harder to reason about.