Do not use tempfile.mktemp() for creating named pipes on Windows #137335
Copy link
Copy link
Closed
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesOS-windowsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotopic-multiprocessingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
I change the pull requests to #137333, replace the mktemp() function.
bandit Tools:
Issue: [B306:blacklist] Use of insecure and deprecated function (mktemp).
Severity: Medium Confidence: High
CWE: CWE-377 (https://cwe.mitre.org/data/definitions/377.html)
More Info: https://bandit.readthedocs.io/en/1.8.6/blacklists/blacklist_calls.html#b306-mktemp-q
Location: C:\Users\Administrator\Desktop\cpython\lib\asyncio\windows_utils.py:34:14
33 """Like os.pipe() but with overlapped support and using handles not fds."""
34 address = tempfile.mktemp(
35 prefix=r'\.\pipe\python-pipe-{:d}-{:d}-'.format(
36 os.getpid(), next(_mmap_counter)))
37
Linked PRs
- gh-137335: Remove use of
mktemp()inasyncio.windows_utils#137333 - gh-137335: Fix unlikely name conflicts for named pipes in multiprocessing and asyncio on Windows #137389
- [3.14] gh-137335: Fix unlikely name conflicts for named pipes in multiprocessing and asyncio on Windows (GH-137389) #145170
- [3.13] gh-137335: Fix unlikely name conflicts for named pipes in multiprocessing and asyncio on Windows (GH-137389) #145171
- gh-137335: remove a mktemp use in multiprocessing.connection to avoid security scanner noise #148578
- [3.14] gh-137335: remove a mktemp use in multiprocessing.connection to avoid security scanner noise (GH-148578) #148583
- [3.13] gh-137335: remove a mktemp use in multiprocessing.connection to avoid security scanner noise (GH-148578) #148584
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesOS-windowsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotopic-multiprocessingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
Activity
[-]tempfile. mktemp() is unsafe[/-][+]tempfile.mktemp() is unsafe[/+][-]tempfile.mktemp() is unsafe[/-][+]`tempfile.mktemp()` is unsafe[/+][-]`tempfile.mktemp()` is unsafe[/-][+]Replace usages of `tempfile.mktemp()` with `tempfile.mkstemp` when possible[/+][-]Replace usages of `tempfile.mktemp()` with `tempfile.mkstemp` when possible[/-][+]Replace usages of `tempfile.mktemp()` with `tempfile.mkstemp` in `asyncio.windows_utils`[/+][-]Replace usages of `tempfile.mktemp()` with `tempfile.mkstemp` in `asyncio.windows_utils`[/-][+]Replace usages of `tempfile.mktemp()` with `tempfile.mkstemp` in `asyncio.windows_utils` and `multiprocessing.util.arbitrary_address`[/+][-]Replace usages of `tempfile.mktemp()` with `tempfile.mkstemp` in `asyncio.windows_utils` and `multiprocessing.util.arbitrary_address`[/-][+]Replace usages of `tempfile.mktemp()` with `tempfile.mkstemp` in `asyncio.windows_utils` and `multiprocessing.util`[/+]picnixz commentedon Aug 3, 2025
I won't consider it a security issue as it remains to show that it's possible to exploit a race condition here. The issue with
mktempis essentially when we have filename collisions, but the occurrences ofmktempuse a prefix to prevent this.[-]Replace usages of `tempfile.mktemp()` with `tempfile.mkstemp` in `asyncio.windows_utils` and `multiprocessing.util`[/-][+]Replace usages of `tempfile.mktemp()` in `asyncio.windows_utils` and `multiprocessing.util`[/+]lighting9999 commentedon Aug 3, 2025
I wrote a POC and found out that it had the possibility of denial of service.
25 remaining items
gh-137335: Fix unlikely name conflicts for named pipes in multiproces…
pythongh-137335: Fix unlikely name conflicts for named pipes in multi…
pythongh-137335: Fix unlikely name conflicts for named pipes in multi…
[3.13] gh-137335: Fix unlikely name conflicts for named pipes in mult…
[3.14] gh-137335: Fix unlikely name conflicts for named pipes in mult…
pythongh-137335: Fix unlikely name conflicts for named pipes in multi…
gh-137335: remove a mktemp use in multiprocessing.connection to avoid…
pythongh-137335: remove a mktemp use in multiprocessing.connection to…
pythongh-137335: remove a mktemp use in multiprocessing.connection to…
[3.14] gh-137335: remove a mktemp use in multiprocessing.connection t…
[3.13] gh-137335: remove a mktemp use in multiprocessing.connection t…
pythongh-137335: Fix unlikely name conflicts for named pipes in multi…
pythongh-137335: remove a mktemp use in multiprocessing.connection to…