directory resolver ignores --exclude for symlink targets - #5253
Open
goingforstudying-ctrl wants to merge 1 commit into
Open
directory resolver ignores --exclude for symlink targets#5253goingforstudying-ctrl wants to merge 1 commit into
goingforstudying-ctrl wants to merge 1 commit into
Conversation
the exclusion visitor only ever matched the excluded directory entry itself, which works for the primary walk because hitting that entry returns SkipDir. but the indexer follows symlinks by resolving the target and queueing it as an additional index root, and that second pass starts at the target file without ever visiting the excluded directory entry, so the exclusion never fires. the net effect was that --exclude ./boot still indexed and cataloged everything under /boot reachable through an unexcluded symlink. fix it two ways: resolve the real path for symlink entries and apply the exclusions to it, and treat literal exclusion patterns as directory prefixes so descendants match too. glob patterns keep their existing doublestar behavior on both the visited and the resolved path. Signed-off-by: goingforstudying-ctrl <goingforstudying@gmail.com>
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
Ran into this while digging through the exclusion code after #5232 popped up:
--excludeonly ever matches the excluded directory entry itself. That's fine for the primary walk (hitting the entry returns SkipDir), but the directory indexer follows symlinks by resolving the target and queueing it as a second index root. That second pass starts at the target file, the excluded directory entry is never visited, and the exclusion never fires.So with
--exclude ./bootand a symlink likeetc/grub2.cfg -> ../boot/grub2/grub.cfg, everything under/bootstill ends up indexed and cataloged. Reproduced it with the fixture from the issue: 745 npm packages cataloged from a yarn.lock that lives in the excluded tree, purely through the symlink.The fix does two things:
Glob patterns keep the same doublestar behavior as before, just applied to both the visited path and the resolved path. Dangling links behave the same as today (resolve to nothing, nothing gets indexed).
Verified end to end on the fixture: before,
syft scan dir:. --exclude ./bootcataloged 745 npm artifacts through the symlink; after, the same command catalogs 0.Type of change
Checklist
Issue references
Fixes #5232