snyk 1.1106.0 → 1.1108.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);
@@ -4468,6 +4474,7 @@ async function getCodeAnalysis(root, options, sastSettings, requestId) {
4468
4474
  const baseURL = isLocalCodeEngineEnabled
4469
4475
  ? sastSettings.localCodeEngine.url
4470
4476
  : code_config_1.getCodeClientProxyUrl();
4477
+ const org = sastSettings.org;
4471
4478
  // TODO(james) This mirrors the implementation in request.ts and we need to use this for deeproxy calls
4472
4479
  // This ensures we support lowercase http(s)_proxy values as well
4473
4480
  // The weird IF around it ensures we don't create an envvar with
@@ -4490,9 +4497,22 @@ async function getCodeAnalysis(root, options, sastSettings, requestId) {
4490
4497
  ? severityToAnalysisSeverity(options.severityThreshold)
4491
4498
  : code_client_1.AnalysisSeverity.info;
4492
4499
  const result = await code_client_1.analyzeFolders({
4493
- connection: { baseURL, sessionToken, source, requestId },
4500
+ connection: {
4501
+ baseURL,
4502
+ sessionToken,
4503
+ source,
4504
+ requestId,
4505
+ org,
4506
+ },
4494
4507
  analysisOptions: { severity },
4495
4508
  fileOptions: { paths: [root] },
4509
+ ...(options.report && {
4510
+ reportOptions: {
4511
+ enabled: (_a = options.report) !== null && _a !== void 0 ? _a : false,
4512
+ projectName: options['project-name'],
4513
+ targetRef: options['target-reference'],
4514
+ },
4515
+ }),
4496
4516
  analysisContext: {
4497
4517
  initiator: 'CLI',
4498
4518
  flow: source,
@@ -4506,15 +4526,25 @@ async function getCodeAnalysis(root, options, sastSettings, requestId) {
4506
4526
  },
4507
4527
  languages: sastSettings.supportedLanguages,
4508
4528
  });
4509
- if ((_a = result === null || result === void 0 ? void 0 : result.fileBundle.skippedOversizedFiles) === null || _a === void 0 ? void 0 : _a.length) {
4529
+ if ((_b = result === null || result === void 0 ? void 0 : result.fileBundle.skippedOversizedFiles) === null || _b === void 0 ? void 0 : _b.length) {
4510
4530
  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
4531
  ...result.fileBundle.skippedOversizedFiles,
4512
4532
  ].join(', ')}`));
4513
4533
  }
4514
- if ((result === null || result === void 0 ? void 0 : result.analysisResults.type) === 'sarif') {
4515
- return result.analysisResults.sarif;
4534
+ if (!result || result.analysisResults.type !== 'sarif') {
4535
+ return null;
4536
+ }
4537
+ result.analysisResults.sarif = parseSecurityResults(result.analysisResults.sarif);
4538
+ // Filter ignored issues when using report
4539
+ if (options.report) {
4540
+ result.analysisResults.sarif = filterIgnoredIssues(result.analysisResults.sarif);
4516
4541
  }
4517
- return null;
4542
+ return result;
4543
+ }
4544
+ function filterIgnoredIssues(codeAnalysis) {
4545
+ const results = codeAnalysis.runs[0].results;
4546
+ 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; });
4547
+ return codeAnalysis;
4518
4548
  }
4519
4549
  function severityToAnalysisSeverity(severity) {
4520
4550
  if (severity === legacy_1.SEVERITY.CRITICAL) {
@@ -4529,9 +4559,6 @@ function severityToAnalysisSeverity(severity) {
4529
4559
  }
4530
4560
  function parseSecurityResults(codeAnalysis) {
4531
4561
  let securityRulesMap;
4532
- if (!codeAnalysis) {
4533
- return codeAnalysis;
4534
- }
4535
4562
  const rules = codeAnalysis.runs[0].tool.driver.rules;
4536
4563
  const results = codeAnalysis.runs[0].results;
4537
4564
  if (rules) {
@@ -4684,24 +4711,26 @@ exports.FeatureNotSupportedBySnykCodeError = FeatureNotSupportedBySnykCodeError;
4684
4711
  "use strict";
4685
4712
 
4686
4713
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4687
- exports.getPrefix = exports.getMeta = exports.getCodeDisplayedOutput = void 0;
4714
+ exports.getCodeReportDisplayedOutput = exports.getPrefix = exports.getMeta = exports.getCodeDisplayedOutput = void 0;
4715
+ const os_1 = __webpack_require__(12087);
4688
4716
  const Debug = __webpack_require__(15158);
4689
4717
  const chalk_1 = __webpack_require__(32589);
4690
4718
  const theme_1 = __webpack_require__(86988);
4691
4719
  const common_1 = __webpack_require__(53110);
4692
4720
  const right_pad_1 = __webpack_require__(80627);
4693
4721
  const debug = Debug('code-output');
4694
- function getCodeDisplayedOutput(codeTest, meta, prefix) {
4722
+ function getCodeDisplayedOutput(testResults, meta, prefix) {
4695
4723
  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 || []);
4724
+ const sarif = testResults.analysisResults.sarif;
4725
+ if (sarif.runs[0].results) {
4726
+ const results = sarif.runs[0].results;
4727
+ const rulesMap = getRulesMap(sarif.runs[0].tool.driver.rules || []);
4699
4728
  issues = getIssues(results, rulesMap);
4700
4729
  }
4701
4730
  const issuesText = issues.low.join('') + issues.medium.join('') + issues.high.join('');
4702
4731
  const summaryOKText = theme_1.color.status.success(`${theme_1.icon.VALID} Test completed`);
4703
4732
  const codeIssueSummary = getCodeIssuesSummary(issues);
4704
- return (prefix +
4733
+ let summary = prefix +
4705
4734
  issuesText +
4706
4735
  '\n' +
4707
4736
  summaryOKText +
@@ -4711,7 +4740,13 @@ function getCodeDisplayedOutput(codeTest, meta, prefix) {
4711
4740
  chalk_1.default.bold('Summary:') +
4712
4741
  '\n\n' +
4713
4742
  codeIssueSummary +
4714
- '\n\n');
4743
+ '\n\n';
4744
+ if (testResults.reportResults) {
4745
+ summary +=
4746
+ getCodeReportDisplayedOutput(testResults.reportResults.reportUrl) +
4747
+ '\n\n';
4748
+ }
4749
+ return summary;
4715
4750
  }
4716
4751
  exports.getCodeDisplayedOutput = getCodeDisplayedOutput;
4717
4752
  function getCodeIssuesSummary(issues) {
@@ -4739,7 +4774,7 @@ function getIssues(results, rulesMap) {
4739
4774
  high: [],
4740
4775
  };
4741
4776
  const issues = results.reduce((acc, res) => {
4742
- var _a, _b;
4777
+ var _a, _b, _c;
4743
4778
  if ((_a = res.locations) === null || _a === void 0 ? void 0 : _a.length) {
4744
4779
  const location = res.locations[0].physicalLocation;
4745
4780
  if (res.level && (location === null || location === void 0 ? void 0 : location.artifactLocation) && (location === null || location === void 0 ? void 0 : location.region)) {
@@ -4755,7 +4790,10 @@ function getIssues(results, rulesMap) {
4755
4790
  const artifactLocationUri = location.artifactLocation.uri;
4756
4791
  const startLine = location.region.startLine;
4757
4792
  const text = res.message.text;
4758
- const title = ruleIdSeverityText;
4793
+ let title = ruleIdSeverityText;
4794
+ if ((_c = res.fingerprints) === null || _c === void 0 ? void 0 : _c['identity']) {
4795
+ title += `\n ID: ${res.fingerprints['identity']}`;
4796
+ }
4759
4797
  const path = ` Path: ${artifactLocationUri}, line ${startLine}`;
4760
4798
  const info = ` Info: ${text}`;
4761
4799
  acc[severity.toLowerCase()].push(`${title} \n ${path} \n ${info}\n\n`);
@@ -4797,6 +4835,15 @@ function getPrefix(path) {
4797
4835
  return chalk_1.default.bold.white('\nTesting ' + path + ' ...\n\n');
4798
4836
  }
4799
4837
  exports.getPrefix = getPrefix;
4838
+ function getCodeReportDisplayedOutput(reportUrl) {
4839
+ return (chalk_1.default.bold('Code Report Complete') +
4840
+ os_1.EOL +
4841
+ os_1.EOL +
4842
+ 'Your test results are available at:' +
4843
+ os_1.EOL +
4844
+ chalk_1.default.bold(reportUrl));
4845
+ }
4846
+ exports.getCodeReportDisplayedOutput = getCodeReportDisplayedOutput;
4800
4847
 
4801
4848
 
4802
4849
  /***/ }),
@@ -4828,7 +4875,7 @@ exports.codePlugin = {
4828
4875
  return '';
4829
4876
  },
4830
4877
  async test(paths, options) {
4831
- var _a, _b, _c, _d;
4878
+ var _a, _b, _c, _d, _e;
4832
4879
  const requestId = uuid_1.v4();
4833
4880
  debug(`Request ID: ${requestId}`);
4834
4881
  try {
@@ -4836,11 +4883,12 @@ exports.codePlugin = {
4836
4883
  const sastSettings = await settings_1.getSastSettings(options);
4837
4884
  // Currently code supports only one path
4838
4885
  const path = paths[0];
4839
- const sarifTypedResult = await analysis_1.getCodeAnalysisAndParseResults(path, options, sastSettings, requestId);
4840
- if (!sarifTypedResult) {
4886
+ const testResults = await analysis_1.getCodeTestResults(path, options, sastSettings, requestId);
4887
+ if (!testResults) {
4841
4888
  throw new errors_1.NoSupportedSastFiles();
4842
4889
  }
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;
4890
+ const sarifTypedResult = (_a = testResults === null || testResults === void 0 ? void 0 : testResults.analysisResults) === null || _a === void 0 ? void 0 : _a.sarif;
4891
+ 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
4892
  analytics.add('sast-issues-found', numOfIssues);
4845
4893
  let newOrg = options.org;
4846
4894
  if (!newOrg && sastSettings.org) {
@@ -4848,9 +4896,9 @@ exports.codePlugin = {
4848
4896
  }
4849
4897
  const meta = output_format_1.getMeta({ ...options, org: newOrg }, path);
4850
4898
  const prefix = output_format_1.getPrefix(path);
4851
- let readableResult = output_format_1.getCodeDisplayedOutput(sarifTypedResult, meta, prefix);
4899
+ let readableResult = output_format_1.getCodeDisplayedOutput(testResults, meta, prefix);
4852
4900
  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 }) => {
4901
+ (_e = (_d = sarifTypedResult.runs) === null || _d === void 0 ? void 0 : _d[0].results) === null || _e === void 0 ? void 0 : _e.forEach(({ message }) => {
4854
4902
  delete message.markdown;
4855
4903
  });
4856
4904
  }