Repository navigation
fix(source): exclude nested paths under excluded dirs reached via symlink - #5419
Open
JasonMetal wants to merge 1 commit into
Open
JasonMetal wants to merge 1 commit into
JasonMetal wants to merge 1 commit into
Conversation
…link When a symlink points directly to a file inside an excluded directory, the walk never visits the excluded directory itself, so the exact doublestar.Match against the exclusion pattern missed the nested file. Add a prefix check: any path under '<exclusion>/' is also skipped, so files reached through symlinks into excluded directories are honored. Fixes anchore#5232 Signed-off-by: JasonMetal <935216773@qq.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.
Description
Fixes #5232.
When a symlink points directly to a file inside an excluded directory (e.g. etc/grub2.cfg -> ../boot/grub2/grub.cfg with --exclude ./boot), the nested file was still indexed because the walk starts at the file itself and never visits the excluded directory entry, so the exact doublestar.Match against the exclusion pattern misses the nested path.
The fix adds a prefix check: any path starting with / is also skipped. This covers nested files reached through symlinks without changing behavior for direct directory walks.
Steps to test
Repro from issue #5232; after fix, syft scan dir:/tmp/repro --exclude ./boot produces no grub matches.
Added a Windows test case in directory_source_win_test.go.