Common mistakes are checking a condition and then acting on it later, which leaves a window for the object to change. Avoid separate validation and use steps for files, permissions or identities when possible, and recheck state immediately before use. Attackers exploit races to swap paths, permissions or data after the check.
Why TOCTOU mistakes happen
The core mistake is treating a check and the later use as if they were one atomic action. In practice, any gap between validation and use can let the underlying file, permission, object, or identity change, so the thing you approved is no longer the thing you act on.
This is why TOCTOU bugs often show up in code that looks reasonable in review but still fails under concurrency, scheduling delays, or attacker-controlled races. The danger is not the check itself, it is the assumption that the checked state remains valid long enough to matter.
When the subject involves file paths, permissions, or trust decisions, the safest design is usually to reduce the time between decision and action, or better, to operate on the same handle, descriptor, or resolved object rather than re-resolving it later. For a broader treatment of race conditions and root-cause weakness patterns, see the CWE Top 25 Guide.
Where teams commonly get TOCTOU wrong
One common error is validating a filename, permission, or ownership state and then opening or using the target by name later. That creates room for symbolic-link swaps, path replacement, permission changes, or object substitution after the check has passed.
Another frequent mistake is relying on a separate authorization or identity check and then assuming the same access still exists moments later. If the decision and the action are split across different calls, threads, or services, the original trust decision can be stale by the time the protected action runs.
A third mistake is using “check first, use later” patterns in code paths that handle sensitive files, temporary objects, or admin operations without considering adversarial timing. If the implementation can be induced to pause, retry, or block, the race window becomes easier to hit. The same pattern appears in remediation programs when teams verify a weakness once and then assume the environment has not changed before the fix is applied; the Vulnerability Management Guide is useful for the broader discipline of verification, prioritisation, and closure.
How to design out the race window
The best fix is to avoid designs that depend on state remaining unchanged between two separate operations. If the platform gives you an atomic operation, use it. If not, keep the check and the use tied to the same object or handle, and revalidate immediately before the action that matters.
For file and path handling, prefer secure creation and access patterns that do not trust a later name lookup. For permission-sensitive operations, confirm that the effective state at the moment of use is the state you intended to approve. For identity-sensitive flows, avoid assuming a prior decision still holds after a delay, redirect, or context switch.
When the environment is already under suspicion, it is reasonable to treat repeated races as a sign of active exploitation rather than random failure. TOCTOU abuse is attractive because it can bypass sensible-looking controls without needing to defeat them directly. If you need a threat-focused reference for exploitation patterns and post-compromise response, the Zero-Day and Exploited Vulnerabilities Guide covers emergency mitigation and compromise assessment.
Risk and Threat Considerations
TOCTOU flaws are risky because the attacker does not need to win the initial validation step, only the interval before use. That makes the weakness especially dangerous in code that protects files, elevated operations, temporary resources, or access decisions that can be altered mid-flight.
Failure mechanism: An attacker changes the object, path, permission state, or linked target after the check succeeds but before the privileged use occurs, so the program acts on a different state than the one it approved.
Impact: The result can be unauthorized file access, privilege abuse, data replacement, policy bypass, or execution of an action against an unintended target, especially when the race is repeatable under load or timing pressure.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP ASVS, NIST SP 800-53 Rev 5 and CIS Controls v8 set the technical controls, while ISO/IEC 27001:2022 defines the regulatory obligations.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP ASVS | V8 — Authorization | TOCTOU often breaks authorization decisions that go stale before use. |
| Recommendation — Apply V8 to keep authorization tied to the exact action and object being accessed. | ||
| NIST SP 800-53 Rev 5 | AC-3 — Access Enforcement | TOCTOU can bypass enforced access decisions when state changes between check and use. |
| SI-10 — Information Input Validation | The issue often starts with validation that is later invalidated by a state change. | |
| Recommendation — Enforce AC-3 at the moment of use, not only at the earlier validation step. Combine SI-10 with atomic use patterns so validation remains effective through execution. | ||
| CIS Controls v8 | CIS-6 — Access Control Management | TOCTOU affects how access decisions are granted and applied in practice. |
| Recommendation — Use CIS-6 to minimize separate check-and-use access flows where possible. | ||
| ISO/IEC 27001:2022 | A.8.2 — Privileged access rights | Privilege-sensitive TOCTOU mistakes can turn a brief race into unauthorized elevated action. |
| Recommendation — Control A.8.2 so privileged actions rely on current, bounded access decisions. | ||
Practitioner Guidance
What to verify: Confirm whether the code validates one object and uses another reference later, especially where names, paths, or permissions are resolved more than once. If the protection depends on “nothing changing in between,” treat that as the design problem, not just an implementation bug.
Decision rule: If the operation has security consequences, prefer atomic primitives or single-handle workflows over separate check-then-act logic. If atomicity is unavailable, recheck immediately before use and assume that any delay, retry, or context switch increases exploitability.
Practitioner takeaway: TOCTOU is usually fixed by removing the gap, not by trusting the check more. The key judgement is whether the security decision and the use can be made against the same live object at the same moment.
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on October 19, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org