Skip to content
Pwnversity
WEB-RACEexpert · 8 min · upd. 2026-11

Race conditions

OWASP A06:2025CWE-362

A race condition happens when two or more requests touch the same state at the same time and the result depends on the exact order the server processes them. Between the moment the app checks something (balance, coupon, stock, limit) and the moment it acts on it there’s a window —sometimes milliseconds— in which several requests see the “old” state and all pass the check. This is the classic TOCTOU (Time-Of-Check to Time-Of-Use), and with the single-packet technique it’s reliably exploitable over the network.

sequenceDiagram
    participant A as Request A
    participant B as Request B
    participant S as Server / DB
    A->>S: check balance = 100 ✓
    B->>S: check balance = 100 ✓ (same window)
    A->>S: act: subtract 100 → 0
    B->>S: act: subtract 100 → -100 (double spend)

The attacker doesn’t break the logic: they run it many times simultaneously before the state updates. If “redeem coupon” checks used == false and then sets used = true, sending 30 redemptions in parallel can slip several through before the first one writes. The damage is direct business loss: money, stock, limits, uniqueness.

The vulnerable pattern is check-then-act as two separate operations over shared state, with no lock serializing access. The collision window runs from reading the state to writing the new one; the more work in between (validations, external calls), the wider it is. The invariant the attack breaks: check and act must be a single atomic operation —a transaction with sufficient isolation or row locking, a conditional UPDATE whose result is checked, or a lock— so only one of the concurrent requests can win. A transaction alone isn’t enough: under common isolation levels two transactions can both pass the read before either writes.

  • Limit-overrun: spend a single-use resource several times (balance, coupon, gift card).
  • Multi-endpoint: two different endpoints touching the same object in parallel (applying a coupon while confirming payment).
  • Single-endpoint, state collision: two updates to the same record stepping on each other.
  • Partial construction: using a half-built object before its invariants are validated.

Look for operations where “once” or “only N times” matters:

  • Redeeming a coupon/gift card, applying a discount once.
  • Withdrawing balance or transferring (spending the same money twice).
  • Attempt limits (bypass rate limiting), vote or like limits.
  • Reserving a unique stock/seat; registering a unique username/email.
  • Elevating privileges in a two-step flow.

Exploitation — arriving in the same window

Section titled “Exploitation — arriving in the same window”

The goal is for all requests to arrive almost simultaneously, removing network jitter:

  • Single-packet attack (HTTP/2): send ~20-30 requests in a single TCP packet so they arrive together. The modern reference technique (James Kettle). In Burp Repeater, group the tabs and use “Send group in parallel”.
  • Last-byte sync (HTTP/1.1): send all of each request except the last byte, then the last byte of all of them at once.

With Turbo Intruder, the single-packet pattern automates like this:

def queueRequests(target, wordlists):
engine = RequestEngine(endpoint=target.endpoint,
concurrentConnections=1,
engine=Engine.BURP2)
# queue 30 copies behind a closed gate
for i in range(30):
engine.queue(target.req, gate='race1')
# release all 30 at once (single packet)
engine.openGate('race1')

If several responses come back “redeemed successfully” (or the balance drops more than once), there’s a race.

  1. Identify an operation with “single use” or “limit N” and its exact request.
  2. Queue 20-30 identical copies and release them in the same window (single-packet).
  3. Count how many took effect: more than one = race confirmed.
  4. Prove minimal impact (e.g. a coupon applied twice) on your own test account, without draining real balances.

Burp Suite (Repeater with parallel groups, single-packet built in), Turbo Intruder (single-packet / last-byte sync scripts) and, for simple HTTP/1.1 cases, curl + GNU parallel. The abused rule is usually business logic.

Free money (double spend, unlimited coupons), bypassing business limits, breaking uniqueness (two accounts with the same email) and privilege escalation. Crosses with business logic (the repeated rule) and with IDOR when the race acts on identifiable objects.

  • Multiple identical requests to the same resource within a millisecond window from the same user.
  • Inconsistent states: negative balance, a coupon with N uses when the max was 1.
  • Concurrency spikes on a single record.

Log with high-resolution timestamps and a request ID; correlate concurrent requests on the same object. Alert on broken invariants (balance < 0, uses > max).

  1. Atomicity in the database: a transaction at the right isolation level; SELECT ... FOR UPDATE (pessimistic lock) or an UPDATE ... WHERE used=false / version (optimistic) so only one write wins.
  2. Unique constraint in the database (unique index) that fails the second write.
  3. Locks at application/record level (per-user or per-resource locks).
  4. Idempotency keys claimed atomically in durable storage (a unique-constraint insert, INSERT ... ON CONFLICT), not just “accepting the token”: accepting a token doesn’t by itself serialize concurrent retries, and a check-then-insert is vulnerable again.
  5. Don’t separate check and act: resolve it in a single atomic operation. Balance double spend and cart TOCTOU are covered in business logic.

Reconcile the state (reverse redemptions/double spends), add the missing lock or constraint, and review logs for historical abuse of the same pattern.

  • James Kettle — “Smashing the state machine” (PortSwigger, 2023) — introduces the single-packet attack; the basis of modern web race exploitation.
  • Starbucks (2015) — gift-card balance duplication via a race (see business logic).
  • E-commerce and fintech — many HackerOne reports of coupons and balances redeemed multiple times; races in invitations and limits on platforms like GitLab/Shopify.

As they’re almost always application-specific, they rarely get a CVE; they’re documented in bug-bounty programs and in PortSwigger’s research.

  • Are there “single use” or “limit N” operations? (coupon, balance, votes)
  • Does sending 20-30 parallel requests (single-packet) slip more than one through?
  • Can the same resource be spent twice? (limit-overrun)
  • Do two endpoints touch the same object with no shared lock? (multi-endpoint)
  • Is there a unique DB constraint, or only a check in code?
  • Are check and act a single atomic transaction?
  • Are idempotency keys claimed atomically (not a check-then-insert)?
  • Impact proven with a minimal PoC on your own account, without draining real balances.