Repository navigation
🐛 fix(env): create a requested env dir privately - #1290
Merged
Merged
Conversation
A requested environment location was accepted whenever it was empty, and its path was resolved again after that check. An account that owned the directory could swap the environment's contents for its own code, and one that controlled a symbolic link could point creation and the cleanup after a successful build at a directory it could not otherwise touch. Resolve the path once, require an existing directory to belong to the current user, and on exit remove the location only while it is still the directory checked on entry.
gaborbernat
force-pushed
the
fix-env-dir-ownership
branch
from
November 18, 2026 01:28
4fd75c4 to
ff341be
Compare
The rejection was only exercised by POSIX tests, so the Windows jobs measured its lines as uncovered. Swap the symbolic link test for one that replaces the location with a file, which runs on every platform.
gaborbernat
marked this pull request as ready for review
November 18, 2026 05:03
Comparing owners drew an arbitrary line and refused setups that work today. Recreate the location instead: removing the empty directory and creating it again with mode 0700 makes it ours, so its previous owner can no longer swap what build installs, and it fails where the removal is not permitted. Resolving the path before the checks is kept. The identity check on exit goes: rmtree already refuses a symbolic link at the path it is given.
layday
approved these changes
Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolve symbolic links in
--env-dirbefore checking it, and recreate the location with access by the running user only.AI-generated supporting detail, not written by the author, but reviewed closely by them
--env-dir PATHandDefaultIsolatedEnv(path=...)accepted any existing empty directory, whoever owned it, and resolved symbolic links in the path only after checking it (old lines). After a successful build, build deleted the resolved path. This addresses draft advisory ANT-2026-3Y7YNDRN.What changes
DefaultIsolatedEnv.__enter__now does two things.os.path.realpathran afterwards. An account that controlled a symbolic link at the location could point it at an empty directory for the check and at a different one for the resolution, and build then created its environment in that directory and deleted it after a successful build. Every check now runs on the resolved path.os.rmdirandos.mkdir(path, 0o700). The owner of a directory can rename the entries in it, so an account that pre-created the location could movelibaside and supply asite-packageswith asitecustomize.py, which Python imports at startup in each hook subprocess. After the recreation the running user owns the directory and nobody else can enter it. In a sticky directory such as/tmp, removing another user's directory is not permitted (inode(7)), so the build fails there.Behavior changes
An existing empty location is removed and created again, so it loses its previous mode and owner and ends up with mode
0700. A location that cannot be removed, such as a mount point or another user's directory under/tmp, now fails with theOSErrorfromrmdir. A file at the location still fails withis not a directory, and a directory with entries withis not empty.Not covered: build does not check who owns or can write to the directories above the location. An account that controls one of them can replace the environment while the build runs. The CLI reference tells users to keep the parent directory writable by their user only.
Reported by Anthropic's OSS Scanner: ANT-2026-3Y7YNDRN, ANT-2026-TSYGXDSU.