In short
A race condition occurs when the result of an operation depends on the order in which concurrent processes are executed. In a web application, an attacker sends multiple requests simultaneously to slip between a validation check and the corresponding update: using a single-use promo code multiple times, withdrawing more than their balance, or bypassing an attempt limit. The fix involves atomic operations on the database side.
How it works
Let’s take a single-use discount coupon as an example. The application verifies that the coupon has not been used, applies the discount, and then marks the coupon as redeemed. There is a brief window between the verification and the marking. If multiple requests arrive simultaneously, some will pass the verification before the first one has recorded the use: the discount is applied multiple times.
This scenario has a name: TOCTOU (time of check to time of use), listed as CWE-367. The time windows are often measured in milliseconds, but techniques such as the “single-packet” attack, presented by PortSwigger in 2023, make it possible to send numerous HTTP/2 requests simultaneously.
Typical examples
- Promo codes, gift cards, or referral codes used multiple times.
- Transfers or withdrawals that exceed the available balance.
- Attempt limits (login, verification code) bypassed through simultaneous attempts.
- Votes or registrations counted multiple times.
How to Protect Against It
- Make the operation atomic: a single SQL query that both checks and updates at the same time (UPDATE … WHERE use = false), or a transaction at an appropriate isolation level.
- Lock the resource during processing (row lock, distributed lock).
- Rely on database uniqueness constraints to prevent duplicates.
- Use idempotence keys for payment transactions.
Frequently asked questions
Does an automated scanner detect race conditions?
Rarely: it is necessary to identify which operation is vulnerable and send synchronized requests to the correct location. This type of vulnerability is most often discovered during a penetration test that examines the application’s logic.
Sources
Find out where an attacker would get in.
Our AI agents actually attack your scope, fully automated, and hand you the proof of every vulnerability.
