Skip to content

fix: Gate ignore-rule metacharacter fix behind an opt-in flag - #667

Merged
danskmt merged 4 commits into
mainfrom
fix/CLI-1709-gate-metacharacter-fix-behind-flag
Jul 29, 2026
Merged

fix: Gate ignore-rule metacharacter fix behind an opt-in flag#667
danskmt merged 4 commits into
mainfrom
fix/CLI-1709-gate-metacharacter-fix-behind-flag

Conversation

@danskmt

@danskmt danskmt commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Description

Adds NewFileFilterFromConfig, which resolves feature-flag-gated FileFilter behavior (currently the ignore-rule metacharacter fix) directly from a configuration.Configuration, so future flags of this kind don't need caller changes. config may be nil, which keeps such behavior at its default.

NewFileFilter is now deprecated in favor of it. Flag keys shared across packages live in a new pkg/featureflags package (avoids an import cycle with pkg/configuration).

Checklist

  • Tests added and all succeed (make test)
  • Regenerated mocks, etc. (make generate)
  • Linted (make lint)
  • Test your changes work for the CLI
    1. Clone / pull the latest CLI main.
    2. Run go get github.com/snyk/go-application-framework@YOUR_LATEST_GAF_COMMIT in the cliv2 directory.
      • Tip: for local testing, you can uncomment the line near the bottom of the CLI's go.mod to point to your local GAF code.
    3. Run go mod tidy in the cliv2 directory.
    4. Run the CLI tests and do any required manual testing.
    5. Open a PR in the CLI repo now with the go.mod and go.sum changes.
    • Once this PR is merged, repeat these steps, but pointing to the latest GAF commit on main and update your CLI PR.

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 small pkg/featureflags package, avoiding an import cycle with pkg/configuration. NewFileFilter is 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.

@snyk-io

snyk-io Bot commented Jul 24, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues
Secrets 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@snyk-io

snyk-io Bot commented Jul 24, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@danskmt
danskmt force-pushed the fix/CLI-1709-gate-metacharacter-fix-behind-flag branch 4 times, most recently from e6c6d03 to cecf965 Compare July 28, 2026 06:54
@danskmt
danskmt force-pushed the fix/CLI-1709-gate-metacharacter-fix-behind-flag branch from cecf965 to a9837d4 Compare July 28, 2026 06:54
@danskmt
danskmt marked this pull request as ready for review July 28, 2026 12:28
@danskmt
danskmt requested review from a team as code owners July 28, 2026 12:28
@snyk-pr-review-bot

This comment has been minimized.

@danskmt
danskmt requested a review from octavian-snyk July 29, 2026 09:34
@snyk-pr-review-bot

This comment has been minimized.

@danskmt
danskmt force-pushed the fix/CLI-1709-gate-metacharacter-fix-behind-flag branch from aa47bf6 to 3cf42ef Compare July 29, 2026 11:43
@snyk-pr-review-bot

This comment has been minimized.

@octavian-snyk
octavian-snyk self-requested a review July 29, 2026 12:08
@snyk-pr-review-bot

This comment has been minimized.

@snyk-pr-review-bot

This comment has been minimized.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread pkg/utils/file_filter.go
@danskmt
danskmt force-pushed the fix/CLI-1709-gate-metacharacter-fix-behind-flag branch from df40d62 to 820cf89 Compare July 29, 2026 13:26
@snyk-pr-review-bot

Copy link
Copy Markdown

PR Reviewer Guide 🔍

🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Inconsistent Defaults 🟡 [minor]

The deprecated NewFileFilter constructor hardcodes enableIgnoreRuleMetacharacterFix = true, while the new recommended NewFileFilterFromConfig defaults to false (via the nil config check or the underlying config provider's default for missing keys). This creates a behavioral divergence where migrating to the 'correct' constructor will silently disable the metacharacter fix unless the consumer also updates their configuration infrastructure to provide the flag.

func NewFileFilter(path string, logger *zerolog.Logger, options ...FileFilterOption) *FileFilter {
	filter := newFileFilterInternal(path, logger, options...)

	// TODO: Temporary - this keeps the metacharacter
	// fix enabled for callers of this deprecated constructor (e.g. Preview CLI) that haven't migrated
	// to NewFileFilterFromConfig yet, so they keep the behavior they already rely on today. Remove
	// once all such callers have migrated.
	filter.enableIgnoreRuleMetacharacterFix = true
📚 Repository Context Analyzed

This review considered 23 relevant code sections from 13 files (average relevance: 0.84)

🤖 Repository instructions applied (from AGENTS.md)

@danskmt
danskmt merged commit f805345 into main Jul 29, 2026
15 checks passed
@danskmt
danskmt deleted the fix/CLI-1709-gate-metacharacter-fix-behind-flag branch July 29, 2026 13:31
// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/utils/file_filter.go
// 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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread pkg/utils/file_filter.go
// 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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Test should cover the public interface as well not just an internal one

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.

3 participants