Skip to content

fix(source): exclude nested paths under excluded dirs reached via symlink - #5419

Open
JasonMetal wants to merge 1 commit into
anchore:mainfrom
JasonMetal:fix/exclude-symlink-nested-paths
Open

JasonMetal wants to merge 1 commit into
anchore:mainfrom
JasonMetal:fix/exclude-symlink-nested-paths

Conversation

@JasonMetal

Copy link
Copy Markdown
Contributor

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.

…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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--exclude is not honored for paths reached via a symlink target

1 participant