926
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
Demonstrative Examples
Example 1:
The following code uses a temporary file for storing intermediate data gathered from the network
before it is processed.
Example Language: C (Bad)
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);
}
...
This otherwise unremarkable code is vulnerable to a number of different attacks because it relies
on an insecure method for creating temporary files. The vulnerabilities introduced by this function
and others are described in the following sections. The most egregious security problems related to
temporary file creation have occurred on Unix-based operating systems, but Windows applications
have parallel risks. This section includes a discussion of temporary file creation on both Unix and
Windows systems. Methods and behaviors can vary between systems, but the fundamental risks
introduced by each are reasonably constant.
Observed Examples
Reference 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
https://www.cve.org/CVERecord?id=CVE-2022-41954
MemberOf Relationships
This MemberOf relationships table shows additional CWE Catgeories 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.
Nature Type ID Name Page
MemberOf 361 7PK - Time and State 700 2320
MemberOf 857 The CERT Oracle Secure Coding Standard for Java
(2011) Chapter 14 - Input Output (FIO)
844 2368
MemberOf 964 SFP Secondary Cluster: Exposure Temporary File 888 2402
MemberOf 1147 SEI CERT Oracle Secure Coding Standard for Java -
Guidelines 13. Input Output (FIO)
1133 2450
MemberOf 1169 SEI CERT C Coding Standard - Guidelines 14.
Concurrency (CON)
1154 2462
MemberOf 1345 OWASP Top Ten 2021 Category A01:2021 - Broken
Access Control
1344 2487
MemberOf 1366 ICS Communications: Frail Security in Protocols 1358 2503
MemberOf 1403 Comprehensive Categorization: Exposed Resource 1400 2528
Notes
Other
Applications require temporary files so frequently that many different mechanisms exist for
creating them in the C Library and Windows(R) API. Most of these functions are vulnerable to
various forms of attacks. The functions designed to aid in the creation of temporary files can be
CWE Version 4.14
CWE-377: Insecure Temporary File
CWE-377: Insecure Temporary File