# Insecure Temporary File (CWE-377) Creating and using insecure temporary files can leave application and system data vulnerable to attack. - Prevalence: मध्यम 1 भाषाएँ कवर की गईं - Impact: मध्यम समीक्षा अनुशंसित - Prevention: प्रलेखित 1 फिक्स उदाहरण **OWASP:** Insecure Design (A04:2021-Insecure Design) - #4 ## Description Temporary files that are created with predictable names, insecure permissions, or in shared directories can be exploited by attackers to read or modify sensitive data, or to inject malicious content. ## Prevention ### Key Practices - Use tempfile ### Python Use tempfile.NamedTemporaryFile or tempfile.mkstemp instead of mktemp ## Warning Signs - [MEDIUM] insecure temporary file creation using tempfile ## Consequences - एप्लिकेशन डेटा पढ़ना - एप्लिकेशन डेटा संशोधित करना - अनधिकृत कोड निष्पादित करना ## Mitigations - सुरक्षित अस्थायी फ़ाइल निर्माण फ़ंक्शनों (जैसे mkstemp) का उपयोग करें - अस्थायी फ़ाइलें सुरक्षित, सभी के लिए लिखने योग्य न होने वाले डायरेक्टरीज़ में बनाएँ - अस्थायी फ़ाइलों पर प्रतिबंधात्मक अनुमतियाँ सेट करें ## Detection - Total rules: 1 - Languages: python ## Rules by Language ### Python (1 rules) - **Insecure Temporary File Creation** [MEDIUM]: Detects insecure temporary file creation using tempfile.mktemp(), predictable names, or world-readable permissions. These can lead to symlink attacks, race conditions, or information disclosure. Use tempfile.mkstemp() or NamedTemporaryFile. - Remediation: Use tempfile.NamedTemporaryFile or tempfile.mkstemp instead of mktemp(). ```python import tempfile with tempfile.NamedTemporaryFile(mode='w+', delete=True) as tmp: tmp.write(data) tmp.flush() result = process_file(tmp.name) ``` Learn more: https://shoulder.dev/learn/python/cwe-377/insecure-tempfile