Insecure temporary file creation exposes three attack vectors: predictable file names enabling symlink attacks, insecure permissions allowing unauthorized access, and missing cleanup leaving sensitive data on disk. Attackers exploit these to read sensitive data, inject malicious content, or cause denial of service. AI-generated code frequently suggests simplistic file handling vulnerable to these attacks.
Never create temporary files without securing their location, naming, permissions, and lifecycle management.
Using a predictable name for a temporary file creates a race condition. An attacker can guess the file name and create a symbolic link (symlink) at that location pointing to a sensitive system file. When the application writes to its "temporary" file, it is actually overwriting the linked file.
Sicherheits-Anti-Pattern für unsichere temporäre Dateien (CWE-377). Wird zum Generieren oder Überprüfen von Code verwendet, der temporäre Dateien erstellt, das Datei-Caching verwaltet oder Uploads über temporären Speicher verarbeitet. Erkennt vorhersehbare Pfade, unsichere Berechtigungen und fehlende Bereinigung. Quelle: igbuend/grimbard.