tempfile.mktemp returns a name another process can take first
What it finds
tempfile.mktemp() returns a name that no file has yet, but another process can create a file or a link of that name before this one opens it (CWE-377). The module's documentation has deprecated it since Python 2.3. tempfile.mkstemp, NamedTemporaryFile and mkdtemp create the file or directory at once.
From the rule's source, tempfile_mktemp.rs.
import tempfilefrom tempfile import mktemp def scratch(): a = tempfile.mktemp()tx0 reports: tempfile.mktemp returns a name that another process can take before it is used b = mktemp(suffix=".txt")tx0 reports: tempfile.mktemp returns a name c = tempfile.mkstemp() return a, b, c Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:tempfile-mktemp" = "off"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:tempfile-mktemp] reason="..."tx0 explain tx0/python:tempfile-mktemp shows the same in the terminal. Found a false positive? Report it.