Time-of-Check to Time-of-Use Testing
What you'll learn: How to identify and exploit TOCTOU race conditions by testing the timing gap between when an application validates data and when it actually uses that data.
The Core Problem
TOCTOU testing specifically targets the vulnerable window between validation checks and action execution. While you learned about TOCTOU vulnerabilities conceptually (lesson 902), now you're learning how to actively test for them. Your goal is to manipulate timing so that the value checked is different from the value used.
The Testing Strategy
Think of it like this: A cashier checks that you have 10 for a $1 bill. The cashier already "checked" but now "uses" the wrong value.
In web application testing, you:
- Identify check-then-use patterns — Look for workflows where the app validates something (balance, inventory, permissions) then performs an action moments later
- Send concurrent requests — Fire multiple requests simultaneously during that vulnerable window
- Manipulate state between check and use — Change the validated data after validation but before the action executes
Common Test Scenarios
- Balance checks: Apply the same coupon code multiple times before the "used" flag is set
- Inventory validation: Purchase the last item multiple times before stock updates
- Permission checks: Modify user roles between authorization check and resource access
- File operations: Change file contents between validation and processing
Detection Techniques
Use tools to send rapid, parallel requests. Monitor for inconsistent results — duplicate transactions succeeding, negative balances, or resource over-allocation all signal TOCTOU vulnerabilities.
Key Takeaway: TOCTOU testing exploits the timing gap between validation and execution by deliberately racing multiple requests to manipulate state during that vulnerable window — successful tests reveal missing transaction controls or inadequate locking mechanisms.