Skip to content

🐛 fix(unix): reject cwd runtime fallback - #744

Merged
gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/avoid-cwd-runtime-fallback
Nov 20, 2026
Merged

gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/avoid-cwd-runtime-fallback

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

When no standard temporary directory is writable, Unix runtime fallback can use the current working directory. An application started in a checkout can then treat a preexisting runtime-<uid> tree there as runtime storage. The fallback now selects an available standard or absolute configured temporary directory before returning a runtime path. Fixes #743.

CPython tries the current directory last when selecting a temporary directory. Unix fallback selection checks that result against /tmp, /var/tmp, /usr/tmp, and current absolute TMPDIR, TEMP, or TMP settings. If Python cached a working directory or an old setting, it tries the current candidates. Runtime file searches can still use a valid XDG_RUNTIME_DIR when the temporary fallback is unavailable.

When Python selects an unsafe directory and no safe candidate works, callers get PermissionError asking them to set XDG_RUNTIME_DIR. If Python finds no temporary directory at all, its FileNotFoundError propagates. Existing runtime directories below an available standard or absolute configured location remain usable.

Reported by OSS Scanner: ANT-2026-YBJMNEUE.

tempfile can select the working directory after the configured and standard
temporary locations fail. A predictable runtime path there can pick up files
from a checkout. Require a standard POSIX or absolute configured temporary
root before using the fallback.

Fixes tox-dev#743
@gaborbernat
gaborbernat requested a review from ofek as a code owner November 20, 2026 01:19
@gaborbernat gaborbernat added the bug Something isn't working label Nov 20, 2026
Use current safe temporary roots when tempfile has cached a working
directory or an old setting. Keep XDG runtime file searches usable when
no temporary directory is available.

Refs tox-dev#743
@gaborbernat
gaborbernat merged commit 0c446d7 into tox-dev:main Nov 20, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runtime fallback can use the working directory

1 participant