Description
Creating and using insecure temporary files can leave application and system data vulnerable to attack.
Potential Impact
Confidentiality, Integrity
Read Files or Directories, Modify Files or Directories
Demonstrative Examples
if (tmpnam_r(filename)) {
FILE* tmp = fopen(filename,"wb+");while((recv(sock,recvbuf,DATA_SIZE, 0) > 0)&(amt!=0)) amt = fwrite(recvbuf,1,DATA_SIZE,tmp);
}...Detection Methods
- Automated Static Analysis High — 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 sea
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| CVE-2022-41954 | A library uses the Java File.createTempFile() method which creates a file with "-rw-r--r--" default permissions on Unix-like operating systems |
Related Weaknesses
Taxonomy Mappings
- 7 Pernicious Kingdoms: — Insecure Temporary File
- CERT C Secure Coding: CON33-C — Avoid race conditions when using library functions
- The CERT Oracle Secure Coding Standard for Java (2011): FIO00-J — Do not operate on files in shared directories
Frequently Asked Questions
What is CWE-377?
CWE-377 (Insecure Temporary File) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Class-level weakness. Creating and using insecure temporary files can leave application and system data vulnerable to attack.
How can CWE-377 be exploited?
Attackers can exploit CWE-377 (Insecure Temporary File) to read files or directories, modify files or directories. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-377?
Follow secure coding practices, conduct code reviews, and use automated security testing tools (SAST/DAST) to detect this weakness early in the development lifecycle.
What is the severity of CWE-377?
CWE-377 is classified as a Class-level weakness (High abstraction). It has been observed in 1 real-world CVEs.