Race Conditions

A flaw where two or more requests touch the same state in overlapping time windows, so the application observes a value that is already stale (time-of-check vs time-of-use) and performs an action it would otherwise refuse.

What it is

The trust boundary that breaks is atomicity. Application logic assumes that “check a condition, then act on it” happens as one indivisible step. In reality the check and the act are separated by a gap — a DB round-trip, a file write, an output-sanitizer pass, a second DNS lookup — and concurrent requests race into that gap. During it the system holds a transient sub-state that the normal single-request flow never exposes: a coupon still marked unused, a common_member row dropped mid-import, a file on disk before the AV deletes it, a hostname that resolved to a safe IP a millisecond ago.

Two root patterns cover almost every web race:

  • Check-then-act / TOCTOU — the result of a validation is used after it can have changed (if check_email_availability(new): add_collaborator(new)). The classic form across file systems, SSRF filters and verification flows.
  • Limit-overrun — a counter or one-time resource (balance, coupon, OTP attempt budget, gift card) is read and decremented non-atomically, so N parallel requests all see the pre-decrement value. See Limit-Overrun Race Conditions.

Tib3rius’s taxonomy splits web races three ways: limit overrun, state changes (bypassing a step like an MFA prompt), and resource access (reaching a shared resource mid-processing).

Why it matters

Impact tracks whatever the raced operation gates:

  • Money / value — multi-redeemed gift cards and coupons, double-spent balances, refund abuse. “Free money glitch.”
  • Authentication / account takeover — racing an OTP/email binding against its validation logs you in as another user; TOCTOU in email-confirmation flows takes over any store (Shopify, $15,250).
  • RCE — a dropped-table window turns a forum DB import into a pre-auth auth bypass and then LFI→RCE (Discuz! X5.0); a validate-then-delete upload window executes a web shell; memory-level signal-handler and HTTP/2 races in C servers (regreSSHion, mod_http2) corrupt the heap.
  • Isolation / escape — shared-mount and /dev/console races let a container write host files (Leaky Vessels, runC 2025).
  • Data exfiltration — an output sanitizer that runs after the browser renders an <img> loses the race (SearchLeak / EchoLeak).

Severity drivers: the width of the window, how many concurrent requests you can land inside it, whether the raced resource is single-use or money, and whether the sub-state is reachable pre-auth.

How it works

  1. Find a shared-state operation — something that reads state, decides, then mutates it or a side resource.
  2. Prove a sub-state exists — fire a batch of overlapping requests and watch for an anomaly (an extra success, a duplicated side-effect, a 50x, a changed response). Kettle’s insight: automate only this “probe” step; races cluster, so even a harmless detected race flags a shaky framework worth manual work (custom scanners).
  3. Minimise jitter — land the requests in the smallest possible window. Over HTTP/1.1 this is dozens of threads; over HTTP/2+ it is the Single-Packet Attack.
  4. Win the race — repeat; it is a numbers game. Widen the window where you can (slow endpoints, large bodies, delegated processing).

Variants, each with its own page:

  • Single-Packet Attack — the timing primitive: HTTP/2 last-byte sync, first-sequence sync for >1,500-byte / >65,535-byte requests, HTTP/3 single-datagram and QPACK orchestration.
  • Limit-Overrun Race Conditions — multi-use of single-use resources; counters and budgets.
  • Multi-Endpoint Races — racing different endpoints (or steps of a flow) against each other: TOCTOU state-machine abuse.

Where to find it

  • Value / counters: coupon and gift-card redemption, loyalty points, referral bonuses, wallet/withdrawal, “apply once” discounts.
  • Auth state machines: multi-step OTP/magic-link login keyed on a flowId, email-change + verification, MFA enrolment, password reset (MFA Bypass, Account Takeover).
  • File handling: upload pipelines that save-then-validate-then-delete (Unrestricted File Upload); image processors that write a temp file then shell out to ImageMagick/GhostScript.
  • SSRF filters: validate-then-fetch with two independent DNS lookups → DNS Rebinding (TOCTOU SSRF).
  • GraphQL: aliasing many mutations in one operation is a built-in concurrency amplifier → GraphQL Batching Attacks.
  • APIs: any endpoint handling financial transactions, coupons or limited resources — standard API-pentest check (API Security, API Rate Limiting).
  • Native / systems code: signal handlers, shared mounts, HTTP/2 stream state in C — memory-corruption races (Go Panics and Concurrency Bugs for the Go analogue).

How to test

  1. Capture the state-changing request; confirm it has an observable side-effect (balance, “redeemed”, a file at a known path, a session).
  2. Baseline: send it ~10× sequentially and record responses.
  3. Send it ~10–50× concurrently through a synchronised gate (Turbo Intruder gate='race1' + openGate, or Nuclei race: true / race_count). Compare against the sequential baseline.
  4. For HTTP/2+ targets use the Single-Packet Attack (one TCP packet, last byte withheld) to remove network jitter entirely.
  5. For multi-step flows, race two different requests (e.g. identity-binding vs validation) in parallel — not the same request repeated (Multi-Endpoint Races).
  6. If the window is too narrow, widen it: pick a slower variant of the endpoint, add a large body, or chain to a delegated processor.
  7. Confirm by the effect (two successes, a doubled balance, a 200 on an executable path), not by response timing alone.

Checklist:

  • Shared resource or counter that gates money, access or files?
  • Check and act separated by a visible gap (DB, disk, network, sanitizer)?
  • Baseline sequential vs concurrent batch shows an anomaly?
  • Gate/single-packet used so requests land <1 ms apart?
  • Multi-step flow: tried racing different steps, not just repeats?
  • Effect reproduced more than once (ruled out coincidence)?

Exploitation and escalation

  • Limit overrun → value: N successful redemptions / withdrawals from a single-use resource — see Limit-Overrun Race Conditions.
  • State race → auth bypass → takeover: win the window where a flow trusts stale identity, then ride the issued session (Account Takeover, MFA Bypass).
  • Resource-access race → code execution: request an uploaded shell inside the save/delete window (Unrestricted File Upload); or a dropped-table window that makes userlogin() return the “needs-activation” branch for an admin, yielding a forged session cookie (Discuz!).
  • Race as one link in a chain: TOCTOU DNS rebinding is an SSRF-filter bypass feeding cloud-metadata theft (DNS Rebinding, Cloud Metadata Service Exploitation); race-infoleak leaks another user’s request data into a JS gadget. Most high-value races are chained (Vulnerability Chaining).

Bypassing defenses

  • Rate limits are not atomicity. Single-packet concurrency lands 20–30 (or, with first-sequence sync, ~1,000–10,000) attempts inside one rate-limit tick, defeating per-attempt OTP/brute-force throttles.
  • Post-hoc validation loses by design. Save-then-delete uploads, and output sanitizers that run after streaming has begun, both leave an exploitable window regardless of how correct the check is.
  • Locks with the wrong scope / granularity. A lock around the check but not the act, or a per-process lock on multi-process deployments, still races.
  • WAFs / gateways that stagger HTTP/1.1 floods are bypassed by HTTP/2 multiplexing and HTTP/3 (one stream per request, no head-of-line blocking).

Real-world cases

  • Shopify partner email confirmation TOCTOU — check-then-act in email change/verify; take over any store given an employee email. H1 #300305, $15,250. (writeup, analysis)
  • OTP login race → full ATO — parallel init-email(victim) + check-otp(attacker OTP) on a flowId-keyed flow authenticates as the victim; critical bounty. (writeup)
  • Discuz! X5.0 pre-auth RCE — DB import drops common_member first, opening a window where userlogin() returns status −1 for an admin, yielding a forged “session authcode” → auth bypass → admin LFI → RCE (KIS-2026-11). (writeup)
  • Web-shell via upload race — PortSwigger lab: exploit.php saved then deleted after a content check; a GET racing into the gap hits a 200 (writeup, playbook).
  • $10,000 HTTP/2 window race — single-packet state-window bypass on a financial SaaS. (writeup)
  • SearchLeak (M365 Copilot) — streaming <img> fires before the output sanitizer runs; HTML-rendering race in a P2P-injection → SSRF exfil chain (writeup, EchoLeak).
  • Discourse image pipeline TOCTOU — narrow file-swap race widened via jpegoptim, arbitrary file read (CVE-2026-55420). (writeup)
  • regreSSHion (CVE-2024-6387) — signal-handler race in sshd → unauth RCE-as-root on 32-bit glibc Linux. (writeup)
  • Apache mod_http2 (CVE-2026-119618) — race in assign_headers() → heap corruption → RCE; found by Anthropic + Google. (writeup)
  • Leaky Vessels / runC (CVE-2024-23651, CVE-2025-52565) — shared-mount and /dev/console races → container escape (Leaky Vessels, runC 2025).
  • PhpSpreadsheet XmlScanner TOCTOU — double-decoded entity passes the scan then expands → XXE/DoS (advisory).
  • AI-client OAuth races — multi-session token-refresh races in LibreChat / Claude Code; fix is atomic temp-file-plus-rename writes (report).

Prevention

  • Make check and act atomic. A single-statement conditional update (UPDATE ... WHERE status='unused' and check affected rows), SELECT ... FOR UPDATE, or a DB unique constraint on the one-time resource. Validation must be atomic with storage — a file becomes reachable only after it is confirmed valid.
  • Pessimistic/optimistic locking at the right granularity (row, not process); version columns / compare-and-swap.
  • Idempotency keys so repeated/parallel submissions collapse to one effect.
  • Pin the TOCTOU value: resolve DNS once and connect to that IP (DNS pinning) to kill validate-then-fetch SSRF races (DNS Rebinding, SSRF Prevention).
  • Don’t gate on post-hoc output filtering: sanitize before emitting, not after rendering starts.
  • Native code: avoid async-unsafe work in signal handlers; guard shared mounts and HTTP/2 stream state.

Tools

  • Turbo Intruder — the gate system (gate=, openGate) and the single-packet engine; HTTP/3 engine adds single-datagram and QPACK race modes (race-http3.py, gateMode='auto').
  • Burp Repeater — “Send group in parallel” (single-packet); 2025.5 ships a Trigger race condition custom-action template.
  • WebSocket Turbo Intruder — THREADED engine, one WS connection per worker, for WebSocket state-desync races.
  • Nuclei — race: true + race_count (last-byte gating) for templated detection.
  • h3fuzz — HTTP/3 fuzzer, ~100k–180k RPS via a resized connection pool, for HTTP/3 race/TOCTOU work.
  • Custom scanners — automate the “probe” step across many endpoints (race clusters).
  • MAccConc — memory-access tracing + stack-based delay injection for confirming and regression-testing native/kernel races.
  • Burp API-security suites (e.g. BurpAPISecuritySuite) ship ready race scripts.

Sub-pages

See also: Business Logic Vulnerabilities

Sources