A temporary file is created with Path.GetTempFileName, in a shared directory under a guessable name

tx0/csharp:predictable-temp-filestrictwarningsecurity/filesdepth fastsecurity, cwe-377

What it finds

Path.GetTempFileName creates a file with a sequential name in the shared temporary directory, readable by other users on some systems, and fails once 65,535 such files exist. A file opened with FileMode.CreateNew under a random name, in a directory only the program can write, avoids both.

From the rule's source, predictable_temp_file.rs.

Example from the rule's tests
using System.IO; class Export{    string Target() => Path.GetTempFileName();tx0 reports: Path.GetTempFileName creates a predictable file in a shared directory}
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/csharp:predictable-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/csharp:predictable-temp-file] reason="..."

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