Prompt
How do I block BOLA and IDOR attacks on APIs?
Latest observation
To block BOLA (Broken Object Level Authorization) and IDOR (Insecure Direct Object Reference) on APIs, the core principle is:
Never trust object identifiers from the client. Always verify the caller is allowed to access that specific object.
What to do
1) Enforce authorization on every object access
For every request that reads, updates, deletes, or lists a resource:
- Load the object by its ID
- Check whether the authenticated user is allowed to access it
- Deny access if not
Example:
- User A requests
/orders/123 - Your API must confirm
order 123belongs to User A or User A has a legitimate role/permission
2) Use server-side access control, not client-side checks
Do not rely on:
- Hidden form fields
- Frontend route protection
- Obfuscated IDs alone
- “This ID is hard to guess” assumptions
These are not security controls.
3) Prefer indirect access patterns where possible
Instead of allowing clients to submit arbitrary IDs:
- Derive object scope from the authenticated context
- Example:
/me/orders/123instead of/users/999/orders/123 - Or use access-controlled lookups like “my projects” rather than raw global IDs
4) Check ownership and permission separately
Some objects are:
- owned by a user
- shared with a team
- accessible via admin/support roles
Your checks should reflect business rules, for example:
- owner can read/write
- team members can read
- admins can manage all
- support can read only with audit logging
5) Protect list endpoints too
BOLA isn’t just for single-object endpoints. Also validate:
- pagination cursors
- filter parameters
- search by ID
- bulk operations
- export/download endpoints
6) Apply authorization consistently across all HTTP methods
Check access for:
GETPOSTPUTPATCHDELETEOPTIONSif it reveals metadata- async jobs / callbacks / webhooks that trigger object operations
7) Don’t expose sequential IDs if you can avoid it
Using UUIDs or random identifiers can reduce easy guessing, but:
- it does not fix BOLA by itself
- authorization checks are still required
8) Centralize authorization logic
Avoid scattered ad hoc checks in controllers. Use:
- policy/service layer
- authorization middleware
- resource-based access control
- ABAC/RBAC rules in one place
This helps prevent missed endpoints.
9) Add object-level tests
Test cases should include:
- user accessing own object → allowed
- user accessing another user’s object → denied
- unauthenticated access → denied
- cross-tenant access → denied
- privileged role access → only if intended
10) Log and monitor unauthorized attempts
Detect abuse by logging:
- object ID
- requesting user/account
- endpoint
- outcome
- tenant/org context
Look for:
- repeated ID enumeration
- high rate of 403s
- access to objects outside normal scope
Common mistakes to avoid
- Checking only “is user logged in?”
- Assuming UUIDs prevent IDOR
- Verifying access in the UI but not in the API
- Applying authorization only on
GET - Forgetting nested resources like
/users/{id}/orders/{orderId} - Missing checks in background jobs or secondary endpoints
Practical rule of thumb
For every API endpoint, ask:
- What object is being accessed?
- Who is the caller?
- What rule determines whether this caller may access that object?
- Where is that rule enforced server-side?
If you want, I can also give you:
- a secure API authorization checklist
- example code in Node/Express, Django, Spring, or .NET
- a test plan for finding BOLA/IDOR in your API