Vulnerability class

How to prove a race condition, and verify the fix with concurrency

Updated

A race condition is proven when parallel requests break an invariant that sequential requests preserve — spending a balance twice, redeeming a coupon twice, accepting two invites to one seat. Prove it with a burst, and verify the fix with the same burst.

Where this class of bug actually lives in an endpoint with a check before a write

  • Balance and credits. Read, compute, write in three statements with no lock or transaction.
  • One-time codes. Password resets, invites, coupons, gift cards: checked then marked used, in two steps.
  • Limits and quotas. Seat counts, plan limits, rate limits implemented as a count then an insert.
  • Uniqueness without a constraint. An application check for an existing record instead of a database unique index.

What to try first

  1. Send the same state-changing request 20 times concurrently and compare the final state with one sequential run.
  2. Do it on the cheapest value: a coupon, a test credit, a free seat.
  3. Look for a check-then-act across two statements in the handler before you spend the burst.
  4. Retest after a fix with the same concurrency and the same starting state.

A reproduction you can keep

Twenty parallel requests, one invariant. Compare the count before and after:

Concurrent redemption
# before
curl -sS https://staging.example.com/api/me -H 'Authorization: Bearer ***' | jq .credits

# 20 at once
seq 20 | xargs -P 20 -I{} curl -sS -o /dev/null -X POST \
  https://staging.example.com/api/redeem \
  -H 'Authorization: Bearer ***' -H 'Content-Type: application/json' \
  -d '{"code":"GIFT-25"}'

# after
curl -sS https://staging.example.com/api/me -H 'Authorization: Bearer ***' | jq .credits

# vulnerable: credits up 500 from one code
# fixed: up 25, and 19 of the 20 responses say already redeemed

What "fixed" has to look like

Make the check and the write atomic — a single conditional UPDATE, a row lock inside a transaction, or a unique constraint that the database enforces. Verify by rerunning the exact burst from the same starting state and confirming the invariant held.

Where people get this wrong

  • A transaction alone does not prevent this at the default isolation level; the read and the write have to be ordered by a lock or a conditional write.
  • Rate limiting is not atomicity. Twenty requests inside the limit still race.
  • In-process locks fail the moment the app runs in more than one worker.

What Offense does here

Offense runs an agent swarm against your app in a disposable sandbox, keeps the request, the identity and the vulnerable response as evidence, and replays the same attack after the fix so the retest is a control comparison rather than a green check. It does not read your source and it does not patch your code: the finding goes to your coding agent with the reproduction attached. The hosted workspace is invite-only — join the waitlist — and the free dependency audit in /install needs no account.

Questions this page answers

How do I test for a race condition without load-testing tooling?

xargs -P 20 or a small concurrent script is enough. The window is usually milliseconds, and twenty simultaneous requests hit it.

Does a database transaction fix a race?

Only with the right isolation or an explicit lock. A read-then-write inside a default-isolation transaction still races.

Written by Offense Research, reviewed December 2, 2026. Correct something? Email imran@offenseresearch.com.