-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4649 from snyk/feat/container-support-sarif-witho…
…ut-file feat: container sarif flag support without file
- Loading branch information
Showing
8 changed files
with
244 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/fixtures/docker/sarif-with-file-container-result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", | ||
"version": "2.1.0", | ||
"runs": [ | ||
{ | ||
"tool": { | ||
"driver": { | ||
"name": "Snyk Container", | ||
"rules": [ | ||
{ | ||
"id": "SNYK-LINUX-BZIP2-106947", | ||
"shortDescription": { | ||
"text": "Low severity - Denial of Service (DoS) vulnerability in bzip2" | ||
}, | ||
"fullDescription": { | ||
"text": "(CVE-2016-3189) bzip2/[email protected]" | ||
}, | ||
"help": { | ||
"text": "", | ||
"markdown": "## Overview\nUse-after-free vulnerability in bzip2recover in bzip2 1.0.6 allows remote attackers to cause a denial of service (crash) via a crafted bzip2 file, related to block ends set to before the start of the block.\n\n## References\n- [GENTOO](https://security.gentoo.org/glsa/201708-08)\n- [CONFIRM](https://bugzilla.redhat.com/show_bug.cgi?id=1319648)\n- [SECTRACK](http://www.securitytracker.com/id/1036132)\n- [BID](http://www.securityfocus.com/bid/91297)\n- [CONFIRM](http://www.oracle.com/technetwork/topics/security/bulletinjul2016-3090568.html)\n- [MLIST](http://www.openwall.com/lists/oss-security/2016/06/20/1)\n" | ||
}, | ||
"defaultConfiguration": { | ||
"level": "warning" | ||
}, | ||
"properties": { | ||
"tags": [ | ||
"security", | ||
"deb" | ||
] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"results": [ | ||
{ | ||
"ruleId": "SNYK-LINUX-BZIP2-106947", | ||
"level": "note", | ||
"message": { | ||
"text": "This file introduces a vulnerable bzip2 package with a low severity vulnerability." | ||
}, | ||
"locations": [ | ||
{ | ||
"physicalLocation": { | ||
"artifactLocation": { | ||
"uri": "Dockerfile" | ||
}, | ||
"region": { | ||
"startLine": 1 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { getResults } from '../../../../../src/lib/formatters/get-sarif-result'; | ||
import { SEVERITY, TestResult } from '../../../../../src/lib/snyk-test/legacy'; | ||
|
||
describe('Retrieving sarif result', () => { | ||
it('should use the test results path as the location uri when target file is not present', () => { | ||
let result = getResults( | ||
getTestResult({ | ||
path: 'alpine:3.18.0', | ||
}), | ||
); | ||
expect(result).toEqual([ | ||
{ | ||
ruleId: 'SNYK-LINUX-EXPAT-450908', | ||
level: 'error', | ||
message: { | ||
text: | ||
'This file introduces a vulnerable expat package with a critical severity vulnerability.', | ||
}, | ||
locations: [ | ||
{ | ||
physicalLocation: { | ||
artifactLocation: { uri: 'alpine:3.18.0' }, | ||
region: { startLine: 1 }, | ||
}, | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
result = getResults( | ||
getTestResult({ | ||
path: 'alpine:3.18.0', | ||
displayTargetFile: undefined, | ||
}), | ||
); | ||
expect(result).toEqual([ | ||
{ | ||
ruleId: 'SNYK-LINUX-EXPAT-450908', | ||
level: 'error', | ||
message: { | ||
text: | ||
'This file introduces a vulnerable expat package with a critical severity vulnerability.', | ||
}, | ||
locations: [ | ||
{ | ||
physicalLocation: { | ||
artifactLocation: { uri: 'alpine:3.18.0' }, | ||
region: { startLine: 1 }, | ||
}, | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
result = getResults( | ||
getTestResult({ | ||
path: 'alpine:3.18.0', | ||
displayTargetFile: null, | ||
}), | ||
); | ||
expect(result).toEqual([ | ||
{ | ||
ruleId: 'SNYK-LINUX-EXPAT-450908', | ||
level: 'error', | ||
message: { | ||
text: | ||
'This file introduces a vulnerable expat package with a critical severity vulnerability.', | ||
}, | ||
locations: [ | ||
{ | ||
physicalLocation: { | ||
artifactLocation: { uri: 'alpine:3.18.0' }, | ||
region: { startLine: 1 }, | ||
}, | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
it('should use the target file as the location uri when target file is present', () => { | ||
const actualResult = getResults( | ||
getTestResult({ | ||
displayTargetFile: 'Dockerfile.test', | ||
}), | ||
); | ||
expect(actualResult).toEqual([ | ||
{ | ||
ruleId: 'SNYK-LINUX-EXPAT-450908', | ||
level: 'error', | ||
message: { | ||
text: | ||
'This file introduces a vulnerable expat package with a critical severity vulnerability.', | ||
}, | ||
locations: [ | ||
{ | ||
physicalLocation: { | ||
artifactLocation: { uri: 'Dockerfile.test' }, | ||
region: { startLine: 1 }, | ||
}, | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
}); | ||
|
||
function getTestResult(testResultOverride = {}, vulnOverride = {}): TestResult { | ||
return { | ||
vulnerabilities: [ | ||
{ | ||
id: 'SNYK-LINUX-EXPAT-450908', | ||
packageName: 'expat', | ||
version: '2.2.5-r0', | ||
below: '', | ||
semver: { | ||
vulnerable: ['<2.2.7-r0'], | ||
}, | ||
patches: [], | ||
isNew: false, | ||
description: '## Overview\nIn libexpat in Expat before 2.2.7...', | ||
title: 'XML External Entity (XXE) Injection', | ||
severity: SEVERITY.CRITICAL, | ||
fixedIn: ['2.2.7-r0'], | ||
credit: [''], | ||
name: 'expat', | ||
from: [ | ||
'docker-image|garethr/snyky@alpine', | ||
'.python-rundeps@0', | ||
'[email protected]', | ||
], | ||
upgradePath: [], | ||
isUpgradable: false, | ||
isPatchable: false, | ||
parentDepType: 'prod', | ||
identifiers: { | ||
ALTERNATIVE: [ | ||
'SNYK-DEBIAN8-EXPAT-450909', | ||
'SNYK-DEBIAN9-EXPAT-450910', | ||
], | ||
CVE: ['CVE-2018-20843'], | ||
CWE: ['CWE-611'], | ||
}, | ||
...vulnOverride, | ||
}, | ||
], | ||
ok: false, | ||
dependencyCount: 969, | ||
org: 'ORG', | ||
policy: '', | ||
isPrivate: true, | ||
licensesPolicy: null, | ||
ignoreSettings: null, | ||
summary: '165 vulnerable dependencies', | ||
...testResultOverride, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters