snyk 1.813.0 → 1.817.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.
@@ -1776,10 +1776,10 @@ const url_1 = __webpack_require__(78835);
1776
1776
  const upperFirst = __webpack_require__(90039);
1777
1777
  const remediation_based_format_issues_1 = __webpack_require__(57995);
1778
1778
  const legacy_format_issue_1 = __webpack_require__(63540);
1779
- const legacy_1 = __webpack_require__(34013);
1780
1779
  const common_1 = __webpack_require__(53110);
1781
1780
  const detect_1 = __webpack_require__(45318);
1782
1781
  const get_severity_value_1 = __webpack_require__(24898);
1782
+ const sarif_output_1 = __webpack_require__(5034);
1783
1783
  const debug = Debug('iac-output');
1784
1784
  function formatIacIssue(issue, isNew, path) {
1785
1785
  const newBadge = isNew ? ' (new)' : '';
@@ -1901,9 +1901,6 @@ function createSarifOutputForIac(iacTestResponses) {
1901
1901
  };
1902
1902
  }
1903
1903
  exports.createSarifOutputForIac = createSarifOutputForIac;
1904
- function getIssueLevel(severity) {
1905
- return severity === legacy_1.SEVERITY.HIGH ? 'error' : 'warning';
1906
- }
1907
1904
  function extractReportingDescriptor(results) {
1908
1905
  const tool = {};
1909
1906
  results.forEach(({ issue }) => {
@@ -1949,7 +1946,7 @@ function extractReportingDescriptor(results) {
1949
1946
  markdown: `${issueMarkdown}${impactMarkdown}${resolveMarkdown}`.replace(/^\s+/g, ''),
1950
1947
  },
1951
1948
  defaultConfiguration: {
1952
- level: getIssueLevel(issue.severity),
1949
+ level: sarif_output_1.getIssueLevel(issue.severity),
1953
1950
  },
1954
1951
  properties: {
1955
1952
  tags,
@@ -2541,6 +2538,112 @@ function reachablePathsTemplate(samplePaths, extraPathsCount) {
2541
2538
  }
2542
2539
 
2543
2540
 
2541
+ /***/ }),
2542
+
2543
+ /***/ 5034:
2544
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
2545
+
2546
+ "use strict";
2547
+
2548
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2549
+ exports.getResults = exports.getTool = exports.getIssueLevel = exports.createSarifOutputForContainers = void 0;
2550
+ const legacy_1 = __webpack_require__(34013);
2551
+ const upperFirst = __webpack_require__(90039);
2552
+ function createSarifOutputForContainers(testResults) {
2553
+ const sarifRes = {
2554
+ version: '2.1.0',
2555
+ runs: [],
2556
+ };
2557
+ testResults.forEach((testResult) => {
2558
+ sarifRes.runs.push({
2559
+ tool: getTool(testResult),
2560
+ results: getResults(testResult),
2561
+ });
2562
+ });
2563
+ return sarifRes;
2564
+ }
2565
+ exports.createSarifOutputForContainers = createSarifOutputForContainers;
2566
+ function getIssueLevel(severity) {
2567
+ return severity === legacy_1.SEVERITY.HIGH || severity === legacy_1.SEVERITY.CRITICAL
2568
+ ? 'error'
2569
+ : 'warning';
2570
+ }
2571
+ exports.getIssueLevel = getIssueLevel;
2572
+ function getTool(testResult) {
2573
+ const tool = {
2574
+ driver: {
2575
+ name: 'Snyk Container',
2576
+ rules: [],
2577
+ },
2578
+ };
2579
+ if (!testResult.vulnerabilities) {
2580
+ return tool;
2581
+ }
2582
+ const pushedIds = {};
2583
+ tool.driver.rules = testResult.vulnerabilities
2584
+ .map((vuln) => {
2585
+ if (pushedIds[vuln.id]) {
2586
+ return;
2587
+ }
2588
+ const level = getIssueLevel(vuln.severity);
2589
+ const cve = vuln['identifiers']['CVE'][0];
2590
+ pushedIds[vuln.id] = true;
2591
+ return {
2592
+ id: vuln.id,
2593
+ shortDescription: {
2594
+ text: `${upperFirst(vuln.severity)} severity - ${vuln.title} vulnerability in ${vuln.packageName}`,
2595
+ },
2596
+ fullDescription: {
2597
+ text: cve
2598
+ ? `(${cve}) ${vuln.name}@${vuln.version}`
2599
+ : `${vuln.name}@${vuln.version}`,
2600
+ },
2601
+ help: {
2602
+ text: '',
2603
+ markdown: vuln.description,
2604
+ },
2605
+ defaultConfiguration: {
2606
+ level: level,
2607
+ },
2608
+ properties: {
2609
+ tags: ['security', ...vuln.identifiers.CWE],
2610
+ },
2611
+ };
2612
+ })
2613
+ .filter(Boolean);
2614
+ return tool;
2615
+ }
2616
+ exports.getTool = getTool;
2617
+ function getResults(testResult) {
2618
+ const results = [];
2619
+ if (!testResult.vulnerabilities) {
2620
+ return results;
2621
+ }
2622
+ testResult.vulnerabilities.forEach((vuln) => {
2623
+ results.push({
2624
+ ruleId: vuln.id,
2625
+ message: {
2626
+ text: `This file introduces a vulnerable ${vuln.packageName} package with a ${vuln.severity} severity vulnerability.`,
2627
+ },
2628
+ locations: [
2629
+ {
2630
+ physicalLocation: {
2631
+ artifactLocation: {
2632
+ uri: testResult.displayTargetFile,
2633
+ },
2634
+ region: {
2635
+ startLine: vuln.lineNumber || 1,
2636
+ },
2637
+ },
2638
+ },
2639
+ ],
2640
+ });
2641
+ });
2642
+ return results;
2643
+ }
2644
+ exports.getResults = getResults;
2645
+
2646
+
2544
2647
  /***/ }),
2545
2648
 
2546
2649
  /***/ 98202:
@@ -4073,7 +4176,9 @@ exports.getExtraProjectCount = getExtraProjectCount;
4073
4176
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4074
4177
  exports.getMultiPluginResult = void 0;
4075
4178
  const cloneDeep = __webpack_require__(83465);
4076
- const path = __webpack_require__(85622);
4179
+ const pathLib = __webpack_require__(85622);
4180
+ const sortBy = __webpack_require__(58254);
4181
+ const groupBy = __webpack_require__(20276);
4077
4182
  const cliInterface = __webpack_require__(65266);
4078
4183
  const chalk_1 = __webpack_require__(32589);
4079
4184
  const theme_1 = __webpack_require__(86988);
@@ -4083,14 +4188,21 @@ const get_single_plugin_result_1 = __webpack_require__(8598);
4083
4188
  const convert_single_splugin_res_to_multi_custom_1 = __webpack_require__(99695);
4084
4189
  const convert_multi_plugin_res_to_multi_custom_1 = __webpack_require__(23110);
4085
4190
  const errors_1 = __webpack_require__(55191);
4191
+ const yarn_workspaces_parser_1 = __webpack_require__(27326);
4086
4192
  const debug = debugModule('snyk-test');
4087
4193
  async function getMultiPluginResult(root, options, targetFiles) {
4194
+ var _a;
4088
4195
  const allResults = [];
4089
4196
  const failedResults = [];
4090
- for (const targetFile of targetFiles) {
4197
+ // process any yarn workspaces first
4198
+ // the files need to be proceeded together as they provide context to each other
4199
+ const { scannedProjects, unprocessedFiles, } = await processYarnWorkspacesProjects(root, options, targetFiles);
4200
+ allResults.push(...scannedProjects);
4201
+ // process the rest 1 by 1 sent to relevant plugins
4202
+ for (const targetFile of unprocessedFiles) {
4091
4203
  const optionsClone = cloneDeep(options);
4092
- optionsClone.file = path.relative(root, targetFile);
4093
- optionsClone.packageManager = detect_1.detectPackageManagerFromFile(path.basename(targetFile));
4204
+ optionsClone.file = pathLib.relative(root, targetFile);
4205
+ optionsClone.packageManager = detect_1.detectPackageManagerFromFile(pathLib.basename(targetFile));
4094
4206
  try {
4095
4207
  const inspectRes = await get_single_plugin_result_1.getSinglePluginResult(root, optionsClone, optionsClone.file);
4096
4208
  let resultWithScannedProjects;
@@ -4107,14 +4219,15 @@ async function getMultiPluginResult(root, options, targetFiles) {
4107
4219
  options.projectNames = resultWithScannedProjects.scannedProjects.map((scannedProject) => { var _a; return (_a = scannedProject === null || scannedProject === void 0 ? void 0 : scannedProject.depTree) === null || _a === void 0 ? void 0 : _a.name; });
4108
4220
  allResults.push(...pluginResultWithCustomScannedProjects.scannedProjects);
4109
4221
  }
4110
- catch (err) {
4222
+ catch (error) {
4223
+ const errMessage = (_a = error.message) !== null && _a !== void 0 ? _a : 'Something went wrong getting dependencies';
4111
4224
  // TODO: propagate this all the way back and include in --json output
4112
4225
  failedResults.push({
4113
4226
  targetFile,
4114
- error: err,
4115
- errMessage: err.message || 'Something went wrong getting dependencies',
4227
+ error,
4228
+ errMessage: errMessage,
4116
4229
  });
4117
- debug(chalk_1.default.bold.red(`\n${theme_1.icon.ISSUE} Failed to get dependencies for ${targetFile}\nERROR: ${err.message}\n`));
4230
+ debug(chalk_1.default.bold.red(`\n${theme_1.icon.ISSUE} Failed to get dependencies for ${targetFile}\nERROR: ${errMessage}\n`));
4118
4231
  }
4119
4232
  }
4120
4233
  if (!allResults.length) {
@@ -4129,6 +4242,44 @@ async function getMultiPluginResult(root, options, targetFiles) {
4129
4242
  };
4130
4243
  }
4131
4244
  exports.getMultiPluginResult = getMultiPluginResult;
4245
+ async function processYarnWorkspacesProjects(root, options, targetFiles) {
4246
+ try {
4247
+ const { scannedProjects } = await yarn_workspaces_parser_1.processYarnWorkspaces(root, {
4248
+ strictOutOfSync: options.strictOutOfSync,
4249
+ dev: options.dev,
4250
+ }, targetFiles);
4251
+ const unprocessedFiles = filterOutProcessedWorkspaces(scannedProjects, targetFiles);
4252
+ return { scannedProjects, unprocessedFiles };
4253
+ }
4254
+ catch (e) {
4255
+ debug('Error during detecting or processing Yarn Workspaces: ', e);
4256
+ return { scannedProjects: [], unprocessedFiles: targetFiles };
4257
+ }
4258
+ }
4259
+ function filterOutProcessedWorkspaces(scannedProjects, allTargetFiles) {
4260
+ const mapped = allTargetFiles.map((p) => ({ path: p, ...pathLib.parse(p) }));
4261
+ const sorted = sortBy(mapped, 'dir');
4262
+ const targetFilesByDirectory = groupBy(sorted, 'dir');
4263
+ const scanned = scannedProjects.map((p) => p.targetFile);
4264
+ const targetFiles = [];
4265
+ for (const directory of Object.keys(targetFilesByDirectory)) {
4266
+ for (const targetFile of targetFilesByDirectory[directory]) {
4267
+ const { base, path } = targetFile;
4268
+ // any non yarn workspace files should be scanned
4269
+ if (!['package.json', 'yarn.lock'].includes(base)) {
4270
+ targetFiles.push(path);
4271
+ continue;
4272
+ }
4273
+ // check if Node manifest has already been processed a part or a workspace
4274
+ const packageJsonFileName = pathLib.join(directory, 'package.json');
4275
+ const alreadyScanned = scanned.some((f) => packageJsonFileName.endsWith(f));
4276
+ if (!alreadyScanned) {
4277
+ targetFiles.push(path);
4278
+ }
4279
+ }
4280
+ }
4281
+ return targetFiles;
4282
+ }
4132
4283
 
4133
4284
 
4134
4285
  /***/ }),
@@ -4400,25 +4551,24 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
4400
4551
  exports.packageJsonBelongsToWorkspace = exports.getWorkspacesMap = exports.processYarnWorkspaces = void 0;
4401
4552
  const baseDebug = __webpack_require__(15158);
4402
4553
  const pathUtil = __webpack_require__(85622);
4403
- // import * as _ from 'lodash';
4404
4554
  const sortBy = __webpack_require__(58254);
4405
4555
  const groupBy = __webpack_require__(20276);
4406
4556
  const micromatch = __webpack_require__(70850);
4407
4557
  const debug = baseDebug('snyk-yarn-workspaces');
4408
4558
  const lockFileParser = __webpack_require__(423);
4409
- const errors_1 = __webpack_require__(55191);
4410
4559
  const get_file_contents_1 = __webpack_require__(84210);
4560
+ const errors_1 = __webpack_require__(55191);
4411
4561
  async function processYarnWorkspaces(root, settings, targetFiles) {
4412
4562
  // the order of yarnTargetFiles folders is important
4413
4563
  // must have the root level most folders at the top
4414
4564
  const mappedAndFiltered = targetFiles
4415
4565
  .map((p) => ({ path: p, ...pathUtil.parse(p) }))
4416
- .filter((res) => ['package.json'].includes(res.base));
4566
+ .filter((res) => ['package.json', 'yarn.lock'].includes(res.base));
4417
4567
  const sorted = sortBy(mappedAndFiltered, 'dir');
4418
4568
  const grouped = groupBy(sorted, 'dir');
4419
4569
  const yarnTargetFiles = grouped;
4420
4570
  debug(`Processing potential Yarn workspaces (${targetFiles.length})`);
4421
- if (Object.keys(yarnTargetFiles).length === 0) {
4571
+ if (settings.yarnWorkspaces && Object.keys(yarnTargetFiles).length === 0) {
4422
4572
  throw errors_1.NoSupportedManifestsFoundError([root]);
4423
4573
  }
4424
4574
  let yarnWorkspacesMap = {};
@@ -4433,6 +4583,7 @@ async function processYarnWorkspaces(root, settings, targetFiles) {
4433
4583
  let rootWorkspaceManifestContent = {};
4434
4584
  // the folders must be ordered highest first
4435
4585
  for (const directory of Object.keys(yarnTargetFiles)) {
4586
+ debug(`Processing ${directory} as a potential Yarn workspace`);
4436
4587
  let isYarnWorkspacePackage = false;
4437
4588
  let isRootPackageJson = false;
4438
4589
  const packageJsonFileName = pathUtil.join(directory, 'package.json');
@@ -4455,7 +4606,11 @@ async function processYarnWorkspaces(root, settings, targetFiles) {
4455
4606
  rootWorkspaceManifestContent = JSON.parse(packageJson.content);
4456
4607
  }
4457
4608
  }
4458
- if (isYarnWorkspacePackage || isRootPackageJson) {
4609
+ if (!(isYarnWorkspacePackage || isRootPackageJson)) {
4610
+ debug(`${packageJsonFileName} is not part of any detected workspace, skipping`);
4611
+ continue;
4612
+ }
4613
+ try {
4459
4614
  const rootDir = isYarnWorkspacePackage
4460
4615
  ? pathUtil.dirname(yarnWorkspacesFilesMap[packageJsonFileName].root)
4461
4616
  : pathUtil.dirname(packageJsonFileName);
@@ -4482,8 +4637,11 @@ async function processYarnWorkspaces(root, settings, targetFiles) {
4482
4637
  };
4483
4638
  result.scannedProjects.push(project);
4484
4639
  }
4485
- else {
4486
- debug(`${packageJsonFileName} is not part of any detected workspace, skipping`);
4640
+ catch (e) {
4641
+ if (settings.yarnWorkspaces) {
4642
+ throw e;
4643
+ }
4644
+ debug(`Error process workspace: ${packageJsonFileName}. ERROR: ${e}`);
4487
4645
  }
4488
4646
  }
4489
4647
  if (!result.scannedProjects.length) {
@@ -6566,7 +6724,7 @@ async function assembleLocalPayloads(root, options) {
6566
6724
  }
6567
6725
  debug('getDepsFromPlugin returned failed results, cannot run test/monitor', failedResults);
6568
6726
  if (options['fail-fast']) {
6569
- throw new errors_1.FailedToRunTestError('Your test request could not be completed. Please email support@snyk.io');
6727
+ throw new errors_1.FailedToRunTestError(errors_1.errorMessageWithRetry('Your test request could not be completed.'));
6570
6728
  }
6571
6729
  }
6572
6730
  analytics.add('pluginName', deps.plugin.name);