Time-of-Check to Time-of-Use (TOCTOU) Vulnerabilities
What you'll learn: How attackers exploit the time gap between validation and action to bypass security controls.
The Core Concept
TOCTOU vulnerabilities occur when an application checks a condition (like permissions, balance, or availability), then later uses that information — but the state changes between the check and the use. This timing gap creates a window where attackers can manipulate outcomes through carefully timed requests.
Real-World Analogy
Imagine a bouncer checking your ID at a club entrance, then you walk 50 feet to the actual door. If someone could swap your wristband during that walk, you might get different access than intended. The check happened at one time, but the use happened at another — and state changed in between.
How TOCTOU Works in Web Applications
- Check Phase: Application validates a condition (e.g., "Does user have $100 balance?")
- Time Gap: Brief window between check and action
- Use Phase: Application performs the action based on the earlier check (e.g., "Deduct $100")
- Exploitation: Attacker sends multiple simultaneous requests, racing to exploit the gap before state updates
Common scenarios include:
- Double-spending: Withdrawing the same balance multiple times before the first transaction completes
- Coupon reuse: Applying a single-use discount code in parallel requests
- Inventory overselling: Purchasing the last item multiple times simultaneously
- File operations: Checking file permissions, then accessing it after permissions change
The Danger
Unlike simple race conditions, TOCTOU specifically exploits the validation-to-action workflow, letting attackers bypass checks that appeared secure.
Key Takeaway: TOCTOU vulnerabilities arise when applications assume state remains constant between validation and action — attackers exploit this assumption with precisely timed parallel requests that manipulate intermediate states.