Skip to content

Commit c03eb3f

Browse files
committed
gosec: exclude G601 and G113
1 parent 4beae6a commit c03eb3f

File tree

1 file changed

+41
-24
lines changed

1 file changed

+41
-24
lines changed

pkg/golinters/gosec/gosec.go

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,6 @@ func toGosecConfig(settings *config.GoSecSettings) gosec.Config {
150150
return conf
151151
}
152152

153-
func convertScoreToString(score issue.Score) string {
154-
switch score {
155-
case issue.Low:
156-
return "low"
157-
case issue.Medium:
158-
return "medium"
159-
case issue.High:
160-
return "high"
161-
default:
162-
return ""
163-
}
164-
}
165-
166153
// based on https://github.com/securego/gosec/blob/47bfd4eb6fc7395940933388550b547538b4c946/config.go#L52-L62
167154
func convertGosecGlobals(globalOptionFromConfig any, conf gosec.Config) {
168155
globalOptionMap, ok := globalOptionFromConfig.(map[string]any)
@@ -179,17 +166,35 @@ func convertGosecGlobals(globalOptionFromConfig any, conf gosec.Config) {
179166
func gosecRuleFilters(includes, excludes []string) []rules.RuleFilter {
180167
var filters []rules.RuleFilter
181168

182-
if len(includes) > 0 {
183-
filters = append(filters, rules.NewRuleFilter(false, includes...))
169+
cleanIncludes := cleanRules(includes)
170+
171+
if len(cleanIncludes) > 0 {
172+
filters = append(filters, rules.NewRuleFilter(false, cleanIncludes...))
184173
}
185174

186-
if len(excludes) > 0 {
187-
filters = append(filters, rules.NewRuleFilter(true, excludes...))
175+
cleanExcludes := cleanRules(excludes)
176+
cleanExcludes = append(cleanExcludes, "G601", "G113")
177+
178+
if len(cleanExcludes) > 0 {
179+
filters = append(filters, rules.NewRuleFilter(true, cleanExcludes...))
188180
}
189181

190182
return filters
191183
}
192184

185+
// code borrowed from https://github.com/securego/gosec/blob/69213955dacfd560562e780f723486ef1ca6d486/cmd/gosec/main.go#L264-L276
186+
func filterIssues(issues []*issue.Issue, severity, confidence issue.Score) []*issue.Issue {
187+
res := make([]*issue.Issue, 0)
188+
189+
for _, i := range issues {
190+
if i.Severity >= severity && i.Confidence >= confidence {
191+
res = append(res, i)
192+
}
193+
}
194+
195+
return res
196+
}
197+
193198
// code borrowed from https://github.com/securego/gosec/blob/69213955dacfd560562e780f723486ef1ca6d486/cmd/gosec/main.go#L250-L262
194199
func convertToScore(str string) (issue.Score, error) {
195200
str = strings.ToLower(str)
@@ -205,15 +210,27 @@ func convertToScore(str string) (issue.Score, error) {
205210
}
206211
}
207212

208-
// code borrowed from https://github.com/securego/gosec/blob/69213955dacfd560562e780f723486ef1ca6d486/cmd/gosec/main.go#L264-L276
209-
func filterIssues(issues []*issue.Issue, severity, confidence issue.Score) []*issue.Issue {
210-
res := make([]*issue.Issue, 0)
213+
func convertScoreToString(score issue.Score) string {
214+
switch score {
215+
case issue.Low:
216+
return "low"
217+
case issue.Medium:
218+
return "medium"
219+
case issue.High:
220+
return "high"
221+
default:
222+
return ""
223+
}
224+
}
211225

212-
for _, i := range issues {
213-
if i.Severity >= severity && i.Confidence >= confidence {
214-
res = append(res, i)
226+
func cleanRules(ruleNames []string) []string {
227+
var cleanRuleNames []string
228+
for _, ruleName := range ruleNames {
229+
if ruleName == "G601" || ruleName == "G113" {
230+
continue
215231
}
232+
cleanRuleNames = append(cleanRuleNames, ruleName)
216233
}
217234

218-
return res
235+
return cleanRuleNames
219236
}

0 commit comments

Comments
 (0)