Skip to content

feat(cli): add --exclude flag to skip paths from scan and ci#690

Merged
shivasurya merged 3 commits into
mainfrom
shiva/exclude-path-arg
May 21, 2026
Merged

feat(cli): add --exclude flag to skip paths from scan and ci#690
shivasurya merged 3 commits into
mainfrom
shiva/exclude-path-arg

Conversation

@shivasurya
Copy link
Copy Markdown
Owner

Summary

  • Adds --exclude (repeatable StringArray) flag to both pathfinder scan and pathfinder ci. Each value is a repo-relative path prefix; files whose path starts with any prefix are skipped at the file-walk layer, so they are never parsed or counted.
  • Introduces sast-engine/cmd/exclude.go with validateExcludePatterns (normalize + reject dangerous inputs) and isExcluded (prefix-boundary match with rules matching rules/foo but not rulesx/foo).
  • Threads ExcludePatterns through graph.ProgressCallbacks into graph.Initialize/getFiles, so exclusion happens before any I/O or AST work begins.

Test plan

  • 36 new tests in exclude_test.go, scan_test.go, ci_test.go, utils_test.go covering: empty list, single prefix, multiple, nested prefix, exact dir match, boundary semantics (rules vs rulesx), trailing slash normalization, case sensitivity, unicode.
  • Security validation: absolute paths, .. traversal, backslashes, null bytes, length > 512 all return a clear error.
  • go test ./... -count=1 passes on all 30 packages (2113 tests total).
  • go vet ./... clean.
  • golangci-lint run ./... clean (v2.9.0).

Security notes

Validation rules applied by validateExcludePatterns before any filesystem access:

Rule Rationale
No leading / Absolute paths could reference files outside the project root
No .. path component Prevents traversal to parent directories
No backslash Rejects Windows-style paths that would silently misbehave on Linux
No null byte Null bytes terminate C strings and bypass naive checks
Length <= 512 Guards against pathological inputs

Go does not shell-expand these patterns (no glob, no os/exec), but inputs are rejected anyway to enforce a clean repo-relative contract and prevent confusion.

🤖 Generated with Claude Code

shivasurya and others added 2 commits May 21, 2026 07:18
New helpers for the --exclude flag:
- validateExcludePatterns: normalizes repo-relative prefixes, rejects
  absolute paths, traversal components, backslashes, null bytes, and
  patterns longer than 512 chars.
- isExcluded: case-sensitive prefix-boundary match (rules matches
  rules/foo but not rulesx/foo).

Also threads ExcludePatterns through ProgressCallbacks into getFiles,
applying the filter at the walk layer so excluded paths are never parsed
or counted.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Registers StringArray flag --exclude on both scan and ci. Reads,
validates, and passes the cleaned patterns to graph.Initialize via
ProgressCallbacks.ExcludePatterns so excluded paths are skipped at
the file-walk layer before parsing begins.

Validation runs before any I/O: absolute prefixes, traversal
components (..), backslashes, null bytes, and oversized patterns all
return a clear error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@shivasurya shivasurya added enhancement New feature or request go Pull requests that update go code labels May 21, 2026
@shivasurya shivasurya self-assigned this May 21, 2026
@safedep
Copy link
Copy Markdown

safedep Bot commented May 21, 2026

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

View complete scan results →

This report is generated by SafeDep Github App

@github-actions
Copy link
Copy Markdown

Code Pathfinder Security Scan

Pass Critical High Medium Low Info

No security issues detected.

Metric Value
Files Scanned 10
Rules 205

Powered by Code Pathfinder

@code-pathfinder
Copy link
Copy Markdown

code-pathfinder Bot commented May 21, 2026

Pathfinder Report

No security findings on the changed files. This pull request is clean.

View report on the dashboard


Powered by Code Pathfinder.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.44%. Comparing base (6371812) to head (4a29334).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #690      +/-   ##
==========================================
+ Coverage   85.43%   85.44%   +0.01%     
==========================================
  Files         187      188       +1     
  Lines       27278    27333      +55     
==========================================
+ Hits        23305    23355      +50     
- Misses       3082     3086       +4     
- Partials      891      892       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

… path

- validateExcludePatterns now silently drops exact duplicates (after
  normalization) so repeated --exclude flags don't bloat the per-file
  check; preserves first-occurrence order. Adds three dedup tests.
- getFiles dropped its defensive 'filepath.Rel error → relPath = path'
  branch (unreachable: filepath.Walk guarantees the path is rooted at
  directory, so Rel never fails). New test covers excluding an
  individual file (non-directory) so the file-level skip path is
  exercised. Brings patch coverage on new code to 100%.
@shivasurya shivasurya merged commit 1faca6c into main May 21, 2026
9 checks passed
@shivasurya shivasurya deleted the shiva/exclude-path-arg branch May 21, 2026 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant