The lab
here is how portswigger describes it
This lab has a logic flaw in its purchasing workflow. To solve the lab, exploit this flaw to buy a "Lightweight l33t leather jacket". You can log in to your own account using the following credentials:
wiener:peter
there are two coupon codes, and the checkout stops you reusing the same code twice in a row, but that is the only check. it only remembers the code applied immediately before, so if we alternate between the two codes neither one is ever the one that came just before, and the discount stacks over and over until the jacket is basically free.
why alternating defeats the check#
the rule the developer wanted was "each coupon once per order". what they actually built was "you cannot apply the same code as the previous apply". that is a weaker rule, it only compares against the last code used, not the full history of what has been applied. so A, A is blocked but A, B, A, B, ... sails through, because every application differs from the one before it. the business rule exists but is enforced with no memory, and that short memory is the whole flaw.
Step 1 - Collect the coupons#
we log in and notice a coupon code on the page, NEWCUST5.

at the bottom of the page we sign up to the newsletter and receive a second code, SIGNUP30.

Step 2 - apply both codes at checkout#
we add the leather jacket to the cart, go to checkout, and apply both coupon codes to get a discount on the order.

Step 3 - alternate to stack the discount#
we try applying a code more than once. entering the same code twice in a row is rejected, the coupon has already been applied. but if we alternate between the two codes, NEWCUST5, SIGNUP30, NEWCUST5, SIGNUP30, and so on, each one differs from the previous application and the control is bypassed, so the discount keeps stacking.

Step 4 - complete the order#
we repeat the alternation until the total is driven down below our store credit, then complete the order.

with this, the lab is solved!
