A file is created at a fixed path in a directory that every user can write to
What it finds
new File("/tmp/report.txt") uses a name that every user of the machine can predict in a directory every user can write to. Another user can create the file first, or put a link there, and so read or replace what the program writes (CWE-377). Files.createTempFile picks an unpredictable name with safe permissions.
Reported is a string literal path in /tmp, /var/tmp or /dev/shm given to the constructor of a File, a file stream, reader or writer, or to Paths.get or Path.of.
From the rule's source, public_temp_path.rs.
import java.io.File;import java.nio.file.Path;import java.nio.file.Paths; class Temp { void write() { File a = new File("/tmp/report.txt");tx0 reports: every user can write to Path b = Paths.get("/var/tmp/cache.bin");tx0 reports: every user can write to File c = new File("/home/app/report.txt"); }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:public-temp-path" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:public-temp-path] reason="..."tx0 explain tx0/java:public-temp-path shows the same in the terminal. Found a false positive? Report it.