What it is: Creation of Temporary File With Insecure Permissions (CWE-378) is a vulnerability where temporary files are created without proper security measures.
Why it matters: This can lead to unauthorized access, modification, or movement of sensitive data and functions.
How to fix it: Use secure temp file functions that restrict permissions and randomize filenames.
TL;DR: Creation of Temporary File With Insecure Permissions (CWE-378) is a vulnerability where temporary files are created without proper security measures, leading to unauthorized access. Securely manage these files with restricted permissions and randomized names.
| Field | Value |
|---|---|
| CWE ID | CWE-378 |
| OWASP Category | Not directly mapped |
| CAPEC | None known |
| Typical Severity | High |
| Affected Technologies | C, C++, Python, Java, Node.js, PHP |
| Detection Difficulty | Moderate |
| Last Updated | 2026-07-29 |
What is Creation of Temporary File With Insecure Permissions?
Creation of Temporary File With Insecure Permissions (CWE-378) is a type of vulnerability that occurs when temporary files are created without appropriate security measures, allowing unauthorized access or modification. As defined by the MITRE Corporation under CWE-378, and classified by the OWASP Foundation as not directly mapped.
Quick Summary
Creation of Temporary File With Insecure Permissions compromises application data integrity and confidentiality by enabling attackers to read, modify, or move sensitive files. This vulnerability can lead to unauthorized access control privileges and potential data breaches. Jump to: Overview · How It Works · Business Impact · Attack Scenario · Detection · Fixing
Jump to: Quick Summary · Creation of Temporary File With Insecure Permissions Overview · How Creation of Temporary File With Insecure Permissions Works · Business Impact of Creation of Temporary File With Insecure Permissions · Creation of Temporary File With Insecure Permissions Attack Scenario · How to Detect Creation of Temporary File With Insecure Permissions · How to Fix Creation of Temporary File With Insecure Permissions · Framework-Specific Fixes for Creation of Temporary File With Insecure Permissions · How to Ask AI to Check Your Code for Creation of Temporary File With Insecure Permissions · Creation of Temporary File With Insecure Permissions Best Practices Checklist · Creation of Temporary File With Insecure Permissions FAQ · Vulnerabilities Related to Creation of Temporary File With Insecure Permissions · References · Scan Your Own Site
Creation of Temporary File With Insecure Permissions Overview
What: CWE-378 involves the creation of temporary files without proper security measures, leading to insecure permissions.
Why it matters: This vulnerability can expose sensitive data and allow unauthorized modifications or movements of critical system files.
Where it occurs: Primarily in applications that use temporary files for various purposes such as caching, logging, or storing intermediate data.
Who is affected: Applications using temporary files without proper security measures are at risk.
Who is NOT affected: Systems already using secure temp file functions and randomized filenames.
How Creation of Temporary File With Insecure Permissions Works
Root Cause
Temporary files are created with insecure permissions that allow unauthorized access or modification by other users or processes.
Attack Flow
- An attacker identifies a temporary file with insecure permissions.
- The attacker reads, modifies, or moves the file to gain additional privileges within the system.
Prerequisites to Exploit
- Temporary files must be accessible and writable by unauthorized entities.
- Permissions on these files should not restrict access properly.
Vulnerable Code
import os
temp_file = open('/tmp/tempfile', 'w')
os.chmod('/tmp/tempfile', 0o777) # Insecure permissions
This code creates a temporary file and sets its permissions to allow read, write, and execute access by all users.
Secure Code
import tempfile
temp_file = tempfile.NamedTemporaryFile(mode='w+b')
The secure version uses tempfile module which ensures proper permissions are set for the temporary file.
Business Impact of Creation of Temporary File With Insecure Permissions
Confidentiality: Sensitive information stored in temporary files can be read by unauthorized users. Integrity: Unauthorized modifications to temporary files may lead to data corruption or tampering. Availability: Critical system functions relying on these files could be disrupted if they are moved or deleted.
Creation of Temporary File With Insecure Permissions Attack Scenario
- An attacker identifies a temporary file with insecure permissions in the
/tmpdirectory. - The attacker reads and modifies the contents of this file to gain additional access control privileges within the system.
- The modified data is used to exploit further vulnerabilities or escalate privileges.
How to Detect Creation of Temporary File With Insecure Permissions
Manual Testing
- Check if temporary files are created with proper permissions.
- Ensure filenames are randomized and not predictable.
Automated Scanners (SAST / DAST)
Static analysis can detect insecure permission settings, while dynamic testing verifies actual file access during runtime.
PenScan Detection
PenScan’s scanner engines such as ZAP, Nuclei, Wapiti, Nikto, SSLyze, Dalfox, and Nmap can identify insecure temporary files.
False Positive Guidance
False positives may occur if the pattern looks risky but is actually safe due to context a scanner cannot determine. Review manually for false alarms.
How to Fix Creation of Temporary File With Insecure Permissions
- Use secure temp file functions that restrict permissions.
- Randomize filenames to prevent predictable creation locations.
- Ensure temporary files are writable and readable only by the process owner.
Framework-Specific Fixes for Creation of Temporary File With Insecure Permissions
Python
import tempfile
temp_file = tempfile.NamedTemporaryFile(mode='w+b')
Java
try (FileWriter writer = new FileWriter(new File(System.getProperty("java.io.tmpdir"), "filename"))) {
// Write to file
}
Node.js
const fs = require('fs');
const tempDir = '/tmp';
const tempFilePath = `${tempDir}/tempfile`;
fs.writeFileSync(tempFilePath, 'data', { mode: 0o600 }); // Secure permissions
PHP
$temp_file_path = sys_get_temp_dir() . "/filename";
file_put_contents($temp_file_path, "data", LOCK_EX); // Exclusive lock for security
How to Ask AI to Check Your Code for Creation of Temporary File With Insecure Permissions
Review the following [language] code block for potential CWE-378 Creation of Temporary File With Insecure Permissions vulnerabilities and rewrite it using secure temp file functions: [paste code here]
Creation of Temporary File With Insecure Permissions Best Practices Checklist
✅ Use secure temp file functions to manage temporary files. ✅ Ensure filenames are randomized to prevent predictable creation locations. ✅ Set proper permissions for temporary files, restricting access only to the process owner.
Creation of Temporary File With Insecure Permissions FAQ
How does the creation of temporary files with insecure permissions work?
The vulnerability occurs when a program creates a temporary file without setting proper permissions, allowing unauthorized access to sensitive data or functionality.
Why is it important to secure temporary files in applications?
Securely managing temporary files prevents attackers from reading, modifying, or moving these files to gain additional privileges within the system.
Can you provide an example of vulnerable code for CWE-378?
A common example includes creating a temporary file with permissions that allow read and write access by all users instead of restricting it to the process owner.
How does one detect creation of temporary files with insecure permissions in code reviews?
Look for instances where temp files are created without proper permission checks or randomization of filenames.
What is a recommended fix for CWE-378?
Use secure functions to create and manage temporary files, ensuring they have restricted permissions and randomized names.
How can I prevent the creation of insecurely managed temporary files in Python?
Utilize modules like tempfile that handle file creation securely with appropriate permissions and randomization.
What are some best practices to avoid CWE-378 in Java applications?
Leverage libraries such as Apache Commons IO for secure temporary file management, ensuring proper permission settings.
Vulnerabilities Related to Creation of Temporary File With Insecure Permissions
| CWE | Name | Relationship |
|---|---|---|
| CWE-377 | Insecure Temporary File | ChildOf |
References
Scan Your Own Site
Manual code review catches what you know to look for. An automated scan catches what you didn’t. Scan your own website using PenScan to find Creation of Temporary File With Insecure Permissions and other risks before an attacker does.