← Race Condition lesson
Advanced / Zero-DayRace ConditionAdvanced35 min+100 XP

Referral Loop

The Referral Service checks whether referral bonus was already used, waits, then writes the result. Two concurrent requests can pass the same check.

“The coupon was valid once. Two requests arrived at the same time.”

CWE-362OWASP Top 10 A04:2021OWASP ASVS 5.1.5
The story
A one-time action has three moments: check, decide, commit. If another request can enter between check and commit, both can believe they are first.

The server reads state, waits, then writes. Two concurrent requests both read the unused state and both commit. The invariant 'used once' is enforced by timing rather than by an atomic operation.

Your objective
  • Inspect the one-time action
  • Identify the check-to-write window
  • Send concurrent requests and capture the flag
Boundary under test

Check to commit

Field guide · request anatomy

Where to look before you type a payload

01Check

The handler reads a balance, quota or status and decides the action is allowed.

02Wait

Time passes while another request performs the same check using the same starting state.

03Act

Both requests write. Without a lock or conditional update, both succeed.

04Commit

The database records an impossible state, such as a negative balance or duplicate redemption.

Progressive hints

Open one hint at a time. The first two build the model; the last two point at the boundary.

Hint 1

Find the one-time action.

Hint 2

Send two identical requests at the same time.

Hint 3

Send two identical POSTs to /claim at the same time.

Hint 4 · near the answer

Win the race and capture the flag.

Guided workbench

Observe → Hypothesize → Test → Prove → Explain

This is the same loop a reviewer expects in a report. Your draft stays in this browser; nothing is submitted until you choose to export it.

0/15steps complete
Observe0/3
Hypothesize0/3
Test0/3
Prove0/3
Explain0/3

Evidence log

Write for a reviewer who was not in the room. Every claim needs a request, response or state change behind it.

Preview the evidence report
# Lab evidence report — Referral Loop

- Family: Race Condition
- Lab ID: web-race-referral
- Date: 2026-12-05

## Workflow

### Observe

- [ ] Open "Referral Loop" and record /claim, the HTTP method and the role you are given.
- [ ] List every parameter, header, cookie and object identifier the normal flow exposes.
- [ ] Save a baseline response: status, body shape, timing and the fields that change by user.

### Hypothesize

- [ ] Name the server decision that protects /claim, and the evidence it should use.
- [ ] Use the clue as a constraint, not an answer: The check and the commit are separated by a deliberate delay. Send two identical requests at the same time.
- [ ] Predict the exact status, body or state change that would prove the decision is missing.

### Test

- [ ] Start from the baseline and change one value: two identical requests in parallel.
- [ ] Keep the request replayable; vary encoding, method or identifier location only after the first result.
- [ ] Capture the full request and response for the winning attempt, including the flag.

### Prove

- [ ] Capture the flag and name the exact foreign object, role or state change it proves.
- [ ] Repeat from a clean session and confirm the result is not cached or stale.
- [ ] State impact precisely: what data or action did you actually obtain?

### Explain

- [ ] State the root cause without naming the payload: which decision failed?
- [ ] Name the control that prevents recurrence and the layer where it belongs.
- [ ] Write one regression test that fails before the fix and passes after it.

## Evidence

### Target and baseline

_Not recorded._

### Hypothesis

_Not recorded._

### Winning request

_Not recorded._

### Proof

_Not recorded._

### Root cause

_Not recorded._

### Control and regression test

_Not recorded._

## Analyst conclusion

The proof demonstrates the missing control above. The regression test should fail against the vulnerable behavior and pass after remediation.
Solution and debrief
Locked until you capture the flag.

The full request, the reasoning and the debrief unlock after a successful capture. That is deliberate: struggle first, then consolidate.

What a reviewer will ask

False positives to rule out

  • Sequential duplicate requests are rejected: the control may still fail under concurrency; test parallel execution.
  • One request returns 409: inspect the final state, not only the response of the losing request.
  • The UI disables the button: an HTTP client can send many requests directly.

Regression tests to name

  • Parallel coupon: Exactly one succeeds and the ledger records one redemption
  • Parallel refund: The total refunded never exceeds the payment
  • Inventory: One reservation succeeds and inventory never becomes negative
The defender's move
  • Use atomic transactions, row locks or conditional updates.
  • Add unique constraints and idempotency keys.
  • Make the check and the commit one indivisible operation.
See the secure-code pattern and all 4 regression tests →
الخلاصة

بين الفحص والتنفيذ نافذة؛ إذا لم تكن ذرية، فهي ثغرة.