A temporary file is created with the default permissions of the process

tx0/java:shared-temp-filestrictwarningsecurity, cwe-377

What it finds

File.createTempFile creates its file with the default permissions of the process, often readable by every user, in the shared temporary directory. Other users can then read what is written there. Files.createTempFile creates the file readable only by its owner on systems with POSIX permissions.

From the rule's source, shared_temp_file.rs.

Example from the rule's tests
import java.io.File;import java.nio.file.Files; class Scratch {  void make() throws Exception {    File a = File.createTempFile("cache", ".tmp");tx0 reports: File.createTempFile leaves the file with the default permissions    Object b = Files.createTempFile("cache", ".tmp");  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:shared-temp-file" = "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:shared-temp-file] reason="..."

tx0 explain tx0/java:shared-temp-file shows the same in the terminal. Found a false positive? Report it.