#Why this matters
Automated vulnerability scanners look for syntax anomalies, database errors, and known signatures. They rarely understand what an application is supposed to mean. An e-commerce API returning HTTP 200 after applying a discount twice, or a support portal letting a standard user invoke an export endpoint meant for managers, produces no crash and no error log. Yet both failures can lead to financial loss, unauthorized data exposure, or full tenant compromise.
In the OWASP Top 10 and OWASP API Security Top 10, Broken Access Control and Broken Function Level Authorization consistently rank at the top because authorization rules live across dozens of endpoints and change as features evolve. Business logic flaws sit right beside them: the code executes cleanly, but the underlying assumptions about user intent, step ordering, or numeric boundaries fail.
#Beyond basic IDOR: context and tenant boundaries
Earlier lessons introduced basic Insecure Direct Object Reference (IDOR), where changing an object identifier exposes another user's record. At advanced tiers, access control bugs hide behind context switches, secondary workflows, and framework conveniences:
- Broken Function Level Authorization (BFLA): The UI hides an administrative button, so developers assume regular users will not call
POST /api/v1/admin/export-audit. If the controller checks only that a valid session exists and omits a role check, any authenticated user can invoke the function. - Cross-tenant leakage: Multi-tenant SaaS applications often derive the caller's identity from a session or JWT, yet read
organization_idfrom a query parameter or JSON body. When those two sources are not cross-checked, a user in Tenant A can query or modify records belonging to Tenant B. - Mass assignment: Modern web frameworks often bind incoming JSON directly to database models. If a user registration or profile update endpoint binds every field, including
role,plan_tier, oris_verified, a caller can include extra attributes in the request body and alter privileged flags. - Secondary and asynchronous paths: Primary endpoints (
GET /invoices/104) may enforce ownership checks, while background job triggers (POST /reports/generate), webhook registrations, or GraphQL resolvers reuse internal service functions that skip authorization.
| Flaw class | Typical root cause | Primary defensive fix |
|---|---|---|
| BFLA | Route checks authentication but not role or capability | Centralize RBAC/ABAC middleware with deny-by-default |
| Tenant leak | Client-supplied org_id trusted over session context |
Derive tenant scope solely from verified session claims |
| Mass assignment | Unfiltered binding of request payload to ORM model | Use explicit DTOs or allow-listed field schemas |
| Logic bypass | Workflow rules enforced only in frontend JavaScript | Enforce server-side state transitions and invariants |
#State-machine and multi-step workflow bypasses
Many web applications model critical operations as multi-step sequences: shopping cart checkout, multi-factor enrollment, password recovery, or document approval. A common flaw arises when the backend assumes every user follows the browser's intended sequence (Step 1 -> Step 2 -> Step 3) and fails to record or verify state on the server.
If /checkout/confirm only checks that cart_id=42 belongs to the logged-in user and does not verify that status == 'paid', the payment step disappears completely. The same pattern appears when applications store workflow progress in a hidden form field, a client-readable cookie, or an unsigned query parameter (?step=3&verified=true).
During a controlled lab audit, a tester inspects whether each endpoint independently validates the preconditions required for its transition:
$ curl -s -i -X POST http://lab.local/api/checkout/confirm \
-H "Cookie: session=lab_user_token" \
-H "Content-Type: application/json" \
-d '{"order_id": 108}' | head -n 6
HTTP/1.1 409 Conflict
Content-Type: application/json
{"error":"invalid_transition","expected":"paid","current":"draft"}A 409 Conflict response like the one above shows a properly enforced server-side state machine: the server tracked current: draft independently and rejected the jump to confirmation.
#Numeric, invariant, and concurrency logic flaws
Business logic vulnerabilities often appear when code checks syntax and data types ("is this an integer?") without checking domain invariants ("must this quantity be positive?"). Common examples include:
- Negative values and sign inversion: If a transfer or item-quantity endpoint computes
total = unit_price * quantityand accepts-5, the total becomes negative, potentially crediting an account or reducing a cart total below zero. - Trusting client-calculated values: Passing
price,discount_rate, orcurrencyfrom the browser allows tampering before submission. Prices and discounts must always be looked up on the server from authoritative records. - Discount stacking and reuse: Applying the same single-use promotional code across parallel requests, or applying multiple mutually exclusive coupons in sequence, breaks intended pricing limits.
- Rounding and precision drift: Repeated conversions between currencies or fractional units can leave small remainders that accumulate over many transactions if rounding rules favour the caller.
- TOCTOU race windows: Checking a balance or coupon status, pausing for external work, and updating the balance later without a database lock allows concurrent requests to pass the check simultaneously.
Consider the difference between trusting input versus enforcing domain invariants in server code:
# Vulnerable: trusts client price and permits non-positive quantity
def add_item_vulnerable(cart, item_id, qty, client_price):
cart.total += qty * client_price
return cart.total
# Fixed: derives price server-side and enforces domain invariants
def add_item_safe(db, cart_id, item_id, qty):
if not isinstance(qty, int) or qty < 1 or qty > 100:
raise ValueError("Quantity must be an integer between 1 and 100")
item = db.get_catalog_item(item_id)
if item is None or not item.active:
raise ValueError("Unavailable item")
return db.atomic_add_line_item(cart_id, item.id, qty, item.unit_price_cents)Using integer minor units (such as cents) rather than floating-point numbers also eliminates binary rounding surprises in financial calculations.
#Defending and common mistakes
Robust authorization and business logic security rely on making invalid states unrepresentable on the backend:
- Deny by default in shared middleware: Require explicit role, permission, and object-ownership policies on every route, including background jobs, webhooks, and admin APIs.
- Derive authority from the server: Read user identity, role, and tenant ID from verified session state or tokens, never from request parameters.
- Enforce explicit state machines: Persist workflow states in the database and validate allowed transitions atomically (
UPDATE orders SET state = 'confirmed' WHERE id = :id AND state = 'paid'). - Protect invariants at the data layer: Combine application validation with database
CHECKconstraints, unique indexes for one-time tokens, idempotency keys, and row-level locking or serializable transactions for balance updates.
Common mistakes in practice include relying on hidden UI controls to restrict access, validating business rules only in Step 1 of a wizard, trusting client-supplied totals or status flags, and checking permissions inconsistently across REST, GraphQL, and export endpoints.
#Summary
Advanced access control and business logic flaws bypass traditional signature scanners because they exploit valid requests that violate authorization boundaries or domain rules. Flaws such as BFLA, cross-tenant leaks, mass assignment, workflow step-skipping, and numeric invariant violations all stem from trusting client-supplied context or execution order. Defending against them requires deny-by-default authorization middleware, server-derived tenant and pricing data, explicit state-machine transitions, and atomic database constraints.