← PHP / Laravel · Contents

PHP-080 / Advanced

Creating temporary files with fixed names in /tmp (symlink race)

A01:2021 Broken Access Control · CWE-377 Insecure Temporary File

Why is this a problem?

Predictable filenames can be claimed in advance to overwrite other files.

How to fix it

php
$tmp = tempnam(sys_get_temp_dir(), 'rpt_');  // Atomic creation, permissions 600

Further reading