Race Condition (Limit Overrun)
A limit is checked and then updated in separate steps, so requests sent at the same moment can all pass the check and exceed the limit.
| Severity | Medium |
| CVSS 3.1 | 5.3 CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:N/I:H/A:N Open in the calculator |
| CVSS 4.0 | 6 CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition |
| MITRE ATT&CK | T1190 Exploit Public-Facing Application |
| Category | Insecure Design |
Description
The application enforces a limit by first checking it and then recording the action in a separate step, without making the two steps a single atomic operation. When several identical requests arrive at the same moment, each one passes the check before any of them records its effect, so the limit is exceeded. This is a time-of-check to time-of-use race condition, often called limit overrun.
An attacker can therefore obtain more than the application intends to allow. Typical targets are single-use vouchers and gift cards redeemed several times for repeated discounts, credit duplicated or a balance spent or withdrawn twice, one-per-user actions such as votes, trials, referral bonuses or reviews repeated, and counters that protect against brute force, such as limits on sign-in or one-time code attempts, bypassed to allow many more guesses at a password or one-time code than the lockout permits. The financial or integrity impact depends on the limit involved and on how many requests win the race, which is often several per attempt. Exploitation usually requires an account, and the duplicated actions can be hard to distinguish from genuine ones afterwards.
The window between check and update is often only milliseconds, but sending requests in parallel makes it practical to hit: techniques such as the single-packet attack over HTTP/2 make many requests arrive together, and tools such as Burp Suite's Repeater, sending a group of requests in parallel, and Turbo Intruder automate this. The weakness is identified by sending the same limited request many times at once and checking whether more than one succeeds, by comparing balances, counts or records before and after. Automated scanners rarely find it.
Remediation
Make the check and the update a single atomic operation, so that only one request can ever succeed:
- Put the condition into the update itself and act only if it changed a row, for example a conditional
UPDATEthat marks a voucher used only where it is still unused, or deducts from a balance only where the balance is sufficient. - Otherwise, read and update within one database transaction that locks the row, for example with
SELECT ... FOR UPDATE. - Use database constraints for one-per-user rules, such as a unique index on the user and the offer, so that duplicate inserts fail.
- Use atomic counters, such as Redis
INCR, for attempt limits, incrementing before the attempt is processed rather than after it fails. - Accept an idempotency key on operations that must happen once per request, and reject repeats.
Confirm the fix by repeating the parallel requests and checking that exactly one succeeds and the others are refused.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.