@cyclonedx/cdxgen 8.3.0 → 8.3.2

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.
package/binary.js CHANGED
@@ -279,8 +279,11 @@ const getOSPackages = (src) => {
279
279
  const bomJsonFile = path.join(tempDir, "trivy-bom.json");
280
280
  const args = [
281
281
  imageType,
282
- "--skip-update",
282
+ "--skip-db-update",
283
283
  "--offline-scan",
284
+ "--no-progress",
285
+ "--exit-code",
286
+ "0",
284
287
  "--format",
285
288
  "cyclonedx",
286
289
  "--output",
@@ -302,11 +305,16 @@ const getOSPackages = (src) => {
302
305
  }
303
306
  }
304
307
  if (fs.existsSync(bomJsonFile)) {
305
- const tmpBom = JSON.parse(
306
- fs.readFileSync(bomJsonFile, {
307
- encoding: "utf-8"
308
- })
309
- );
308
+ let tmpBom = {};
309
+ try {
310
+ tmpBom = JSON.parse(
311
+ fs.readFileSync(bomJsonFile, {
312
+ encoding: "utf-8"
313
+ })
314
+ );
315
+ } catch (e) {
316
+ // ignore errors
317
+ }
310
318
  // Clean up
311
319
  if (tempDir && tempDir.startsWith(os.tmpdir())) {
312
320
  if (DEBUG_MODE) {
package/docker.js CHANGED
@@ -159,9 +159,11 @@ const getConnection = async (options) => {
159
159
  dockerConn = got.extend(opts);
160
160
  if (DEBUG_MODE) {
161
161
  if (isDockerRootless) {
162
- console.log("Docker service in rootless mode detected!");
162
+ console.log("Docker service in rootless mode detected.");
163
163
  } else {
164
- console.log("Docker service in root mode detected!");
164
+ console.log(
165
+ "Docker service in root mode detected. Consider switching to rootless mode to improve security. See https://docs.docker.com/engine/security/rootless/"
166
+ );
165
167
  }
166
168
  }
167
169
  } catch (err) {
@@ -172,7 +174,7 @@ const getConnection = async (options) => {
172
174
  dockerConn = got.extend(opts);
173
175
  isDockerRootless = true;
174
176
  if (DEBUG_MODE) {
175
- console.log("Docker service in rootless mode detected!");
177
+ console.log("Docker service in rootless mode detected.");
176
178
  }
177
179
  return dockerConn;
178
180
  } catch (err) {
@@ -185,7 +187,7 @@ const getConnection = async (options) => {
185
187
  dockerConn = got.extend(opts);
186
188
  isWinLocalTLS = true;
187
189
  if (DEBUG_MODE) {
188
- console.log("Docker desktop on Windows detected!");
190
+ console.log("Docker desktop on Windows detected.");
189
191
  }
190
192
  } else {
191
193
  opts.prefixUrl = opts.podmanRootlessPrefixUrl;
@@ -194,7 +196,9 @@ const getConnection = async (options) => {
194
196
  isPodmanRootless = true;
195
197
  dockerConn = got.extend(opts);
196
198
  if (DEBUG_MODE) {
197
- console.log("Podman in rootless mode detected!");
199
+ console.log(
200
+ "Podman in rootless mode detected. Thank you for using podman!"
201
+ );
198
202
  }
199
203
  }
200
204
  } catch (err) {
@@ -205,7 +209,9 @@ const getConnection = async (options) => {
205
209
  isPodman = true;
206
210
  isPodmanRootless = false;
207
211
  dockerConn = got.extend(opts);
208
- console.log("Podman in root mode detected!");
212
+ console.log(
213
+ "Podman in root mode detected. Consider switching to rootless mode to improve security. See https://github.com/containers/podman/blob/main/docs/tutorials/rootless_tutorial.md"
214
+ );
209
215
  } catch (err) {
210
216
  if (os.platform() === "win32") {
211
217
  console.warn(
@@ -416,14 +422,24 @@ const extractTar = async (fullImageName, dir) => {
416
422
  strict: true,
417
423
  C: dir,
418
424
  portable: true,
419
- onwarn: () => {}
425
+ onwarn: () => {},
426
+ filter: (path) => {
427
+ // Some files are known to cause issues with extract
428
+ if (path.includes("cacerts") || path.includes("ssl/certs")) {
429
+ return false;
430
+ }
431
+ return true;
432
+ }
420
433
  })
421
434
  );
422
435
  return true;
423
436
  } catch (err) {
424
- if (DEBUG_MODE) {
425
- console.log(err);
426
- }
437
+ console.log(
438
+ "Error during extraction. Please file this bug to the cdxgen repo. https://github.com/CycloneDX/cdxgen/issues"
439
+ );
440
+ console.log("------------");
441
+ console.log(err);
442
+ console.log("------------");
427
443
  return false;
428
444
  }
429
445
  };
package/docker.test.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const dockerLib = require("./docker");
2
+ const { jest, expect, test } = require("@jest/globals");
2
3
 
3
4
  test("docker connection", async () => {
4
5
  const dockerConn = await dockerLib.getConnection();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyclonedx/cdxgen",
3
- "version": "8.3.0",
3
+ "version": "8.3.2",
4
4
  "description": "Creates CycloneDX Software Bill-of-Materials (SBOM) from source or container image",
5
5
  "homepage": "http://github.com/cyclonedx/cdxgen",
6
6
  "author": "Prabhu Subramanian <prabhu@appthreat.com>",
@@ -33,9 +33,9 @@
33
33
  "cdxgen": "./bin/cdxgen"
34
34
  },
35
35
  "scripts": {
36
- "test": "jest",
37
- "watch": "jest --watch",
38
- "lint": "eslint index.js utils.js binary.js server.js docker.js bin/cdxgen",
36
+ "test": "jest --inject-globals false",
37
+ "watch": "jest --watch --inject-globals false",
38
+ "lint": "eslint index.js utils.js binary.js server.js docker.js *.test.js bin/cdxgen",
39
39
  "pretty": "prettier --write *.js bin/cdxgen --trailing-comma=none"
40
40
  },
41
41
  "engines": {
@@ -49,8 +49,8 @@
49
49
  "url": "https://github.com/cyclonedx/cdxgen/issues"
50
50
  },
51
51
  "dependencies": {
52
- "@babel/parser": "^7.20.15",
53
- "@babel/traverse": "^7.20.13",
52
+ "@babel/parser": "^7.21.4",
53
+ "@babel/traverse": "^7.21.4",
54
54
  "cheerio": "^1.0.0-rc.12",
55
55
  "edn-data": "^1.0.0",
56
56
  "glob": "^8.1.0",
@@ -59,24 +59,24 @@
59
59
  "js-yaml": "^4.1.0",
60
60
  "jws": "^4.0.0",
61
61
  "node-stream-zip": "^1.15.0",
62
- "packageurl-js": "^1.0.0",
62
+ "packageurl-js": "^1.0.2",
63
63
  "parse-packagejson-name": "^1.0.1",
64
64
  "prettify-xml": "^1.2.0",
65
65
  "properties-reader": "^2.2.0",
66
- "semver": "^7.3.8",
66
+ "semver": "^7.5.0",
67
67
  "ssri": "^8.0.1",
68
68
  "table": "^6.8.1",
69
69
  "tar": "^6.1.13",
70
70
  "uuid": "^9.0.0",
71
71
  "xml-js": "^1.6.11",
72
72
  "xmlbuilder": "^15.1.1",
73
- "yargs": "^17.6.2"
73
+ "yargs": "^17.7.1"
74
74
  },
75
75
  "optionalDependencies": {
76
- "@cyclonedx/cdxgen-plugins-bin": "^1.0.5",
77
- "connect": "^3.7.0",
78
- "body-parser": "^1.20.1",
79
- "compression": "^1.7.4"
76
+ "@cyclonedx/cdxgen-plugins-bin": "^1.1.0",
77
+ "body-parser": "^1.20.2",
78
+ "compression": "^1.7.4",
79
+ "connect": "^3.7.0"
80
80
  },
81
81
  "files": [
82
82
  "*.js",
@@ -88,7 +88,7 @@
88
88
  "queries.json"
89
89
  ],
90
90
  "devDependencies": {
91
- "eslint": "^8.31.0",
91
+ "eslint": "^8.39.0",
92
92
  "jest": "^26.6.3"
93
93
  }
94
94
  }
package/utils.js CHANGED
@@ -4207,8 +4207,13 @@ const extractJarArchive = function (jarFile, tempDir) {
4207
4207
  }
4208
4208
  if (pomname && fs.existsSync(pomname)) {
4209
4209
  tempDir = path.dirname(jarFile);
4210
- } else {
4211
- fs.copyFileSync(jarFile, path.join(tempDir, fname));
4210
+ } else if (!fs.existsSync(path.join(tempDir, fname))) {
4211
+ // Only copy if the file doesn't exist
4212
+ fs.copyFileSync(
4213
+ jarFile,
4214
+ path.join(tempDir, fname),
4215
+ fs.constants.COPYFILE_FICLONE
4216
+ );
4212
4217
  }
4213
4218
  if (jarFile.endsWith(".war") || jarFile.endsWith(".hpi")) {
4214
4219
  let jarResult = spawnSync("jar", ["-xf", path.join(tempDir, fname)], {
@@ -4405,7 +4410,11 @@ const addPlugin = function (projectPath, plugin) {
4405
4410
  var originalPluginsFile = null;
4406
4411
  if (fs.existsSync(pluginsFile)) {
4407
4412
  originalPluginsFile = pluginsFile + ".cdxgen";
4408
- fs.copyFileSync(pluginsFile, originalPluginsFile);
4413
+ fs.copyFileSync(
4414
+ pluginsFile,
4415
+ originalPluginsFile,
4416
+ fs.constants.COPYFILE_FICLONE
4417
+ );
4409
4418
  }
4410
4419
 
4411
4420
  fs.writeFileSync(pluginsFile, plugin, { flag: "a" });
@@ -4429,7 +4438,11 @@ const cleanupPlugin = function (projectPath, originalPluginsFile) {
4429
4438
  return !fs.existsSync(pluginsFile);
4430
4439
  } else {
4431
4440
  // Bring back the original file
4432
- fs.copyFileSync(originalPluginsFile, pluginsFile);
4441
+ fs.copyFileSync(
4442
+ originalPluginsFile,
4443
+ pluginsFile,
4444
+ fs.constants.COPYFILE_FICLONE
4445
+ );
4433
4446
  fs.unlinkSync(originalPluginsFile);
4434
4447
  return true;
4435
4448
  }
package/utils.test.js CHANGED
@@ -1,10 +1,11 @@
1
1
  const utils = require("./utils");
2
2
  const fs = require("fs");
3
3
  const ssri = require("ssri");
4
+ const { jest, expect, test } = require("@jest/globals");
4
5
 
5
6
  test("SSRI test", () => {
6
7
  // gopkg.lock hash
7
- ss = ssri.parse(
8
+ let ss = ssri.parse(
8
9
  "2ca532a6bc655663344004ba102436d29031018eab236247678db1d8978627bf"
9
10
  );
10
11
  expect(ss).toEqual(null);
@@ -529,7 +530,7 @@ test("parse go version data", async () => {
529
530
 
530
531
  test("parse cargo lock", async () => {
531
532
  expect(await utils.parseCargoData(null)).toEqual([]);
532
- dep_list = await utils.parseCargoData(
533
+ let dep_list = await utils.parseCargoData(
533
534
  fs.readFileSync("./test/Cargo.lock", { encoding: "utf-8" })
534
535
  );
535
536
  expect(dep_list.length).toEqual(224);
@@ -555,7 +556,7 @@ test("parse cargo lock", async () => {
555
556
 
556
557
  test("parse cargo toml", async () => {
557
558
  expect(await utils.parseCargoTomlData(null)).toEqual([]);
558
- dep_list = await utils.parseCargoTomlData(
559
+ let dep_list = await utils.parseCargoTomlData(
559
560
  fs.readFileSync("./test/data/Cargo1.toml", { encoding: "utf-8" })
560
561
  );
561
562
  expect(dep_list.length).toEqual(4);
@@ -581,7 +582,7 @@ test("parse cargo toml", async () => {
581
582
 
582
583
  test("parse cargo auditable data", async () => {
583
584
  expect(await utils.parseCargoAuditableData(null)).toEqual([]);
584
- dep_list = await utils.parseCargoAuditableData(
585
+ let dep_list = await utils.parseCargoAuditableData(
585
586
  fs.readFileSync("./test/data/cargo-auditable.txt", { encoding: "utf-8" })
586
587
  );
587
588
  expect(dep_list.length).toEqual(32);
@@ -621,7 +622,7 @@ test("get crates metadata", async () => {
621
622
 
622
623
  test("parse pub lock", async () => {
623
624
  expect(await utils.parsePubLockData(null)).toEqual([]);
624
- dep_list = await utils.parsePubLockData(
625
+ let dep_list = await utils.parsePubLockData(
625
626
  fs.readFileSync("./test/data/pubspec.lock", { encoding: "utf-8" })
626
627
  );
627
628
  expect(dep_list.length).toEqual(26);
@@ -668,7 +669,7 @@ test("get dart metadata", async () => {
668
669
 
669
670
  test("parse cabal freeze", async () => {
670
671
  expect(await utils.parseCabalData(null)).toEqual([]);
671
- dep_list = await utils.parseCabalData(
672
+ let dep_list = await utils.parseCabalData(
672
673
  fs.readFileSync("./test/data/cabal.project.freeze", { encoding: "utf-8" })
673
674
  );
674
675
  expect(dep_list.length).toEqual(24);
@@ -688,7 +689,7 @@ test("parse cabal freeze", async () => {
688
689
 
689
690
  test("parse conan data", async () => {
690
691
  expect(await utils.parseConanLockData(null)).toEqual([]);
691
- dep_list = await utils.parseConanLockData(
692
+ let dep_list = await utils.parseConanLockData(
692
693
  fs.readFileSync("./test/data/conan.lock", { encoding: "utf-8" })
693
694
  );
694
695
  expect(dep_list.length).toEqual(3);
@@ -786,7 +787,7 @@ test("parse clojure data", () => {
786
787
 
787
788
  test("parse mix lock data", async () => {
788
789
  expect(await utils.parseMixLockData(null)).toEqual([]);
789
- dep_list = await utils.parseMixLockData(
790
+ let dep_list = await utils.parseMixLockData(
790
791
  fs.readFileSync("./test/data/mix.lock", { encoding: "utf-8" })
791
792
  );
792
793
  expect(dep_list.length).toEqual(16);
@@ -806,7 +807,7 @@ test("parse mix lock data", async () => {
806
807
 
807
808
  test("parse github actions workflow data", async () => {
808
809
  expect(await utils.parseGitHubWorkflowData(null)).toEqual([]);
809
- dep_list = await utils.parseGitHubWorkflowData(
810
+ let dep_list = await utils.parseGitHubWorkflowData(
810
811
  fs.readFileSync("./.github/workflows/nodejs.yml", { encoding: "utf-8" })
811
812
  );
812
813
  expect(dep_list.length).toEqual(3);
@@ -1722,7 +1723,7 @@ test("parse container spec like files", async () => {
1722
1723
 
1723
1724
  test("parse cloudbuild data", async () => {
1724
1725
  expect(await utils.parseCloudBuildData(null)).toEqual([]);
1725
- dep_list = await utils.parseCloudBuildData(
1726
+ let dep_list = await utils.parseCloudBuildData(
1726
1727
  fs.readFileSync("./test/data/cloudbuild.yaml", { encoding: "utf-8" })
1727
1728
  );
1728
1729
  expect(dep_list.length).toEqual(1);