The lab
here is how portswigger describes it
This lab's purchasing flow contains a race condition that enables you to purchase items for an unintended price. To solve the lab, successfully purchase a Lightweight L33t Leather Jacket. You can log in to your account with the following credentials:
wiener:peter.
the new pieces in this lab#
since this is our first dedicated race-conditions lab, a thorough introduction, because the whole topic rests on these ideas.
- a race condition is a flaw where the outcome of two or more operations depends on the timing in which they happen to interleave. the developer assumed the operations would run one after another (serially), but under concurrency they can overlap, and that overlap produces a state the code never anticipated.
- the race window is the brief interval during which the system is in that in-between, exploitable state. it opens when one operation reads or checks something, and closes when that operation finishes writing the result back. anything that happens inside the window sees the "old" state.
- a collision is when multiple requests land inside the same race window and all act on the same stale state. to collide, the requests must operate on the same shared record (here, the same cart, keyed on your session), and they must arrive close enough together to overlap.
- a limit-overrun (or TOCTOU, "time-of-check to time-of-use") race is the specific pattern in this lab: the application enforces a limit with a check ("has this coupon already been applied?"), and then a separate action ("apply the discount and record that it's been used"). between the check and the record being written, the "already applied" flag is still false. if several coupon-apply requests all read that false flag at once, every one of them passes the check and applies the discount, overrunning the "once only" limit.
- the tool: modern Burp can fire a group of requests in parallel with extreme timing precision (the "single-packet attack" over HTTP/2, surfaced in Repeater as the Custom actions > Trigger race condition template). firing ~20 copies of the coupon-apply request at once maximises the chance that several hit the window together. the method: study the cart flow, confirm the cart is shared server-side state keyed on our session (so collisions are possible), benchmark the "coupon already applied" limit, then fire many coupon-apply requests in parallel so the discount stacks far below our store credit, and buy the jacket.
why the limit can be overrun#
the coupon logic is a classic check-then-act sequence: on each POST /cart/coupon the server (1) reads whether the coupon is already applied, (2) if not, applies the 20% discount, and (3) records that the coupon is now used. steps 1 and 3 touch the same piece of shared state, but they are not atomic, there is a real gap between reading "not applied yet" and writing "applied now". the developer assumed requests arrive one at a time, so by the time a second request checks, the first would already have recorded the coupon. that assumption fails under concurrency. if we send many coupon-apply requests simultaneously, they all execute step 1 before any of them reaches step 3, so every request sees "not applied", passes the check, and applies the discount. the single-use limit is enforced on a flag that is still false for all of them inside the race window. the result is the 20% reduction applied many times over, compounding the price down below our store credit.
Step 1 - study the purchasing flow#
we log in and buy the cheapest item we can, using the provided discount code, so the full purchase flow (add to cart, apply coupon, checkout) lands in the proxy history for study.

Step 2 - map the cart endpoints and restrictions#
in the proxy history we identify every endpoint that touches the cart. POST /cart adds items; POST /cart/coupon applies the discount code. we probe the restrictions: applying the discount code a second time returns Coupon already applied, that single-use rule is the limit we'll try to overrun.
Step 3 - confirm the cart is shared, session-keyed state#
with an item in the cart, we send GET /cart to Repeater and try it with and without our session cookie. without the cookie we only ever see an empty cart. from this we infer two things that make a race possible:
- the cart's state is stored server-side in our session, not client-side.
- cart operations are keyed on our session id / user id, so concurrent requests all act on the same shared record. that shared, session-keyed state is exactly what a collision needs. we reason there may be a race window between first applying the discount and the database recording that it's been used.
Step 4 - benchmark the limit#
we make sure no discount is currently applied, then send POST /cart/coupon to Repeater and send it twice in sequence. the first response confirms the discount was applied; the second rejects it with Coupon already applied. so sent serially, the limit holds, exactly what we need to beat with concurrency.

Step 5 - trigger the race condition#
we remove the discount code from the cart. in Repeater we open the Custom actions side panel, click New > From template, and select Trigger race condition. we save the template without modifying it. clicking the action beside Trigger race condition sends the POST /cart/coupon request 20 times in parallel. we refresh the cart in the browser and confirm the 20% reduction has been applied more than once, the limit was overrun and the order is significantly cheaper.


Step 6 - prove the concept on the jacket#
we remove the applied codes and the arbitrary item, and add the Lightweight L33t Leather Jacket to the cart instead. we resend the group of POST /cart/coupon requests in parallel, then refresh and check the order total:
- if the total is still above our remaining store credit, we remove the discount codes and repeat the parallel attack (stacking more reductions).
- once the total drops below our store credit, we purchase the jacket.


how the whole attack worked, in detail#
step back and trace the full mechanism.

the intended (serial) design. each POST /cart/coupon is meant to run to completion before the next begins. in order: the server reads the cart's coupon_applied state; sees it is false; applies a 20% discount to the total; and writes coupon_applied = true. a second request then reads true and is rejected with "Coupon already applied". enforced one-at-a-time, the coupon can only ever reduce the price once.
the race window. the vulnerability is the gap between the read ("is it applied?") and the write ("mark it applied"). during that gap the state still says false. in a single request the gap is invisible, nothing else runs in it. but the gap is real wall-clock time on the server, and if two requests overlap, the second can perform its read before the first performs its write.
the collision. because the cart is shared server-side state keyed on our session (Step 3), every one of our concurrent requests reads and writes the same coupon_applied flag, that's the shared record required for a collision. we send 20 copies of the coupon-apply request as close to simultaneously as possible (the single-packet attack aligns them to within microseconds). many of them execute their read step inside the same window, before any has written back. all of those reads return false, so all of them pass the "already applied?" check, and all of them apply the 20% discount. the single-use limit is enforced against a flag that was still false for every request in the window.
the compounding effect. each successful apply reduces the running total, and with the discount applied N times the price is driven far below its real value, eventually under our store credit, letting us check the jacket out for an unintended price. if one burst doesn't stack enough reductions, repeating the parallel attack adds more.
the root cause in one line. a limit ("use this coupon once") was enforced with a non-atomic check-then-act on shared state, so concurrent requests all passed the check against the same stale value before any of them updated it.
with this, the lab is solved!
