The Coupon That Stacked Itself

Easy

· Backend

Incident

SEV-2

BUG-STACK10

Priority: High (margin) · reported by e-commerce

Time to fix: 10 min

Failing checks on the shipped build

  • case variants of one code apply once

    expected 9000 but got 7290

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

Black Friday

Inspired by the promo-code exploits that make it to Twitter every Black Friday: enter SAVE10, then save10, then Save10 — and watch the discounts stack. Codes must apply once, case-insensitively.

Promotions.java applies a list of entered codes to a total.

Code map

import java.util.*;

class Promotions {
    static long applyCodes(long totalCents, String[] codes) {
        long total = totalCents;
        for (String code : codes) {
            Integer pct = PromoTable.PERCENT.get(code.toLowerCase());
            if (pct != null) {
                total = total * (100 - pct) / 100;
            }
        }
        return total;
    }
}

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

The Coupon That Stacked Itself — Java Bug Hunt

Inspired by the promo-code exploits that make it to Twitter every Black Friday: enter SAVE10, then save10, then Save10 — and watch the discounts stack.

  • Language: Java
  • Layer: Backend
  • Difficulty: Easy
  • Concepts: Idempotency, Pricing
  • Modelled on: Black Friday
  • Visible tests: case variants of one code apply once; distinct codes compound
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-2 (priority: High (margin))
  • Ticket: BUG-STACK10
  • Reported by: e-commerce
  • Time to fix: 10 minutes, the target for an easy incident

Failing checks on the shipped build

  • case variants of one code apply once — expected 9000 but got 7290

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Briefing

Inspired by the promo-code exploits that make it to Twitter every Black Friday: enter SAVE10, then save10, then Save10 — and watch the discounts stack. Codes must apply once, case-insensitively.

Promotions.java applies a list of entered codes to a total.

Bug report

BUG-STACK10 · Priority: High (margin) · Reported by: e-commerce

applyCodes(totalCents, codes):

  • each KNOWN code applies its percentage once, case-insensitive dedupe
  • unknown codes are ignored
  • discounts compound multiplicatively, integer cents floor at each step

Observed: "SAVE10" + "save10" gives 19%; script kiddies found it in hours.

Logs

[cart] codes=[SAVE10, save10, SAVE10] total 10000 -> 7290

The code as shipped

Promotions.java (editable)

import java.util.*;

class Promotions {
    static long applyCodes(long totalCents, String[] codes) {
        long total = totalCents;
        for (String code : codes) {
            Integer pct = PromoTable.PERCENT.get(code.toLowerCase());
            if (pct != null) {
                total = total * (100 - pct) / 100;
            }
        }
        return total;
    }
}

Read-only context: PromoTable.java.

Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Java bug hunts.