A file is opened at a fixed path in a directory that every user can write, such as /tmp

tx0/python:public-temp-pathrecommendedwarningsecurity/filesdepth fastsecurity, cwe-377

What it finds

Another user can create /tmp/app.lock or a symbolic link of that name before the program does, and so read its data or make it overwrite a file of their choice. The tempfile module creates files with unpredictable names and safe permissions.

From the rule's source, public_temp_path.rs.

Example from the rule's tests
import osimport tempfile def save(data):    with open("/tmp/report.txt", "w") as f:tx0 reports: a fixed name in a shared temporary directory        f.write(data)    fd = os.open("/var/tmp/app.lock", os.O_CREAT)tx0 reports: a fixed name in a shared temporary directory    with tempfile.NamedTemporaryFile() as g:        g.write(data)    return fd
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 recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python: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/python:public-temp-path] reason="..."

tx0 explain tx0/python:public-temp-path shows the same in the terminal. Found a false positive? Report it.