| Impact | Details |
|---|---|
|
Alter Execution Logic; Unexpected State |
Scope: Integrity, Other
The attacker can gain access to otherwise unauthorized resources.
|
|
Modify Application Data; Modify Files or Directories; Modify Memory; Other |
Scope: Integrity, Other
Race conditions such as this kind may be employed to gain read or write access to resources which are not normally readable or writable by the user in question.
|
|
Other |
Scope: Integrity, Other
The resource in question, or other resources (through the corrupted one), may be changed in undesirable ways by a malicious user.
|
|
Hide Activities |
Scope: Non-Repudiation
If a file or other resource is written in this method, as opposed to in a valid way, logging of the activity may not occur.
|
|
Other |
Scope: Non-Repudiation, Other
In some cases it may be possible to delete files a malicious user might not otherwise have access to, such as log files.
|
|
Unexpected State |
Scope: Other
The product may perform invalid actions when the resource is in an unexpected state.
|
| Phase(s) | Mitigation |
|---|---|
|
Implementation |
The most basic advice for TOCTOU vulnerabilities is to not perform a check before the use. This does not resolve the underlying issue of the execution of a function on a resource whose state and identity cannot be assured, but it does help to limit the false sense of security given by the check.
|
|
Implementation |
When the file being altered is owned by the current user and group, set the effective gid and uid to that of the current user and group when executing this statement.
|
|
Architecture and Design |
Limit the interleaving of operations on files from multiple processes.
|
|
Implementation; Architecture and Design |
If you cannot perform operations atomically and you must share access to the resource between multiple processes or threads, then try to limit the amount of time (CPU cycles) between the check and use of the resource. This will not fix the problem, but it could make it more difficult for an attack to succeed.
|
|
Implementation |
Recheck the resource after the use call to verify that the action was taken appropriately.
|
|
Architecture and Design |
Ensure that some environmental locking mechanism can be used to protect resources effectively.
|
|
Implementation |
Ensure that locking occurs before the check, as opposed to afterwards, such that the resource, as checked, is the same as it is when in use.
|
| Nature | Type | ID | Name |
|---|---|---|---|
| ChildOf | Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. | 362 | Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition') |
| ParentOf | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 363 | Race Condition Enabling Link Following |
| PeerOf | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 386 | Symbolic Name not Mapping to Correct Object |
| CanFollow | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 609 | Double-Checked Locking |
| Nature | Type | ID | Name |
|---|---|---|---|
| MemberOf | Category Category - a CWE entry that contains a set of other entries that share a common characteristic. | 557 | Concurrency Issues |
| Nature | Type | ID | Name |
|---|---|---|---|
| ChildOf | Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. | 362 | Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition') |
| Phase | Note |
|---|---|
| Implementation | This weakness can be security-relevant when an attacker can influence the state of the resource between check and use. This can happen with shared resources such as files, memory, or even variables in multithreaded programs. |
Class: Not Language-Specific (Undetermined Prevalence)
Example 1
The following code checks a file, then updates its contents.
Potentially the file could have been updated between the time of the check and the lstat, especially since the printf has latency.
Example 2
The following code is from a program installed setuid root. The program performs certain file operations on behalf of non-privileged users, and uses access checks to ensure that it does not use its root privileges to perform operations that should otherwise be unavailable the current user. The program uses the access() system call to check if the person running the program has permission to access the specified file before it opens the file and performs the necessary operations.
The call to access() behaves as expected, and returns 0 if the user running the program has the necessary permissions to write to the file, and -1 otherwise. However, because both access() and fopen() operate on filenames rather than on file handles, there is no guarantee that the file variable still refers to the same file on disk when it is passed to fopen() that it did when it was passed to access(). If an attacker replaces file after the call to access() with a symbolic link to a different file, the program will use its root privileges to operate on the file even if it is a file that the attacker would otherwise be unable to modify. By tricking the program into performing an operation that would otherwise be impermissible, the attacker has gained elevated privileges. This type of vulnerability is not limited to programs with root privileges. If the application is capable of performing any operation that the attacker would not otherwise be allowed perform, then it is a possible target.
Example 3
This code prints the contents of a file if a user has permission.
This code attempts to resolve symbolic links before checking the file and printing its contents. However, an attacker may be able to change the file from a real file to a symbolic link between the calls to is_link() and file_get_contents(), allowing the reading of arbitrary files. Note that this code fails to log the attempted access (CWE-778).
Example 4
This example is adapted from [REF-18]. Assume that this code block is invoked from multiple threads. The switch statement will execute different code depending on the time when MYFILE.txt was last changed.
If this code block were executed within multiple threads, and MYFILE.txt changed between the operation of one thread and another, then the switch could produce different, possibly unexpected results.
Note: this is a curated list of examples for users to understand the variety of ways in which this weakness can be introduced. It is not a complete list of all CVEs that are related to this CWE entry.
| Reference | Description |
|---|---|
|
TOCTOU in sandbox process allows installation of untrusted browser add-ons by replacing a file after it has been verified, but before it is executed
|
|
|
PHP flaw allows remote attackers to execute arbitrary code by aborting execution before the initialization of key data structures is complete.
|
|
|
chain: time-of-check time-of-use (TOCTOU) race condition in program allows bypass of protection mechanism that was designed to prevent symlink attacks.
|
|
|
chain: time-of-check time-of-use (TOCTOU) race condition in program allows bypass of protection mechanism that was designed to prevent symlink attacks.
|
| Method | Details |
|---|---|
|
Automated Static Analysis |
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
Effectiveness: High |
| Nature | Type | ID | Name |
|---|---|---|---|
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 361 | 7PK - Time and State |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 743 | CERT C Secure Coding Standard (2008) Chapter 10 - Input Output (FIO) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 877 | CERT C++ Secure Coding Section 09 - Input Output (FIO) |
| MemberOf | ViewView - a subset of CWE entries that provides a way of examining CWE content. The two main view structures are Slices (flat lists) and Graphs (containing relationships between entries). | 884 | CWE Cross-section |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 988 | SFP Secondary Cluster: Race Condition Window |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1401 | Comprehensive Categorization: Concurrency |
Rationale
This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.Comments
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.Relationship
Research Gap
| Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
|---|---|---|---|
| PLOVER | Time-of-check Time-of-use race condition | ||
| 7 Pernicious Kingdoms | File Access Race Conditions: TOCTOU | ||
| CLASP | Time of check, time of use race condition | ||
| CLASP | Race condition in switch | ||
| CERT C Secure Coding | FIO01-C | Be careful using functions that use file names for identification | |
| Software Fault Patterns | SFP20 | Race Condition Window |
| Submissions | |||
|---|---|---|---|
| Submission Date | Submitter | Organization | |
|
2006年07月19日
(CWE Draft 3, 2006年07月19日) |
PLOVER | ||
| Modifications | |||
| Modification Date | Modifier | Organization | |
|
2025年09月09日
(CWE 4.18, 2025年09月09日) |
CWE Content Team | MITRE | |
| updated Common_Consequences, Description, Diagram, Modes_of_Introduction | |||
|
2025年04月03日
(CWE 4.17, 2025年04月03日) |
CWE Content Team | MITRE | |
| updated Affected_Resources, Observed_Examples | |||
| 2023年06月29日 | CWE Content Team | MITRE | |
| updated Mapping_Notes | |||
| 2023年04月27日 | CWE Content Team | MITRE | |
| updated Detection_Factors, References, Relationships | |||
| 2023年01月31日 | CWE Content Team | MITRE | |
| updated Description | |||
| 2022年06月28日 | CWE Content Team | MITRE | |
| updated Observed_Examples | |||
| 2022年04月28日 | CWE Content Team | MITRE | |
| updated Demonstrative_Examples, References, Relationships, Taxonomy_Mappings | |||
| 2020年02月24日 | CWE Content Team | MITRE | |
| updated References, Relationships | |||
| 2019年06月20日 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2017年11月08日 | CWE Content Team | MITRE | |
| updated Applicable_Platforms, Demonstrative_Examples, Likelihood_of_Exploit, References, Relationships, Taxonomy_Mappings, White_Box_Definitions | |||
| 2014年07月30日 | CWE Content Team | MITRE | |
| updated Demonstrative_Examples, Relationships, Taxonomy_Mappings | |||
| 2012年10月30日 | CWE Content Team | MITRE | |
| updated Potential_Mitigations | |||
| 2012年05月11日 | CWE Content Team | MITRE | |
| updated Demonstrative_Examples, Observed_Examples, References, Relationships | |||
| 2011年09月13日 | CWE Content Team | MITRE | |
| updated Relationships, Taxonomy_Mappings | |||
| 2011年06月27日 | CWE Content Team | MITRE | |
| updated Common_Consequences | |||
| 2011年06月01日 | CWE Content Team | MITRE | |
| updated Common_Consequences | |||
| 2010年12月13日 | CWE Content Team | MITRE | |
| updated Alternate_Terms, Relationships | |||
| 2010年09月27日 | CWE Content Team | MITRE | |
| updated Description, Relationships | |||
| 2009年07月27日 | CWE Content Team | MITRE | |
| updated White_Box_Definitions | |||
| 2009年07月17日 | KDM Analytics | ||
| Improved the White_Box_Definition | |||
| 2009年05月27日 | CWE Content Team | MITRE | |
| updated Demonstrative_Examples | |||
| 2009年01月12日 | CWE Content Team | MITRE | |
| updated Alternate_Terms, Observed_Examples, Other_Notes, References, Relationship_Notes, Relationships, Research_Gaps | |||
| 2008年11月24日 | CWE Content Team | MITRE | |
| updated Relationships, Taxonomy_Mappings | |||
| 2008年10月14日 | CWE Content Team | MITRE | |
| updated Description, Name, Relationships | |||
| 2008年09月08日 | CWE Content Team | MITRE | |
| updated Common_Consequences, Relationships, Other_Notes, Taxonomy_Mappings | |||
| 2008年08月01日 | KDM Analytics | ||
| added/updated white box definitions | |||
| 2008年07月01日 | Eric Dalci | Cigital | |
| updated Time_of_Introduction | |||
| Previous Entry Names | |||
| Change Date | Previous Entry Name | ||
| 2008年10月14日 | Time-of-check Time-of-use Race Condition | ||
Use of the Common Weakness Enumeration (CWE™) and the associated references from this website are subject to the Terms of Use. CWE is sponsored by the U.S. Department of Homeland Security (DHS) Cybersecurity and Infrastructure Security Agency (CISA) and managed by the Homeland Security Systems Engineering and Development Institute (HSSEDI) which is operated by The MITRE Corporation (MITRE). Copyright © 2006–2025, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation.