930
Example Language: Java (Bad)
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
CVE-2022-24823 A network application framework uses the Java function createTempFile(),
which will create a file that is readable by other local users of the system
https://www.cve.org/CVERecord?id=CVE-2022-24823
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 964 SFP Secondary Cluster: Exposure Temporary File 888 2402
MemberOf 1403 Comprehensive Categorization: Exposed Resource 1400 2528
Taxonomy Mappings
Mapped Taxonomy Name Node ID Fit Mapped Node Name
CLASP Improper temp file opening
References
[REF-18]Secure Software, Inc.. "The CLASP Application Security Process". 2005. < https://
cwe.mitre.org/documents/sources/TheCLASPApplicationSecurityProcess.pdf >.
CWE-379: Creation of Temporary File in Directory with Insecure Permissions
Weakness ID : 379
Structure : Simple
Abstraction : Base
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
CWE Version 4.14
CWE-379: Creation of Temporary File in Directory with Insecure Permissions
CWE-379: Creation of Temporary File in Directory with Insecure Permissions