@@ -26,20 +26,11 @@ func NewGosec(settings *config.GoSecSettings) *goanalysis.Linter {
26
26
var mu sync.Mutex
27
27
var resIssues []goanalysis.Issue
28
28
29
- conf := gosec .NewConfig ()
30
-
31
29
var filters []rules.RuleFilter
30
+ conf := gosec .NewConfig ()
32
31
if settings != nil {
33
32
filters = gosecRuleFilters (settings .Includes , settings .Excludes )
34
-
35
- for k , v := range settings .Config {
36
- if k != gosec .Globals {
37
- // Uses ToUpper because the parsing of the map's key change the key to lowercase.
38
- // The value is not impacted by that: the case is respected.
39
- k = strings .ToUpper (k )
40
- }
41
- conf .Set (k , v )
42
- }
33
+ conf = toGosecConfig (settings )
43
34
}
44
35
45
36
logger := log .New (io .Discard , "" , 0 )
@@ -140,6 +131,35 @@ func runGoSec(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoS
140
131
return issues
141
132
}
142
133
134
+ func toGosecConfig (settings * config.GoSecSettings ) gosec.Config {
135
+ conf := gosec .NewConfig ()
136
+
137
+ for k , v := range settings .Config {
138
+ if k == gosec .Globals {
139
+ convertGosecGlobals (v , conf )
140
+ continue
141
+ }
142
+
143
+ // Uses ToUpper because the parsing of the map's key change the key to lowercase.
144
+ // The value is not impacted by that: the case is respected.
145
+ conf .Set (strings .ToUpper (k ), v )
146
+ }
147
+
148
+ return conf
149
+ }
150
+
151
+ // based on https://github.com/securego/gosec/blob/47bfd4eb6fc7395940933388550b547538b4c946/config.go#L52-L62
152
+ func convertGosecGlobals (globalOptionFromConfig any , conf gosec.Config ) {
153
+ globalOptionMap , ok := globalOptionFromConfig .(map [string ]any )
154
+ if ! ok {
155
+ return
156
+ }
157
+
158
+ for k , v := range globalOptionMap {
159
+ conf .SetGlobal (gosec .GlobalOption (k ), fmt .Sprintf ("%v" , v ))
160
+ }
161
+ }
162
+
143
163
// based on https://github.com/securego/gosec/blob/569328eade2ccbad4ce2d0f21ee158ab5356a5cf/cmd/gosec/main.go#L170-L188
144
164
func gosecRuleFilters (includes , excludes []string ) []rules.RuleFilter {
145
165
var filters []rules.RuleFilter
@@ -173,10 +193,12 @@ func convertToScore(str string) (gosec.Score, error) {
173
193
// code borrowed from https://github.com/securego/gosec/blob/69213955dacfd560562e780f723486ef1ca6d486/cmd/gosec/main.go#L264-L276
174
194
func filterIssues (issues []* gosec.Issue , severity , confidence gosec.Score ) []* gosec.Issue {
175
195
res := make ([]* gosec.Issue , 0 )
196
+
176
197
for _ , issue := range issues {
177
198
if issue .Severity >= severity && issue .Confidence >= confidence {
178
199
res = append (res , issue )
179
200
}
180
201
}
202
+
181
203
return res
182
204
}
0 commit comments