Feat/exclude values#1663
Conversation
656e5c1 to
621cadb
Compare
efef057 to
39c5837
Compare
e8ccb74 to
bc9372b
Compare
7927a9b to
c8a4d2d
Compare
|
Thanks for this contribution. This seems AI generated. Why was required to rename the methods/functions? Can you reduce the size of the changes only to the hardcode credentials? |
This was not AI generated. I did not even use AI for autocomplete. I renamed some symbols because they mentioned "Path Exclusion", but I was adding functionality not related to paths. To avoid the misleading implication that PathExclusion symbols dealt only with paths, I removed "Path" from the names. This is still WIP, and I'm looking into whether I should push the config deeper to be more tightly coupled to G101. I also want to write tests. EDIT 2026-05-07: Since I really want to restrict the exclusions to particular paths, path_filters.go is the most natural place to trigger the key-value excluder. But I separated the logic out to its own files as much as I could. |
|
Please do first the minimum change required to incorporate the functionality you mentioned without refactoring. You can follow up with refactoring if it is needed afterwards. This will make reviewing the change much easier. Thanks |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1663 +/- ##
==========================================
- Coverage 80.57% 80.25% -0.32%
==========================================
Files 109 109
Lines 10181 10260 +79
==========================================
+ Hits 8203 8234 +31
- Misses 1495 1541 +46
- Partials 483 485 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ccojocar
left a comment
There was a problem hiding this comment.
Can you please add some info in the README regarding the usage of this exclusion filter?
Is this introducing any breaking changes for the existing filter format?
…er issues with it
…ing logic, ensure k-v is always provided
… TODO except-rules
…onfigured and in the issue
c8a4d2d to
8f6972a
Compare
…emove "Path" from name" This reverts commit 91e65cb.
ccojocar
left a comment
There was a problem hiding this comment.
Also make sure to update the https://github.com/securego/gosec/blob/master/RULES.md#g101 with the added functionality when is implemented.
99239e0 to
2cc4ef0
Compare
2cc4ef0 to
9d7c266
Compare
… arg, instead of the file and ruleID
9d7c266 to
a722960
Compare
Done. There should be no breaking changes for the existing filter format. The new feature is only configurable via JSON right now, via a new field in the path filter config. I weighed allowing configs via CLI arguments, but that seemed too complicated at this stage. |
Done! |
Adds
.G101.keysand.G101.valuesfields to the PathExcludeRule type. If provided with a slice of regex patterns, G101 "Possible hardcoded credentials" issues will also be excluded if the hardcoded-value matches any of thevaluespatterns, or if its key matches any of thekeyspatterns.For example, the following code, common in test files, used to trigger an error:
With this PR, a config can be set to exclude that issue when encountered in test files, based on the hardcoded value matching a pattern:
{ "exclude-rules": [{ "path": ".+_test\\.go$", "G101": { "values": [ "(?i)^test", "(?i)^fake" ] } }] }Variable names can be excluded as well, even if the value looks like a credential:
{ "exclude-rules": [{ "path": ".+_test\\.go$", "G101": { "keys": ["(?i)^test"] } }] }