snyk 1.977.0 → 1.978.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/917.index.js
CHANGED
|
@@ -3640,6 +3640,7 @@ const iac_output_1 = __webpack_require__(68145);
|
|
|
3640
3640
|
const iac_output_2 = __webpack_require__(68145);
|
|
3641
3641
|
const json_2 = __webpack_require__(27019);
|
|
3642
3642
|
const errors_1 = __webpack_require__(87198);
|
|
3643
|
+
const sarif_1 = __webpack_require__(87999);
|
|
3643
3644
|
function buildOutput({ scanResult, testSpinner, projectName, orgSettings, options, }) {
|
|
3644
3645
|
if (scanResult.results) {
|
|
3645
3646
|
testSpinner === null || testSpinner === void 0 ? void 0 : testSpinner.succeed(iac_output_1.spinnerSuccessMessage);
|
|
@@ -3647,18 +3648,37 @@ function buildOutput({ scanResult, testSpinner, projectName, orgSettings, option
|
|
|
3647
3648
|
else {
|
|
3648
3649
|
testSpinner === null || testSpinner === void 0 ? void 0 : testSpinner.stop();
|
|
3649
3650
|
}
|
|
3650
|
-
const
|
|
3651
|
+
const { responseData, jsonData, sarifData } = buildTestCommandResultData({
|
|
3652
|
+
scanResult,
|
|
3653
|
+
projectName,
|
|
3654
|
+
orgSettings,
|
|
3655
|
+
options,
|
|
3656
|
+
});
|
|
3657
|
+
if (options.json || options.sarif) {
|
|
3658
|
+
return types_1.TestCommandResult.createJsonTestCommandResult(responseData, jsonData, sarifData);
|
|
3659
|
+
}
|
|
3660
|
+
return types_1.TestCommandResult.createHumanReadableTestCommandResult(responseData, jsonData, sarifData);
|
|
3661
|
+
}
|
|
3662
|
+
exports.buildOutput = buildOutput;
|
|
3663
|
+
function buildTestCommandResultData({ scanResult, projectName, orgSettings, options, }) {
|
|
3664
|
+
let responseData = '';
|
|
3651
3665
|
const jsonData = json_2.jsonStringifyLargeObject(json_1.convertEngineToJsonResults({
|
|
3652
3666
|
results: scanResult,
|
|
3653
3667
|
projectName,
|
|
3654
3668
|
orgSettings,
|
|
3655
3669
|
}));
|
|
3670
|
+
const sarifData = json_2.jsonStringifyLargeObject(sarif_1.convertEngineToSarifResults(scanResult));
|
|
3656
3671
|
if (options.json) {
|
|
3657
|
-
|
|
3672
|
+
responseData = jsonData;
|
|
3673
|
+
}
|
|
3674
|
+
else if (options.sarif) {
|
|
3675
|
+
responseData = sarifData;
|
|
3658
3676
|
}
|
|
3659
|
-
|
|
3677
|
+
else {
|
|
3678
|
+
responseData = buildTextOutput({ scanResult, projectName, orgSettings });
|
|
3679
|
+
}
|
|
3680
|
+
return { responseData, jsonData, sarifData };
|
|
3660
3681
|
}
|
|
3661
|
-
exports.buildOutput = buildOutput;
|
|
3662
3682
|
const SEPARATOR = '\n-------------------------------------------------------\n';
|
|
3663
3683
|
function buildTextOutput({ scanResult, projectName, orgSettings, }) {
|
|
3664
3684
|
let response = '';
|
|
@@ -3692,6 +3712,171 @@ function buildTextOutput({ scanResult, projectName, orgSettings, }) {
|
|
|
3692
3712
|
}
|
|
3693
3713
|
|
|
3694
3714
|
|
|
3715
|
+
/***/ }),
|
|
3716
|
+
|
|
3717
|
+
/***/ 87999:
|
|
3718
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
3719
|
+
|
|
3720
|
+
"use strict";
|
|
3721
|
+
|
|
3722
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
3723
|
+
exports.convertEngineToSarifResults = void 0;
|
|
3724
|
+
const url_1 = __webpack_require__(78835);
|
|
3725
|
+
const marked_1 = __webpack_require__(30970);
|
|
3726
|
+
const path = __webpack_require__(85622);
|
|
3727
|
+
const upperFirst = __webpack_require__(90039);
|
|
3728
|
+
const camelCase = __webpack_require__(76884);
|
|
3729
|
+
const version_1 = __webpack_require__(38217);
|
|
3730
|
+
const sarif_output_1 = __webpack_require__(5034);
|
|
3731
|
+
const git_1 = __webpack_require__(82421);
|
|
3732
|
+
// Used to reference the base path in results.
|
|
3733
|
+
const PROJECT_ROOT_KEY = 'PROJECTROOT';
|
|
3734
|
+
function convertEngineToSarifResults(scanResult) {
|
|
3735
|
+
let repoRoot;
|
|
3736
|
+
try {
|
|
3737
|
+
repoRoot = git_1.getRepositoryRoot() + '/';
|
|
3738
|
+
}
|
|
3739
|
+
catch {
|
|
3740
|
+
repoRoot = path.join(process.cwd(), '/'); // the slash at the end is required, otherwise the artifactLocation.uri starts with a slash
|
|
3741
|
+
}
|
|
3742
|
+
const tool = {
|
|
3743
|
+
driver: {
|
|
3744
|
+
name: 'Snyk IaC',
|
|
3745
|
+
fullName: 'Snyk Infrastructure as Code',
|
|
3746
|
+
version: version_1.getVersion(),
|
|
3747
|
+
informationUri: 'https://docs.snyk.io/products/snyk-infrastructure-as-code',
|
|
3748
|
+
rules: extractReportingDescriptor(scanResult.results),
|
|
3749
|
+
},
|
|
3750
|
+
};
|
|
3751
|
+
return {
|
|
3752
|
+
$schema: 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json',
|
|
3753
|
+
version: '2.1.0',
|
|
3754
|
+
runs: [
|
|
3755
|
+
{
|
|
3756
|
+
// https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317498
|
|
3757
|
+
originalUriBaseIds: {
|
|
3758
|
+
[PROJECT_ROOT_KEY]: {
|
|
3759
|
+
uri: url_1.pathToFileURL(repoRoot).href,
|
|
3760
|
+
description: {
|
|
3761
|
+
text: 'The root directory for all project files.',
|
|
3762
|
+
},
|
|
3763
|
+
},
|
|
3764
|
+
},
|
|
3765
|
+
tool,
|
|
3766
|
+
automationDetails: {
|
|
3767
|
+
id: 'snyk-iac',
|
|
3768
|
+
},
|
|
3769
|
+
results: mapSnykIacTestResultsToSarifResults(scanResult.results),
|
|
3770
|
+
},
|
|
3771
|
+
],
|
|
3772
|
+
};
|
|
3773
|
+
}
|
|
3774
|
+
exports.convertEngineToSarifResults = convertEngineToSarifResults;
|
|
3775
|
+
function extractReportingDescriptor(results) {
|
|
3776
|
+
const rules = {};
|
|
3777
|
+
if (!(results === null || results === void 0 ? void 0 : results.vulnerabilities)) {
|
|
3778
|
+
return Object.values(rules);
|
|
3779
|
+
}
|
|
3780
|
+
results.vulnerabilities.forEach((vulnerability) => {
|
|
3781
|
+
if (rules[vulnerability.rule.id]) {
|
|
3782
|
+
return;
|
|
3783
|
+
}
|
|
3784
|
+
const tags = ['security']; // switch to rules.labels once `snyk-iac-test` includes this info
|
|
3785
|
+
rules[vulnerability.rule.id] = {
|
|
3786
|
+
id: vulnerability.rule.id,
|
|
3787
|
+
name: upperFirst(camelCase(vulnerability.rule.title)).replace(/ /g, ''),
|
|
3788
|
+
shortDescription: {
|
|
3789
|
+
text: `${upperFirst(vulnerability.severity)} severity - ${vulnerability.rule.title}`,
|
|
3790
|
+
},
|
|
3791
|
+
fullDescription: {
|
|
3792
|
+
text: vulnerability.rule.description,
|
|
3793
|
+
},
|
|
3794
|
+
help: {
|
|
3795
|
+
text: renderMarkdown(vulnerability.remediation),
|
|
3796
|
+
markdown: vulnerability.remediation,
|
|
3797
|
+
},
|
|
3798
|
+
defaultConfiguration: {
|
|
3799
|
+
level: sarif_output_1.getIssueLevel(vulnerability.severity),
|
|
3800
|
+
},
|
|
3801
|
+
properties: {
|
|
3802
|
+
tags,
|
|
3803
|
+
problem: {
|
|
3804
|
+
severity: vulnerability.severity,
|
|
3805
|
+
},
|
|
3806
|
+
},
|
|
3807
|
+
helpUri: `https://snyk.io/security-rules/${vulnerability.rule.id}`,
|
|
3808
|
+
};
|
|
3809
|
+
});
|
|
3810
|
+
return Object.values(rules);
|
|
3811
|
+
}
|
|
3812
|
+
function renderMarkdown(markdown) {
|
|
3813
|
+
const renderer = {
|
|
3814
|
+
em(text) {
|
|
3815
|
+
return text;
|
|
3816
|
+
},
|
|
3817
|
+
strong(text) {
|
|
3818
|
+
return text;
|
|
3819
|
+
},
|
|
3820
|
+
link(text) {
|
|
3821
|
+
return text;
|
|
3822
|
+
},
|
|
3823
|
+
blockquote(quote) {
|
|
3824
|
+
return quote;
|
|
3825
|
+
},
|
|
3826
|
+
list(body) {
|
|
3827
|
+
return body;
|
|
3828
|
+
},
|
|
3829
|
+
listitem(text) {
|
|
3830
|
+
return text;
|
|
3831
|
+
},
|
|
3832
|
+
paragraph(text) {
|
|
3833
|
+
return text;
|
|
3834
|
+
},
|
|
3835
|
+
codespan(text) {
|
|
3836
|
+
return text;
|
|
3837
|
+
},
|
|
3838
|
+
code(code) {
|
|
3839
|
+
return code;
|
|
3840
|
+
},
|
|
3841
|
+
heading(text) {
|
|
3842
|
+
return `${text}\n`;
|
|
3843
|
+
},
|
|
3844
|
+
};
|
|
3845
|
+
marked_1.marked.use({ renderer });
|
|
3846
|
+
return marked_1.marked.parse(markdown);
|
|
3847
|
+
}
|
|
3848
|
+
function mapSnykIacTestResultsToSarifResults(results) {
|
|
3849
|
+
const result = [];
|
|
3850
|
+
if (!(results === null || results === void 0 ? void 0 : results.vulnerabilities)) {
|
|
3851
|
+
return result;
|
|
3852
|
+
}
|
|
3853
|
+
results.vulnerabilities.forEach((vulnerability) => {
|
|
3854
|
+
result.push({
|
|
3855
|
+
ruleId: vulnerability.rule.id,
|
|
3856
|
+
message: {
|
|
3857
|
+
text: `This line contains a potential ${vulnerability.severity} severity misconfiguration`,
|
|
3858
|
+
},
|
|
3859
|
+
locations: [
|
|
3860
|
+
{
|
|
3861
|
+
physicalLocation: {
|
|
3862
|
+
artifactLocation: {
|
|
3863
|
+
uri: vulnerability.resource.file,
|
|
3864
|
+
uriBaseId: PROJECT_ROOT_KEY,
|
|
3865
|
+
},
|
|
3866
|
+
// We exclude the `region` key when the line number is missing or -1.
|
|
3867
|
+
// https://docs.oasis-open.org/sarif/sarif/v2.0/csprd02/sarif-v2.0-csprd02.html#_Toc10127873
|
|
3868
|
+
region: {
|
|
3869
|
+
startLine: vulnerability.resource.line,
|
|
3870
|
+
},
|
|
3871
|
+
},
|
|
3872
|
+
},
|
|
3873
|
+
],
|
|
3874
|
+
});
|
|
3875
|
+
});
|
|
3876
|
+
return result;
|
|
3877
|
+
}
|
|
3878
|
+
|
|
3879
|
+
|
|
3695
3880
|
/***/ }),
|
|
3696
3881
|
|
|
3697
3882
|
/***/ 50277:
|