Skip to content

Commit bbb5ef0

Browse files
Merge pull request #331 from damoasis/fix-sarif-level
fix: sarif level
2 parents 99dbc88 + e2cc7c4 commit bbb5ef0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

cmd/detail/detail.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ func (v *Vuln) SecurityLevel() string {
170170
return "Unknown"
171171
}
172172

173+
// SarifLevel 返回SARIF格式的漏洞级别
174+
func (v *Vuln) SarifLevel() string {
175+
switch v.SecurityLevelId {
176+
case 1, 2: // Critical, High
177+
return "error"
178+
case 3: // Medium
179+
return "warning"
180+
case 4: // Low
181+
return "note"
182+
}
183+
return "warning" // Unknown
184+
}
185+
173186
func vulnLanguageKey(language model.Language) []string {
174187
switch language {
175188
case model.Lan_Java:

cmd/format/sarif.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func Sarif(report Report, out string) {
103103

104104
result := sarifResult{
105105
RuleId: vuln.Id,
106-
Level: "warning",
106+
Level: vuln.SarifLevel(),
107107
}
108108
result.Message.Text = fmt.Sprintf("引入的组件 %s 中存在 %s", n.Dep.Key()[:strings.LastIndex(n.Dep.Key(), ":")], vuln.Name)
109109
for i, path := range n.Paths {

0 commit comments

Comments
 (0)