Join our Newsletter — 33% off our NHI Course
Home Glossary AI Security Time-of-check/time-of-use (TOCTOU)
AI Security

Time-of-check/time-of-use (TOCTOU)

← Back to Glossary
By NHI Mgmt Group Updated August 19, 2026 Domain: AI Security

A TOCTOU flaw happens when a system verifies one thing and later acts on a different version of it. In agentic workflows, that means a script, package, or binary can look safe during inspection but be altered before execution, breaking the trust chain.

Expanded Definition

Time-of-check/time-of-use, or TOCTOU, describes a race condition where a system validates a resource, decision, or file at one moment and then relies on it later, after the underlying state may have changed. The flaw is not the check itself, but the gap between verification and action. In cybersecurity, that gap can exist in local file handling, permission checks, package installation, container startup, and automated workflows that hand off execution to scripts or agents.

TOCTOU is especially important in agentic and software-supply-chain contexts because inspection often happens before execution, not during it. A binary may be hashed, a package may be scanned, or a path may be approved, yet the object can be swapped, relinked, or rewritten before the system acts. The issue sits close to broader integrity and authorization concerns covered by the NIST Cybersecurity Framework 2.0, but TOCTOU is a specific implementation flaw rather than a governance objective.

Definitions vary across vendors when TOCTOU appears inside broader labels such as race condition, integrity bypass, or unsafe execution flow. NHI Management Group treats it as a precision term: the relevant question is whether the checked object, identity, or permission can change before the operation completes. The most common misapplication is treating any later failure as TOCTOU, which occurs when the change happens after the decision point but before the action, not simply when a system behaves unexpectedly.

Examples and Use Cases

Implementing controls against TOCTOU rigorously often introduces latency and revalidation overhead, requiring organisations to weigh execution speed against stronger integrity guarantees.

  • A build pipeline scans a package, then installs it from a mutable location where the archive is replaced before installation.
  • A file permission check confirms a script is safe, but an attacker swaps the file contents through a symlink or rename before execution.
  • An agentic workflow approves a tool invocation, yet the command target changes between policy evaluation and runtime dispatch.
  • A privileged automation job verifies a configuration file, then reads a different version after a mount, link, or path change.
  • A deployment process validates a container image digest, then pulls from an unpinned source that no longer matches the original check.

These patterns are discussed in secure coding and systems guidance from sources such as MITRE CWE-367, which names the underlying race-condition class, and they map well to controls that insist on immutable references, atomic operations, and post-check verification. In practice, the safest designs reduce or eliminate the interval between validation and use, especially when secrets, credentials, or executable artifacts are involved.

Why It Matters for Security Teams

TOCTOU matters because it undermines confidence in almost every control that depends on a one-time decision: access checks, malware scans, integrity validation, package trust, and policy approval. If the object can change after inspection, then the control records a false sense of safety. That creates a weak point for privilege escalation, supply-chain tampering, and agent hijacking, especially where an AI agent or automation runner executes on behalf of a trusted identity.

Security teams should look for TOCTOU risk in workflows that combine file-system access, external downloads, ephemeral containers, delegated execution, and identity-based approvals. NIST guidance on access control and system integrity aligns with the practical response: use atomic operations, pin immutable artifacts, revalidate at the point of use, and restrict write access to anything that has already been checked. The same thinking also applies to non-human identities that retrieve or execute artifacts on a schedule or in response to events.

Organisations typically encounter TOCTOU only after a benign validation step is followed by a compromised action, at which point the flaw becomes operationally unavoidable to address.

Standards & Framework Alignment

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

OWASP Agentic AI Top 10 and OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST CSF 2.0, NIST SP 800-53 Rev 5 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
NIST CSF 2.0PR.AC-4Access decisions lose meaning if the checked resource changes before use.
NIST SP 800-53 Rev 5SI-7Integrity checks are relevant when data or code can change after inspection.
OWASP Agentic AI Top 10Agentic execution paths can be redirected between approval and runtime action.
OWASP Non-Human Identity Top 10NHI credentials and automation identities can be abused when checked artifacts change later.
NIST Zero Trust (SP 800-207)3.3Zero Trust emphasizes continuous verification, which reduces trust in stale checks.

Revalidate access-sensitive objects at the point of use and minimize mutable intermediates.

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