Repository navigation
Conversation
memdir.ScopedPath is used to keep user-supplied paths (template paths,
values paths, helm chart path, fetch subPath, inline file paths, etc.)
within the App working directory. The check is lexical only, so a path
that goes through a symlink inside the directory passes the check even
when the symlink points outside of the directory, and the caller then
reads from the symlink target.
In addition to the existing lexical check, resolve symlinks in both the
base directory and the joined path and check containment again. Since
some callers check paths that are about to be written, symlinks are
resolved on the deepest existing ancestor and the remaining components
are joined unchanged. The returned path is still the lexical path, so
callers are not affected.
Symlinks that stay within the directory, and base directories that are
themselves symlinks (e.g. /var -> /private/var on macOS), keep working.
vendir already rejects fetched content containing symlinks that point
outside of the fetched directory, so this mainly makes ScopedPath not
depend on that.
Changes:
1. pkg/memdir/scoped.go
- Re-check containment after resolving symlinks
2. pkg/memdir/scoped_test.go (new)
- Add tests for paths within the directory, not yet existing paths,
symlinks within the directory, symlinks pointing outside of the
directory (absolute and relative, existing and not yet existing
targets), and a base directory that is a symlink
3. pkg/template/ytt_test.go (new)
- Add Test_Ytt_PathThroughSymlinkOutsideDir_IsRejected, which runs
ytt with a path through a symlink in the working directory and
verifies that content outside the working directory is not
rendered. Without this change the outside content is rendered.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Himanshu Singh <himansh.singh3@gmail.com>
This branch has not been deployed
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.
memdir.ScopedPath is used to keep user-supplied paths (template paths, values paths, helm chart path, fetch subPath, inline file paths, etc.) within the App working directory. The check is lexical only, so a path that goes through a symlink inside the directory passes the check even when the symlink points outside of the directory, and the caller then reads from the symlink target.
In addition to the existing lexical check, resolve symlinks in both the base directory and the joined path and check containment again. Since some callers check paths that are about to be written, symlinks are resolved on the deepest existing ancestor and the remaining components are joined unchanged. The returned path is still the lexical path, so callers are not affected.
Symlinks that stay within the directory, and base directories that are themselves symlinks (e.g. /var -> /private/var on macOS), keep working.
vendir already rejects fetched content containing symlinks that point outside of the fetched directory, so this mainly makes ScopedPath not depend on that.
Changes:
pkg/memdir/scoped.go
pkg/memdir/scoped_test.go (new)
pkg/template/ytt_test.go (new)
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Does this PR introduce a user-facing change?
Additional Notes for your reviewer:
Review Checklist:
a link to that PR
change
Additional documentation e.g., Proposal, usage docs, etc.: