Join our Newsletter — 33% off our NHI Course
Home› Glossary› Cyber Security› TOCTOU Race Condition
Cyber Security

TOCTOU Race Condition

← Back to Glossary
By NHI Mgmt Group Updated October 31, 2026 Domain: Cyber Security

A TOCTOU race condition happens when a program checks something, then acts on it later, and the state changes in between. In security terms, attackers exploit that gap to swap files, paths, or permissions so a trusted process performs an unsafe action.

What Makes TOCTOU Race Conditions Dangerous

A time-of-check, time-of-use flaw is dangerous because security decisions are made on stale assumptions. The program validates a file, path, object, or permission state, then uses it later without preserving that state, creating a window where an attacker can change what is actually acted on.

This class of bug matters whenever a trusted process crosses a boundary between verification and execution. A pathname that looked safe during the check may point somewhere else at use time, or a permission state may no longer be the one the code relied on.

Common Security Failure Modes

TOCTOU bugs often show up in file handling, temporary-file workflows, link following, permission checks, and any code that assumes a resource will not change between two separate operations. They are especially risky when privileged code trusts user-controlled inputs or shared system state.

Attackers typically exploit the gap by swapping a file, replacing a path with a symbolic link, or otherwise changing the object the program will later touch. The vulnerability is not the check itself, but the fact that the check and the use are not atomic.

Concurrency makes the problem harder to spot because the failure can be intermittent. A test that passes many times can still fail under contention, high load, or deliberate timing manipulation by an attacker.

Why Atomicity Is the Real Control

The practical defence is to remove the gap rather than hope it is too small to exploit. Safe designs use atomic operations, single-step permission decisions, kernel-enforced file descriptors, locking, transaction semantics, or other mechanisms that ensure the checked state is the same state being used.

Where atomicity is not possible, the code should reduce trust in mutable names and re-validate the exact object it will act on. That is why secure implementations tend to prefer descriptor-based handling, constrained directories, and patterns that avoid re-resolving a path after validation.

TOCTOU is a design problem as much as a coding mistake. Once a workflow depends on state being unchanged across two separate steps, the burden shifts to the implementation to prove that the state cannot be altered in a meaningful way.

Detection and Review After Exploitation

Because TOCTOU exploitation often blends into ordinary program flow, detection usually depends on tracing the sequence of events around the sensitive action. Unusual file replacements, link swaps, permission changes, or rapid state transitions near a privileged operation are all useful signals.

After a suspected compromise, review the exact resources the process checked, the exact resources it used, and whether any security-sensitive action occurred in the gap. If the flaw involved files, paths, or credentials, treat the post-incident review as a state-integrity investigation, not just a generic malware check.

For deeper background on the vulnerability class, Race Condition Vulnerabilities Guide explains how TOCTOU flaws arise and how atomic design patterns reduce them. A related weakness taxonomy is covered in CWE Top 25 Guide, which helps place TOCTOU within broader software weakness patterns.

Risk and Threat Considerations

TOCTOU races are dangerous because they let an attacker turn a legitimate validation step into a false reassurance. If a privileged process checks one thing and then acts on a different state, the attacker can steer that action toward a file, path, or permission state that would not have passed the original check.

Failure mechanism: The attacker changes a mutable object between validation and use, often through path replacement, symbolic links, or rapid state changes that exploit non-atomic code.

Impact: The trusted process may overwrite, execute, or disclose the wrong resource, creating privilege abuse, data tampering, or unauthorized access.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

NIST SP 800-53 Rev 5, CIS Controls v8 and OWASP ASVS set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
NIST SP 800-53 Rev 5SC-39 — Process IsolationTOCTOU exploits cross trust boundaries between validation and use.
AC-3 — Access EnforcementTOCTOU can bypass the access decision a process thought it had already verified.
CM-5 — Access Restrictions for ChangeRace conditions often arise when objects or paths can be modified during sensitive operations.
Recommendation — Use process isolation to reduce opportunities for state changes between check and use. Enforce access at the moment of use, not only during pre-checks. Restrict concurrent changes to security-sensitive objects during privileged operations.
CIS Controls v8CIS-4 — Secure Configuration of Enterprise Assets and SoftwareRace-prone workflows are often created or amplified by unsafe system and software configuration.
Recommendation — Harden sensitive workflows so paths, permissions, and temporary objects cannot be swapped mid-operation.
OWASP ASVSV15 — Secure Coding and ArchitectureTOCTOU is a secure design and implementation flaw in state handling.
Recommendation — Design checks and uses to be atomic wherever security decisions depend on mutable state.

Practitioner Guidance

What to watch for: Review any code that checks a resource and later reopens, re-resolves, or reuses it by name. The risk is highest when the operation runs with elevated privileges, touches security-sensitive files, or depends on filesystem state remaining unchanged.

Governance implication: Treat atomicity as a design requirement, not a hardening detail. If a workflow cannot guarantee stable state across check and use, redesign it around a single authoritative operation or a handle that binds the check to the use.

Practitioner takeaway: If the resource can change between the check and the action, the check is not a security control, it is only a momentary observation.

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.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 31, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org