Exploiting Race Condition to apply discount coupon multiple times
A shop's coupon endpoint allowed the same discount to be applied multiple times when concurrent requests were sent, because the server checked coupon usage before marking it used. An attacker could buy an item far below its intended price, or even for free.
medium.com
Published on medium.com
Recently I was solving a ctf where i was given a online shop and i was supposed to purchase a leather jacket worth $1217.I was given only 50$ in my account. So in these conditions the first thing that came to my mind was race condition that could help me.Race conditions enable us to send multiple coupon requests in…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the server checked coupon eligibility and applied the discount without an atomic lock, so concurrent requests all passed the check before the coupon was marked as used.
Impact
An attacker could buy goods at a fraction of the price or for free, causing financial loss to the shop.
What the attacker needed
A shop account; a valid coupon code; ability to send concurrent requests
The fix
The coupon application should be made atomic, for example with a database lock or a single-use token, so that only one request can apply it.
How it was found
- Find the coupon application endpoint that accepts a coupon code.
- Send many requests to apply the coupon at the same time using a tool or script.
- Observe that the discount is applied repeatedly, lowering the order price.
- Complete the purchase at the reduced price.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A race condition happens when a program does two things at once and gets confused. Here, the shop checked whether a coupon was already used, but before it could mark it as used, another request slipped in and applied the same coupon again. By sending many requests at the same moment, the attacker stacked discounts and paid much less.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.