×
pepdep
PD.26.300

Two codes, four discounts (2026)

WEB CTF Published 27.10.2026

A 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.

ONE COUPON REQUEST, TWO QUESTIONS ABOUT ITPROMO FIELDcalls .trim()DUPLICATE CHECKapplied already?PROMOTIONwhich one is it?CART TOTAL% off the subtotalPOST /api/cart/coupon {"code":"NIGHT20 "}NEW? yes"NIGHT20 " is not "NIGHT20"so it is acceptedWHICH? NIGHT20"NIGHT20 " resolves to NIGHT20the one already in the cartNIGHT20 × 2counted twicethe check reads what was sent. the discount reads what it means.
Two questions about one submitted string, answered by different rules. The form's trim sits in front of both, where a direct request never meets it. The split between the checks is inferred from responses, not source.

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.

SENTDUPLICATE CHECKCART"NIGHT20"not applied yet -> acceptNIGHT20 × 1"NIGHT20"already applied -> rejectno change"NIGHT20 "looks new -> acceptNIGHT20 × 2an exact repeat is caught. one space later, it is not.
The exact repeat is caught. The same code with one trailing space is waved through, then filed under the promotion it was supposed to be a duplicate of.

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:

  1. Add the Midnight Collection (midnight-vault) to the bag. It goes through POST /api/cart/items.
  2. Subscribe to the newsletter to reveal NEWS30. That is POST /api/newsletter.
  3. Send "NIGHT20", then "NEWS30", to POST /api/cart/coupon. The total is now €333.00.
  4. Send "NIGHT20 ", then "NEWS30 ", to the same endpoint, with each trailing space intact in the JSON. The total is now €0.00.
  5. 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.

THE TOTAL, ONE COUPON REQUEST AT A TIME€66 store credit€666.00start€532.80−€133.20"NIGHT20"€333.00−€199.80"NEWS30"€199.80−€133.20"NIGHT20 "€0.00−€199.80"NEWS30 "as intended, once eachthe same two, again20% + 30% + 20% + 30% of €666 = €666
The two legitimate codes stop at €333. The same two codes with a trailing space finish the job, and the €66 credit is never touched.

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.

THE SPACE ONLY SURVIVES A DIRECT REQUESTPROMO FIELDyou type "NIGHT20 ".trim()in the browser{"code":"NIGHT20"}REJECTEDalready appliedDIRECT REQUESTconsole, curl, a proxynothing in the way{"code":"NIGHT20 "}ACCEPTEDNIGHT20 × 2a .trim() in the browser is a convenience, not a control
Through the page, the space is gone before the request is built. A direct request carries it to the server, and that is the only path where it matters.

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

ONE CODE, ONE IDENTITYNORMALISEtrim, fold caseLOOK UPto a promotion idDE-DUPLICATEon that idSTOREthe id, not the textcheckout recounts: each promotion at most oncewhatever the earlier steps let throughde-duplicate what you pay out on, not what was typed
Normalise once on the server, key everything on the promotion, and recount at checkout.
  1. 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().
  2. 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.
  3. 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.
  4. 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.