Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
Fix reportingDescriptor according to sarif validator
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgurwara99 committed Feb 5, 2023
1 parent 5ae587c commit 6debfcd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "/Users/taj/personal/vulnny/cmd/vulnny",
"cwd": "/Users/taj/personal/vulnny/cmd/vulnny/testdata/vuln",
"program": "/Users/taj/personal/vulnny",
"cwd": "${workspaceFolder}/testdata/vuln",
}
]
}
32 changes: 29 additions & 3 deletions internal/sarif/sarif.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sarif

import (
"fmt"
"go/build"
"os"
"strings"
Expand All @@ -15,6 +16,7 @@ func FromResult(r *vulncheck.Result) (*Log, error) {
})
var j int
var results []Result
var rules []ReportingDescriptor
for i, v := range filtered {
fn, ok := r.Calls.Functions[v.CallSink]
if !ok {
Expand Down Expand Up @@ -45,21 +47,45 @@ func FromResult(r *vulncheck.Result) (*Log, error) {
}
locations = append(locations, loc)
}
shortDescription := fmt.Sprintf("Vulnerable package %s is being used", v.ModPath)
message := Message{
Text: v.OSV.Details,
Text: shortDescription,
}
level := LevelError
ruleID := v.OSV.ID
rule := ReportingDescriptor{
ID: ruleID,
Name: "VulnerablePackage",
HelpURI: fmt.Sprintf("https://osv.dev/vulnerability/%s", strings.ToLower(v.OSV.ID)),
ShortDescription: &MultiFormatMessageString{
Text: shortDescription,
},
FullDescription: &MultiFormatMessageString{
Text: v.OSV.Details,
},
Properties: &RDProperties{
ID: v.OSV.ID,
Problem: string(level),
Name: shortDescription,
Description: v.OSV.Details,
Kind: "problem",
Tags: []string{"security", "vulnerability"},
},
}
results = append(results, Result{
Message: &message,
Level: level,
RuleID: ruleID,
Level: level,
Locations: locations,
})
rules = append(rules, rule)
}
tool := Tool{
Driver: ToolComponent{
Name: "Vulnny",
Name: "Vulnny",
SemanitcVersion: "0.0.2",
InformationURI: "https://github.com/tjgurwara99/vulnny",
Rules: rules,
},
}
runs := []Run{
Expand Down
34 changes: 29 additions & 5 deletions internal/sarif/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,36 @@ type MultiFormatMessageString struct {
Markdown string `json:"markdown,omitempty"`
}

type RDProperties struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Kind string `json:"kind,omitempty"`
Precision string `json:"precision,omitempty"`
Tags []string `json:"tags,omitempty"`
Problem string `json:"problem.severity,omitempty"`
}

type ReportingDescriptor struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
HelpURI string `json:"helpUri,omitempty"`
ShortDescription *MultiFormatMessageString `json:"shortDescription,omitempty"`
FullDescription *MultiFormatMessageString `json:"fullDescription,omitempty"`
Help *MultiFormatMessageString `json:"help,omitempty"`
// propertyBag that makes sense for this tool.
Properties *RDProperties `json:"properties,omitempty"`
}

type ToolComponent struct {
Name string `json:"name"`
GUID string `json:"guid,omitempty"`
SemanitcVersion string `json:"semanticVersion,omitempty"`
Language string `json:"language,omitempty"`
ShortDescription *MultiFormatMessageString `json:"shortDescription,omitempty"`
FullDescription *MultiFormatMessageString `json:"fullDescription,omitempty"`
InformationURI string `json:"informationUri,omitempty"`
Rules []ReportingDescriptor `json:"rules,omitempty"`
// there are some other fields that might be useful
// but at this stage it would be overengineering.
}
Expand Down Expand Up @@ -110,11 +133,12 @@ type Location struct {
}

type Result struct {
Message *Message `json:"message"`
RuleID string `json:"ruleId,omitempty"`
RuleIndex int `json:"ruleIndex,omitempty"` // default -1 & minimum -1
Level Level `json:"level,omitempty"`
Locations []Location `json:"locations,omitempty"`
Message *Message `json:"message"`
RuleID string `json:"ruleId,omitempty"`
RuleIndex int `json:"ruleIndex,omitempty"` // default -1 & minimum -1
Rule *ReportingDescriptor `json:"rule,omitempty"`
Level Level `json:"level,omitempty"`
Locations []Location `json:"locations,omitempty"`
}

type Run struct {
Expand Down

0 comments on commit 6debfcd

Please sign in to comment.