CWE-379: Creation of Temporary File in Directory with Insecure PermissionsWeakness ID: 379 Vulnerability Mapping:
ALLOWEDThis CWE ID may be used to map to real-world vulnerabilities Abstraction: BaseBase - 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. |
Description The product creates a temporary file in a directory whose permissions allow unintended actors to determine the file's existence or otherwise access that file. Extended Description On some operating systems, the fact that the temporary file exists may be apparent to any user with sufficient privileges to access that directory. Since the file is visible, the application that is using the temporary file could be known. If one has access to list the processes on the system, the attacker has gained information about what the user is doing at that time. By correlating this with the applications the user is running, an attacker could potentially discover what a user's actions are. From this, higher levels of security could be breached. Relationships This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined as ChildOf, ParentOf, MemberOf and give insight to similar items that may exist at higher and lower levels of abstraction. In addition, relationships such as PeerOf and CanAlsoBe are defined to show similar weaknesses that the user may want to explore. Relevant to the view "Research Concepts" (CWE-1000) Nature | Type | ID | Name |
---|
ChildOf | 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. | 377 | Insecure Temporary File |
This table shows the weaknesses and high level categories that are related to this weakness. These relationships are defined as ChildOf, ParentOf, MemberOf and give insight to similar items that may exist at higher and lower levels of abstraction. In addition, relationships such as PeerOf and CanAlsoBe are defined to show similar weaknesses that the user may want to explore. Relevant to the view "Software Development" (CWE-699) Nature | Type | ID | Name |
---|
MemberOf | Category - a CWE entry that contains a set of other entries that share a common characteristic. | 1219 | File Handling Issues |
Modes Of Introduction The different Modes of Introduction provide information about how and when this weakness may be introduced. The Phase identifies a point in the life cycle at which introduction may occur, while the Note provides a typical scenario related to introduction during the given phase. Common Consequences This table specifies different individual consequences associated with the weakness. The Scope identifies the application security area that is violated, while the Impact describes the negative technical impact that arises if an adversary succeeds in exploiting this weakness. The Likelihood provides information about how likely the specific consequence is expected to be seen relative to the other consequences in the list. For example, there may be high likelihood that a weakness will be exploited to achieve a certain impact, but a low likelihood that it will be exploited to achieve a different impact.Scope | Impact | Likelihood |
---|
Confidentiality
| Technical Impact: Read Application Data Since the file is visible and the application which is using the temp file could be known, the attacker has gained information about what the user is doing at that time. | |
Likelihood Of Exploit Demonstrative Examples Example 1 In the following code examples a temporary file is created and written to. After using the temporary file, the file is closed and deleted from the file system. (bad code) Example Language: C
FILE *stream; if( (stream = tmpfile()) == NULL ) {
perror("Could not open new temporary file\n"); return (-1);
}
// write data to tmp file
... // remove tmp file rmtmp();
However, within this C/C++ code the method tmpfile() is used to create and open the temp file. The tmpfile() method works the same way as the fopen() method would with read/write permission, allowing attackers to read potentially sensitive information contained in the temp file or modify the contents of the file. (bad code) Example Language: Java
try { File temp = File.createTempFile("pattern", ".suffix"); temp.deleteOnExit(); BufferedWriter out = new BufferedWriter(new FileWriter(temp)); out.write("aString"); out.close(); } catch (IOException e) { }
Similarly, the createTempFile() method used in the Java code creates a temp file that may be readable and writable to all users. Additionally both methods used above place the file into a default directory. On UNIX systems the default directory is usually "/tmp" or "/var/tmp" and on Windows systems the default directory is usually "C:\\Windows\\Temp", which may be easily accessible to attackers, possibly enabling them to read and modify the contents of the temp file. Observed Examples Reference | Description |
| A hotkey daemon written in Rust creates a domain socket file underneath /tmp, which is accessible by any user. |
| A Java-based application for a rapid-development framework uses File.createTempFile() to create a random temporary file with insecure default permissions. |
Potential Mitigations
Phase: Requirements Many contemporary languages have functions which properly handle this condition. Older C temp file functions are especially susceptible. |
Phase: Implementation Try to store sensitive tempfiles in a directory which is not world readable -- i.e., per-user directories. |
Phase: Implementation Avoid using vulnerable temp file functions. |
Detection Methods
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.) |
Memberships This MemberOf Relationships table shows additional CWE Categories and Views that reference this weakness as a member. This information is often useful in understanding where a weakness fits within the context of external information sources. Vulnerability Mapping Notes Usage: ALLOWED (this CWE ID could be used to map to real-world vulnerabilities) | Reason: Acceptable-Use | 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. |
Taxonomy Mappings Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
CLASP | | | Guessed or visible temporary file |
CERT C Secure Coding | FIO15-C | | Ensure that file operations are performed in a secure directory |
References
|
[REF-62] Mark Dowd, John McDonald
and Justin Schuh. "The Art of Software Security Assessment". Chapter 9, "Temporary Files", Page 538. 1st Edition. Addison Wesley. 2006.
|
Content History Submissions |
---|
Submission Date | Submitter | Organization |
---|
2006-07-19 (CWE Draft 3, 2006-07-19) | CLASP | | | Modifications |
---|
Modification Date | Modifier | Organization |
---|
2008-07-01 | Eric Dalci | Cigital | updated Time_of_Introduction | 2008-09-08 | CWE Content Team | MITRE | updated Common_Consequences, Relationships, Other_Notes, Taxonomy_Mappings | 2008-11-24 | CWE Content Team | MITRE | updated Relationships, Taxonomy_Mappings | 2009-05-27 | CWE Content Team | MITRE | updated Description, Name | 2009-07-27 | CWE Content Team | MITRE | updated Description, Other_Notes, Potential_Mitigations | 2011-06-01 | CWE Content Team | MITRE | updated Common_Consequences | 2011-09-13 | CWE Content Team | MITRE | updated Relationships, Taxonomy_Mappings | 2012-05-11 | CWE Content Team | MITRE | updated References, Relationships | 2012-10-30 | CWE Content Team | MITRE | updated Demonstrative_Examples | 2014-07-30 | CWE Content Team | MITRE | updated Relationships | 2017-11-08 | CWE Content Team | MITRE | updated Applicable_Platforms, Demonstrative_Examples, Taxonomy_Mappings | 2019-06-20 | CWE Content Team | MITRE | updated Type | 2020-02-24 | CWE Content Team | MITRE | updated Name, References, Relationships, Type | 2021-03-15 | CWE Content Team | MITRE | updated Demonstrative_Examples | 2023-01-31 | CWE Content Team | MITRE | updated Description | 2023-04-27 | CWE Content Team | MITRE | updated Detection_Factors, Relationships, Time_of_Introduction | 2023-06-29 | CWE Content Team | MITRE | updated Mapping_Notes | 2023-10-26 | CWE Content Team | MITRE | updated Observed_Examples | Previous Entry Names |
---|
Change Date | Previous Entry Name |
---|
2008-04-11 | Guessed or Visible Temporary File | | 2009-05-27 | Creation of Temporary File in Directory with Insecure Permissions | | 2020-02-24 | Creation of Temporary File in Directory with Incorrect Permissions | |
More information is available — Please edit the custom filter or select a different filter.
|