Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use gosec severities #4470

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion pkg/golinters/gosec.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func runGoSec(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoS

issues := make([]goanalysis.Issue, 0, len(secIssues))
for _, i := range secIssues {
text := fmt.Sprintf("%s: %s", i.RuleID, i.What) // TODO: use severity and confidence
text := fmt.Sprintf("%s: %s", i.RuleID, i.What)

var r *result.Range

Expand All @@ -118,6 +118,7 @@ func runGoSec(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoS
}

issues = append(issues, goanalysis.NewIssue(&result.Issue{
Severity: convertScoreToString(i.Severity),
Pos: token.Position{
Filename: i.File,
Line: line,
Expand Down Expand Up @@ -149,6 +150,19 @@ func toGosecConfig(settings *config.GoSecSettings) gosec.Config {
return conf
}

func convertScoreToString(score issue.Score) string {
switch score {
case issue.Low:
return "low"
case issue.Medium:
return "medium"
case issue.High:
return "high"
default:
ldez marked this conversation as resolved.
Show resolved Hide resolved
return ""
}
}

// based on https://github.com/securego/gosec/blob/47bfd4eb6fc7395940933388550b547538b4c946/config.go#L52-L62
func convertGosecGlobals(globalOptionFromConfig any, conf gosec.Config) {
globalOptionMap, ok := globalOptionFromConfig.(map[string]any)
Expand Down
Loading