Repository navigation
Conversation
* File.stat returns the stat of the target * Symlink are ignored and replaced with files * If the target is absent File.stat will raise and we can't build the image * Using lstat and add_symlink adds symlinks to the tar archive Change-Id: If36368071a4373b12836dd00210d12e988cae819
Change-Id: I1be5aa7b47f9c117944851e3bd1a83e054e2ea5e
ls-todd-lunter
pushed a commit
that referenced
this pull request
Oct 24, 2026
Docker::Util could pull files from outside the build directory into the build context in two ways. create_relative_dir_tar stats and opens each path with File.stat and File.open, both of which follow symlinks, so a link sitting in the build directory was packed with its target's bytes under the link's own name. Separately, docker_context joins each .dockerignore negation pattern onto the build directory with File.join and hands the result to Dir.glob with nothing checking that it stays underneath, so a pattern containing ../ resolved outside. Either way the file landed in the tar sent to the daemon and could be read from inside the build. docker build does not work this way: moby matches .dockerignore against paths it gets from walking the context root, so a pattern cannot name anything outside it, and a COPY that leaves the context is refused. Archive symlinks as symlinks instead of following them, as PR #530 has proposed since 2018, and check that regular files really resolve under the build directory. Both are needed: lstat does not stop a ../ pattern, and validating the pattern string does not stop a symlink or a file reached through a symlinked directory. The check sits in the tar loop rather than in docker_context so that file_hash_from_paths is covered too, which reaches the same code through Container#archive_in and Image#insert_local. Using lstat also clears up the Errno::ENOENT that a dangling symlink previously raised out of build_from_dir. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
|
Thanks for this. The same approach (lstat + add_symlink) landed in #611, which also adds containment checks for the build context and shipped in v2.5.0. Closing as superseded. |
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.
Change-Id: If36368071a4373b12836dd00210d12e988cae819