Skip to content

🐛 fix: correct directory creation, lookup and test isolation - #745

Merged
gaborbernat merged 18 commits into
tox-dev:mainfrom
gaborbernat:fix/directory-regressions
Nov 20, 2026
Merged

gaborbernat merged 18 commits into
tox-dev:mainfrom
gaborbernat:fix/directory-regressions

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Applications can create private directories under Android's system-owned paths and in container homes owned by another account. Shared sticky directories, their entries and symlinks must belong to root or the caller. In a group-writable parent without the sticky bit, entries may also belong to the parent's owner. Group members can replace entries there after the check. Previous creation checks

Root can look up an existing service-owned Unix site directory. Creating a directory or calling a place_*_file method there requires a root-owned path. Root-owned group-writable ancestors are allowed. Root requests mode 0755 for new site directories, subject to the umask. Unix also reads trusted media settings under a group-writable ~/.config and requests mode 0775 for configured media directories.

Unix site runtime lookup and creation select the same fallback for a rejected XDG override. With root redirection, a direct site lookup returns the inherited path. With ensure_exists=True, it creates a missing base with mode 0700 and rejects an invalid base or parent. A rejected override no longer hides files in a valid fallback. A lookup can return a group-writable temporary fallback. File searches skip it until ensure_exists repairs its mode. On macOS, searches find files placed in the native fallback. Windows ignores UNC folder overrides with a missing server or share, or with . or .. as either name.

All threads share the newest active isolated_dirs() root. Forked children inherit it. Closing a nested context restores any patches that were in place when it opened. Overlapping contexts

Record each scope's entry state so nested tests recover their own patches.
Fork under the same lock used for context changes so workers inherit a
complete redirect.
Allow group-writable parents for ordinary user paths. Keep stricter
ownership and mode checks for runtime paths and privileged site writes.
Cap new root site directories at 0755 under permissive umasks.

Check each runtime search directory against its own base so a rejected
override cannot hide a valid fallback. On macOS, use the checked user
runtime directory for site lookup as well.
@gaborbernat
gaborbernat requested a review from ofek as a code owner November 20, 2026 05:28
@gaborbernat gaborbernat added bug Something isn't working documentation Improvements or additions to documentation labels Nov 20, 2026
Use the checked user runtime path when creating beneath an XDG override.
Root can still look up the invoking user's path. Accept an owned,
group-writable temporary fallback for lookup and skip it in file searches
until its owner repairs the permissions.
Android and container homes can have system-owned ancestors. Check each
symlink and each entry in a writable parent. Keep runtime ownership checks
strict and verify new directories before descending into them.

Allow root to look up an existing service directory. Require root-owned
components for creation or file placement. Cap new root site directories at
0755 and configured media directories at 0775 before applying the umask.
Use the same patch stack for the temporary runtime tree and its ownership
overrides. Pytest can then remove old temporary directories with the
original os.lstat after the tests finish.
Windows Python 3.11 drops the share when normalizing an extended UNC path
ending in a parent reference at the share root. Later versions retain it.
Check that the override is accepted only when the share survives.
The sticky bit still lets the directory owner rename entries. Require a
shared sticky parent to belong to root or the caller before using it.
Use the same checked user runtime path for lookup and creation under an
XDG override. Resolve it once when iterating. Root may look up an inherited
runtime path, but creation requires a validated base.
@gaborbernat
gaborbernat merged commit 47c34b7 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 documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant