8
8
// The implementation covers the subset of the specification available
9
9
// at https://www.oasis-open.org/committees/tc_home.php?wg_abbrev=sarif.
10
10
//
11
- // If govulncheck is used in source mode, the locations will include a
12
- // physical location implemented as a path relative to either the source
13
- // module (%SRCROOT%), Go root (%GOROOT%), or Go module cache (%GOMODCACHE%)
14
- // URI base id.
11
+ // The sarif encoding models govulncheck findings as Results. Each
12
+ // Result encodes findings for a unique OSV entry at the most precise
13
+ // detected level only. CodeFlows summarize call stacks, similar to govulncheck
14
+ // textual output, while Stacks contain call stack information verbatim.
15
+ //
16
+ // The result Levels are defined by the govulncheck.ScanLevel and the most
17
+ // precise level at which the finding was detected. Result error is produced
18
+ // when the finding level matches the user desired level of scan precision;
19
+ // all other finding levels are then classified as progressively weaker.
20
+ // For instance, if the user specified symbol scan level and govulncheck
21
+ // detected a use of a vulnerable symbol, then the Result will have error
22
+ // Level. If the symbol was not used but its package was imported, then the
23
+ // Result Level is warning, and so on.
24
+ //
25
+ // Each Result is attached to the first line of the go.mod file. Other
26
+ // ArtifactLocations are paths relative to their enclosing modules.
27
+ // Similar to JSON output format, this makes govulncheck sarif locations
28
+ // portable.
29
+ //
30
+ // The relative paths in PhysicalLocations also come with a URIBaseID offset.
31
+ // Paths for the source module analyzed, the Go standard library, and third-party
32
+ // dependencies are relative to %SRCROOT%, %GOROOT%, and %GOMODCACHE% offsets,
33
+ // resp. We note that the URIBaseID offsets are not explicitly defined in
34
+ // the sarif output. It is the clients responsibility to set them to resolve
35
+ // paths at their local machines.
36
+ //
37
+ // All paths use "/" delimiter for portability.
38
+ //
39
+ // Properties field of a Tool.Driver is a govulncheck.Config used for the
40
+ // invocation of govulncheck producing the Results. Properties field of
41
+ // a Rule contains information on CVE and GHSA aliases for the corresponding
42
+ // rule OSV. Clients can use this information to, say, supress and filter
43
+ // vulnerabilities.
44
+ //
45
+ // Please see the definition of types below for more information.
15
46
package sarif
16
47
17
48
import "golang.org/x/vuln/internal/govulncheck"
@@ -34,7 +65,7 @@ type Log struct {
34
65
type Run struct {
35
66
Tool Tool `json:"tool,omitempty"`
36
67
// Results contain govulncheck findings. There should be exactly one
37
- // Result per a detected OSV.
68
+ // Result per a detected use of an OSV.
38
69
Results []Result `json:"results,omitempty"`
39
70
}
40
71
@@ -45,11 +76,11 @@ type Tool struct {
45
76
46
77
// Driver provides details about the govulncheck binary being executed.
47
78
type Driver struct {
48
- // Name should be "govulncheck"
79
+ // Name is "govulncheck"
49
80
Name string `json:"name,omitempty"`
50
- // Version should be the govulncheck version
81
+ // Version is the govulncheck version
51
82
Version string `json:"semanticVersion,omitempty"`
52
- // InformationURI should point to the description of govulncheck tool
83
+ // InformationURI points to the description of govulncheck tool
53
84
InformationURI string `json:"informationUri,omitempty"`
54
85
// Properties are govulncheck run metadata, such as vuln db, Go version, etc.
55
86
Properties govulncheck.Config `json:"properties,omitempty"`
@@ -66,9 +97,9 @@ type Rule struct {
66
97
FullDescription Description `json:"fullDescription,omitempty"`
67
98
Help Description `json:"help,omitempty"`
68
99
HelpURI string `json:"helpUri,omitempty"`
69
- // Properties should contain OSV.Aliases (CVEs and GHSAs) as tags.
100
+ // Properties contain OSV.Aliases (CVEs and GHSAs) as tags.
70
101
// Consumers of govulncheck SARIF can use these tags to filter
71
- // results based on, say, CVEs .
102
+ // results.
72
103
Properties RuleTags `json:"properties,omitempty"`
73
104
}
74
105
@@ -85,27 +116,28 @@ type Description struct {
85
116
86
117
// Result is a set of govulncheck findings for an OSV. For call stack
87
118
// mode, it will contain call stacks for the OSV. There is exactly
88
- // one Result per detected OSV. Only findings at the lowest possible
89
- // level appear in the Result. For instance, if there are findings
90
- // with call stacks for an OSV, those findings will be in the Result,
91
- // but not the “imports” and “requires” findings for the same OSV.
119
+ // one Result per detected OSV. Only findings at the most precise
120
+ // detected level appear in the Result. For instance, if there are
121
+ // symbol findings for an OSV, those findings will be in the Result,
122
+ // but not the package and module level findings for the same OSV.
92
123
type Result struct {
93
124
// RuleID is the Rule.ID/OSV producing the finding.
94
125
RuleID string `json:"ruleId,omitempty"`
95
- // Level is one of "error", "warning", "note", and "none ".
126
+ // Level is one of "error", "warning", and "note ".
96
127
Level string `json:"level,omitempty"`
97
128
// Message explains the overall findings.
98
129
Message Description `json:"message,omitempty"`
99
- // Locations to which the findings are associated.
130
+ // Locations to which the findings are associated. Always
131
+ // a single location pointing to the first line of the go.mod
132
+ // file. The path to the file is "go.mod".
100
133
Locations []Location `json:"locations,omitempty"`
101
- // CodeFlows can encode call stacks produced by govulncheck.
134
+ // CodeFlows summarize call stacks produced by govulncheck.
102
135
CodeFlows []CodeFlow `json:"codeFlows,omitempty"`
103
- // Stacks can encode call stacks produced by govulncheck.
136
+ // Stacks encode call stacks produced by govulncheck.
104
137
Stacks []Stack `json:"stacks,omitempty"`
105
- // TODO: support Fixes when integration points to the same
106
138
}
107
139
108
- // CodeFlow describes a detected offending flow of information in terms of
140
+ // CodeFlow summarizes a detected offending flow of information in terms of
109
141
// code locations. More precisely, it can contain several related information
110
142
// flows, keeping them together. In govulncheck, those can be all call stacks
111
143
// for, say, a particular symbol or package.
@@ -128,8 +160,6 @@ type ThreadFlowLocation struct {
128
160
Module string `json:"module,omitempty"`
129
161
// Location also contains a Message field.
130
162
Location Location `json:"location,omitempty"`
131
- // Can also contain Stack field that encodes a call stack
132
- // leading to this thread flow location.
133
163
}
134
164
135
165
// Stack is a sequence of frames and can encode a govulncheck call stack.
@@ -167,12 +197,10 @@ const (
167
197
168
198
// ArtifactLocation is a path to an offending file.
169
199
type ArtifactLocation struct {
170
- // URI is a path to the artifact. If URIBaseID is empty, then
171
- // URI is absolute and it needs to start with, say, "file://."
200
+ // URI is a path relative to URIBaseID.
172
201
URI string `json:"uri,omitempty"`
173
- // URIBaseID is offset for URI. An example is %SRCROOT%, used by
174
- // Github Code Scanning to point to the root of the target repo.
175
- // Its value must be defined in URIBaseIDs of a Run.
202
+ // URIBaseID is offset for URI, one of %SRCROOT%, %GOROOT%,
203
+ // and %GOMODCACHE%.
176
204
URIBaseID string `json:"uriBaseId,omitempty"`
177
205
}
178
206
0 commit comments