fix: Gate ignore-rule metacharacter fix behind an opt-in flag - #667
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
e6c6d03 to
cecf965
Compare
cecf965 to
a9837d4
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
aa47bf6 to
3cf42ef
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit df40d62. Configure here.
df40d62 to
820cf89
Compare
PR Reviewer Guide 🔍
|
| // Feature flag to enable native implementation for code, used in code-client-go's code workflow | ||
| FF_CODE_NATIVE_IMPLEMENTATION string = "internal_snyk_code_native_implementation" | ||
| // Feature flag to enable the fix for ignore rules/paths containing regex metacharacters | ||
| FF_FILE_FILTER_METACHARACTER_FIX string = featureflags.FileFilterMetacharacterFix |
There was a problem hiding this comment.
@danskmt please don't add more feature flags here, instead keep them close to the logic where they are used. In this case file filter.
| package featureflags | ||
|
|
||
| // FeatureFlagReader is satisfied by any configuration.Configuration. | ||
| type FeatureFlagReader interface { |
There was a problem hiding this comment.
Question: Why are you limiting the interface here? Why not just use configuration.Configuration? The existing Configuration interface is much richer and supports for example retrieving values with Errors. Limiting to a narrow interface does create additional cognitive and maintenance complexity.
There was a problem hiding this comment.
Context: The design goal of the configuration package is to decouple the source and the consumption of configuration values. So that a consumer doesn't know if a value is a feature flag or a command line argument or an environment variable. It is just all configuration accessed via a name.
| // NewFileFilterFromConfig resolves feature-flag-gated behavior (like the ignore-rule | ||
| // metacharacter fix) from config, so future flags of this kind need no caller changes. config | ||
| // may be nil, in which case such behavior stays at its default. | ||
| func NewFileFilterFromConfig(path string, logger *zerolog.Logger, config featureflags.FeatureFlagReader, options ...FileFilterOption) *FileFilter { |
There was a problem hiding this comment.
Issue: Introducing a new NewXyZ function is the opposite of what we have been doing in the GAF interface design, instead we have been shifting to the Functional Options Pattern. Why do we do both here?
| // escapeSpecialGlobCharsLegacy escapes special characters that should be treated literally in | ||
| // glob patterns. Special Characters to escape: $ | ||
| // This is the legacy behavior, to be removed in future releases. | ||
| func escapeSpecialGlobCharsLegacy(rule string) string { |
There was a problem hiding this comment.
Question: Why is this function duplicated rather then escapeIgnoreRuleMetaChars() parameterized with ruleRegexMetaChars?
| createFileInPath(t, tempFile2, []byte{}) | ||
|
|
||
| fileFilter := NewFileFilter(tempDir, &log.Logger) | ||
| fileFilter := newFileFilterInternal(tempDir, &log.Logger) |
There was a problem hiding this comment.
Suggestion: Test should cover the public interface as well not just an internal one

Description
Adds
NewFileFilterFromConfig, which resolves feature-flag-gatedFileFilterbehavior (currently the ignore-rule metacharacter fix) directly from aconfiguration.Configuration, so future flags of this kind don't need caller changes.configmay benil, which keeps such behavior at its default.NewFileFilteris now deprecated in favor of it. Flag keys shared across packages live in a newpkg/featureflagspackage (avoids an import cycle withpkg/configuration).Checklist
make test)make generate)make lint)go get github.com/snyk/go-application-framework@YOUR_LATEST_GAF_COMMITin thecliv2directory.go.modto point to your local GAF code.go mod tidyin thecliv2directory.go.modandgo.sumchanges.PR in CLI: snyk/cli#7039
Note
Medium Risk
Changes which files are excluded when paths or rules contain regex metacharacters; behavior depends on the flag and which constructor callers use, so incorrect rollout could alter scan scope.
Overview
Introduces
NewFileFilterFromConfig, which reads feature-flag-gated behavior (starting with the ignore-rule metacharacter fix) from configuration via a smallpkg/featureflagspackage, avoiding an import cycle withpkg/configuration.NewFileFilteris deprecated but still forces the metacharacter fix on for unmigrated callers.When the flag is off (the default for
newFileFilterInternal/ nil config), ignore parsing uses a legacy glob path that only escapes$; when on, rules and base paths escape the full set of regex metacharacters gitignore treats as literal before matching with go-gitignore.Reviewed by Cursor Bugbot for commit 820cf89. Bugbot is set up for automated code reviews on this repo. Configure here.