Skip to content

feat(scan): add --exclude-paths flag for full Tier 1 exclusion (port of #1298)#1306

Merged
John-David Dalton (jdalton) merged 1 commit intomainfrom
chore/port-1298-exclude-paths
May 6, 2026
Merged

feat(scan): add --exclude-paths flag for full Tier 1 exclusion (port of #1298)#1306
John-David Dalton (jdalton) merged 1 commit intomainfrom
chore/port-1298-exclude-paths

Conversation

@jdalton
Copy link
Copy Markdown
Collaborator

@jdalton John-David Dalton (jdalton) commented May 6, 2026

Summary

  • Ports feat(scan): add --exclude-paths flag for full Tier 1 exclusion #1298 (originally targeted v1.x by Simon (@simonhj)) to main.
  • Adds a --exclude-paths flag to socket scan create and socket scan reach that excludes the listed glob patterns from BOTH SCA/SBOM manifest discovery and (when --reach is enabled) Tier 1 reachability analysis.
  • Bare directory names are auto-extended to recursive globs (teststests/**); trailing slashes are stripped; gitignore-style negation patterns (!path) are rejected up front.

Translation notes (v1.x → main)

  • @socketsecurity/registry/lib/*@socketsecurity/lib/*
  • ../../utils/errors.mts../../utils/error/errors.mts
  • co-located tests live under packages/cli/test/{integration,unit}/...
  • preserved existing test snapshots; only the new --exclude-paths line was added to help-text snapshots.

Internally, --exclude-paths is wired into projectIgnorePaths for SCA manifest discovery and into Coana's --exclude-dirs for reachability, preserving existing --reach-exclude-paths semantics for users who only need the Coana-side exclusion.

Credit: original implementation by Simon (@simonhj) on the v1.x branch.

Test plan

  • pnpm exec tsc --noEmit passes for @socketsecurity/cli
  • pnpm exec vitest run test/unit/commands/scan/exclude-paths.test.mts passes (13 new unit tests for the helpers)
  • pnpm exec vitest run test/unit/commands/scan/handle-create-new-scan.test.mts test/unit/commands/scan/handle-scan-reach.test.mts passes (existing handler tests adapted to the new excludePaths field)
  • pnpm exec vitest run test/unit/commands/scan/ — all 665 scan unit tests pass
  • pnpm run build for @socketsecurity/cli succeeds
  • pnpm --filter @socketsecurity/cli run check passes (path hygiene + bundle deps + size + link deps)
  • Manual end-to-end smoke: socket scan create --exclude-paths tests --dry-run succeeds; --exclude-paths '!tests/keep' fails with the expected error.

Note: pre-existing analytics test failures on origin/main (verified against a pristine checkout) are unrelated to this port and were not addressed here.


Note

Medium Risk
Adds new exclusion semantics that affect which manifests are discovered and which directories reachability analysis skips, so misconfiguration could change scan coverage. The change touches core scan/reach handlers but is guarded by validation and new unit/integration tests.

Overview
Adds a new --exclude-paths flag to socket scan create and socket scan reach to exclude user-specified globs from both manifest discovery (via socket.yml projectIgnorePaths) and Tier 1 reachability analysis (by translating them into Coana --exclude-dirs).

Introduces exclude-paths.mts helpers to normalize/translate patterns and reject negation (!) up front, threads excludePaths through reachability option types and call sites (handle-create-new-scan, handle-scan-reach, CI/default scan creation), and updates bash completions and help-text snapshots/tests accordingly.

Reviewed by Cursor Bugbot for commit 3cfb459. Configure here.

#1298)

Port of #1298 (originally targeted v1.x by @simonhj) to main.

Adds a --exclude-paths flag to socket scan create and socket scan reach
that excludes the listed glob patterns from BOTH SCA/SBOM manifest
discovery and (when --reach is enabled) Tier 1 reachability analysis.
Patterns are matched relative to the project root; bare directory names
are auto-extended to recursive globs (tests -> tests/**); trailing
slashes are stripped; gitignore-style negation patterns (!path) are
rejected up front.

Internally, --exclude-paths is wired into projectIgnorePaths for SCA
manifest discovery and into Coana's --exclude-dirs for reachability,
preserving existing --reach-exclude-paths semantics for users who only
need the Coana-side exclusion.

Translation notes for v1.x -> main:
- @socketsecurity/registry/lib/* -> @socketsecurity/lib/*
- ../../utils/errors.mts -> ../../utils/error/errors.mts
- co-located tests live under packages/cli/test/{integration,unit}/...
- preserved existing test snapshots; only the new --exclude-paths line
  was added to help-text snapshots.

DISABLE_PRECOMMIT_TEST=1 used for this commit because pre-existing
unrelated analytics tests are broken on origin/main (verified against
a pristine checkout). Type checks and the new exclude-paths unit tests
all pass.
@jdalton John-David Dalton (jdalton) merged commit 8774783 into main May 6, 2026
2 checks passed
@jdalton John-David Dalton (jdalton) deleted the chore/port-1298-exclude-paths branch May 6, 2026 00:15
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 3 potential issues.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3cfb459. Configure here.

const targetPath = path.isAbsolute(options.target)
? path.relative(options.cwd, options.target)
: options.target
const targetPattern = toPosixPath(stripTrailingSlash(targetPath))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nested relative targets drop excludes

Medium Severity

The projectIgnorePathsToReachExcludePaths function preserves leading ./ in relative targets, while projectIgnorePaths are normalized without it. This path normalization mismatch prevents --exclude-paths from correctly applying to nested targets, causing Coana to analyze directories that should be excluded.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3cfb459. Configure here.

*/
export function excludePathToProjectIgnorePath(path: string): string {
const stripped = stripTrailingSlash(path)
return stripped.endsWith('/**') ? stripped : `${stripped}/**`
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Windows paths miss SCA exclusion

Medium Severity

excludePathToProjectIgnorePath stores --exclude-paths values in projectIgnorePaths without converting backslashes. Windows-style paths can still reach Coana after later normalization, but SCA manifest discovery receives unmatched patterns and includes manifests from excluded directories.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3cfb459. Configure here.

if (normalized.startsWith(recursiveTargetPrefix)) {
return normalized.slice(targetPrefix.length)
}
return undefined
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wildcard excludes miss nested targets

Medium Severity

pathRelativeToTarget treats glob patterns as literal prefixes when translating to Coana paths. Project-root patterns containing wildcards before the target, such as workspace globs, are dropped for nested reachability targets even when they match directories inside that target.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3cfb459. Configure here.

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.

1 participant