The textbook race condition is a single-use coupon that gets applied three times. A transfer that takes a balance below zero is the same bug, and so is a 2FA code with "three attempts" that lets you try nine: the server checks a condition, then acts, and a second request gets in between.

You can find these by hand with Burp Repeater's "send group in parallel" and some luck. The harder part is proving the bug well enough that the developer can't reply "works on my machine", and later checking in CI that the fix still holds. I wrote PhotoFinish, an open-source Go tool, for that part.

PhotoFinish runs a coupon race against the demo shop: trials arrive live and the verdict is VIOLATED

Why 20 threads aren't enough

Send 20 requests from 20 threads and they reach the server milliseconds apart, because each one goes through its own TCP, TLS and scheduler path. The race window in a typical handler (between the SELECT and the UPDATE) is often under a millisecond, so most of those requests just pass through it one after another.

In 2023 James Kettle of PortSwigger published the HTTP/2 single-packet attack ("Smashing the state machine"):

  1. Open one HTTP/2 connection.
  2. For every request, send HEADERS and all of the body except the last byte, without END_STREAM. The server holds each request open.
  3. Wait briefly.
  4. Write the final frames of every stream (the last body byte, or an empty DATA frame with END_STREAM) in one write call. That is one TLS record and usually one TCP packet.

All the requests complete at the server at the same moment, and network jitter drops out of the picture. For HTTP/1.1 the older last-byte sync does the same thing with one connection per request.

What I was missing

Tools for sending these races already exist: Turbo Intruder in Burp and the h2spacex Python library. They handle the sending. After that you have 20 responses, you decide yourself whether a race happened, and there's no way to repeat it in CI.

I wanted something that would:

  • prepare state before every trial (reset data, create a cart);
  • check a business rule after the race instead of looking at status codes;
  • repeat the trial and report honestly how often the rule broke;
  • keep the evidence, meaning per-stream timings and the server-side arrival time;
  • exit with a code CI understands.

A scenario

Scenarios are YAML. This is a shortened version of the coupon scenario for the demo shop that ships with the tool:

version: 1 name: coupon-vuln target: https://127.0.0.1:8443/vuln/api tls: { insecure: true } scope: allow_hosts: [127.0.0.1:8443] setup: - request: POST /reset - id: cart request: POST /carts extract: { cart_id: "$.id" } race: engine: auto copies: 20 request: raw: | POST /carts/{{cart_id}}/coupons HTTP/2 Content-Type: application/json {"code":"WELCOME10"} check: request: GET /carts/{{cart_id}} invariant: > size(check.json.discounts) <= 1 && size(race.filter(r, r.status == 200)) <= 1 trials: 10 

The rule is written in CEL, the expression language Kubernetes and Envoy use. PhotoFinish evaluates each conjunct separately, so the report says size(check.json.discounts) <= 1 was 3 <= 1 rather than a bare false.

scope.allow_hosts is mandatory. The tool talks only to the hosts listed there and enforces a request budget, so a typo in a URL can't send twenty payments somewhere else.

Verdicts

  • VIOLATED: the rule broke in at least one trial. That counts as proof.
  • HELD: it never broke. The summary says so in plain words: "not reproduced in 10 trials … this is not proof of absence".
  • INCONCLUSIVE: the tool can't tell. Responses arrived before release (the server didn't wait for the body), 429s, network errors, or a setup step failed.
  • ERROR: the scenario didn't run.

The exit codes, in the same order, are 1, 0, 2 and 3.

Numbers

The demo shop has four classic races (coupon, transfer, 2FA attempt limit, gift card). Each comes in a vulnerable variant and a fixed one that uses a transaction with a row lock. I didn't stretch the race window artificially; it's ordinary read-check-write code over SQLite.

The benchmark ran on a GitHub Actions runner with 4 CPUs, with the tool and the shop on the same machine, 20 copies and 30 trials per combination. I ran it on plain loopback first, then with delay and jitter added to loopback by tc netem, which delays each packet independently the way a real network does.

The first thing I wanted to know was whether the requests really arrive together. The demo puts the moment it has the whole request, body included, into an X-Arrival-Ns header. Here is the median spread of that moment within one race:

Network h2 h1 burst
loopback 0.05–0.14 ms 0.05–0.13 ms 0.49–2.37 ms
1 ms ± 0.5 ms jitter 0.05–0.17 ms 1.36–1.85 ms 0.76–2.09 ms
5 ms ± 2 ms jitter 0.08–0.21 ms 6.05–7.43 ms 3.06–4.82 ms

With h2 the ends of all 20 requests travel in one TCP packet, so jitter has nothing to pull apart. With h1 the last bytes go out as 20 packets on separate connections, and each packet gets its own delay.

And this is how many of the 30 trials broke the rule on the vulnerable variants:

Scenario Network h2 h1 burst
coupon loopback 18 17 6
transfer loopback 19 25 5
2FA 1 ms jitter 29 9 19
gift card 1 ms jitter 25 9 12
2FA 5 ms jitter 29 0 14
coupon 5 ms jitter 7 4 14

The last row breaks the pattern: with 5 ms of jitter, burst broke the coupon rule 14 times and h2 only 7. Requests have to arrive close together for a race to happen, but that alone doesn't guarantee one. Once every request is at the server, the server's scheduling decides whether they interleave inside the window. In the demo that means 20 goroutines taking turns on one SQLite connection. That's why the report shows the arrival spread next to the verdict: if the spread is tight and the rule held, the sync did its job and the requests just didn't interleave on the server.

The fixed variants came out HELD in all 1,080 trials, with every engine and on every network. BENCHMARKS.md has the full tables and caveats.

Reports and CI

Besides text, PhotoFinish writes JSON, SARIF (for GitHub code scanning), JUnit XML and a self-contained HTML page with a stream timeline. There's a GitHub Action too:

- uses: TroubieD3v/PhotoFinish@v0 with: scenarios: tests/race/*.yaml 

The run screen: trials, the timeline of one race and the evaluated invariant

There's also a local web UI (photofinish serve) with a scenario editor that validates as you type, plus runs, the timeline and history. Since it can send attack traffic, it listens only on 127.0.0.1 and requires a session token.

Not there yet

  • First sequence sync (RyotaK's technique for HTTP/1.1) is planned.
  • No HTTP/3.
  • It doesn't find races by itself. It proves a hypothesis you state, so you need an idea of where to look; anywhere a limit is checked before something is spent is a good start.

Try it

Prebuilt binaries for Linux, macOS and Windows are on the release page: https://github.com/TroubieD3v/PhotoFinish/releases/tag/v0.1.0. The quickest way in is the web UI, which comes with the demo shop and the examples:

./photofinish serve --demo --open 

From the command line, using the examples in the repository:

git clone https://github.com/TroubieD3v/PhotoFinish && cd PhotoFinish go build -o bin/photofinish ./cmd/photofinish ./bin/photofinish demo & ./bin/photofinish run examples/coupon-vuln.yaml 

There's also go install github.com/TroubieD3v/photofinish/cmd/photofinish@latest (no web UI in that build) and a Docker image, ghcr.io/troubied3v/photofinish.

Repo: https://github.com/TroubieD3v/PhotoFinish (MIT). Only test systems you own or are authorized to test.

If you have scenarios from real cases (with nobody's secrets in them) or measurements against other servers like nginx, Node or Python ASGI, I'd like to see them. I'm especially curious where h2 and burst diverge the most.