snyk 1.1146.0 → 1.1148.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.
@@ -158222,7 +158222,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
158222
158222
  exports.determinePaths = exports.readRawBuildInfo = exports.extractModuleInformation = exports.GoBinary = void 0;
158223
158223
  const depGraph = __webpack_require__(26326);
158224
158224
  const event_loop_spinner_1 = __webpack_require__(77158);
158225
- const path = __webpack_require__(85622);
158225
+ // NOTE: Paths will always be normalized to POSIX even on Windows.
158226
+ // This makes it easier to ignore differences between Linux and Windows.
158227
+ const path_1 = __webpack_require__(85622);
158226
158228
  const varint = __webpack_require__(94676);
158227
158229
  const _1 = __webpack_require__(5998);
158228
158230
  const go_module_1 = __webpack_require__(79160);
@@ -158258,8 +158260,9 @@ class GoBinary {
158258
158260
  // matchFilesToModules goes through all files, extracts the package name and
158259
158261
  // adds it to the relevant module in the GoBinary.
158260
158262
  matchFilesToModules(files) {
158261
- const { modCachePath, vendorPath } = determinePaths(this.modules, files);
158262
- for (const fileName of files) {
158263
+ const normalizedFiles = files.map((file) => path_1.posix.normalize(file));
158264
+ const { modCachePath, vendorPath } = determinePaths(this.modules, normalizedFiles);
158265
+ for (const fileName of normalizedFiles) {
158263
158266
  if (fileName === "<autogenerated>") {
158264
158267
  continue;
158265
158268
  }
@@ -158304,8 +158307,8 @@ class GoBinary {
158304
158307
  // (github.com/my/pkg@v0.0.1/a.go), the path.parse expression returns
158305
158308
  // just a slash. This would result in a package name with a trailing
158306
158309
  // slash, which is incorrect.
158307
- let dirName = path.parse(parts[1]).dir;
158308
- if (dirName === "/") {
158310
+ let dirName = path_1.posix.parse(parts[1]).dir;
158311
+ if (dirName === path_1.posix.sep) {
158309
158312
  dirName = "";
158310
158313
  }
158311
158314
  const pkgName = module.name + dirName;
@@ -158323,7 +158326,9 @@ function extractModuleInformation(binary) {
158323
158326
  if (!mod) {
158324
158327
  throw Error("binary contains empty module info");
158325
158328
  }
158326
- const [pathDirective, mainModuleLine, ...versionsLines] = mod.split("\n");
158329
+ const [pathDirective, mainModuleLine, ...versionsLines] = mod
158330
+ .replace("\r", "")
158331
+ .split("\n");
158327
158332
  const lineSplit = mainModuleLine.split("\t");
158328
158333
  let name = lineSplit[1];
158329
158334
  if (lineSplit[0] !== "mod") {
@@ -158527,7 +158532,7 @@ function isTrimmed(files) {
158527
158532
  // whether `trimpath` has been used or not, but there are binaries out there
158528
158533
  // that have trimmed paths without that annotation (for example
158529
158534
  // kyverno@v1.8.1).
158530
- return files.every((file) => !file.startsWith("/"));
158535
+ return files.every((file) => !file.startsWith(path_1.posix.sep));
158531
158536
  }
158532
158537
  // determinePaths returns the modCachePath and vendorPath for a binary.
158533
158538
  // goModCachePath is the path at which the modules are downloaded to. When
@@ -158539,12 +158544,13 @@ function isTrimmed(files) {
158539
158544
  // Binaries built with `-trimpath` will have all paths trimmed away, meaning
158540
158545
  // that both returned values will be empty.
158541
158546
  function determinePaths(modules, files) {
158542
- if (isTrimmed(files)) {
158547
+ const normalizedFiles = files.map((file) => path_1.posix.normalize(file));
158548
+ if (isTrimmed(normalizedFiles)) {
158543
158549
  return { modCachePath: "", vendorPath: "" };
158544
158550
  }
158545
158551
  return {
158546
- modCachePath: determineGoModCachePath(modules, files),
158547
- vendorPath: determineVendorPath(modules, files),
158552
+ modCachePath: determineGoModCachePath(modules, normalizedFiles),
158553
+ vendorPath: determineVendorPath(modules, normalizedFiles),
158548
158554
  };
158549
158555
  }
158550
158556
  exports.determinePaths = determinePaths;
@@ -158556,7 +158562,10 @@ function determineVendorPath(modules, files) {
158556
158562
  // We check for other files in that root to make sure that we really got the
158557
158563
  // right vendor folder, and not just a random folder named `vendor` somewhere.
158558
158564
  for (const [, mod] of Object.entries(modules)) {
158559
- const vendoredModulePath = path.join("vendor", mod.name) + "/";
158565
+ // use path.join so that we will always get linux-style paths even if
158566
+ // the plugin runs on Windows. This is necessary because the Go binaries
158567
+ // always contain linux-style path separators.
158568
+ const vendoredModulePath = path_1.posix.join("vendor", mod.name) + path_1.posix.sep;
158560
158569
  const file = files.find((file) => file.includes(vendoredModulePath));
158561
158570
  if (file) {
158562
158571
  // make sure that we find other files in that path not in the vendor
@@ -158564,7 +158573,7 @@ function determineVendorPath(modules, files) {
158564
158573
  const mainModulePath = file.split(vendoredModulePath)[0];
158565
158574
  const success = files.find((file) => file.includes(mainModulePath) && !file.includes(vendoredModulePath));
158566
158575
  if (success) {
158567
- return path.join(mainModulePath, "vendor") + "/";
158576
+ return path_1.posix.join(mainModulePath, "vendor") + path_1.posix.sep;
158568
158577
  }
158569
158578
  }
158570
158579
  }
@@ -158573,7 +158582,7 @@ function determineVendorPath(modules, files) {
158573
158582
  function determineGoModCachePath(modules, files) {
158574
158583
  // files in the go mod cache path always contain the module name and version.
158575
158584
  for (const [, mod] of Object.entries(modules)) {
158576
- const file = files.find((file) => file.includes("/" + mod.fullName()));
158585
+ const file = files.find((file) => file.includes(path_1.posix.sep + mod.fullName()));
158577
158586
  if (file) {
158578
158587
  return file.split(mod.fullName())[0];
158579
158588
  }
@@ -158624,28 +158633,31 @@ exports.goModulesToScannedProjects = exports.getGoModulesContentAction = exports
158624
158633
  const Debug = __webpack_require__(15158);
158625
158634
  const elf = __webpack_require__(18);
158626
158635
  const event_loop_spinner_1 = __webpack_require__(77158);
158627
- const path = __webpack_require__(85622);
158636
+ // NOTE: Paths will always be normalized to POSIX even on Windows.
158637
+ // This makes it easier to ignore differences between Linux and Windows.
158638
+ const path_1 = __webpack_require__(85622);
158628
158639
  const go_binary_1 = __webpack_require__(6803);
158629
158640
  const debug = Debug("snyk");
158630
158641
  const ignoredPaths = [
158631
- path.normalize("/boot"),
158632
- path.normalize("/dev"),
158633
- path.normalize("/etc"),
158634
- path.normalize("/home"),
158635
- path.normalize("/media"),
158636
- path.normalize("/mnt"),
158637
- path.normalize("/proc"),
158638
- path.normalize("/root"),
158639
- path.normalize("/run"),
158640
- path.normalize("/sbin"),
158641
- path.normalize("/sys"),
158642
- path.normalize("/tmp"),
158643
- path.normalize("/var"),
158642
+ path_1.posix.normalize("/boot"),
158643
+ path_1.posix.normalize("/dev"),
158644
+ path_1.posix.normalize("/etc"),
158645
+ path_1.posix.normalize("/home"),
158646
+ path_1.posix.normalize("/media"),
158647
+ path_1.posix.normalize("/mnt"),
158648
+ path_1.posix.normalize("/proc"),
158649
+ path_1.posix.normalize("/root"),
158650
+ path_1.posix.normalize("/run"),
158651
+ path_1.posix.normalize("/sbin"),
158652
+ path_1.posix.normalize("/sys"),
158653
+ path_1.posix.normalize("/tmp"),
158654
+ path_1.posix.normalize("/var"),
158644
158655
  ];
158645
158656
  exports.DEP_GRAPH_TYPE = "gomodules";
158646
158657
  function filePathMatches(filePath) {
158647
- const dirName = path.dirname(filePath);
158648
- return (!path.parse(filePath).ext &&
158658
+ const normalizedPath = path_1.posix.normalize(filePath);
158659
+ const dirName = path_1.posix.dirname(normalizedPath);
158660
+ return (!path_1.posix.parse(normalizedPath).ext &&
158649
158661
  !ignoredPaths.some((ignorePath) => dirName.startsWith(ignorePath)));
158650
158662
  }
158651
158663
  exports.getGoModulesContentAction = {
@@ -158694,7 +158706,7 @@ async function findGoBinaries(stream, streamSize) {
158694
158706
  .split(/\0+/g)
158695
158707
  .filter(Boolean);
158696
158708
  const go = strings[strings.length - 2];
158697
- const buildIdParts = strings[strings.length - 1].split("/");
158709
+ const buildIdParts = strings[strings.length - 1].split(path_1.posix.sep);
158698
158710
  // Build ID's precise form is actionID/[.../]contentID.
158699
158711
  // Usually the buildID is simply actionID/contentID, but with exceptions.
158700
158712
  // https://github.com/golang/go/blob/master/src/cmd/go/internal/work/buildid.go#L23
@@ -158753,6 +158765,12 @@ async function goModulesToScannedProjects(filePathToContent) {
158753
158765
  facts: [depGraphFact],
158754
158766
  identity: {
158755
158767
  type: exports.DEP_GRAPH_TYPE,
158768
+ // TODO: The path will contain forward slashes on Linux or backslashes on Windows.
158769
+ // So if you scanned the exact same image but from two different machines,
158770
+ // we'd generate two different identities.
158771
+ // These two identities would create two different Projects if monitored... so is this a bug?
158772
+ // If we enforce forward-slashes in every case, would that create duplicate Projects
158773
+ // for existing users who are using the current "backslashes on Windows" behaviour?
158756
158774
  targetFile: filePath,
158757
158775
  },
158758
158776
  });