Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enforce correct type for security-severity in sarif output #5091

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/formatters/open-source-sarif-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ${vuln.description}`.replace(/##\s/g, '# '),
testResult.packageManager!,
],
cvssv3_baseScore: vuln.cvssScore, // AWS
'security-severity': vuln.cvssScore, // GitHub
'security-severity': String(vuln.cvssScore), // GitHub
},
};
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/formatters/sarif-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function getTool(testResult): sarif.Tool {
testResult.packageManager!,
],
cvssv3_baseScore: vuln.cvssScore, // AWS
'security-severity': vuln.cvssScore, // GitHub
'security-severity': String(vuln.cvssScore), // GitHub
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe if vuln.cvssScore is null, this pushes "undefined" to the property bag.

I would suggest adding a null testcase and verifying.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm. Github Code Scanning is now rejecting sarif files from Snyk CLI.

},
};
})
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/docker/sarif-container-result.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"deb"
],
"cvssv3_baseScore": 6.5,
"security-severity": 6.5
"security-severity": "6.5"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"deb"
],
"cvssv3_baseScore": 6.5,
"security-severity": 6.5
"security-severity": "6.5"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('snyk test --sarif', () => {

expect(stdout).toContain('"artifactsScanned": 1');
expect(stdout).toContain('"cvssv3_baseScore": 5.3');
expect(stdout).toContain('"security-severity": 5.3');
expect(stdout).toContain('"security-severity": "5.3"');
expect(stdout).toContain('"fullyQualifiedName": "[email protected]"');
expect(stdout).toContain('Upgrade to [email protected]');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Object {
"id": "SNYK-JS-AJV-584908",
"properties": Object {
"cvssv3_baseScore": 7.5,
"security-severity": 7.5,
"security-severity": "7.5",
"tags": Array [
"security",
"CWE-400",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ In libexpat in Expat before 2.2.7, XML input including XML names that contain a
"id": "SNYK-LINUX-EXPAT-450908",
"properties": Object {
"cvssv3_baseScore": 7.5,
"security-severity": 7.5,
"security-severity": "7.5",
"tags": Array [
"security",
"CWE-611",
Expand Down Expand Up @@ -162,7 +162,7 @@ In libexpat in Expat before 2.2.7, XML input including XML names that contain a
"id": "SNYK-LINUX-EXPAT-450908",
"properties": Object {
"cvssv3_baseScore": 7.5,
"security-severity": 7.5,
"security-severity": "7.5",
"tags": Array [
"security",
"npm",
Expand Down Expand Up @@ -252,7 +252,7 @@ In libexpat in Expat before 2.2.7, XML input including XML names that contain a
"id": "SNYK-LINUX-EXPAT-450908",
"properties": Object {
"cvssv3_baseScore": 7.5,
"security-severity": 7.5,
"security-severity": "7.5",
"tags": Array [
"security",
"CWE-611",
Expand Down
Loading