Skip to content

Commit

Permalink
feat: show only unique vulnerabilities in sarif format
Browse files Browse the repository at this point in the history
Today in sarif output we have a result item per each "vulnerable path"
This will reduce the number of items to be the number of vulnerabilities
  • Loading branch information
admons committed May 18, 2021
1 parent cbdd680 commit 713edf3
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/cli/commands/test/open-source-sarif-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,29 @@ ${vuln.description}`.replace(/##\s/g, '# '),
}

export function getResults(testResult): sarif.Result[] {
return testResult.vulnerabilities.map((vuln) => ({
ruleId: vuln.id,
level: getLevel(vuln),
message: {
text: `This file introduces a vulnerable ${vuln.packageName} package with a ${vuln.severity} severity vulnerability.`,
},
locations: [
{
physicalLocation: {
artifactLocation: {
uri: testResult.displayTargetFile,
},
region: {
startLine: vuln.lineNumber || 1,
const groupedVulnerabilities = groupBy(testResult.vulnerabilities, 'id');
return map(
groupedVulnerabilities,
([vuln]): sarif.Result => ({
ruleId: vuln.id,
level: getLevel(vuln),
message: {
text: `This file introduces a vulnerable ${vuln.packageName} package with a ${vuln.severity} severity vulnerability.`,
},
locations: [
{
physicalLocation: {
artifactLocation: {
uri: testResult.displayTargetFile,
},
region: {
startLine: vuln.lineNumber || 1,
},
},
},
},
],
}));
],
}),
);
}

export function getLevel(vuln: AnnotatedIssue) {
Expand Down

0 comments on commit 713edf3

Please sign in to comment.