Two codes, four discounts (2026)
WEB CTF Published 27.10.2026A duplicate check is only as good as its idea of what counts as a duplicate.
This one is from Intigriti's monthly challenge series: the October 2026 edition, 1026, a Halloween shop that closed on 26 October. I'm writing it up now that it has closed.
The shop gives you €66 in store credit. The one thing worth buying, the Midnight Collection, costs €666. Somebody enjoyed picking those numbers. Two promotion codes are legitimately on offer: NIGHT20 sits in the banner, and subscribing to the newsletter hands you NEWS30. Each takes a percentage off the original subtotal.
Applying a code involves two decisions. One is whether this code has already been applied. The other is which promotion it is, and so how many times that promotion counts towards the discount. Judging by what the API sends back, those two decisions disagree about a single character.
That disagreement is the bug, and a single trailing space is enough to get through it.
Finding it
The obvious route runs out of money. NIGHT20 takes €666 down to €532.80, and NEWS30 takes it to €333.00. That is still €267 more than the credit covers, and the flag is behind checkout.
Applying NIGHT20 a second time returned "Coupon already applied." That is a useful control: the shop does have a duplicate check, and it catches an exact repeat. The question became what it counts as a repeat.
Two things on the client pointed at the answer. The coupon form cleans its input before it sends anything:
body: JSON.stringify({ code: input.value.trim() })
And the page's own cart code is written to show a promotion more than once, with a count beside it. That struck me as odd for discounts that are meant to apply once.
A .trim() in the browser tells you the server might not be doing the same. The endpoint takes plain JSON, and nothing stops a request from carrying the space that the form would have removed.
The seam
So I sent the space myself:
POST /api/cart/coupon
Content-Type: application/json
{"code":"NIGHT20 "}
The response was 200, "20% promotion applied." The returned cart filed it under plain NIGHT20 with count: 2, and the total dropped to €199.80. "NEWS30 " did the same.
For one submission, the two questions got two different answers. Is this new? Yes: the string is not the one already applied. Which promotion is it? NIGHT20: the one already in the cart.
I did not have the server source, so I can't say exactly where it trims or normalises, or in what order. I don't need to. The count: 2 in the response and the size of each discount show the behaviour on their own.
Doing it
Five steps, all in one session:
- Add the Midnight Collection (
midnight-vault) to the bag. It goes throughPOST /api/cart/items. - Subscribe to the newsletter to reveal
NEWS30. That isPOST /api/newsletter. - Send
"NIGHT20", then"NEWS30", toPOST /api/cart/coupon. The total is now €333.00. - Send
"NIGHT20 ", then"NEWS30 ", to the same endpoint, with each trailing space intact in the JSON. The total is now €0.00. - Call
POST /api/checkout.
Step 4 is the whole trick. The space has to reach the server, and the shop's own form is built to make sure it never does.
Every percentage comes off the original €666 rather than the running total. Two uses of NIGHT20 take €266.40, and two uses of NEWS30 take €399.60. Twenty, thirty, twenty and thirty make a hundred, so four accepted codes remove exactly the price.
After adding the item and getting the newsletter code through the page, this runs the rest from the browser console:
const post = (path, body) =>
fetch(path, {
method: "POST",
credentials: "include",
headers: { "content-type": "application/json" },
body: JSON.stringify(body)
}).then(response => response.json());
for (const code of ["NIGHT20", "NEWS30", "NIGHT20 ", "NEWS30 "]) {
const result = await post("/api/cart/coupon", { code });
console.log(JSON.stringify(code), result.cart?.total);
}
console.log(await post("/api/checkout", {}));
Checkout succeeds with paid: 0, and the receipt carries the flag:
INTIGRITI{094638e6-ba2f-4c50-8bb4-41ced0d5debd}
What does not work
Typing "NIGHT20 " into the shop's promotion field does nothing useful. The form trims it, sends NIGHT20, and gets "Coupon already applied" back. This is the step that makes the bug look absent if you only test through the page.
Repeating a code exactly fails too, for the same reason. The duplicate check is real, and for the input it was written for, it works.
Impact
Anyone with a session can take a €666 order to €0 and check out with paid: 0, using two codes the shop gives away. In a real store that's free goods, sent from the browser console. The report has it as a Medium business logic error.
I stopped once the total hit zero. I did not test whether a third variant, two spaces for example, stacks again, so I'm not claiming more than two applications per code. Here, two was already the whole price.
Root cause
The shop never decides, once, what a coupon code is.
"NIGHT20 "
|
+-- duplicate check -> compared as sent -> not seen before (accepted)
|
+-- promotion lookup -> normalised -> NIGHT20 (counted again)
There are really two failures here, and only one of them is interesting. The whitespace mismatch is the fun part, but lots of systems tidy input in more than one place and never get hurt by it. This one got hurt because the discount calculation was happy to count the same promotion twice, and nothing at the end said no. The duplicate check was the only thing holding each promotion to one use, and all it compared was strings.
The browser's .trim() made all of this invisible from the page. It was doing the server's normalisation for it, so the server never had to.
The fix
- Normalise every submitted code on the server, once, before anything else touches it: trim it, and pick a rule for case. Never rely on the form's
.trim(). - Resolve the normalised code to a promotion ID, and use that ID for the duplicate check, the cart and the calculation. The cart should hold promotions. What someone typed only matters for the lookup.
- Make the limit part of the promotion. When the total is calculated, count each promotion at most as many times as it allows, whatever the earlier steps let through.
- Recompute the payable amount from that promotion set at checkout, before accepting an order at
paid: 0.
If I could only ship one of these, it would be number 3. The space is a cute trick, but the real problem is a calculation that will happily apply a 20% discount twice.