Race Conditions Explained: The Bug That Lets You Spend Money Twice


Imagine an ATM that checks your balance, then hands you cash, then updates the balance — in three separate steps. Now imagine two ATMs doing that at the exact same second. Both check, both see enough money, both pay out. You’ve just spent the same money twice. That gap between “check” and “act” is a race condition, and it’s one of the most profitable bugs in bug bounty hunting.

What Is a Race Condition?

A race condition happens when a system performs a check and an action as separate steps, and two requests squeeze into the gap between them. The classic pattern:

  1. Request A: server checks “does this account have 100 credits?” — yes.
  2. Request B: server checks the same — still yes, because A hasn’t deducted anything yet.
  3. Both requests complete the action. 100 credits spent twice.

The bug isn’t bad code in one request — it’s that two requests racing each other break an assumption the code made: that it would run alone.

Where Hunters Find Them

Race conditions hide anywhere a limited resource is spent:

  • Coupon and discount codes — redeem the same one-time code twice in parallel.
  • Account credits and wallet balances — withdraw or spend the same balance twice.
  • Limited stock or ticket sales — buy the last item twice.
  • Rate limits and vote counters — bypass “one per user” checks by firing requests simultaneously.
  • Password reset and OTP flows — reuse a single-use token before it expires.

How to Test (Legally, In Scope)

Race conditions only count when the target is yours or in an authorized bounty scope — never test a live site without permission. In a lab or an in-scope program:

  1. Find a single-use action — a coupon redemption, a credit spend, a claim button.
  2. Capture the request in Burp Suite (we covered Burp basics in an earlier post).
  3. Send it in parallel — Burp’s Turbo Intruder or a simple script firing 10–20 identical requests at once.
  4. Compare the result — did the action succeed more times than it should have? Check the balance, the order history, the redemption count.
  5. Report with proof — timestamps, request counts, and the before/after balance. Race conditions are hard to reproduce, so evidence is everything.

A basic parallel-request script in Python uses threads — but only point it at targets you are authorized to test, and keep the request count modest. Flooding a target is a denial-of-service, not a bounty report.

Why They Pay Well

Race conditions are hard to find by automated scanners, hard to reproduce, and often directly tied to money — which is why they command serious bounties. They also teach a deep lesson: security isn’t just about blocking bad input, it’s about designing operations that stay correct when the world happens all at once.

The Defense Side

If you build web apps, the fixes are well known: database transactions with proper locking, atomic “check-and-deduct” operations, idempotency keys on requests, and unique constraints on single-use codes. Test your own apps for races the same way hunters do — before someone else does it for money.

Find the gap between check and act, and you’ve found one of the oldest, richest bug classes in security.

Comments

Popular Posts