Business logic vulnerabilities
Business logic flaws arise when application flows ignore the ordering, conditions, or business rules that should be enforced.
Material
Business logic flaws are not a technical leak but a business rule enforced in the wrong place or not enforced at all. Names, prices, order states, and user roles are taken on faith from the client side, so steps that must happen in order can simply be skipped.
How it works
The server usually validates each endpoint in isolation without ever looking at the flow from start to finish. One endpoint then checks a precondition that an earlier endpoint should have guaranteed, and the attacker issues requests in an order the normal application never produces.
POST /cart/add HTTP/1.1
Host: lab.cidadaxsec.local
Content-Type: application/x-www-form-urlencoded
Cookie: session=3f9a1c7e
productId=1&quantity=1
POST /checkout/confirm HTTP/1.1
Host: lab.cidadaxsec.local
Content-Type: application/x-www-form-urlencoded
Cookie: session=3f9a1c7e
discountCode=FREE100# ganti nilai yang seharusnya dihitung server, lalu kirim ulang
curl -sS -X POST "https://lab.cidadaxsec.local/cart/add" \
-b "session=3f9a1c7e" -d "productId=1&quantity=-5"
# panggil endpoint checkout tanpa langkah sebelumnya yang diwajibkan
curl -sS -X POST "https://lab.cidadaxsec.local/checkout/confirm" \
-b "session=3f9a1c7e" -d "discountCode=FREE100"Attack vectors
- Excessive trust in client-side values: price, discount, or balance is edited straight in the request.
- Authentication bypass through a flawed state machine: the final endpoint is called without passing the login step.
- Inconsistent controls: one flow hides the field, another validates it.
- Inconsistent handling of exceptional input: negative, zero, or oddly typed values slip through.
- Weak isolation on a dual-use endpoint: an endpoint usable both ways only enforces one direction.
Logic bugs must be told apart from technical ones. If a disabled HTML button is the only obstacle, that is a logic weakness; if the server accepts any command because a filter is wrong, that is an injection. Both must be fixed, but the fix lives in different places.
Preventing
- Model the flow as a state machine: the server decides which transitions are legal, not the client that orders the steps.
- Compute derived values on the server; price, discount, and totals must be recalculated from server-side data.
- Enforce authorization per object and per action, on the server, on every endpoint that touches the resource.
- Validate type and range on the server with a strict schema, rejecting negative numbers in every numeric field.
- Test the flow with unnatural request sequences: skip a step, repeat a step, and reorder steps within one session.
from decimal import Decimal
def price_for(order, catalog) -> Decimal:
total = Decimal("0")
for item in order.items:
product = catalog.get(item.product_id)
if product is None:
raise ValueError("unknown product")
if item.quantity <= 0:
raise ValueError("quantity must be positive")
total += product.price * item.quantity
discount = catalog.valid_codes.get(order.discount_code)
if discount is None:
return total
return total * (Decimal("1") - discount)Labs
- Excessive trust in client-side controls
- High-level logic vulnerability
- Inconsistent security controls
- Flawed enforcement of business rules
- Low-level logic flaw
- Inconsistent handling of exceptional input
- Weak isolation on dual-use endpoint
- Insufficient workflow validation
- Authentication bypass via flawed state machine
- Infinite money logic flaw
- Authentication bypass via encryption oracle
- Bypassing access controls using email address parsing discrepancies
Labs in this topic
Labs run on a domain separate from this site, so a payload cannot reach your account session.
Labs for this category land in Phase 2. The material is readable now.
Challenges in this category
Challenges from the PortSwigger Web Security Academy. The original labs run on PortSwigger domains, so the link opens there.