Skip to content

Commit 547803b

Browse files
authored
Add Boost Sarif Metadata (#367)
* add bost confidence * add boost taxonomy
1 parent 3b535b6 commit 547803b

File tree

1 file changed

+53
-14
lines changed

1 file changed

+53
-14
lines changed

formatters/sarif/sarif.go

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,43 @@ func (f *Format) Format(ctx context.Context, packages []*models.PackageInsights)
3939
return parts[0]
4040
}
4141

42+
levelToConfidence := func(level string) string {
43+
switch level {
44+
case "error":
45+
return "high"
46+
case "warning":
47+
return "medium"
48+
case "note":
49+
return "low"
50+
case "none":
51+
return "not_set"
52+
default:
53+
return "not_set"
54+
}
55+
}
56+
4257
docs := docs.GetPagesContent()
4358

4459
for _, pkg := range packages {
4560
run := sarif.NewRunWithInformationURI("poutine", "https://github.com/boostsecurityio/poutine")
4661
run.Tool.Driver.WithSemanticVersion(f.version)
62+
run.Tool.Driver.WithOrganization("boostsecurity")
4763
run.Properties = map[string]interface{}{
4864
"purl": pkg.Purl,
4965
}
66+
version := "1.0.0"
67+
organization := "boostsecurity"
68+
69+
taxonomy := &sarif.ToolComponent{
70+
Name: "boost/sast",
71+
Version: &version,
72+
Organization: &organization,
73+
}
74+
75+
taxonomyRef := sarif.NewToolComponentReference().WithName("boost/sast")
76+
run.Tool.Driver.WithSupportedTaxonomies([]*sarif.ToolComponentReference{taxonomyRef})
77+
78+
run.WithTaxonomies([]*sarif.ToolComponent{taxonomy})
5079

5180
sourceGitRepoURI := pkg.GetSourceGitRepoURI()
5281

@@ -98,23 +127,33 @@ func (f *Format) Format(ctx context.Context, packages []*models.PackageInsights)
98127

99128
run.AddDistinctArtifact(path)
100129

101-
run.CreateResultForRule(ruleId).
130+
fingerprint := finding.GenerateFindingFingerprint()
131+
confidence := levelToConfidence(rule.Level)
132+
133+
result := run.CreateResultForRule(ruleId).
102134
WithLevel(rule.Level).
103135
WithMessage(sarif.NewTextMessage(ruleDescription)).
104136
WithPartialFingerPrints(map[string]interface{}{
105-
"primaryLocationLineHash": finding.GenerateFindingFingerprint(),
106-
}).
107-
AddLocation(
108-
sarif.NewLocationWithPhysicalLocation(
109-
sarif.NewPhysicalLocation().
110-
WithArtifactLocation(
111-
sarif.NewSimpleArtifactLocation(path),
112-
).
113-
WithRegion(
114-
sarif.NewSimpleRegion(line, line),
115-
),
116-
),
117-
)
137+
"primaryLocationLineHash": fingerprint,
138+
})
139+
140+
result.AddLocation(
141+
sarif.NewLocationWithPhysicalLocation(
142+
sarif.NewPhysicalLocation().
143+
WithArtifactLocation(
144+
sarif.NewSimpleArtifactLocation(path),
145+
).
146+
WithRegion(
147+
sarif.NewSimpleRegion(line, line),
148+
),
149+
),
150+
)
151+
152+
result.AttachPropertyBag(&sarif.PropertyBag{
153+
Properties: map[string]interface{}{
154+
"boost/confidence": confidence,
155+
},
156+
})
118157
}
119158
sarifReport.AddRun(run)
120159
}

0 commit comments

Comments
 (0)