Skip to content
Back to Blog
·10 min read·technology

Race Condition Attacks in Web Apps: TOCTOU and Limit Overruns

Race condition attacks exploit TOCTOU timing windows and limit overruns to duplicate coupons, drain wallets, and oversell stock. A guide for Indian dev teams.

BR

Bachao.AI Research Team

Cybersecurity Research

Scan Your Attack Surface

Security exposure this creates

Unpatched vulnerabilities in your tech stack are the #1 entry point for breaches targeting Indian businesses. Here's what to watch.

A race condition attack exploits the timing gap between when an application checks a condition and when it acts on it — the time-of-check-to-time-of-use (TOCTOU) window. By firing multiple requests at the exact same instant, an attacker makes a system evaluate the same "is this allowed" check several times before any is marked complete, so a single-use coupon gets redeemed ten times, a wallet withdrawal clears twice, or stock shown as sold out still ships. This is a limit-overrun attack, one of the most underestimated flaws in fintech and e-commerce apps today. The fix is not more validation — it's atomicity: locking, idempotency keys, and database constraints that make concurrent requests physically unable to both win.

What a Race Condition Attack Actually Is

Most web applications validate business rules in application code: check the coupon hasn't been used, check the balance covers the withdrawal, check the item is in stock — then perform the action. Under normal single-request traffic that sequence is safe. The problem appears the moment two or more requests for the same operation arrive close enough together that both pass the check before either has recorded its result.

graph TD A[Send Concurrent Requests] --> B[Checks Pass Together] B --> C[Limit Overrun Occurs] C --> D[Unintended State Reached] D --> E[Fix With Locking] style A fill:#1e3a5f,stroke:#3B82F6,color:#e2e8f0 style B fill:#1e3a5f,stroke:#3B82F6,color:#e2e8f0 style C fill:#5f1e1e,stroke:#EF4444,color:#e2e8f0 style D fill:#5f1e1e,stroke:#EF4444,color:#e2e8f0 style E fill:#1e3d2f,stroke:#10B981,color:#e2e8f0

This class of bug is formally tracked as CWE-362 — Concurrent Execution using Shared Resource with Improper Synchronization — and TOCTOU (CWE-367) is its most common web manifestation. It predates the web by decades, in operating systems and file handling. Modern web apps, built on stateless handlers hitting shared databases, reintroduced the same bug at the application layer, and most developers never think about it because ORMs make check-then-act feel deceptively safe.

ℹ️
INFO
TOCTOU is not limited to money and coupons. It shows up in password-reset flows using a token twice before it's invalidated, duplicate account creation on the same email, role changes not applied before an action completes, and rate limiters bypassed by bursting past the counter increment.

Limit-Overrun Attacks: Redeeming and Withdrawing More Than Once

A limit-overrun attack is the financially damaging form of a race condition: any rule enforcing "this may happen at most N times" is a target if the enforcement isn't atomic.

Attack PatternWhat Should HappenWhat Actually Happens Under Race
Coupon or voucher redemptionCoupon used once, marked redeemedSame coupon applied 5-50 times in parallel requests before the "used" flag commits
Wallet or account balance withdrawalBalance debited once per withdrawalTwo simultaneous withdrawal requests both read the same starting balance and both succeed
Referral or signup bonusBonus credited once per unique referralAttacker fires duplicate referral-claim requests before the "already claimed" check writes
Inventory and flash-sale checkoutStock decremented, sold out enforcedMore units sold than exist because stock checks race ahead of the decrement
API rate limitsRequests capped per windowBurst of parallel requests all pass the counter check before increments land
⚠️
WARNING
Limit-overrun bugs rarely throw errors. Every individual request looks completely valid to logging and monitoring — no malformed input, no injection payload, nothing that trips a WAF signature. The only signal is the aggregate outcome: a balance that shouldn't be possible, or a coupon usage count that exceeds one.

The Single-Packet Attack: Making the Race Window Reliable

Early race-condition exploitation was unreliable because network jitter — the variable delay between requests leaving the attacker's machine and arriving at the server — meant "simultaneous" requests often landed milliseconds apart, enough time for the server to process one before the other arrived. Security researcher James Kettle's PortSwigger Research published "Smashing the state machine: the true potential of web race conditions" in 2023, introducing the single-packet attack technique, which withholds the final byte of 20-30 HTTP/2 requests and releases them together in one TCP packet, eliminating network jitter as a variable.

CWE-362Official MITRE classification for the Race Condition weakness class (MITRE CWE Database)
4-10xReported effectiveness gain of the single-packet attack over prior race-condition timing techniques (PortSwigger Research, "Smashing the state machine," 2023)
6.08 million USDAverage cost of a data breach in the financial services sector, 22% above the global average (IBM Cost of a Data Breach Report, 2024)

This research moved race conditions from a hard-to-reproduce curiosity into a practical, repeatable technique that any tester with Burp Suite's Repeater tab can now run — and the same tooling is equally available to an attacker probing a checkout flow, wallet API, or coupon endpoint.

Know your vulnerabilities before attackers do

Run a free VAPT scan — takes 5 minutes, no signup required.

Book Your Free Scan

Real Impact for Indian Fintech and E-Commerce

Indian digital-payment and e-commerce platforms are structurally exposed to this bug class for the same reason they're valuable targets: high request volume, real-time balance and inventory logic, and growth-stage engineering that prioritises shipping over hardening every state transition. A wallet top-up, UPI-linked balance check, cashback credit, or flash-sale checkout is exactly the check-then-act logic race conditions exploit — and unlike a stolen card number, a successful limit-overrun exploit produces direct financial loss with no fraud-detection lag, because every individual transaction looks legitimate.

The RBI's Cyber Security Framework for banks requires regulated entities to maintain a board-approved cybersecurity policy covering transaction integrity, treating detection and response — not just prevention — as a core obligation. A race condition in a balance or ledger update is exactly the transaction-integrity failure that framework expects institutions to have already tested for, not discovered from a support ticket. Flash sales and limited-inventory drops are the e-commerce equivalent: fixed quantity, high concurrent demand, a check-then-decrement pattern under load, where overselling becomes direct loss on loss-leader promotions.

🛡️
SECURITY
Race condition losses rarely appear as a single large incident. They surface gradually, as reconciliation mismatches, unexplained ledger drift, or a coupon-liability number that keeps climbing — easy to write off as "data quality issues" for weeks before anyone traces the root cause to concurrent request handling.

How Security Teams Discover Race Conditions

Finding race conditions requires deliberately looking for them; they rarely surface through functional QA, because a single test request never triggers the bug.

  1. Map check-then-act endpoints — any request that reads a value (balance, stock count, usage flag) and later writes based on that read is a candidate, found through code review of the handler, not the API spec.
  2. Send grouped concurrent requests — using Burp Suite Repeater's "send group in parallel" feature, or the single-packet attack for HTTP/2 targets, fire the same request 10-30 times simultaneously.
  3. Compare expected vs. actual state — check whether the coupon, balance, or stock count moved once or multiple times.
  4. Vary timing and volume — some race windows only open at specific request counts or delays, so testers sweep a range rather than trying once.
  5. Check for token and idempotency key reuse — many exploits combine the race with reuse of a session token, API key, or one-time code across the parallel requests.
💡
TIP
If your team runs regular VAPT assessments, ask explicitly whether concurrent-request and race-condition testing is included in scope. Many standard web app pentests focus on injection, auth, and access control, and skip multi-request timing attacks unless specifically requested.

Defending Against Race Conditions

The fix is architectural, not procedural. No amount of added validation closes a TOCTOU gap, because the vulnerability is in the sequencing of check and act, not the correctness of either step.

DefenceHow It Closes the GapWhere to Apply It
Database unique constraintsMakes a duplicate write physically fail at the DB layer, regardless of application logicCoupon redemption records, referral claims, one-time token usage
Atomic operations (UPDATE ... WHERE balance >= amount)Combines check and act into a single indivisible DB statementWallet debits, inventory decrements
Row-level locking (SELECT ... FOR UPDATE)Forces concurrent transactions touching the same row to queue rather than interleaveBalance updates, stock reservation during checkout
Idempotency keysEnsures a retried or duplicated request with the same key executes exactly oncePayment initiation, withdrawal requests, order creation
Serializable transaction isolationPrevents one transaction from seeing another's uncommitted intermediate stateMulti-step financial transactions spanning several tables
Application-level distributed locks (Redis, etc.)Serializes access to a resource across multiple app server instancesHigh-throughput endpoints where DB locking alone creates contention
🚨
DANGER
A lock or constraint added only in application code — an in-memory flag, a variable set before the DB call — does nothing against a real race, because it doesn't survive across concurrent requests handled by different server processes or threads. The enforcement has to live at the layer that's actually shared and atomic: the database, or a dedicated locking service.
🎯Key Takeaway
A race condition is not a bug you patch by adding a check — it's fixed by removing the gap between checking and acting. If validation and state change are two separate steps that concurrent requests can interleave, an attacker with nothing more than Burp Suite's Repeater can turn that gap into free money, unlimited coupon usage, or oversold inventory, and none of the individual requests will look malicious in your logs.

Building This Into Your Engineering Process

Race condition testing needs to be a deliberate line item in code review and security testing, not an afterthought found after a finance team flags a reconciliation gap. Every endpoint enforcing a limit — redemption counts, withdrawal caps, stock levels, one-time actions — should have an explicit answer to "what happens if this exact request arrives twice in the same millisecond," enforced at the database layer.

At Bachao.AI, automated VAPT assessments probe exactly this class of concurrency flaw across authentication, payment, and business-logic endpoints, alongside the broader vulnerability classes most web app pentests cover. Dhisattva AI Pvt Ltd built the platform on the premise that the most damaging bugs are rarely exotic — they're ordinary check-then-act patterns never tested under real concurrent load. If your checkout, wallet, or coupon flow has never been deliberately race-tested, a free VAPT scan is a fast way to find out where the gaps sit. For platforms where a reconciliation failure could trigger regulatory exposure, our DPDP compliance guide covers the broader obligations, and our blog has more attack-pattern breakdowns like this one.

Where Race Conditions Fit Among Business-Logic Risks

Race conditions sit alongside other business-logic flaws as the class most likely missed by automated scanners, since there's no malformed payload to flag — the exploit is purely timing and sequencing.

pie title Race Condition Impact Areas "Coupon and Voucher Abuse" : 28 "Wallet and Balance Drain" : 26 "Inventory Overselling" : 20 "Referral and Bonus Abuse" : 16 "Rate Limit Bypass" : 10

Coupon abuse and wallet-balance manipulation dominate impact because they translate directly into liquid financial loss, while inventory overselling and rate-limit bypass produce operational and reputational damage that's harder to quantify but still real.

Frequently Asked Questions

Frequently Asked Questions

What is a TOCTOU race condition in web applications?
TOCTOU (time-of-check-to-time-of-use) is a race condition where an application checks a condition — such as balance or coupon validity — then acts on it as a separate step. If concurrent requests land in that gap, more than one can pass the check before either records its result, letting an action happen multiple times when it should happen once.
What is a limit-overrun attack?
A limit-overrun attack is the practical exploitation of a TOCTOU race condition against any rule that caps how many times something can happen — redeeming a coupon, withdrawing a balance, claiming a referral bonus. Sending many requests at nearly the same instant gets the check to pass repeatedly before the system records the limit was reached.
What is the single-packet attack technique?
The single-packet attack, published by PortSwigger Research in 2023, sends a group of HTTP/2 requests that all complete at the exact same moment by withholding the final byte of each and releasing them together in one TCP packet. This eliminates network jitter, making race-condition exploitation far more reliable than older techniques.
How do you detect race conditions in a web application?
Map every endpoint with a check-then-act pattern, then fire grouped concurrent requests at each using a tool like Burp Suite's Repeater and compare the expected outcome against what actually happened in the database. Standard functional testing rarely catches these bugs because a single test request can never trigger the race.
What is the correct way to fix a race condition?
Close the gap between checking and acting rather than adding more validation. Use atomic database operations, row-level locking such as SELECT ... FOR UPDATE, unique constraints, idempotency keys on writes, and serializable transaction isolation. The enforcement must live at the shared, atomic layer — the database — not in per-request application memory.
Are race conditions a common finding in security testing of Indian fintech apps?
They're a well-documented, recurring class of business-logic flaw across payment, wallet, and e-commerce platforms, because high-concurrency check-then-act logic around balances and inventory is common in these systems. Standard penetration tests don't always include dedicated concurrent-request testing unless explicitly scoped, so teams should confirm it's covered rather than assume it.
BR

Bachao.AI Research Team

Cybersecurity Research

AI-powered security research and threat intelligence from the Bachao.AI team. Covering the latest vulnerabilities, CVEs, and cybersecurity developments affecting Indian businesses.

Get cybersecurity insights for Indian SMBs

Weekly vulnerability alerts, DPDP compliance tips, and security guides. No spam — unsubscribe anytime.

We respect your privacy. Your email is never shared.

Find out if you're exposed to this class of threat

Free automated scan — risk score in under 2 hours. No credit card required.

Scan Your Attack Surface
Find your vulnerabilitiesStart free scan →