Business logic flaws
A logic flaw has no payload. Every request is syntactically correct and, on its own, legitimate: add to cart, apply a coupon, confirm an order, accept an invitation. The mistake is in the design: the application allows a sequence, a value or an actor the business shouldn’t allow, because the developer assumed something the server never checks. That’s why scanners barely see them and why they pay well: the impact is usually money, fraud or someone else’s account.
flowchart LR
A["Client<br/>POST /cart"] --> B["Backend<br/>POST /checkout"]
B --> C["Gateway<br/>authorizes $100"]
C --> D["Backend<br/>POST /order/confirm"]
D --> E["Warehouse<br/>creates the shipment"]
X((Attacker)) -. "1 · order: confirm without paying" .-> D
X -. "2 · value: price=1, qty=-2" .-> B
X -. "3 · state: add items<br/>during authorization" .-> E
Threat model
Section titled “Threat model”The attacker is a regular user of the application, with or without an account, who talks straight to the API instead of using the interface. Nothing needs breaking: it’s enough to send a request the interface would never send (another order, another value, another account, another moment) and see whether the server accepts it. The goal depends on the business: buy below price, spend the same balance twice, use paid features without paying, join someone else’s organization or take over another person’s account.
Anatomy
Section titled “Anatomy”A business rule can live in three places: the client (JavaScript, hidden fields, disabled buttons), the server (controllers, services) and the database (constraints, transactions). The flaw appears when the rule only exists in a layer the attacker controls or can get ahead of: the price comes from a hidden input, “step 2 done” lives in a cookie, “one coupon per order” is enforced by JavaScript, “enough balance” is checked in one query and deducted in another.
Mapping the flow
Section titled “Mapping the flow”Before attacking, rebuild each feature step by step. You don’t need all of them, only the ones that move value or change identity (purchase, redemption, refund, sign-up, reset, invitation, plan change, verification). For each step, four axes:
| Axis | Question |
|---|---|
| Action and request | What does the user do and which endpoint runs it? |
| Identity and permissions | Which account or object does it act on? Who should be allowed? |
| Data and dependencies | Which IDs, tokens or results does it need from the previous step? |
| State and effect | What must be true before? What changes afterwards? |
The map is good when you can explain how each request depends on the previous ones and which rule should stop the invalid operation. Name the actor in each box (client, backend, mailer, gateway, verification provider): hand-offs between systems are where logic breaks most. If the application publishes an OpenAPI spec, use it as the map; otherwise build one from the proxy history and the routes in the JavaScript.
With the map done, ask three questions of each step: what if I send it many times at once?, what if I send it at another point in the flow?, what if I change a value?
The three levers
Section titled “The three levers”| Lever | What you test | Example |
|---|---|---|
| Order | Skip, repeat or reverse steps | POST /order/confirm without going through payment |
| Values | Negatives, zero, limits, unexpected types | qty=-1, price=0, coupon=["A","B"] instead of "A" |
| Identity and state | Act as someone else or in the wrong state | Use A’s verification challenge on account B; accept an invitation after downgrading |
Client-side controls (hidden fields, dropdowns, disabled buttons, the price in the form, the
limit in JavaScript) are only “read-only” in the browser. In the proxy you change them like any
other parameter. The server has to check two things: that the value is logically valid and
that you’re allowed to send it.
Variants
Section titled “Variants”Grouped by the flow where they show up. Authentication and federation cases are covered in depth in authentication flaws and OAuth; concurrency, in race conditions.
Accounts and identity
Section titled “Accounts and identity”- Setting the initial password again. Sign-up sends a link to
POST /set-password. If the endpoint doesn’t check that a password is already set or ask for the current one, anyone with the victim’s session (or a CSRF or XSS that calls it for them) overwrites it. - Pre-account takeover. The attacker registers with the victim’s email first; the application doesn’t verify it. When the victim signs in through a federated provider, the application merges by email and the attacker’s password still works: two keys to one account. Details in OAuth.
- Password reset. Tokens derived from predictable data, several alive at once, that never expire, aren’t bound to the user or don’t end active sessions. Covered in authentication flaws.
- Invitations. The invitation token isn’t bound to the invited email and is accepted with whatever account is logged in: anyone with the link joins the organization.
- Verification challenges. The backend issues a
challenge_idand an answer, then only checks that they match, not that the challenge belongs to the session’s user. You solve the challenge for your account and apply it to another. Affects “confirm your email” and identity verification.
Purchases, payments and balances
Section titled “Purchases, payments and balances”flowchart LR
A["Cart"] --> B["POST /cart/coupon"]
B --> C{"Minimum spend?<br/>One coupon per order?"}
C --> D["Recalculate total"]
D --> E["Checkout"]
The key coupon question is where and when each rule is checked:
| Vector | What fails |
|---|---|
| Rule only in the UI | The UI swaps coupon A for B; the server keeps both |
| Stackable types | Percentage + free shipping + gift card + loyalty points |
| Threshold checked on apply | Reach the minimum, apply the coupon, remove items |
| Order of application | 20% then −$15 isn’t the same as −$15 then 20% |
| Unnormalized codes | SUMMER10 and summer10 count as different coupons |
| Race | Twenty simultaneous requests with a single-use coupon |
| “First purchase” per account | Email aliases (ana+1@) and free new accounts |
| Refund not prorated | The full price is refunded for an item bought at a discount |
- Skipping steps. Cart → shipping → gateway payment →
POST /order/confirm. Ifconfirmdoesn’t require a prior authorized payment on the server, a direct POST creates the order. The same pattern appears in identity verification, onboarding and second factors: if the state doesn’t live on the server, the order of steps is optional. - Price and quantity from the client. The backend takes
priceandqtyfrom the request and passes them to the gateway.price=1, or a negative quantity that subtracts from the total and ends up as a credit. - Double spend through a race. Redeeming a gift card means reading the balance, checking it’s enough, deducting it and committing. If that isn’t atomic, twenty parallel requests read the same balance before any of them deducts it (check-then-act, CWE-367). The technique is in race conditions.
- Cart/payment TOCTOU. The cart is worth $100, the gateway authorizes $100 and, when creating the shipment, the backend reads the current cart again. Add items while the payment is being authorized and it charges $100 and ships more. You don’t control the backend process, but you do control a variable it reads: your cart.
- Replays without idempotency.
POST /refundsent three times refunds three times if there’s no idempotency key and no state check. Same for credits, points and redemptions. - Unsigned third-party callbacks. The gateway or the verification provider reports the result to an endpoint in your application that “only the third party should call”. If it doesn’t check the signature or the prior state, anyone can call it and decide the outcome.
SaaS platforms and deadlines
Section titled “SaaS platforms and deadlines”- Subscription limits. The Pro plan allows 10 seats and the limit is checked when inviting, not when accepting. Send 50 invitations on Pro, downgrade to Free and have them accepted: 50 users on Free. Variants: paid features not revoked on downgrade, trials reset by recreating the workspace.
- Deadlines. The cut-off for a submission, an offer or a vote is validated against a timestamp sent by the client, or not validated on submit. The server sets the cut-off; also watch retries and tamperable start times.
- Password length and CPU. bcrypt, scrypt and Argon2 are slow on purpose. A 1 MB password,
many times and in parallel, saturates the login service’s CPU. bcrypt also only uses the first
72 bytes: the PyPI
bcryptpackage 4.3.0 truncates silently (a password of 72Aand another of 72AplusXvalidate the same) and 5.0.0 raisesValueErrorabove 72 bytes. Cap the length before hashing and rate limit.
Second factor
Section titled “Second factor”Four assumptions that often break, detailed in authentication flaws: the session issued after the password already authorizes the API before the second factor; password reset disables MFA “so the user isn’t locked out”; adding a new factor only requires an active session; the 6-digit code has no attempt limit bound to the code.
Canonicalization
Section titled “Canonicalization”Validating a string and then normalizing it means the validated value and the used value can
differ (CWE-180, Validate Before Canonicalize). The typical case is email: the validator checks
there’s a single @ in the original string, but the mailer applies Unicode NFKC normalization,
which turns the fullwidth @ (U+FF20) into @:
>>> import unicodedata>>> s = "victim@company.com@attacker.com">>> s.count("@"), unicodedata.normalize("NFKC", s).count("@")(1, 2)Validation sees one @; the mailer sees two and the sign-in link may end up in the attacker’s
mailbox. Rule: canonicalize first, validate afterwards, and validate exactly the value you’re
going to use. The same applies to case, accents, zero-width spaces and other homoglyphs in
usernames, coupons and paths.
Red Team
Section titled “Red Team”Hunting methodology
Section titled “Hunting methodology”- Understand the expected flow: which steps exist, in what order, who can do each one and what state is assumed at each point. Use it as a legitimate user from start to finish.
- Intercept the whole flow in the proxy and mark:
- where sensitive values travel: price, quantity, total, role, status, IDs;
- hand-offs between systems: cart → gateway, front end → backend, application → webhook;
- endpoints the interface doesn’t link, pulled from the JavaScript and the traffic.
- List the assumptions of each step: order, values, identity and state, trust in the client.
- Break each assumption one by one with the three levers, one at a time, so you know which one isn’t enforced.
Typical tests
Section titled “Typical tests”Negative quantity (if the total drops, the shop credits you the difference):
POST /cart/checkout HTTP/1.1Content-Type: application/json
{"item":"tv","qty":-2,"price":500}Price decided by the client:
POST /cart/checkout HTTP/1.1Content-Type: application/json
{"item":"tv","qty":1,"price":1}Confirm an order that was never paid:
POST /order/confirm HTTP/1.1Content-Type: application/json
{"order":3}Type change: an array where a scalar is expected can get past the “one coupon” check if the code counts elements in one place and applies discounts in another:
POST /cart/coupon HTTP/1.1Content-Type: application/json
{"code":["SUMMER10","WELCOME15"]}Tokens: request two or three for your own account and compare them before fuzzing anything. If decoding them shows your username, a date or a counter, you can build someone else’s:
echo 'YW5hOjIwMjYtMTEtMjM=' | base64 -d; echo # ana:2026-11-23echo 'TOKEN' | xxd | head # fixed structure, repeated bytes?For concurrency tests (redemptions, single-use coupons, refunds) use Repeater’s parallel group send (Send group in parallel), which relies on the single-packet attack; details in race conditions.
- An intercepting proxy (Burp Suite or similar), where almost everything happens: Repeater to alter and repeat steps, parallel group send for races and Intruder for bulk repetition.
- A diagram of the flow, on paper or in Mermaid, as a state machine.
- Decoding utilities for tokens:
base64,xxd, a JWT decoder. - The application’s OpenAPI spec, if it exists, or the JavaScript bundles, to find endpoints the interface doesn’t link.
Proving the impact
Section titled “Proving the impact”“The price can be changed” isn’t a finding; “order 4127 shipped for $1 with this sequence of requests” is. Show the result (the order, the balance spent N times, someone else’s account with your password), document the expected flow versus the broken flow step by step with the requests, and translate it into business terms: financial loss, fraud, account takeover, failure of a mandatory verification. Always do it on your own accounts and objects, without completing real purchases or touching third-party data.
Impact and chaining
Section titled “Impact and chaining”Direct financial loss, coupon, points or balance fraud, paid features for free, account takeover
and access to other organizations. Chains with IDOR/BOLA (acting on someone
else’s objects), mass assignment (setting role or status from the
request), race conditions (breaking limits through concurrency) and
CSRF or XSS (making the victim call the badly designed
endpoint).
Blue Team
Section titled “Blue Team”Detection
Section titled “Detection”- Orders with total ≤ 0, negative quantities or prices different from the catalog.
- Impossible state transitions:
SHIPPEDwithoutPAID, verification completed with no challenge issued for that account. - Single-use resources applied several times (coupon, card, token, refund), especially within the same second.
- Invitations accepted by an account other than the invited email; seats above the plan.
- Payment or verification callbacks arriving without a valid signature or from unexpected origins.
Telemetry and sources
Section titled “Telemetry and sources”Log every business transition with actor, object, values and previous and new state, not just the HTTP request. Correlate gateway events (authorization, capture, refund) with orders, and verification events with accounts. A logic flaw shows up in business data long before it shows up in WAF logs.
Hardening
Section titled “Hardening”- Recalculate on the server everything with value: price from the catalog, total from the line items, discounts against the rules. From the client you only accept intent (“I want 2 of this product”).
- Model the flow as a state machine and enforce each transition on the server with a
condition on the current state (
UPDATE … WHERE status='PAID'). Don’t keep progress in cookies or on the client. - Atomic check-and-act: a locked transaction, a conditional
UPDATEor a unique constraint in the database. Anifin the code isn’t enough. - Idempotency for everything that moves money or points: an idempotency key claimed atomically and a final state (“refunded”) that rejects retries.
- Bind tokens and challenges to their subject and context: user, invited email, purpose and expiry. Store only their hash, consume them on use and keep one alive per purpose.
- Check limits where they materialize (when accepting the invitation, not only when sending it) and revoke them on downgrade.
- Verify the signature and prior state on third-party callbacks.
- Canonicalize before validating (NFKC, lowercase, trimming) and use exactly the validated value. Cap password length before hashing.
- Abuse cases in design: for each user story, its “what if…?” with the three levers, turned into an automated test.
Response
Section titled “Response”Reconcile the affected transactions (orders, balances, refunds), fix the rule on the server and search history for the same pattern: anomalous totals, impossible transitions and reuse. If the flaw affects accounts, invalidate sessions and tokens for the accounts involved.
CVEs and real-world cases
Section titled “CVEs and real-world cases”- Most have no CVE. They’re specific to each application and get documented in bug bounty programs.
- CVE-2026-73420 / GHSA-7rqj-j65f-68wh (Auth.js, July 2026).
- The default email normalizer checked for a single
@before applying Unicode normalization. An address with a character that normalizes to@passed validation, and the mailer could send the sign-in link to an attacker-controlled mailbox. - GitHub’s advisory was published on July 20 with CWE-180 and a CVSS 4.0 score of 9.1.
- Fixed in
@auth/core0.41.3,next-auth4.24.15 andnext-auth5.0.0-beta.32. - It’s only exploitable with the email provider enabled, the default normalizer and a mailer that normalizes recipients.
- The default email normalizer checked for a single
- Starbucks (2015). Egor Homakov duplicated balance between gift cards through a race in the transfer. It’s the reference double-spend case (see race conditions).
Testing checklist
Section titled “Testing checklist”- Flows that move value or identity mapped with the four axes.
- Does the server recalculate price, total and discounts, or accept the client’s?
- Negative, zero, huge and wrongly typed quantities (array, string, decimal).
- Can a step be skipped, repeated or reversed (payment, verification, second factor)?
- Coupons: stackable, threshold after removing items, case, email aliases, in parallel.
- Single-use resources sent in parallel (redemption, coupon, refund).
- Refunds and credits repeated with the same request.
- Tokens and challenges: random? bound to user and purpose? do they expire? are they consumed?
- Invitations accepted with another account; plan limits on accept and on downgrade.
- Third-party callbacks called directly, unsigned.
- Emails and names with characters that change when normalized.
- Impact proven with a minimal PoC on your own accounts.
Cheat sheet
Section titled “Cheat sheet”| Concept | What to remember |
|---|---|
| Definition | Valid request, broken assumption. No payload; scanners miss it. |
| Mapping | Action and endpoint · identity · dependencies · state and effect. |
| Three levers | Order · values · identity and state. |
| Questions per step | Many at once? At another moment? With another value? |
| Client-side controls | Hidden, disabled, dropdowns and prices are editable in the proxy. |
| Skipping steps | Direct POST to the last step. If state doesn’t live on the server, order is optional. |
| Race and TOCTOU | Non-atomic check-then-act → parallel requests. Freeze what was authorized. |
| Values | Negative, zero, huge, array vs scalar, client-side price. |
| Replays | Without idempotency, the same refund or redemption N times. |
| Tokens | Random? Bound to the user? Expire? Consumed? End sessions? |
| Accounts | Pre-account takeover and merge by unverified email; re-callable set-password. |
| Second factor | Session valid before the factor · reset removes it · enrollment without re-auth · unlimited OTP. |
| Canonicalization | CWE-180: normalize before validating (@ U+FF20 → @). |
| Callbacks | Third-party webhooks without signature or state = public endpoints. |
| Impact | Expected vs broken flow, with the business outcome in plain sight. |
Review questions
Section titled “Review questions”-
Why does an automated scanner almost never find a logic flaw? Give an example of a legitimate request that is an attack.
Answer
Because there’s no signature to look for: each request is valid and the response is normal. The scanner doesn’t know an order shouldn’t become shipped without payment. Example:
POST /order/confirm {"order":3}on an order that was never paid. -
Map the password reset with the four axes. What do you check about the token?
Answer
Action:
POST /forgotand thenPOST /reset. Identity: the account for the given email. Dependencies: the token that arrives by email. State: beforehand there’s an issued, valid token; afterwards the password changes and sessions should be ended. For the token: that it’s random rather than derived from predictable data, bound to the user (not accepted with anotheruser), expiring, single-use, and that requesting a new one invalidates the old one. -
Explain pre-account takeover. Which two controls prevent it?
Answer
The attacker registers an account with the victim’s email without it being verified. When the victim signs in through a federated provider, the application merges by email and the attacker’s password keeps working. It’s prevented by verifying the email before activating the account and requiring re-authentication (and invalidating previous credentials and sessions) when linking identities.
-
Give five ways to stack discounts in a shop. Which one needs parallel requests?
Answer
A “one coupon” rule only in the UI, stackable types, a threshold checked only on apply, coupons that differ only in case, and email aliases to repeat the “first purchase”. The one that needs parallelism is reusing a single-use coupon through a race.
-
How does the shop know you’ve paid? What do you test against the confirmation step?
Answer
It should know from server-side state, set by the gateway’s signed notification. You try calling confirmation without going through payment, calling the payment callback directly without a signature, and confirming with the ID of a different paid order.
-
How do a balance double spend and a cart TOCTOU differ?
Answer
In the double spend, several identical requests of yours win the window between reading the balance and deducting it. In the cart TOCTOU you modify the object the backend reads again later: what was authorized ($100) and what ships (the current cart) no longer match. The fix for the second is to freeze the cart on authorization and compare it when creating the order.
-
The seat limit is checked when the invitation is sent. Describe the abuse and the fix.
Answer
On the higher plan you send many invitations, downgrade to the free plan and they get accepted afterwards. Fix: check the limit on acceptance, against the plan in force at that moment, and revoke pending invitations on downgrade.
-
After the password is validated you get a cookie and are sent to
/2fa. What do you check?Answer
Whether that cookie or token already works for calling authenticated API endpoints directly without completing the second factor. The pre-second-factor session should be a different type that’s only valid for submitting the code.
-
Why doesn’t a per-IP rate limit protect a 6-digit code?
Answer
Because there are a million combinations and the attacker spreads attempts across many IPs. The counter has to be tied to the code or the account, with few attempts and a short expiry.
-
Explain the fullwidth
@case. Why is the order of validating and normalizing the cause?Answer
The validator counts a single
@in the original string, but the mailer normalizes with NFKC and the@(U+FF20) becomes a second@. What was validated and what is used are different strings. Normalizing first, validation sees both@and rejects the address. -
An external identity verification provider notifies the application through a callback. Which assumptions do you attack?
Answer
That only the provider calls it (is the signature checked?), that the result belongs to a verification started for that account (is it bound to the subject?), that it arrives only once (can it be replayed?) and that it arrives after the process started (can it be marked verified without starting?).
-
Why isn’t a double spend fixed by adding one more
if balance >= amountin the code?Answer
Because the problem is the window between check and act, and another check in code has the same window. The check and the change must happen in one atomic operation: a locked transaction, a conditional
UPDATEor a database constraint.
References
Section titled “References”- PortSwigger — Business logic vulnerabilities
- PortSwigger — Examples of logic flaws
- PortSwigger Research — Smashing the state machine
- OWASP WSTG — Business Logic Testing
- OWASP Top 10 2025 — A06 Insecure Design
- CWE-840 — Business Logic Errors
- CWE-841 — Improper Enforcement of Behavioral Workflow
- CWE-367 — Time-of-check Time-of-use (TOCTOU) Race Condition
- CWE-180 — Incorrect Behavior Order: Validate Before Canonicalize
- GitHub Advisory — GHSA-7rqj-j65f-68wh (Auth.js)
- Unicode — UAX #15: Normalization Forms
- Stripe — Idempotent requests
- OWASP — Password Storage Cheat Sheet