# 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 ([[#Real-world cases|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 ([[#Tools|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**. ([[raw/oxo.is/bypass-partner-email-confirmation-to-take-over-any-store-15-250-15690|writeup]], [[raw/medium.com/the-gap-between-check-and-use-how-a-race-condition-earned-15-250-from-14815|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. ([[raw/medium.com/race-condition-authentication-bypass-full-account-takeover-4362|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). ([[raw/karmainsecurity.com/chaining-security-bugs-in-discuz-x5-0-from-race-condition-to-pre-auth-9623|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 ([[raw/medium.com/web-shell-upload-via-race-condition-13759|writeup]], [[raw/medium.com/the-file-upload-vulnerabilities-playbook-14235|playbook]]). - **$10,000 HTTP/2 window race** — single-packet state-window bypass on a financial SaaS. ([[raw/medium.com/how-i-turned-a-single-packet-mismatch-into-a-10-000-single-packet-race-14400|writeup]]) - **SearchLeak (M365 Copilot)** — streaming `<img>` fires before the output sanitizer runs; HTML-rendering race in a P2P-injection → SSRF exfil chain ([[raw/varonis.com/searchleak-how-we-turned-m365-copilot-into-a-one-click-data-exfiltrati-9315|writeup]], [[EchoLeak]]). - **Discourse image pipeline TOCTOU** — narrow file-swap race widened via `jpegoptim`, arbitrary file read (CVE-2026-55420). ([[raw/slcyber.io/a-jpeg-a-race-and-a-ghost-breaking-discourse-s-image-pipeline-12233|writeup]]) - **regreSSHion (CVE-2024-6387)** — signal-handler race in sshd → unauth RCE-as-root on 32-bit glibc Linux. ([[raw/wiz.io/rce-vulnerability-in-openssh-everything-you-need-to-know-9626|writeup]]) - **Apache mod_http2 (CVE-2026-119618)** — race in `assign_headers()` → heap corruption → RCE; found by Anthropic + Google. ([[raw/wiz.io/critical-rce-vulnerability-in-apache-http-server-everything-you-need-t-14333|writeup]]) - **Leaky Vessels / runC (CVE-2024-23651, CVE-2025-52565)** — shared-mount and `/dev/console` races → container escape ([[raw/wiz.io/leaky-vessels-runc-and-buildkit-container-escape-vulnerabilities-every-9724|Leaky Vessels]], [[raw/sysdig.com/new-runc-vulnerabilities-allow-container-escape-in-docker-and-kubernet-3454|runC 2025]]). - **PhpSpreadsheet XmlScanner TOCTOU** — double-decoded entity passes the scan then expands → XXE/DoS ([[raw/github.com/phpspreadsheet-xmlscanner-bypass-via-double-encoded-unentity-toctou-al-12617|advisory]]). - **AI-client OAuth races** — multi-session token-refresh races in LibreChat / Claude Code; fix is atomic temp-file-plus-rename writes ([[raw/redcaller.com/major-ai-clients-shipping-with-broken-oauth-implementations-june-2026-9161|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 - [[Single-Packet Attack]] — the HTTP/2/3 timing primitive that makes remote races local. - [[Limit-Overrun Race Conditions]] — multi-redeeming single-use resources and counters. - [[Multi-Endpoint Races]] — racing different endpoints/steps (TOCTOU state-machine abuse). See also: [[Business Logic Vulnerabilities]] ## Sources - [[raw/portswigger.net/how-to-build-custom-scanners-for-web-security-research-automation-5577|How to build custom scanners for web security research automation]] - [[raw/portswigger.net/turbo-intruder-embracing-the-billion-request-attack-4240|Turbo Intruder: Embracing the Billion-Request Attack]] - [[raw/portswigger.net/http-3-in-burp-suite-it-s-time-to-find-a-bigger-wordlist-12081|HTTP/3 in Burp Suite - it's time to find a bigger wordlist]] - [[raw/portswigger.net/websocket-turbo-intruder-unearthing-the-websocket-goldmine-8619|WebSocket Turbo Intruder: Unearthing the WebSocket Goldmine]] - [[raw/portswigger.net/burp-suite-professional-2025-5-release-3409|Burp Suite Professional 2025.5 Release]] - [[raw/portswigger.net/can-ai-do-novel-security-research-meet-the-http-terminator-11152|Can AI do novel security research? Meet the HTTP Terminator]] - [[raw/flatt.tech/beyond-the-limit-expanding-single-packet-race-condition-with-a-first-s-6120|Beyond the Limit: Expanding single-packet race condition]] - [[raw/medium.com/how-i-turned-a-single-packet-mismatch-into-a-10-000-single-packet-race-14400|How I Turned a Single Packet Mismatch into a $10,000 Single-Packet Race Condition]] - [[raw/medium.com/race-condition-authentication-bypass-full-account-takeover-4362|Race Condition Authentication Bypass: Full Account Takeover]] - [[raw/medium.com/web-shell-upload-via-race-condition-13759|Web Shell Upload via Race Condition]] - [[raw/medium.com/the-gap-between-check-and-use-how-a-race-condition-earned-15-250-from-14815|The Gap Between Check and Use: How a Race Condition Earned $15,250 from Shopify]] - [[raw/oxo.is/bypass-partner-email-confirmation-to-take-over-any-store-15-250-15690|Bypass partner email confirmation to take over any store ($15,250)]] - [[raw/medium.com/backend-mastery-the-real-bug-bounty-superpower-2026-3601|Backend Mastery: The Real Bug Bounty Superpower (2026)]] - [[raw/karmainsecurity.com/chaining-security-bugs-in-discuz-x5-0-from-race-condition-to-pre-auth-9623|Chaining Security Bugs in Discuz! X5.0: from Race Condition to Pre-Auth RCE]] - [[raw/slcyber.io/a-jpeg-a-race-and-a-ghost-breaking-discourse-s-image-pipeline-12233|A JPEG, a Race, and a Ghost: Breaking Discourse's Image Pipeline]] - [[raw/slcyber.io/how-practical-is-100k-requests-per-second-introducing-h3fuzz-12316|How practical is 100k requests per second? Introducing h3fuzz]] - [[raw/varonis.com/searchleak-how-we-turned-m365-copilot-into-a-one-click-data-exfiltrati-9315|SearchLeak: Turning M365 Copilot Into a One-Click Data Exfiltration Weapon]] - [[raw/wiz.io/rce-vulnerability-in-openssh-everything-you-need-to-know-9626|RCE vulnerability in OpenSSH (regreSSHion, CVE-2024-6387)]] - [[raw/wiz.io/critical-rce-vulnerability-in-apache-http-server-everything-you-need-t-14333|Critical RCE in Apache HTTP Server mod_http2 (CVE-2026-119618)]] - [[raw/wiz.io/leaky-vessels-runc-and-buildkit-container-escape-vulnerabilities-every-9724|Leaky Vessels: runC and BuildKit container escape]] - [[raw/sysdig.com/new-runc-vulnerabilities-allow-container-escape-in-docker-and-kubernet-3454|New runC Vulnerabilities Allow Container Escape]] - [[raw/github.com/phpspreadsheet-xmlscanner-bypass-via-double-encoded-unentity-toctou-al-12617|PhpSpreadsheet XmlScanner TOCTOU bypass allows XXE]] - [[raw/redcaller.com/major-ai-clients-shipping-with-broken-oauth-implementations-june-2026-9161|Major AI Clients Shipping With Broken OAuth Implementations]] - [[raw/projectzero.google/testing-race-conditions-with-memory-access-tracing-and-stack-based-del-11978|Testing race conditions with memory access tracing and stack-based delay injection]] - [[raw/tib3rius.com/web-appsec-interview-questions-5906|Web AppSec Interview Questions]] - [[raw/nahamsec.com/top-vulnerabilities-for-pentest-bug-bounty-in-2025-4269|Top Vulnerabilities for Pentest & Bug Bounty in 2025]] - [[raw/intigriti.com/31-bite-sized-tips-and-bug-bounty-resources-for-2026-3611|31 Bite-Sized Tips and Bug Bounty Resources for 2026]] - [[raw/projectdiscovery.io/the-ultimate-guide-to-finding-bugs-with-nuclei-projectdiscovery-4445|The Ultimate Guide to Finding Bugs With Nuclei]]