Toutes les vulnérabilités
HIGHAppSecexploited in the wild

APPSEC-RACE-TOCTOU

Web app · Business-logic race condition / TOCTOU

Résumé

A business-logic race condition exploits the brief window between a check on shared state and the act that mutates it (time-of-check to time-of-use), letting concurrent requests each pass the same check before any of them commits, so a limited resource is consumed more times than allowed (OWASP API6:2023, Unrestricted Access to Sensitive Business Flows). The vulnerable code is any check-then-act sequence on shared state without atomic database-level locking: validate a single-use coupon or gift card then redeem it, check a balance then withdraw or transfer, or verify a one-per-user limit then grant. Firing many near-simultaneous requests collapses the state machine and redeems one coupon multiple times, withdraws the same balance twice, or bypasses a per-user cap. James Kettle's 'Smashing the state machine: the true potential of web race conditions' (PortSwigger, published 9 August 2023, presented at Black Hat USA and DEF CON 31) introduced the single-packet attack, which withholds the final HTTP/2 frames of 20-30 requests and releases them in one TCP packet, neutralizing network jitter and squeezing arrivals into a sub-millisecond window so the race becomes reliably exploitable.

Comment l’éviter dans votre code

  • Use atomic database operations or SELECT FOR UPDATE row locks for check-then-act flows.
  • Enforce uniqueness with database constraints so duplicate redemptions fail on commit.
  • Wrap limited-resource updates in a single serializable transaction.
  • Apply idempotency keys so retried or concurrent requests collapse to one effect.
  • Use atomic counters/decrements instead of read-modify-write on shared state.

Références

Vulnérabilités liées

Tout AppSec →