@@ -26,20 +26,11 @@ func NewGosec(settings *config.GoSecSettings) *goanalysis.Linter {
2626 var mu sync.Mutex
2727 var resIssues []goanalysis.Issue
2828
29- conf := gosec .NewConfig ()
30-
3129 var filters []rules.RuleFilter
30+ conf := gosec .NewConfig ()
3231 if settings != nil {
3332 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 )
4334 }
4435
4536 logger := log .New (io .Discard , "" , 0 )
@@ -140,6 +131,35 @@ func runGoSec(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoS
140131 return issues
141132}
142133
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+
143163// based on https://github.com/securego/gosec/blob/569328eade2ccbad4ce2d0f21ee158ab5356a5cf/cmd/gosec/main.go#L170-L188
144164func gosecRuleFilters (includes , excludes []string ) []rules.RuleFilter {
145165 var filters []rules.RuleFilter
@@ -173,10 +193,12 @@ func convertToScore(str string) (gosec.Score, error) {
173193// code borrowed from https://github.com/securego/gosec/blob/69213955dacfd560562e780f723486ef1ca6d486/cmd/gosec/main.go#L264-L276
174194func filterIssues (issues []* gosec.Issue , severity , confidence gosec.Score ) []* gosec.Issue {
175195 res := make ([]* gosec.Issue , 0 )
196+
176197 for _ , issue := range issues {
177198 if issue .Severity >= severity && issue .Confidence >= confidence {
178199 res = append (res , issue )
179200 }
180201 }
202+
181203 return res
182204}
0 commit comments