snyk 1.985.0 → 1.986.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.
@@ -712,7 +712,7 @@ exports.InvalidVarFilePath = InvalidVarFilePath;
712
712
  "use strict";
713
713
 
714
714
  Object.defineProperty(exports, "__esModule", ({ value: true }));
715
- exports.pull = exports.localTest = exports.cleanLocalCache = exports.trackUsage = exports.formatScanResultsV2 = exports.applyCustomSeverities = exports.getIacOrgSettings = exports.scanFiles = exports.parseFiles = exports.loadContentForFiles = exports.initLocalCache = exports.performanceAnalyticsDecorator = exports.asyncPerformanceAnalyticsDecorator = void 0;
715
+ exports.pull = exports.localTest = exports.cleanLocalCache = exports.trackUsage = exports.formatScanResults = exports.applyCustomSeverities = exports.getIacOrgSettings = exports.scanFiles = exports.parseFiles = exports.loadContentForFiles = exports.initLocalCache = exports.performanceAnalyticsDecorator = exports.asyncPerformanceAnalyticsDecorator = void 0;
716
716
  const file_parser_1 = __webpack_require__(39331);
717
717
  const file_scanner_1 = __webpack_require__(88361);
718
718
  const results_formatter_1 = __webpack_require__(11059);
@@ -763,7 +763,7 @@ exports.applyCustomSeverities = measurableApplyCustomSeverities;
763
763
  const measurableCleanLocalCache = performanceAnalyticsDecorator(local_cache_1.cleanLocalCache, types_1.PerformanceAnalyticsKey.CacheCleanup);
764
764
  exports.cleanLocalCache = measurableCleanLocalCache;
765
765
  const measurableFormatScanResults = performanceAnalyticsDecorator(results_formatter_1.formatScanResults, types_1.PerformanceAnalyticsKey.ResultFormatting);
766
- exports.formatScanResultsV2 = measurableFormatScanResults;
766
+ exports.formatScanResults = measurableFormatScanResults;
767
767
  const measurableTrackUsage = asyncPerformanceAnalyticsDecorator(usage_tracking_1.trackUsage, types_1.PerformanceAnalyticsKey.UsageTracking);
768
768
  exports.trackUsage = measurableTrackUsage;
769
769
  const measurableLocalTest = asyncPerformanceAnalyticsDecorator(index_1.test, types_1.PerformanceAnalyticsKey.Total);
@@ -1262,12 +1262,17 @@ exports.processResults = void 0;
1262
1262
  const policy_1 = __webpack_require__(91434);
1263
1263
  const share_results_1 = __webpack_require__(68971);
1264
1264
  const measurable_methods_1 = __webpack_require__(5687);
1265
+ const cloneDeep = __webpack_require__(83465);
1265
1266
  async function processResults(resultsWithCustomSeverities, orgPublicId, iacOrgSettings, policy, tags, attributes, options, projectRoot, meta) {
1266
1267
  let projectPublicIds = {};
1267
1268
  let gitRemoteUrl;
1268
1269
  if (options.report) {
1269
1270
  ({ projectPublicIds, gitRemoteUrl } = await share_results_1.formatAndShareResults({
1270
- results: resultsWithCustomSeverities,
1271
+ // this is to fix a bug where we mutated the "results" in the formatAndShareResults
1272
+ // and these were used again in the formatScanResults below
1273
+ // resulting in double count of issues
1274
+ // note: this happened only in multi-YAML documents
1275
+ results: cloneDeep(resultsWithCustomSeverities),
1271
1276
  options,
1272
1277
  orgPublicId,
1273
1278
  policy,
@@ -1277,7 +1282,7 @@ async function processResults(resultsWithCustomSeverities, orgPublicId, iacOrgSe
1277
1282
  meta,
1278
1283
  }));
1279
1284
  }
1280
- const formattedResults = measurable_methods_1.formatScanResultsV2(resultsWithCustomSeverities, options, iacOrgSettings.meta, projectPublicIds, projectRoot, gitRemoteUrl);
1285
+ const formattedResults = measurable_methods_1.formatScanResults(resultsWithCustomSeverities, options, iacOrgSettings.meta, projectPublicIds, projectRoot, gitRemoteUrl);
1281
1286
  return policy_1.filterIgnoredIssues(policy, formattedResults);
1282
1287
  }
1283
1288
  exports.processResults = processResults;
@@ -1302,10 +1307,10 @@ const cloud_config_parser_1 = __webpack_require__(98611);
1302
1307
  const path = __webpack_require__(85622);
1303
1308
  const detect_1 = __webpack_require__(45318);
1304
1309
  const severitiesArray = common_1.SEVERITIES.map((s) => s.verboseName);
1305
- function formatScanResults(scanResults, options, meta, projectPublicIds, porjectRoot, gitRemoteUrl) {
1310
+ function formatScanResults(scanResults, options, meta, projectPublicIds, projectRoot, gitRemoteUrl) {
1306
1311
  try {
1307
1312
  const groupedByFile = scanResults.reduce((memo, scanResult) => {
1308
- const res = formatScanResult(scanResult, meta, options, porjectRoot);
1313
+ const res = formatScanResult(scanResult, meta, options, projectRoot);
1309
1314
  if (memo[scanResult.filePath]) {
1310
1315
  memo[scanResult.filePath].result.cloudConfigResults.push(...res.result.cloudConfigResults);
1311
1316
  }
@@ -3401,11 +3406,21 @@ function getErrorUserMessage(code) {
3401
3406
  }
3402
3407
  exports.getErrorUserMessage = getErrorUserMessage;
3403
3408
  class SnykIacTestError extends errors_1.CustomError {
3404
- constructor(error) {
3405
- super(error.message);
3406
- this.code = error.code;
3409
+ constructor(scanError) {
3410
+ super(scanError.message);
3411
+ this.code = scanError.code;
3407
3412
  this.strCode = error_utils_1.getErrorStringCode(this.code);
3408
3413
  this.userMessage = getErrorUserMessage(this.code);
3414
+ this.fields = Object.assign({
3415
+ path: '',
3416
+ }, scanError.fields);
3417
+ }
3418
+ get path() {
3419
+ var _a;
3420
+ return (_a = this.fields) === null || _a === void 0 ? void 0 : _a.path;
3421
+ }
3422
+ set path(path1) {
3423
+ this.fields.path = path1;
3409
3424
  }
3410
3425
  }
3411
3426
  exports.SnykIacTestError = SnykIacTestError;
@@ -3621,16 +3636,16 @@ function orgSettingsToIgnoreSettings(orgSettings) {
3621
3636
  "use strict";
3622
3637
 
3623
3638
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3624
- exports.FoundIssuesError = exports.buildOutput = void 0;
3639
+ exports.FoundIssuesError = exports.NoSuccessfulScansError = exports.buildOutput = void 0;
3625
3640
  const os_1 = __webpack_require__(12087);
3626
3641
  const json_1 = __webpack_require__(71909);
3627
3642
  const types_1 = __webpack_require__(55246);
3628
3643
  const iac_output_1 = __webpack_require__(68145);
3629
3644
  const iac_output_2 = __webpack_require__(68145);
3630
3645
  const json_2 = __webpack_require__(27019);
3631
- const errors_1 = __webpack_require__(87198);
3632
3646
  const sarif_1 = __webpack_require__(87999);
3633
- const errors_2 = __webpack_require__(55191);
3647
+ const errors_1 = __webpack_require__(55191);
3648
+ const strip_ansi_1 = __webpack_require__(76003);
3634
3649
  function buildOutput({ scanResult, testSpinner, projectName, orgSettings, options, }) {
3635
3650
  if (scanResult.results) {
3636
3651
  testSpinner === null || testSpinner === void 0 ? void 0 : testSpinner.succeed(iac_output_1.spinnerSuccessMessage);
@@ -3651,14 +3666,18 @@ function buildOutput({ scanResult, testSpinner, projectName, orgSettings, option
3651
3666
  }
3652
3667
  exports.buildOutput = buildOutput;
3653
3668
  function buildTestCommandResultData({ scanResult, projectName, orgSettings, options, }) {
3654
- var _a, _b;
3655
- let responseData = '';
3669
+ var _a, _b, _c, _d, _e;
3656
3670
  const jsonData = json_2.jsonStringifyLargeObject(json_1.convertEngineToJsonResults({
3657
3671
  results: scanResult,
3658
3672
  projectName,
3659
3673
  orgSettings,
3660
3674
  }));
3661
3675
  const sarifData = json_2.jsonStringifyLargeObject(sarif_1.convertEngineToSarifResults(scanResult));
3676
+ const isPartialSuccess = ((_b = (_a = scanResult.results) === null || _a === void 0 ? void 0 : _a.resources) === null || _b === void 0 ? void 0 : _b.length) || !((_c = scanResult.errors) === null || _c === void 0 ? void 0 : _c.length);
3677
+ if (!isPartialSuccess) {
3678
+ throw new NoSuccessfulScansError({ json: jsonData, sarif: sarifData }, scanResult.errors, options);
3679
+ }
3680
+ let responseData;
3662
3681
  if (options.json) {
3663
3682
  responseData = jsonData;
3664
3683
  }
@@ -3668,9 +3687,13 @@ function buildTestCommandResultData({ scanResult, projectName, orgSettings, opti
3668
3687
  else {
3669
3688
  responseData = buildTextOutput({ scanResult, projectName, orgSettings });
3670
3689
  }
3671
- const isFoundIssues = !!((_b = (_a = scanResult.results) === null || _a === void 0 ? void 0 : _a.vulnerabilities) === null || _b === void 0 ? void 0 : _b.length);
3690
+ const isFoundIssues = !!((_e = (_d = scanResult.results) === null || _d === void 0 ? void 0 : _d.vulnerabilities) === null || _e === void 0 ? void 0 : _e.length);
3672
3691
  if (isFoundIssues) {
3673
- throw new FoundIssuesError({ responseData, jsonData, sarifData });
3692
+ throw new FoundIssuesError({
3693
+ response: responseData,
3694
+ json: jsonData,
3695
+ sarif: sarifData,
3696
+ });
3674
3697
  }
3675
3698
  return { responseData, jsonData, sarifData };
3676
3699
  }
@@ -3684,18 +3707,10 @@ function buildTextOutput({ scanResult, projectName, orgSettings, }) {
3684
3707
  shouldShowLineNumbers: true,
3685
3708
  });
3686
3709
  if (scanResult.errors) {
3687
- const testFailures = scanResult.errors.map((error) => {
3688
- var _a;
3689
- const formattedError = new errors_1.SnykIacTestError(error);
3690
- // If we received an error without a path it means that the scan failed
3691
- if (!((_a = error === null || error === void 0 ? void 0 : error.fields) === null || _a === void 0 ? void 0 : _a.path)) {
3692
- throw formattedError;
3693
- }
3694
- return {
3695
- filePath: error.fields.path,
3696
- failureReason: formattedError.userMessage,
3697
- };
3698
- });
3710
+ const testFailures = scanResult.errors.map((error) => ({
3711
+ filePath: error.fields.path,
3712
+ failureReason: error.userMessage,
3713
+ }));
3699
3714
  response += os_1.EOL.repeat(2) + iac_output_1.formatIacTestFailures(testFailures);
3700
3715
  }
3701
3716
  response += os_1.EOL;
@@ -3705,14 +3720,45 @@ function buildTextOutput({ scanResult, projectName, orgSettings, }) {
3705
3720
  response += os_1.EOL;
3706
3721
  return response;
3707
3722
  }
3708
- class FoundIssuesError extends errors_2.CustomError {
3709
- constructor(props) {
3710
- super(props.responseData);
3723
+ class NoSuccessfulScansError extends errors_1.FormattedCustomError {
3724
+ constructor(responseData, errors, options) {
3725
+ const firstErr = errors[0];
3726
+ const isText = !options.json && !options.sarif;
3727
+ const message = options.json
3728
+ ? responseData.json
3729
+ : options.sarif
3730
+ ? responseData.sarif
3731
+ : firstErr.message;
3732
+ super(message, isText
3733
+ ? iac_output_1.formatIacTestFailures(errors.map((scanError) => ({
3734
+ failureReason: scanError.userMessage,
3735
+ filePath: scanError.fields.path,
3736
+ })))
3737
+ : strip_ansi_1.default(message));
3738
+ this.strCode = firstErr.strCode;
3739
+ this.code = firstErr.code;
3740
+ this.json = isText ? responseData.json : message;
3741
+ this.jsonStringifiedResults = responseData.json;
3742
+ this.sarifStringifiedResults = responseData.sarif;
3743
+ this.fields = firstErr.fields;
3744
+ }
3745
+ get path() {
3746
+ var _a;
3747
+ return (_a = this.fields) === null || _a === void 0 ? void 0 : _a.path;
3748
+ }
3749
+ set path(path1) {
3750
+ this.fields.path = path1;
3751
+ }
3752
+ }
3753
+ exports.NoSuccessfulScansError = NoSuccessfulScansError;
3754
+ class FoundIssuesError extends errors_1.CustomError {
3755
+ constructor(responseData) {
3756
+ super(responseData.response);
3711
3757
  this.code = 'VULNS';
3712
3758
  this.strCode = 'VULNS';
3713
- this.userMessage = props.responseData;
3714
- this.jsonStringifiedResults = props.jsonData;
3715
- this.sarifStringifiedResults = props.sarifData;
3759
+ this.userMessage = responseData.response;
3760
+ this.jsonStringifiedResults = responseData.json;
3761
+ this.sarifStringifiedResults = responseData.sarif;
3716
3762
  }
3717
3763
  }
3718
3764
  exports.FoundIssuesError = FoundIssuesError;
@@ -3897,6 +3943,7 @@ const errors_1 = __webpack_require__(55191);
3897
3943
  const types_1 = __webpack_require__(94820);
3898
3944
  const error_utils_1 = __webpack_require__(36401);
3899
3945
  const newDebug = __webpack_require__(15158);
3946
+ const results_1 = __webpack_require__(89752);
3900
3947
  const os = __webpack_require__(12087);
3901
3948
  const fs = __webpack_require__(35747);
3902
3949
  const path = __webpack_require__(85622);
@@ -3929,14 +3976,15 @@ function scanWithConfig(options, policyEnginePath, rulesBundlePath, configPath)
3929
3976
  if (process.error) {
3930
3977
  throw new ScanError(`spawning process: ${process.error}`);
3931
3978
  }
3932
- let output;
3979
+ let snykIacTestOutput;
3933
3980
  try {
3934
- output = JSON.parse(process.stdout);
3981
+ snykIacTestOutput = JSON.parse(process.stdout);
3935
3982
  }
3936
3983
  catch (e) {
3937
3984
  throw new ScanError(`invalid output encoding: ${e}`);
3938
3985
  }
3939
- return output;
3986
+ const testOutput = results_1.mapSnykIacTestOutputToTestOutput(snykIacTestOutput);
3987
+ return testOutput;
3940
3988
  }
3941
3989
  function processFlags(options, rulesBundlePath, configPath) {
3942
3990
  var _a, _b, _c;
@@ -4001,6 +4049,31 @@ class ScanError extends errors_1.CustomError {
4001
4049
  }
4002
4050
 
4003
4051
 
4052
+ /***/ }),
4053
+
4054
+ /***/ 89752:
4055
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
4056
+
4057
+ "use strict";
4058
+
4059
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
4060
+ exports.mapSnykIacTestOutputToTestOutput = void 0;
4061
+ const errors_1 = __webpack_require__(87198);
4062
+ function mapSnykIacTestOutputToTestOutput(snykIacOutput) {
4063
+ var _a;
4064
+ const errors = (_a = snykIacOutput.errors) === null || _a === void 0 ? void 0 : _a.map((err) => new errors_1.SnykIacTestError(err));
4065
+ const errWithoutPath = errors === null || errors === void 0 ? void 0 : errors.find((err) => { var _a; return !((_a = err.fields) === null || _a === void 0 ? void 0 : _a.path); });
4066
+ if (errWithoutPath) {
4067
+ throw errWithoutPath;
4068
+ }
4069
+ return {
4070
+ results: snykIacOutput.results,
4071
+ errors,
4072
+ };
4073
+ }
4074
+ exports.mapSnykIacTestOutputToTestOutput = mapSnykIacTestOutputToTestOutput;
4075
+
4076
+
4004
4077
  /***/ }),
4005
4078
 
4006
4079
  /***/ 88929: