Skip to content
Business logic Write-up Intermediate

A 666 EUR box for 66 EUR

A shop's coupon de-duplication only compared a new code against the most recently applied promotion, so re-applying an existing code that was not last incremented its count. Combined with no cap on the total discount, an attacker could stack two codes to reach a 100% discount and buy a 666 EUR item for free.

medium.com

Published on medium.com

Cybersecurity

Krishna_Jonnagaddala, on medium.com

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

Context

Intigriti runs a monthly challenge, and the October 2026 edition was a shop called the "Halloween Store," built by Globules. The store is a small single page app talking to a JSON API. One product mattered: a numbered keepsake chest called The Midnight Collection, priced at 666 EUR. Every player was handed 66 EUR of store credit and told to buy the box; the flag would be waiting on the receipt of a successful vault purchase.

Prices are in cents. The vault is 66600. Your credit is 6600. Checkout is gated server side: if the order total is greater than your credit you get a flat 402 insufficient_credit, and the flag only appears in the receipt of a successful vault purchase. There is no top-up button. The whole challenge lives in the gap between 66 and 666.

The API surface is small:

Text
GET  /api/session            start a session, seeded with 6600 (66.00 EUR) credit
GET  /api/products           the catalogue
POST /api/cart/items         add a product by id
POST /api/cart/coupon        apply a promotion code
POST /api/cart/coupon/remove remove one
POST /api/checkout           pay with store credit, get a receipt
POST /api/newsletter         subscribe, returns a promo code

There are exactly two promotions, and both only apply when the vault is in the cart:

  • NIGHT20, 20 percent off, advertised right in the site banner.
  • NEWS30, 30 percent off, handed to you by the newsletter endpoint.

Apply both and you land at 50 percent off. The vault drops from 666.00 to 333.00 EUR, still five times the budget. That 50 percent wall is the thing the challenge dares you to climb.

Setup

The challenge is a single session against the shop API. You start a session with GET /api/session, which seeds the account with 6600 cents of credit, add the vault to the cart, subscribe to the newsletter to obtain NEWS30, and then work the coupon endpoints. No account registration, roles or admin interface are involved.

The backend identifies itself as Python's http.server and sits behind istio-envoy. That pairing is what shaped most of the early effort: a permissive, hand rolled Python HTTP stack behind a smart proxy is the classic setup for HTTP request smuggling and connection desync.

Finding it

The trap

If you poke the shared backend connections you can watch other people's request bodies leak into your responses as malformed 501 lines. The desync is real, and it looks exactly like the intended path. The researcher built the whole kit: raw socket TLS clients, CL.0, CL.TE and TE.CL framings, dual Content-Length headers, HTTP/2 with the h2 library for H2.CL and CRLF-in-header-value request splitting, and the single packet attack for races, spending hours trying to make the backend process a checkout that envoy never validated.

It does not work, and the reason is a lesson on its own. istio-envoy is RFC compliant. It rejects dual Content-Length with a 400, it rejects CRLF in header values with a stream reset, and it recomputes Content-Length when it downgrades HTTP/2 to HTTP/1.1. Every desync that could be manufactured was either refused by envoy or, at best, pipelined in a way envoy still parsed. And the credit check lives in the Python backend, not in envoy, so even a perfect smuggle would hit the same 402. Envoy was confirmed as the gatekeeper with a single header: the 402 carried x-envoy-upstream-service-time, which means envoy forwarded the request upstream and the backend answered. The check is behind the proxy, not in front of it. The smuggling was a beautifully constructed red herring; the architecture was the trap.

Ruling out the rest

Before the real bug clicked, the shop logic was put through everything a shop can get wrong:

  • Price and quantity tampering. The add-to-cart handler reads only productId. Injected quantity, price, lineTotal, even -Infinity and NaN (Python's json accepts those), are all ignored. Quantity is pinned to 1 per item, and items cannot be removed.
  • Checkout parameter injection. The checkout body is ignored entirely. Twenty eight variants, including total, credit, paid, skipCredit, __proto__, negatives and nested objects, all return 402. The backend reads only server side cart state.
  • Credit manipulation. The session cookie is 32 random bytes, an opaque server side id, not a signed token. Cookie parameter pollution and crafted session values all return the same 66.00 EUR. The credit math on normal purchases is exact.
  • Races. The coupon endpoint is protected by an optimistic version lock. Forty parallel applies gave one 200 and thirty nine 409. The single packet attack made it worse, not better. A checkout versus add-vault TOCTOU, about 6400 attempts with single packet timing, never produced a vault receipt. The checkout reads an atomic cart snapshot.
  • Client side. The entire client escapes its output with a custom escapeHtml. No DOM sink takes attacker input, there is no reflected or stored XSS, no CSP to bypass, and no admin bot to target.

Every door was locked, which in hindsight was the hint.

The tell

When a challenge resists every exotic vector and every obvious logic flaw, the bug is usually hiding in a place you already looked, in a behaviour you did not fully exercise. The thing that had been skimmed past was a single field in the promotion object. When a coupon is applied, the cart renders it like this:

Text
Promotion NIGHT20 - 20% off x 2

That x 2 is a count. The server stores each promotion with a count, and the discount is computed as:

Text
amount = count * percent * price

The UI only shows the multiplier when it is greater than 1, so the backend clearly supports a coupon being counted more than once. In the normal flow it is always 1, because applying the same code twice is de-duplicated. But if the backend can hold a count of 2, the only question left is how to make it do that. That reframed the whole challenge: it was never about discovering a new discount, it was about making an existing one apply twice.

Exploitation

Step 1: exercise the coupon state machine

The one thing not done properly was exercising the coupon state machine: not static carts, but sequences. Apply, remove, re-apply, in different orders, and watch the count. The moment it broke was this sequence:

Text
apply NIGHT20     ->  NIGHT20 x1
apply NEWS30      ->  NIGHT20 x1, NEWS30 x1   (50% off, the cap)
remove NIGHT20    ->  NEWS30 x1
re-apply NIGHT20  ->  NEWS30 x1, NIGHT20 x1
remove NEWS30     ->  NIGHT20 x1
apply NEWS30      ->  NIGHT20 x1, NEWS30 x1
apply NIGHT20     ->  NIGHT20 x2, NEWS30 x1   <-- count went to 2

NIGHT20 at count 2, discount at 70 percent, well past the 50 percent ceiling. The de-duplication had failed.

The reason is simple and a little bit elegant. The duplicate check is order dependent: it only compares the code you are applying against the last promotion in the list. If you apply a code that is already present but is not the most recent one, the check says "not a duplicate" and increments its count instead of rejecting it. And nothing clamps the total discount to the subtotal.

That means the remove dance is not even needed. You just need each code to not be the last one when you re-apply it. Alternating does exactly that.

From the original on medium.com

Step 2: alternate the two codes

Add the vault, then apply the two codes in alternating order. Four applies:

Text
Step   Apply     Promotions               Discount   Total
1      NIGHT20   NIGHT20 x1               20%        532.80
2      NEWS30    NIGHT20 x1, NEWS30 x1    50%        333.00
3      NIGHT20   NIGHT20 x2, NEWS30 x1    70%        199.80
4      NEWS30    NIGHT20 x2, NEWS30 x2    100%       0.00

At step 4 both promotions sit at count 2. The discount is 2*20% + 2*30% = 100% of the vault price. The total is 0.00, canCheckout flips to true, and checkout returns a receipt with the flag. The 66 EUR of credit is never even touched.

Step 3: the full sequence in one session

Text
GET  /api/session
POST /api/cart/items     {"productId":"midnight-vault"}
POST /api/newsletter     {"email":"[redacted]"}
POST /api/cart/coupon    {"code":"NIGHT20"}
POST /api/cart/coupon    {"code":"NEWS30"}
POST /api/cart/coupon    {"code":"NIGHT20"}
POST /api/cart/coupon    {"code":"NEWS30"}
POST /api/checkout       {}

The session call seeds the credit, the cart call adds the vault by id, the newsletter call returns the NEWS30 code, and the four coupon calls alternate the two codes so that neither is the last promotion when it is re-applied. The checkout body is empty because the backend reads only server side cart state.

The cart, right before checkout:

From the original on medium.com

And the receipt (flag redacted while the challenge is still live):

From the original on medium.com

Paid: 0.00. A 666 EUR one-of-a-kind item, taken for free.

Root cause

Two small decisions combine into a full payment bypass:

  1. The duplicate guard compares the incoming code against only the most recently applied promotion, instead of the whole promotions list. So any code that is already present, but not last, gets counted again.
  2. The cumulative discount is never clamped to the cart subtotal, so the total is free to reach 0, or go negative.

Neither alone is catastrophic. Together they turn two legitimate marketing codes into a "buy anything for free" button.

Impact

An attacker with a normal session can obtain the vault, priced at 666 EUR, for a total of 0.00, without spending any of the 66 EUR of credit. The conditions are that both promotions are available and apply to the item in the cart, and that the attacker can drive the coupon endpoints in sequence. The report does not describe any effect outside this shop.

Fix

The report recommends:

  • De-duplicate promotions by code across the entire cart, not just against the last one. Reject a second application of a code that is already present rather than incrementing its count.
  • Independently, clamp the combined discount so it can never exceed the subtotal. The order total should never be allowed below 0, even if another stacking path is ever found.
  • Recompute and re-validate the total, discount and credit server side at checkout, rather than trusting the running cart state.

Defence in depth matters here precisely because the two bugs were independent. Fixing the dedup closes this path; clamping the discount closes the whole class.

Variants to test

  • Order-dependent duplicate checks on other carts. Apply code A, then B, then A again, and inspect the promotion list for a count above 1. A positive result is a promotion object showing x 2 or an equivalent multiplier, or a discount percentage above the advertised cap.
  • Remove and re-apply sequences. Apply A, apply B, remove A, re-apply A, remove B, apply B, apply A. A positive result is any code reaching a count of 2 or more after a removal.
  • Discount clamping. Stack every available code and watch the total. A positive result is a total of 0.00 or a negative total, or a checkout that succeeds with no credit spent.
  • Checkout body injection. Send total, credit, paid, skipCredit, __proto__, negatives and nested objects in the checkout body. A positive result is any variant that changes the outcome from 402 to a receipt.
  • Concurrent coupon applies. Fire many parallel applies of the same code and look for more than one 200. A positive result is a count above 1 without a sequential sequence, which would indicate the version lock is not covering the count increment.
  • Client-side rendering of counts. Check whether the multiplier is rendered from server state or computed client side. A positive result is a client that displays a count the server does not hold, or a server that trusts a client-supplied count.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 25 min read.

What happened, in plain words

Every month the security testing platform Intigriti publishes a small practice target, called a challenge, that anyone can try to break into. The October 2026 challenge was an online shop called the "Halloween Store," built by a team called Globules. The goal was simple to state: buy one very expensive item using far less money than it costs, and the shop would hand you a secret code called a flag as proof you succeeded.

The item was a numbered keepsake chest called The Midnight Collection, priced at 666 EUR. Every player started with 66 EUR of store credit. There was no button to add more money. So the whole puzzle was the gap between 66 and 666: how do you pay ten times what you have?

The author of this write-up spent a very long time attacking the wrong thing. The shop's server software looked, at first glance, like it had a serious technical weakness in the way it handled network traffic. It did have that weakness, but it turned out to be a decoy. The real bug was much simpler and was sitting in the shopping cart the whole time, in the form of a tiny label that said x 2.

This article walks through the same journey: the shop, the decoy, the dead ends, the clue, the bug, the exploit, and the fix. Every technical term is explained as it appears, and every request and piece of code is shown exactly as it was used, followed by a plain-language explanation of what it does.

The shop

The store is a small single page app talking to a JSON API. Let us unpack that sentence, because it contains several ideas that come up constantly.

A single page app is a website that loads once and then updates itself in place, rather than loading a brand new page every time you click something. Think of a paper form versus a whiteboard: a normal website hands you a fresh printed page for each step, while a single page app keeps one whiteboard and rubs parts of it out and redraws them.

An API (Application Programming Interface) is the set of instructions a program uses to talk to another program. A useful comparison is a restaurant menu: you do not walk into the kitchen and cook; you pick an item from the menu, a waiter carries your order to the kitchen, and food comes back. The API is the menu plus the waiter. The website you see in your browser is the dining room; the API is how the dining room asks the kitchen for things.

JSON is a common text format for those orders and replies. It looks a lot like a shopping list written with curly brackets, and it is easy for both humans and machines to read.

Prices are in cents. The vault costs 66600 and your credit is 6600. This is a very common programming habit: storing money as whole numbers of the smallest unit avoids rounding errors that creep in with decimal numbers. So 66600 means 666.00 EUR and 6600 means 66.00 EUR.

Checkout is gated server side. The word server means the computer in the background that holds the shop's data and makes the decisions. The word client means your browser, the thing in front of you. "Server side" means the important decision is made on the shop's computer, not in your browser. That matters enormously: anything your browser decides can be changed by you, but the server's decisions are the ones that count. The gate here is a rule: if the order total is greater than your credit, the server refuses with a flat 402 insufficient_credit. A 402 is an HTTP status code, which is a short number a server sends back to say how a request went; 402 specifically means "payment required." The flag only appears in the receipt of a successful vault purchase.

The API surface is small:

Text
GET  /api/session            start a session, seeded with 6600 (66.00 EUR) credit
GET  /api/products           the catalogue
POST /api/cart/items         add a product by id
POST /api/cart/coupon        apply a promotion code
POST /api/cart/coupon/remove remove one
POST /api/checkout           pay with store credit, get a receipt
POST /api/newsletter         subscribe, returns a promo code

Line by line:

  • GET /api/session starts a session. A session is the shop's way of remembering who you are between requests. Because the web is forgetful by design, the shop gives you a session and tracks your cart and credit against it. "Seeded with 6600" means the shop puts 66.00 EUR of credit into that new session for you.
  • GET /api/products returns the catalogue, the list of things for sale.
  • POST /api/cart/items adds a product to your cart, identified by its id (a short internal name).
  • POST /api/cart/coupon applies a promotion code, which is a discount voucher such as a percentage off.
  • POST /api/cart/coupon/remove removes one of the applied codes.
  • POST /api/checkout pays using store credit and returns a receipt.
  • POST /api/newsletter subscribes you to the newsletter and, as a reward, returns a promo code.

The words GET and POST are HTTP methods, the verbs of web requests. GET means "give me something," and POST means "here is some data, do something with it." You can see them in your browser's address bar history whenever you submit a form.

There are exactly two promotions, and both only apply when the vault is in the cart:

  • NIGHT20, 20 percent off, advertised right in the site banner.
  • NEWS30, 30 percent off, handed to you by the newsletter endpoint.

Apply both and you land at 50 percent off. The vault drops from 666.00 to 333.00 EUR, still five times the budget. That 50 percent wall is the thing the challenge dares you to climb. A promotion here is a discount rule attached to the cart; a percentage off means the price is reduced by that share of the original.

Setup

The challenge is a single session against the shop API. You start a session with GET /api/session, which seeds the account with 6600 cents of credit, add the vault to the cart, subscribe to the newsletter to obtain NEWS30, and then work the coupon endpoints. No account registration, roles or admin interface are involved. In other words, there is no special account to obtain and no hidden admin panel to find; everything happens through the same handful of requests any visitor can make.

The backend identifies itself as Python's http.server and sits behind istio-envoy. Two more terms to unpack.

Python is a popular programming language. http.server is a small web server that ships with Python; it is handy for learning and small jobs, but it is not the heavy-duty server most big sites use.

istio-envoy is a proxy, a piece of software that sits in front of the real server and passes requests through to it. A good comparison is a receptionist in an office building: visitors do not walk straight to the desks; they talk to the receptionist, who checks them and forwards them on. Envoy is a well-known, carefully written receptionist.

That pairing is what shaped most of the early effort: a permissive, hand rolled Python HTTP stack behind a smart proxy is the classic setup for HTTP request smuggling and connection desync. Those two terms deserve a proper explanation, because they are the heart of the decoy.

HTTP is the language browsers and servers speak. A request is a short block of text: a first line saying what you want, then headers (labelled lines of extra information, like a form's fields), then optionally a body (the actual data, such as the contents of a form).

HTTP request smuggling is a class of bug where an attacker crafts a request that two pieces of software in a chain read differently. Imagine handing a receptionist a note that says "deliver this parcel, and by the way the next visitor is my friend." If the receptionist and the person at the desk disagree about where your note ends and the next one begins, part of your text can be treated as a separate request. That is smuggling: sneaking one request inside another.

Connection desync is the same idea seen from the other side: the two programs fall out of step about where one message ends, so replies and requests get mixed up. CL.0, CL.TE, TE.CL, H2.CL are names for specific ways of creating that disagreement, mostly by playing with the Content-Length header (which states how many bytes the body has) and the Transfer-Encoding header (which describes how the body is chunked).

Finding it

The trap

If you poke the shared backend connections you can watch other people's request bodies leak into your responses as malformed 501 lines. A 501 is another HTTP status code, meaning "not implemented," and "malformed" means the text was not in the shape the server expected. Seeing other people's data in your own replies is a strong sign that messages are getting crossed, which is exactly what desync looks like.

The desync is real, and it looks exactly like the intended path. The researcher built the whole kit: raw socket TLS clients, CL.0, CL.TE and TE.CL framings, dual Content-Length headers, HTTP/2 with the h2 library for H2.CL and CRLF-in-header-value request splitting, and the single packet attack for races, spending hours trying to make the backend process a checkout that envoy never validated.

That sentence is dense, so let us take it apart:

  • A raw socket TLS client is a program that talks to a server at the lowest level, sending the exact bytes of a request itself instead of letting a browser do it. TLS is the encryption that puts the padlock in your address bar; a raw client still uses it, but controls every byte inside.
  • Framings here means the different ways of marking where a request's body starts and ends. Dual Content-Length headers means sending two Content-Length headers with different values, hoping the two programs in the chain pick different ones.
  • HTTP/2 is a newer version of HTTP; h2 is a Python library for speaking it. CRLF-in-header-value request splitting means putting the special characters that mark the end of a line (carriage return and line feed, the invisible characters that end each line of a request) inside a header value, hoping to trick the server into thinking a new request starts there.
  • The single packet attack is a race technique: you send several requests packed so tightly that they arrive almost simultaneously, hoping the server handles them in an order that benefits you. A race in security means exploiting the tiny window between two operations that are supposed to happen together.

It does not work, and the reason is a lesson on its own. istio-envoy is RFC compliant. An RFC is a published standards document; "RFC compliant" means the software follows the rules exactly. It rejects dual Content-Length with a 400 (a status code meaning "bad request"), it rejects CRLF in header values with a stream reset (it simply drops the connection), and it recomputes Content-Length when it downgrades HTTP/2 to HTTP/1.1 (it recalculates the length itself rather than trusting the client). Every desync that could be manufactured was either refused by envoy or, at best, pipelined in a way envoy still parsed. Pipelining means sending several requests one after another on the same connection; envoy still read them correctly.

And the credit check lives in the Python backend, not in envoy, so even a perfect smuggle would hit the same 402. The backend is the real application behind the proxy. Envoy was confirmed as the gatekeeper with a single header: the 402 carried x-envoy-upstream-service-time, which means envoy forwarded the request upstream and the backend answered. Upstream means the server further along the chain, behind the proxy. That header is envoy's own note saying "I passed this on and here is how long the other side took," which proves the refusal came from the shop itself, not from the receptionist. The check is behind the proxy, not in front of it. The smuggling was a beautifully constructed red herring; the architecture was the trap. A red herring is a deliberate distraction that leads you away from the real answer.

Ruling out the rest

Before the real bug clicked, the shop logic was put through everything a shop can get wrong. This is a normal and healthy habit: list the obvious weaknesses, test each one, and write down why it failed, so you can stop wondering about it later.

  • Price and quantity tampering. The add-to-cart handler reads only productId. A handler is the piece of code that deals with a particular request. Tampering means changing values you are not supposed to change. Injected quantity, price, lineTotal, even -Infinity and NaN (Python's json accepts those), are all ignored. NaN means "not a number," a special value for invalid arithmetic; -Infinity is negative infinity. The point is that even absurd values were ignored. Quantity is pinned to 1 per item, and items cannot be removed.
  • Checkout parameter injection. The checkout body is ignored entirely. Parameter injection means adding extra fields to a request in the hope the server uses them. Twenty eight variants, including total, credit, paid, skipCredit, __proto__, negatives and nested objects, all return 402. __proto__ is a special field name in JavaScript that has caused bugs in the past; nested objects means JSON values inside JSON values. The backend reads only server side cart state, meaning it looks at its own stored cart, not at anything you send.
  • Credit manipulation. The session cookie is 32 random bytes, an opaque server side id, not a signed token. A cookie is a small piece of data your browser stores for a site and sends back with every request, like a cloakroom ticket. Opaque means it carries no readable information; it is just a random label the server looks up in its own records. A signed token would be a value the server can verify was issued by it; here there is nothing to forge because the value means nothing by itself. Cookie parameter pollution and crafted session values all return the same 66.00 EUR. Cookie parameter pollution means sending several cookies with the same name to confuse the server about which one to use. The credit math on normal purchases is exact.
  • Races. The coupon endpoint is protected by an optimistic version lock. A lock is a rule that stops two operations from interfering; optimistic means the server assumes no clash and checks at the end, rejecting the loser. Forty parallel applies gave one 200 and thirty nine 409. 200 means success; 409 means conflict, the server saying "someone else changed this first." The single packet attack made it worse, not better. A checkout versus add-vault TOCTOU, about 6400 attempts with single packet timing, never produced a vault receipt. TOCTOU stands for "time of check to time of use," a gap between when something is verified and when it is used, which an attacker can try to slip through. The checkout reads an atomic cart snapshot. Atomic means all at once, as a single consistent picture, so there is no half-finished state to exploit.
  • Client side. The entire client escapes its output with a custom escapeHtml. Escaping means converting dangerous characters into harmless text so they display rather than run. No DOM sink takes attacker input, there is no reflected or stored XSS, no CSP to bypass, and no admin bot to target. The DOM is the browser's in-memory model of the page; a sink is a place where data gets inserted and could be executed. XSS (cross-site scripting) is a bug where an attacker's text runs as code in someone else's browser; reflected means it bounces straight back in a response, stored means it is saved and shown to others later. CSP (Content Security Policy) is a browser rule limiting what scripts may run. An admin bot is an automated browser, logged in as an administrator, that some challenges provide as a target. None of it applied here.

Every door was locked, which in hindsight was the hint.

The tell

When a challenge resists every exotic vector and every obvious logic flaw, the bug is usually hiding in a place you already looked, in a behaviour you did not fully exercise. A vector is a route of attack. The thing that had been skimmed past was a single field in the promotion object. When a coupon is applied, the cart renders it like this:

Text
Promotion NIGHT20 - 20% off x 2

That x 2 is a count. The server stores each promotion with a count, and the discount is computed as:

Text
amount = count * percent * price

Line by line: amount is the money taken off. count is how many times the promotion is being counted. percent is the discount rate, and price is the item's price. So if a 20 percent code is counted twice on a 666.00 EUR item, the discount is two times 20 percent of 666.00. The multiplication is the whole story: a bigger count means a bigger discount.

The UI only shows the multiplier when it is greater than 1, so the backend clearly supports a coupon being counted more than once. UI means user interface, the part you see and click. In the normal flow it is always 1, because applying the same code twice is de-duplicated. De-duplicated means the server notices the code is already there and refuses to add it again. But if the backend can hold a count of 2, the only question left is how to make it do that. That reframed the whole challenge: it was never about discovering a new discount, it was about making an existing one apply twice.

Exploitation

Step 1: exercise the coupon state machine

The one thing not done properly was exercising the coupon state machine: not static carts, but sequences. A state machine is just a system that moves between states depending on what you do, like a vending machine that only releases a drink after you insert a coin and press a button. A static cart means looking at one fixed situation; a sequence means doing things in order and watching how the state changes. Apply, remove, re-apply, in different orders, and watch the count. The moment it broke was this sequence:

Text
apply NIGHT20     ->  NIGHT20 x1
apply NEWS30      ->  NIGHT20 x1, NEWS30 x1   (50% off, the cap)
remove NIGHT20    ->  NEWS30 x1
re-apply NIGHT20  ->  NEWS30 x1, NIGHT20 x1
remove NEWS30     ->  NIGHT20 x1
apply NEWS30      ->  NIGHT20 x1, NEWS30 x1
apply NIGHT20     ->  NIGHT20 x2, NEWS30 x1   <-- count went to 2

Line by line:

  1. apply NIGHT20 puts the 20 percent code in the cart, counted once.
  2. apply NEWS30 adds the 30 percent code, also once. Together they give 50 percent off, which is the advertised cap.
  3. remove NIGHT20 takes the 20 percent code out, leaving only the 30 percent one.
  4. re-apply NIGHT20 puts it back. Now the list shows NEWS30 first and NIGHT20 second.
  5. remove NEWS30 takes the 30 percent code out, leaving only NIGHT20.
  6. apply NEWS30 adds the 30 percent code back, so both are present again.
  7. apply NIGHT20 is the crucial step: the 20 percent code is already in the cart, but it is not the most recent one, and the server counts it a second time. The label becomes NIGHT20 x2.

NIGHT20 at count 2, discount at 70 percent, well past the 50 percent ceiling. The de-duplication had failed.

The reason is simple and a little bit elegant. The duplicate check is order dependent: it only compares the code you are applying against the last promotion in the list. If you apply a code that is already present but is not the most recent one, the check says "not a duplicate" and increments its count instead of rejecting it. And nothing clamps the total discount to the subtotal. Clamping means capping a value so it cannot go beyond a limit; the subtotal is the price of the goods before discounts. A helpful comparison: a bouncer who only checks whether you match the person who just walked in, rather than everyone already inside. Slip in behind someone else and you get through.

That means the remove dance is not even needed. You just need each code to not be the last one when you re-apply it. Alternating does exactly that.

From the original on medium.com

Step 2: alternate the two codes

Add the vault, then apply the two codes in alternating order. Four applies:

Text
Step   Apply     Promotions               Discount   Total
1      NIGHT20   NIGHT20 x1               20%        532.80
2      NEWS30    NIGHT20 x1, NEWS30 x1    50%        333.00
3      NIGHT20   NIGHT20 x2, NEWS30 x1    70%        199.80
4      NEWS30    NIGHT20 x2, NEWS30 x2    100%       0.00

Line by line:

  1. Applying NIGHT20 once takes 20 percent off 666.00, leaving 532.80.
  2. Applying NEWS30 adds 30 percent, so 50 percent comes off in total, leaving 333.00.
  3. Applying NIGHT20 again works because NEWS30 is now the last code in the list, so the duplicate check does not see NIGHT20 as the most recent one. It counts NIGHT20 twice, giving 70 percent off and a total of 199.80.
  4. Applying NEWS30 again works for the same reason: NIGHT20 is now last, so NEWS30 is not the most recent one and gets counted twice. Both codes sit at count 2.

At step 4 both promotions sit at count 2. The discount is 2*20% + 2*30% = 100% of the vault price. The total is 0.00, canCheckout flips to true, and checkout returns a receipt with the flag. canCheckout is simply the shop's internal yes/no switch for whether the checkout button is allowed; it turns true once the total is affordable. The 66 EUR of credit is never even touched.

Step 3: the full sequence in one session

Text
GET  /api/session
POST /api/cart/items     {"productId":"midnight-vault"}
POST /api/newsletter     {"email":"[redacted]"}
POST /api/cart/coupon    {"code":"NIGHT20"}
POST /api/cart/coupon    {"code":"NEWS30"}
POST /api/cart/coupon    {"code":"NIGHT20"}
POST /api/cart/coupon    {"code":"NEWS30"}
POST /api/checkout       {}

Line by line:

  • GET /api/session starts the session and seeds the 66.00 EUR of credit.
  • POST /api/cart/items with {"productId":"midnight-vault"} adds the vault to the cart by its id. The curly brackets are JSON, and productId is the field naming which product to add.
  • POST /api/newsletter with an email address subscribes you and returns the NEWS30 code. The email is redacted here because it is personal data.
  • The four POST /api/cart/coupon calls alternate NIGHT20 and NEWS30, so that neither code is the last promotion when it is re-applied. This is the whole trick.
  • POST /api/checkout with an empty body {} pays. The body is empty because the backend reads only server side cart state; it does not need you to tell it the total.

The session call seeds the credit, the cart call adds the vault by id, the newsletter call returns the NEWS30 code, and the four coupon calls alternate the two codes so that neither is the last promotion when it is re-applied. The checkout body is empty because the backend reads only server side cart state.

The cart, right before checkout:

From the original on medium.com

And the receipt (flag redacted while the challenge is still live):

From the original on medium.com

Paid: 0.00. A 666 EUR one-of-a-kind item, taken for free.

Root cause

Two small decisions combine into a full payment bypass:

  1. The duplicate guard compares the incoming code against only the most recently applied promotion, instead of the whole promotions list. So any code that is already present, but not last, gets counted again.
  2. The cumulative discount is never clamped to the cart subtotal, so the total is free to reach 0, or go negative.

Neither alone is catastrophic. Together they turn two legitimate marketing codes into a "buy anything for free" button. Serialises here means making simultaneous writes happen one at a time; the lock kept the writes tidy but never checked whether the list of promotions made sense.

Impact

An attacker with a normal session can obtain the vault, priced at 666 EUR, for a total of 0.00, without spending any of the 66 EUR of credit. The conditions are that both promotions are available and apply to the item in the cart, and that the attacker can drive the coupon endpoints in sequence. The report does not describe any effect outside this shop.

Fix

The report recommends:

  • De-duplicate promotions by code across the entire cart, not just against the last one. Reject a second application of a code that is already present rather than incrementing its count.
  • Independently, clamp the combined discount so it can never exceed the subtotal. The order total should never be allowed below 0, even if another stacking path is ever found.
  • Recompute and re-validate the total, discount and credit server side at checkout, rather than trusting the running cart state.

Defence in depth matters here precisely because the two bugs were independent. Defence in depth means layering several protections so that one failure does not sink you, like wearing both a seatbelt and having airbags. Fixing the dedup closes this path; clamping the discount closes the whole class.

Variants to test

These are the same ideas applied elsewhere, useful if you want to look for similar bugs in other shops:

  • Order-dependent duplicate checks on other carts. Apply code A, then B, then A again, and inspect the promotion list for a count above 1. A positive result is a promotion object showing x 2 or an equivalent multiplier, or a discount percentage above the advertised cap.
  • Remove and re-apply sequences. Apply A, apply B, remove A, re-apply A, remove B, apply B, apply A. A positive result is any code reaching a count of 2 or more after a removal.
  • Discount clamping. Stack every available code and watch the total. A positive result is a total of 0.00 or a negative total, or a checkout that succeeds with no credit spent.
  • Checkout body injection. Send total, credit, paid, skipCredit, __proto__, negatives and nested objects in the checkout body. A positive result is any variant that changes the outcome from 402 to a receipt.
  • Concurrent coupon applies. Fire many parallel applies of the same code and look for more than one 200. A positive result is a count above 1 without a sequential sequence, which would indicate the version lock is not covering the count increment.
  • Client-side rendering of counts. Check whether the multiplier is rendered from server state or computed client side. A positive result is a client that displays a count the server does not hold, or a server that trusts a client-supplied count.

Glossary

  • API: the set of instructions one program uses to talk to another, like a menu and waiter between you and the kitchen.
  • Backend: the real application behind a proxy, where the data and decisions live.
  • Client: the program in front of you, usually your browser.
  • Server: the computer in the background that holds data and makes decisions.
  • Single page app: a website that loads once and updates itself in place instead of loading new pages.
  • JSON: a text format for structured data, using curly brackets, colons and commas.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • HTTP method: the verb of a request, such as GET (give me) or POST (here is data, act on it).
  • Header: a labelled line of extra information in a request or response.
  • Body: the actual data carried by a request or response.
  • Status code: a short number a server returns to say how a request went, such as 200, 400, 402, 409 or 501.
  • 402: the status code meaning payment required.
  • 400: the status code meaning bad request.
  • 409: the status code meaning conflict, often used when two changes clash.
  • 501: the status code meaning not implemented.
  • Session: the shop's way of remembering who you are between requests.
  • Cookie: a small piece of data your browser stores for a site and sends back with each request, like a cloakroom ticket.
  • Opaque: carrying no readable information by itself.
  • Signed token: a value the server can verify it issued, so it cannot be forged.
  • Proxy: software sitting in front of a server that passes requests through, like a receptionist.
  • istio-envoy: a well-known proxy used in front of web applications.
  • Python: a popular programming language.
  • http.server: a small web server that ships with Python.
  • RFC: a published standards document; RFC compliant means following it exactly.
  • HTTP request smuggling: crafting a request that two programs in a chain read differently, so part of it is treated as a separate request.
  • Connection desync: two programs falling out of step about where one message ends and the next begins.
  • Content-Length: a header stating how many bytes a request body has.
  • Transfer-Encoding: a header describing how a body is chunked.
  • CL.0, CL.TE, TE.CL, H2.CL: names for specific ways of creating a disagreement about message boundaries.
  • Raw socket TLS client: a program that sends the exact bytes of an encrypted request itself instead of using a browser.
  • TLS: the encryption that puts the padlock in your address bar.
  • HTTP/2: a newer version of HTTP; h2 is a Python library for speaking it.
  • CRLF: the invisible characters that end a line in an HTTP request.
  • Single packet attack: a race technique that sends several requests packed so tightly they arrive almost at once.
  • Race: exploiting the tiny window between two operations that should happen together.
  • Pipelining: sending several requests one after another on the same connection.
  • Upstream: the server further along the chain, behind the proxy.
  • Red herring: a deliberate distraction that leads you away from the real answer.
  • Handler: the piece of code that deals with a particular request.
  • Tampering: changing values you are not supposed to change.
  • Parameter injection: adding extra fields to a request hoping the server uses them.
  • NaN: "not a number," a special value for invalid arithmetic.
  • Nested objects: JSON values inside JSON values.
  • Cookie parameter pollution: sending several cookies with the same name to confuse the server.
  • Lock: a rule that stops two operations from interfering.
  • Optimistic version lock: a lock that assumes no clash and rejects the loser at the end.
  • TOCTOU: "time of check to time of use," a gap between verification and use that an attacker can try to slip through.
  • Atomic: happening all at once, as a single consistent picture.
  • Escaping: converting dangerous characters into harmless text.
  • DOM: the browser's in-memory model of the page.
  • Sink: a place where data gets inserted and could be executed.
  • XSS: cross-site scripting, a bug where an attacker's text runs as code in someone else's browser.
  • Reflected XSS: XSS that bounces straight back in a response.
  • Stored XSS: XSS that is saved and shown to others later.
  • CSP: Content Security Policy, a browser rule limiting what scripts may run.
  • Admin bot: an automated browser, logged in as an administrator, used as a target in some challenges.
  • Vector: a route of attack.
  • UI: user interface, the part you see and click.
  • De-duplicated: the server notices a value is already present and refuses to add it again.
  • State machine: a system that moves between states depending on what you do, like a vending machine.
  • Static cart: looking at one fixed situation rather than a sequence.
  • Sequence: doing things in order and watching how the state changes.
  • Clamping: capping a value so it cannot go beyond a limit.
  • Subtotal: the price of the goods before discounts.
  • Serialises: makes simultaneous writes happen one at a time.
  • Defence in depth: layering several protections so one failure does not sink you.
  • Flag: the secret code a challenge hands you as proof of success.
  • Promotion: a discount rule attached to the cart.
  • Percentage off: a reduction equal to that share of the original price.
  • Count: how many times a promotion is being counted in the discount calculation.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.