Skip to content

feat: support path-based rule exclusions via exclude-rules#1465

Merged
ccojocar merged 2 commits intosecurego:masterfrom
ravisastryk:feature/1287-path-based-exclude-rules
Jan 15, 2026
Merged

feat: support path-based rule exclusions via exclude-rules#1465
ccojocar merged 2 commits intosecurego:masterfrom
ravisastryk:feature/1287-path-based-exclude-rules

Conversation

@ravisastryk
Copy link
Copy Markdown
Contributor

Summary

Add path-based rule exclusions for excluding specific rules from specific paths. This will help large monorepos to apply different security rules to different components (e.g., CLI tools vs services).

Implements Issue: #1287

Changes:

  • Add PathExcludeRule struct and PathExclusionFilter for path-based filtering
  • Add ParseCLIExcludeRules for --exclude-rules CLI flag parsing
  • Add GetExcludeRules method to Config for JSON config support

Configuration example:

{
  "exclude-rules": [
    {"path": "cmd/.*", "rules": ["G204", "G304"]},
    {"path": "scripts/.*", "rules": ["*"]}
  ]
}

CLI example:

gosec --exclude-rules="cmd/.*:G204,G304" ./...

Tests
Ran all tests

make test

Unit tests

go test -v ./... -run TestShouldExclude
go test -v ./... -run PathExclusionFilter

Manual test

go build -o gosec ./cmd/gosec
./gosec --exclude-rules=\"cmd/.*:G204\" ./...

Implements securego#1287

* Ssupport for excluding specific rules from specific paths, enabling large monorepos to apply different security rules to different components (e.g., CLI tools vs services).
@ravisastryk ravisastryk marked this pull request as ready for review January 14, 2026 06:07
@ravisastryk
Copy link
Copy Markdown
Contributor Author

@ccojocar @dannyc-grafana, When you get a chance, can you please review my PR? TIA

Copy link
Copy Markdown
Member

@ccojocar ccojocar left a comment

Choose a reason for hiding this comment

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

LGTM, please could you fix the lint warning?

@ravisastryk
Copy link
Copy Markdown
Contributor Author

LGTM, please could you fix the lint warning?

@ccojocar Thank you for taking your time and reviewing. I have fixed the formatting issue. Everything should be good now.
@gcmurphy Can you please take a look when you get a chance?

@ccojocar ccojocar merged commit 9f20212 into securego:master Jan 15, 2026
6 checks passed
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 15, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 62.40602% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.86%. Comparing base (1216c9b) to head (a943c54).
⚠️ Report is 165 commits behind head on master.

Files with missing lines Patch % Lines
config.go 0.00% 17 Missing ⚠️
path_filter.go 83.00% 15 Missing and 2 partials ⚠️
cmd/gosec/main.go 0.00% 16 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1465      +/-   ##
==========================================
+ Coverage   68.49%   68.86%   +0.36%     
==========================================
  Files          75       82       +7     
  Lines        4384     6404    +2020     
==========================================
+ Hits         3003     4410    +1407     
- Misses       1233     1775     +542     
- Partials      148      219      +71     

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

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