← Java / Spring · Contents

JAVA-085 / Intermediate

Creating temporary files with fixed names in /tmp

A01:2021 · CWE-377 Insecure Temporary File

Why is this a problem?

Predictable names can be claimed in advance, and files belonging to other users may be overwritten.

How to fix it

java
Path p = Files.createTempFile("rpt_", ".csv", PosixFilePermissions.asFileAttribute(
    PosixFilePermissions.fromString("rw-------")));

Further reading