Lion Cipher Lab

Exploit and Fix a Race Condition in Your Own Lab

Why it matters

A race condition is one of the most counter-intuitive bugs in software: the code looks obviously correct when you read it top to bottom, and it passes every test you run one request at a time — and then it hands out unlimited money the moment two requests arrive together. The classic form is TOCTOU (time-of-check-to-time-of-use): the app READS some state ('is this coupon unused?'), does a little work, then WRITES ('mark it used, credit the wallet') — and in the gap between the check and the write, other requests read the same not-yet-updated state and all decide they may proceed. The result…

What you'll learn

Steps in this lab

  1. The vocabulary: race conditions, TOCTOU, and the check-then-act gap
  2. Set up: confirm Python, make a folder, install Flask
  3. Build the VULNERABLE app (check, work, then write — no locking)
  4. Prove it is 'correct' one request at a time
  5. Build the attack: fire many requests at once
  6. Run the exploit and watch the limit overrun
  7. Fix it: collapse the check and the act into one atomic UPDATE
  8. Re-run the SAME attack and prove it is closed
  9. Judgment: the real remedies, and why 'make the window smaller' is not one
  10. What you did — and the reflex to keep

Open the full interactive lab →