snyk 1.1105.0 → 1.1107.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.
@@ -4436,7 +4436,7 @@ exports.tryGetSpec = tryGetSpec;
4436
4436
  "use strict";
4437
4437
 
4438
4438
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4439
- exports.getCodeAnalysisAndParseResults = void 0;
4439
+ exports.getCodeTestResults = void 0;
4440
4440
  const code_client_1 = __webpack_require__(95951);
4441
4441
  const legacy_1 = __webpack_require__(34013);
4442
4442
  const api_token_1 = __webpack_require__(95181);
@@ -4450,16 +4450,22 @@ const chalk_1 = __webpack_require__(32589);
4450
4450
  const debugLib = __webpack_require__(15158);
4451
4451
  const code_config_1 = __webpack_require__(55203);
4452
4452
  const debug = debugLib('snyk-code');
4453
- async function getCodeAnalysisAndParseResults(root, options, sastSettings, requestId) {
4453
+ async function getCodeTestResults(root, options, sastSettings, requestId) {
4454
4454
  await spinner_1.spinner.clearAll();
4455
4455
  utils_1.analysisProgressUpdate();
4456
4456
  const codeAnalysis = await getCodeAnalysis(root, options, sastSettings, requestId);
4457
4457
  spinner_1.spinner.clearAll();
4458
- return parseSecurityResults(codeAnalysis);
4458
+ if (!codeAnalysis) {
4459
+ return null;
4460
+ }
4461
+ return {
4462
+ reportResults: codeAnalysis.reportResults,
4463
+ analysisResults: codeAnalysis.analysisResults,
4464
+ };
4459
4465
  }
4460
- exports.getCodeAnalysisAndParseResults = getCodeAnalysisAndParseResults;
4466
+ exports.getCodeTestResults = getCodeTestResults;
4461
4467
  async function getCodeAnalysis(root, options, sastSettings, requestId) {
4462
- var _a;
4468
+ var _a, _b;
4463
4469
  const isLocalCodeEngineEnabled = isLocalCodeEngine(sastSettings);
4464
4470
  if (isLocalCodeEngineEnabled) {
4465
4471
  validateLocalCodeEngineUrl(sastSettings.localCodeEngine.url);
@@ -4490,9 +4496,21 @@ async function getCodeAnalysis(root, options, sastSettings, requestId) {
4490
4496
  ? severityToAnalysisSeverity(options.severityThreshold)
4491
4497
  : code_client_1.AnalysisSeverity.info;
4492
4498
  const result = await code_client_1.analyzeFolders({
4493
- connection: { baseURL, sessionToken, source, requestId },
4499
+ connection: {
4500
+ baseURL,
4501
+ sessionToken,
4502
+ source,
4503
+ requestId,
4504
+ },
4494
4505
  analysisOptions: { severity },
4495
4506
  fileOptions: { paths: [root] },
4507
+ ...(options.report && {
4508
+ reportOptions: {
4509
+ enabled: (_a = options.report) !== null && _a !== void 0 ? _a : false,
4510
+ projectName: options['project-name'],
4511
+ targetRef: options['target-reference'],
4512
+ },
4513
+ }),
4496
4514
  analysisContext: {
4497
4515
  initiator: 'CLI',
4498
4516
  flow: source,
@@ -4506,15 +4524,25 @@ async function getCodeAnalysis(root, options, sastSettings, requestId) {
4506
4524
  },
4507
4525
  languages: sastSettings.supportedLanguages,
4508
4526
  });
4509
- if ((_a = result === null || result === void 0 ? void 0 : result.fileBundle.skippedOversizedFiles) === null || _a === void 0 ? void 0 : _a.length) {
4527
+ if ((_b = result === null || result === void 0 ? void 0 : result.fileBundle.skippedOversizedFiles) === null || _b === void 0 ? void 0 : _b.length) {
4510
4528
  debug('\n', chalk_1.default.yellow(`Warning!\nFiles were skipped in the analysis due to their size being greater than ${code_client_1.MAX_FILE_SIZE}B. Skipped files: ${[
4511
4529
  ...result.fileBundle.skippedOversizedFiles,
4512
4530
  ].join(', ')}`));
4513
4531
  }
4514
- if ((result === null || result === void 0 ? void 0 : result.analysisResults.type) === 'sarif') {
4515
- return result.analysisResults.sarif;
4532
+ if (!result || result.analysisResults.type !== 'sarif') {
4533
+ return null;
4534
+ }
4535
+ result.analysisResults.sarif = parseSecurityResults(result.analysisResults.sarif);
4536
+ // Filter ignored issues when using report
4537
+ if (options.report) {
4538
+ result.analysisResults.sarif = filterIgnoredIssues(result.analysisResults.sarif);
4516
4539
  }
4517
- return null;
4540
+ return result;
4541
+ }
4542
+ function filterIgnoredIssues(codeAnalysis) {
4543
+ const results = codeAnalysis.runs[0].results;
4544
+ codeAnalysis.runs[0].results = results === null || results === void 0 ? void 0 : results.filter((rule) => { var _a, _b; return ((_b = (_a = rule.suppressions) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === 0; });
4545
+ return codeAnalysis;
4518
4546
  }
4519
4547
  function severityToAnalysisSeverity(severity) {
4520
4548
  if (severity === legacy_1.SEVERITY.CRITICAL) {
@@ -4529,9 +4557,6 @@ function severityToAnalysisSeverity(severity) {
4529
4557
  }
4530
4558
  function parseSecurityResults(codeAnalysis) {
4531
4559
  let securityRulesMap;
4532
- if (!codeAnalysis) {
4533
- return codeAnalysis;
4534
- }
4535
4560
  const rules = codeAnalysis.runs[0].tool.driver.rules;
4536
4561
  const results = codeAnalysis.runs[0].results;
4537
4562
  if (rules) {
@@ -4684,24 +4709,26 @@ exports.FeatureNotSupportedBySnykCodeError = FeatureNotSupportedBySnykCodeError;
4684
4709
  "use strict";
4685
4710
 
4686
4711
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4687
- exports.getPrefix = exports.getMeta = exports.getCodeDisplayedOutput = void 0;
4712
+ exports.getCodeReportDisplayedOutput = exports.getPrefix = exports.getMeta = exports.getCodeDisplayedOutput = void 0;
4713
+ const os_1 = __webpack_require__(12087);
4688
4714
  const Debug = __webpack_require__(15158);
4689
4715
  const chalk_1 = __webpack_require__(32589);
4690
4716
  const theme_1 = __webpack_require__(86988);
4691
4717
  const common_1 = __webpack_require__(53110);
4692
4718
  const right_pad_1 = __webpack_require__(80627);
4693
4719
  const debug = Debug('code-output');
4694
- function getCodeDisplayedOutput(codeTest, meta, prefix) {
4720
+ function getCodeDisplayedOutput(testResults, meta, prefix) {
4695
4721
  let issues = {};
4696
- if (codeTest.runs[0].results) {
4697
- const results = codeTest.runs[0].results;
4698
- const rulesMap = getRulesMap(codeTest.runs[0].tool.driver.rules || []);
4722
+ const sarif = testResults.analysisResults.sarif;
4723
+ if (sarif.runs[0].results) {
4724
+ const results = sarif.runs[0].results;
4725
+ const rulesMap = getRulesMap(sarif.runs[0].tool.driver.rules || []);
4699
4726
  issues = getIssues(results, rulesMap);
4700
4727
  }
4701
4728
  const issuesText = issues.low.join('') + issues.medium.join('') + issues.high.join('');
4702
4729
  const summaryOKText = theme_1.color.status.success(`${theme_1.icon.VALID} Test completed`);
4703
4730
  const codeIssueSummary = getCodeIssuesSummary(issues);
4704
- return (prefix +
4731
+ let summary = prefix +
4705
4732
  issuesText +
4706
4733
  '\n' +
4707
4734
  summaryOKText +
@@ -4711,7 +4738,13 @@ function getCodeDisplayedOutput(codeTest, meta, prefix) {
4711
4738
  chalk_1.default.bold('Summary:') +
4712
4739
  '\n\n' +
4713
4740
  codeIssueSummary +
4714
- '\n\n');
4741
+ '\n\n';
4742
+ if (testResults.reportResults) {
4743
+ summary +=
4744
+ getCodeReportDisplayedOutput(testResults.reportResults.reportUrl) +
4745
+ '\n\n';
4746
+ }
4747
+ return summary;
4715
4748
  }
4716
4749
  exports.getCodeDisplayedOutput = getCodeDisplayedOutput;
4717
4750
  function getCodeIssuesSummary(issues) {
@@ -4739,7 +4772,7 @@ function getIssues(results, rulesMap) {
4739
4772
  high: [],
4740
4773
  };
4741
4774
  const issues = results.reduce((acc, res) => {
4742
- var _a, _b;
4775
+ var _a, _b, _c;
4743
4776
  if ((_a = res.locations) === null || _a === void 0 ? void 0 : _a.length) {
4744
4777
  const location = res.locations[0].physicalLocation;
4745
4778
  if (res.level && (location === null || location === void 0 ? void 0 : location.artifactLocation) && (location === null || location === void 0 ? void 0 : location.region)) {
@@ -4755,7 +4788,10 @@ function getIssues(results, rulesMap) {
4755
4788
  const artifactLocationUri = location.artifactLocation.uri;
4756
4789
  const startLine = location.region.startLine;
4757
4790
  const text = res.message.text;
4758
- const title = ruleIdSeverityText;
4791
+ let title = ruleIdSeverityText;
4792
+ if ((_c = res.fingerprints) === null || _c === void 0 ? void 0 : _c['identity']) {
4793
+ title += `\n ID: ${res.fingerprints['identity']}`;
4794
+ }
4759
4795
  const path = ` Path: ${artifactLocationUri}, line ${startLine}`;
4760
4796
  const info = ` Info: ${text}`;
4761
4797
  acc[severity.toLowerCase()].push(`${title} \n ${path} \n ${info}\n\n`);
@@ -4797,6 +4833,15 @@ function getPrefix(path) {
4797
4833
  return chalk_1.default.bold.white('\nTesting ' + path + ' ...\n\n');
4798
4834
  }
4799
4835
  exports.getPrefix = getPrefix;
4836
+ function getCodeReportDisplayedOutput(reportUrl) {
4837
+ return (chalk_1.default.bold('Code Report Complete') +
4838
+ os_1.EOL +
4839
+ os_1.EOL +
4840
+ 'Your test results are available at:' +
4841
+ os_1.EOL +
4842
+ chalk_1.default.bold(reportUrl));
4843
+ }
4844
+ exports.getCodeReportDisplayedOutput = getCodeReportDisplayedOutput;
4800
4845
 
4801
4846
 
4802
4847
  /***/ }),
@@ -4828,7 +4873,7 @@ exports.codePlugin = {
4828
4873
  return '';
4829
4874
  },
4830
4875
  async test(paths, options) {
4831
- var _a, _b, _c, _d;
4876
+ var _a, _b, _c, _d, _e;
4832
4877
  const requestId = uuid_1.v4();
4833
4878
  debug(`Request ID: ${requestId}`);
4834
4879
  try {
@@ -4836,11 +4881,12 @@ exports.codePlugin = {
4836
4881
  const sastSettings = await settings_1.getSastSettings(options);
4837
4882
  // Currently code supports only one path
4838
4883
  const path = paths[0];
4839
- const sarifTypedResult = await analysis_1.getCodeAnalysisAndParseResults(path, options, sastSettings, requestId);
4840
- if (!sarifTypedResult) {
4884
+ const testResults = await analysis_1.getCodeTestResults(path, options, sastSettings, requestId);
4885
+ if (!testResults) {
4841
4886
  throw new errors_1.NoSupportedSastFiles();
4842
4887
  }
4843
- const numOfIssues = ((_b = (_a = sarifTypedResult.runs) === null || _a === void 0 ? void 0 : _a[0].results) === null || _b === void 0 ? void 0 : _b.length) || 0;
4888
+ const sarifTypedResult = (_a = testResults === null || testResults === void 0 ? void 0 : testResults.analysisResults) === null || _a === void 0 ? void 0 : _a.sarif;
4889
+ const numOfIssues = ((_c = (_b = sarifTypedResult.runs) === null || _b === void 0 ? void 0 : _b[0].results) === null || _c === void 0 ? void 0 : _c.length) || 0;
4844
4890
  analytics.add('sast-issues-found', numOfIssues);
4845
4891
  let newOrg = options.org;
4846
4892
  if (!newOrg && sastSettings.org) {
@@ -4848,9 +4894,9 @@ exports.codePlugin = {
4848
4894
  }
4849
4895
  const meta = output_format_1.getMeta({ ...options, org: newOrg }, path);
4850
4896
  const prefix = output_format_1.getPrefix(path);
4851
- let readableResult = output_format_1.getCodeDisplayedOutput(sarifTypedResult, meta, prefix);
4897
+ let readableResult = output_format_1.getCodeDisplayedOutput(testResults, meta, prefix);
4852
4898
  if (numOfIssues > 0 && options['no-markdown']) {
4853
- (_d = (_c = sarifTypedResult.runs) === null || _c === void 0 ? void 0 : _c[0].results) === null || _d === void 0 ? void 0 : _d.forEach(({ message }) => {
4899
+ (_e = (_d = sarifTypedResult.runs) === null || _d === void 0 ? void 0 : _d[0].results) === null || _e === void 0 ? void 0 : _e.forEach(({ message }) => {
4854
4900
  delete message.markdown;
4855
4901
  });
4856
4902
  }