@@ -27,6 +27,31 @@ import (
2727 "github.com/securego/gosec/v2/issue"
2828)
2929
30+ // HardcodedCredentialAddenda holds info about a
31+ // G101 "Possible hardcoded value" Issue,
32+ // which is needed to apply value regex-based exclude rules.
33+ type HardcodedCredentialAddenda struct {
34+ key , value string
35+ }
36+
37+ func (a HardcodedCredentialAddenda ) Format (f fmt.State , verb rune ) {
38+ if verb == 'v' && f .Flag ('#' ) {
39+ fmt .Fprintf (f , `rules.HardcodedCredentialAddenda{Key: %q, Value: %q}` ,
40+ a .key , a .value ,
41+ )
42+ return
43+ }
44+
45+ var not string
46+ if a .value != "" {
47+ not = "!"
48+ }
49+ fmt .Fprintf (f , `HardcodedCredentialAddenda[Key:%q Value %s== ""]` , a .key , not )
50+ }
51+
52+ func (a HardcodedCredentialAddenda ) Key () string { return a .key }
53+ func (a HardcodedCredentialAddenda ) Value () string { return a .value }
54+
3055type secretPattern struct {
3156 name string
3257 regexp * regexp.Regexp
@@ -246,6 +271,7 @@ func (r *credentials) issueForMatchedKey(n ast.Node, lhs string, rhs ast.Expr, c
246271 }
247272 if r .ignoreEntropy || r .isHighEntropyString (val ) {
248273 iss := ctx .NewIssue (n , r .ID (), r .What , r .Severity , r .Confidence )
274+ iss .Addenda = HardcodedCredentialAddenda {key : lhs , value : val }
249275 return iss
250276 }
251277 return nil
@@ -261,6 +287,7 @@ func (r *credentials) issueIfValueInSecretFormat(n ast.Node, lhs string, rhs ast
261287 if ok , patternName := r .isSecretPattern (val ); ok {
262288 what := fmt .Sprintf ("%s: %s" , r .What , patternName )
263289 iss := ctx .NewIssue (n , r .ID (), what , r .Severity , r .Confidence )
290+ iss .Addenda = HardcodedCredentialAddenda {key : lhs , value : val }
264291 return iss
265292 }
266293 }
0 commit comments