Skip to content
Back to CurriculumLesson 24 of 30
authz-rbacIntermediate

Object-Level Authorization: Preventing IDOR (BOLA) & Multi-Tenant Data Breaches

Insecure Direct Object References (IDOR), classified as Broken Object-Level Authorization (BOLA) in the OWASP API Security Top 10 (#1), occur when an application relies on client-supplied resource IDs without verifying that the authenticated user possesses authorization to access that specific object.

Interactive Visual Concept ExplainerStep-by-Step Educational Simulation
Visual Step-by-Step Concept Explainerauthz-rbac
Object-Level Authorization: Preventing IDOR (BOLA) & Multi-Tenant Data Breaches
Steps:
GET /api/documents/1042404 NOT FOUND (SECURE)
SELECT * FROM documents WHERE id = 1042 AND tenant_id = current_user.tenant_id;
Tenant Filter Mode:
Step 1 of 6
Auto-stepping (1x)

Step 1: User requests a specific resource by ID (e.g. GET /api/v1/invoices/:id).

Security Guarantee: BOLA/IDOR is the #1 vulnerability on the OWASP API Security Top 10.
Why This Architectural Concept Exists

Modern REST and GraphQL APIs expose object identifiers directly in URLs (e.g. GET /api/documents/1042). Attackers simply increment or tamper with the ID (to 1043) to read or manipulate records belonging to other tenants. Without mandatory object-level validation, authenticated users can access the entire database.

Intuitive Mental Model

The Hotel Room Key that Turns Every Lock: You check in to Room 201 and receive a keycard. If the hotel lock system only checks that you are a registered hotel guest (Authentication) without checking if your keycard matches Room 201 specifically (Object Authorization), you can open Room 202, 203, and 204.

Architectural System TopologyProtocol Diagram
[ Malicious User (Tenant Acme, id: usr_1) ]
       │
       ▼ (1) Submits: GET /api/invoices/9924 (belongs to Tenant Beta!)
[ API Gateway ] ── Authenticated as usr_1 (AuthN OK)
       │
       ├── VULNERABLE CODE:
       │   SELECT * FROM invoices WHERE id = 9924;  <-- BREACH! Data leaked!
       │
       └── HARDENED COSMOSAPP CODE:
           SELECT * FROM invoices 
           WHERE id = 9924 AND organization_id = session.orgId;
           │
           ▼ Query returns 0 rows!
       [ Return HTTP 404 Not Found (Prevent Tenant Enumeration) ]
CosmosApp Production Milestone

In CosmosApp, every database table contains an organization_id foreign key. When Alice requests GET /api/projects/:id, CosmosApp never executes a bare SELECT WHERE id = :id. Instead, it scopes every query to Alice's active organization ID: WHERE id = :id AND org_id = :orgId. If an attacker guesses another tenant's project ID, the database returns 0 rows.

Step-by-Step Execution Sequence
01

Step 1: User requests a specific resource by ID (e.g. GET /api/v1/invoices/:id).

02

Step 2: Framework middleware authenticates caller and extracts user_id and tenant_id from the session.

03

Step 3: Route handler passes both the requested resource ID and the trusted tenant_id to the data layer.

04

Step 4: SQL query binds tenant_id directly into the WHERE clause (enforcing multi-tenant isolation at the database layer).

05

Step 5: If zero rows are returned, the server responds with HTTP 404 Not Found (preventing attackers from confirming the resource exists).

06

Step 6: If resource exists within the user's tenant, permissions are evaluated before returning data.

Production Architecture Blueprint
// CosmosApp Multi-Tenant Scoped Database Access:
export async function getInvoice(invoiceId: string, userOrgId: string) {
  // CRITICAL: Always bind organization_id from the verified session!
  const query = `
    SELECT id, amount, customer_name, status
    FROM invoices
    WHERE id = $1 AND organization_id = $2
  `;

  const result = await db.query(query, [invoiceId, userOrgId]);

  if (result.rows.length === 0) {
    // Return 404 rather than 403 to prevent object existence enumeration:
    throw new NotFoundError('Invoice not found');
  }

  return result.rows[0];
}
Common Architectural Misconceptions
  • ✕Using UUIDs instead of sequential integers eliminates IDOR (UUIDs make guessing IDs harder, but do not prevent IDOR; if an ID leaks via URLs, logs, or APIs, an unauthorized user can still access it).
  • ✕Authentication protects against IDOR (Authentication only proves who you are; it does not check if you own the specific object requested).

Key Architectural Takeaways

  • ✓BOLA/IDOR is the #1 vulnerability on the OWASP API Security Top 10.
  • ✓Always enforce tenant boundaries at the database query level: WHERE id = $1 AND tenant_id = $2.
  • ✓Return HTTP 404 Not Found instead of 403 Forbidden to prevent resource ID enumeration.
Common Architectural Pitfall

Relying on UUIDs as 'security through obscurity' and executing queries without scoping by the caller's organization ID.

Production Best Practice Fix

Always include the authenticated user's organization/tenant ID in every SELECT, UPDATE, and DELETE query.

Interactive Knowledge Check

Why is replacing auto-incrementing integer IDs with UUIDv4 insufficient on its own to prevent IDOR/BOLA vulnerabilities?