Skip to content

Commit 732f759

Browse files
wolfeidauCosmin Cojocar
authored andcommitted
fix for sarif which maps level from issue severity
1 parent 327b2a0 commit 732f759

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

output/formatter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func convertToSarifReport(rootPaths []string, data *reportInfo) (*sarifReport, e
196196
result := &sarifResult{
197197
RuleID: fmt.Sprintf("%s (CWE-%s)", issue.RuleID, issue.Cwe.ID),
198198
RuleIndex: index,
199-
Level: sarifWarning,
199+
Level: getSarifLevel(issue.Severity.String()),
200200
Message: &sarifMessage{
201201
Text: issue.What,
202202
},

output/sarif_format.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,20 @@ func buildSarifLocation(issue *gosec.Issue, rootPaths []string) (*sarifLocation,
155155

156156
return location, nil
157157
}
158+
159+
// From https://docs.oasis-open.org/sarif/sarif/v2.0/csprd02/sarif-v2.0-csprd02.html#_Toc10127839
160+
// * "warning": The rule specified by ruleId was evaluated and a problem was found.
161+
// * "error": The rule specified by ruleId was evaluated and a serious problem was found.
162+
// * "note": The rule specified by ruleId was evaluated and a minor problem or an opportunity to improve the code was found.
163+
func getSarifLevel(s string) sarifLevel {
164+
switch s {
165+
case "LOW":
166+
return sarifWarning
167+
case "MEDIUM":
168+
return sarifError
169+
case "HIGH":
170+
return sarifError
171+
default:
172+
return sarifNote
173+
}
174+
}

0 commit comments

Comments
 (0)