CWE-639OWASP API1:2023OWASP A01:2021CWE-284

CWE-639: Insecure Direct Object Reference (IDOR / BOLA)

An endpoint accepts an object id and acts on it without checking the caller is allowed that specific object, so changing the id reaches someone else's data.

Also known as: IDOR, BOLA, Insecure direct object reference, Broken object level authorization

Risk

Typically high to critical. IDOR / BOLA is the most frequent cause of real-world data breaches and needs no exploit chain, just an authenticated user changing an id.

Definition

What it is

CWE-639 occurs when an application uses a client-supplied identifier to select an object but checks only that the caller is authenticated, not that they are authorized for that particular object. Because the id is predictable or enumerable, a logged-in user can substitute another user's id, an order number, an invoice, an account, and the server returns or modifies it. The authorization check for the specific object is missing; being logged in is treated as enough.

Use-cases

How it shows up in real code

Reading another user's invoice

An invoice endpoint takes an id and returns the invoice. Nothing checks ownership, so incrementing the id walks through every customer's invoices.

Editing someone else's record

An update endpoint trusts the id in the request body to pick the record. A user changes the id to another user's record and modifies data they do not own.

Account takeover via a profile id

A 'update my profile' call accepts a userId field. Setting it to another user's id changes that user's email or password-reset address, leading to takeover.

Enumerable export

A report-download link embeds a sequential document id with no ownership check, so a user downloads every tenant's reports by iterating the number.

AI risk

Why AI-generated code has increased the exposure

  • Assistants generate the fetch-by-id or update-by-id handler the prompt asked for and typically add only an authentication guard, because 'is this user authorized for THIS object' is business context the model does not have.
  • Ownership depends on the data model (which table links an object to its owner or tenant) that the assistant cannot infer from a short prompt, so the per-object check is left out by default.
  • Generated CRUD scaffolding produces many id-driven endpoints quickly, each inheriting the same missing object-level check.
  • The insecure pattern, trust the id, verify only the session, is extremely common in training data and is reproduced as the default.
  • More generated endpoints means more object-level authorization decisions, every one an independent chance to omit the ownership check.

Vibe coding

How vibe coding amplifies the risk

  • Vibe coding ships id-driven endpoints without the ownership check, because verifying per-object authorization is invisible logic that an unread diff will not reveal as missing.
  • During vibe-coded testing the developer uses their own account and their own ids, so every request succeeds and nothing looks wrong, the flaw only appears when a second user swaps ids.
  • Prompt-and-ship skips the review where someone would ask 'does this check the caller owns this record?'.
  • Rapid CRUD generation multiplies id-driven endpoints faster than anyone audits each for an ownership check.
  • Scanners rarely catch IDOR because it is missing business logic, not a bad string, so an unreviewed vibe-coded endpoint has no automated backstop.

Detection

How to find it

  • For every endpoint that takes an object id, confirm the server verifies the caller is authorized for that specific object, not merely that they are logged in.
  • Scope data queries by owner or tenant at the server (e.g. `where id = ? and ownerId = session.user`), rather than selecting by id alone.
  • Test with two accounts: confirm one cannot read or modify the other's objects by substituting ids.
  • Treat ids in the request body and query string the same as those in the path, all are client-controlled.

Remediation

How to fix it

  • Enforce an object-level authorization check on every access: confirm the authenticated caller owns or may access the specific object before returning or modifying it.
  • Scope every query by the caller's identity or tenant at the server, so an unauthorized id simply returns nothing.
  • Never derive the owner from client input; take it from the authenticated session.
  • Consider unguessable identifiers (UUIDs) as defense in depth, but treat them as a supplement to the authorization check, never a replacement.
  • Add integration tests that attempt cross-account access and fail the build if they succeed.

Frequently asked questions

What is CWE-639 (IDOR / BOLA)?
CWE-639 is when an endpoint selects an object by a client-supplied id but checks only that the caller is logged in, not that they are authorized for that specific object. Changing the id reaches another user's data. It is the most frequent cause of real-world data breaches.
How have AI assistants and vibe coding increased IDOR risk?
Assistants generate the fetch-by-id handler with only an authentication guard, because per-object ownership is business context they do not have. Vibe coding ships those endpoints unread, and because the developer tests with their own account and ids, every request succeeds and the missing ownership check stays invisible until a second user swaps ids.
How do I fix IDOR / BOLA?
Enforce an object-level authorization check on every access, scope every query by the caller's identity or tenant at the server, take the owner from the authenticated session rather than client input, and add integration tests that attempt cross-account access and fail the build if they succeed.

Related weaknesses

Catch CWE-639 before you ship

Tethlyn Audit scans your codebase and its git history for CWE-639 and the rest of the broken access control & authorization class, then ranks each finding by real exploitability and data sensitivity.

See Tethlyn Audit