A file is created under a fixed name in a shared temporary directory
What it finds
os.Create("/tmp/report.txt"): every user can write to /tmp, so another account can create the name first, as a file it controls or a link to a file of the program's user, and the program then writes into it or truncates the target. os.CreateTemp and os.MkdirTemp pick a fresh name and create it atomically.
The path must be a constant string of the file that starts with /tmp/, /var/tmp/ or /dev/shm/, passed to Create, WriteFile, OpenFile or Mkdir of os, resolved through the imports.
From the rule's source, fixed_temp_path.rs.
package p import "os" func f(data []byte) error { if err := os.WriteFile("/tmp/report.txt", data, 0o600); err != nil {tx0 reports: os.WriteFile uses the fixed path /tmp/report.txt in a directory every user can write to return err } f, err := os.CreateTemp("", "report-*.txt") if err != nil { return err } defer f.Close() _, err = f.Write(data) return err} 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/go:fixed-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/go:fixed-temp-path] reason="..."tx0 explain tx0/go:fixed-temp-path shows the same in the terminal. Found a false positive? Report it.