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.
Antipatrón de seguridad para archivos temporales inseguros (CWE-377). Úselo al generar o revisar código que crea archivos temporales, maneja el almacenamiento en caché de archivos o procesa cargas a través del almacenamiento temporal. Detecta rutas predecibles, permisos inseguros y falta de limpieza. Fuente: igbuend/grimbard.