The Negative Invoice

Easy

· Backend

Incident

SEV-1

BUG-MINUS

Priority: Critical (fraud) · reported by fintech risk

Time to fix: 10 min

Failing checks on the shipped build

  • negative amounts are rejected

    negative amount: expected an error to be raised

  • insufficient funds are rejected

    expected an error to be raised

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

PayPal-class exploits

Inspired by the classic negative-amount exploits that have hit payment processors: transfer -$500 to someone and the money flows backwards, straight past every balance check.

transfer.py moves money between accounts. It trusts the amount.

Code map

# Moves money between account balances (a dict of name -> cents).

def transfer(balances, src, dst, amount):
    balances[src] = balances[src] - amount
    balances[dst] = balances[dst] + amount
    return balances

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 Negative Invoice — Python Bug Hunt

Inspired by the classic negative-amount exploits that have hit payment processors: transfer -$500 to someone and the money flows backwards, straight past…

  • Language: Python
  • Layer: Backend
  • Difficulty: Easy
  • Concepts: Validation, Payments
  • Modelled on: PayPal-class exploits
  • Visible tests: a normal transfer moves the money; negative amounts are rejected; insufficient funds are rejected
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: Critical (fraud))
  • Ticket: BUG-MINUS
  • Reported by: fintech risk
  • Time to fix: 10 minutes, the target for an easy incident

Failing checks on the shipped build

  • negative amounts are rejected — negative amount: expected an error to be raised
  • insufficient funds are rejected — expected an error to be raised

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 classic negative-amount exploits that have hit payment processors: transfer -$500 to someone and the money flows backwards, straight past every balance check.

transfer.py moves money between accounts. It trusts the amount.

Bug report

BUG-MINUS · Priority: Critical (fraud) · Reported by: fintech risk

transfer(balances, src, dst, amount) rules:

  • amount must be a positive number -> otherwise raise ValueError
  • src must hold at least amount -> otherwise raise ValueError
  • on success, debit src and credit dst; return the updated dict

Observed: amount=-500 silently DRAINS the destination account.

Logs

[xfer] alice->bob amount=-500 | alice 1500 (+500), bob -300 (-500)

The code as shipped

src/pay/transfer.py (editable)

# Moves money between account balances (a dict of name -> cents).

def transfer(balances, src, dst, amount):
    balances[src] = balances[src] - amount
    balances[dst] = balances[dst] + amount
    return balances

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 Python bug hunts.