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.
Антишаблон безопасности для небезопасных временных файлов (CWE-377). Используйте при создании или проверке кода, который создает временные файлы, обрабатывает кэширование файлов или обрабатывает загрузку через временное хранилище. Обнаруживает предсказуемые пути, небезопасные разрешения и недостающую очистку. Источник: igbuend/grimbard.