@cyclonedx/cdxgen 9.8.3 → 9.8.5

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/README.md CHANGED
@@ -238,6 +238,22 @@ docker run --rm -v /tmp:/tmp -p 9090:9090 -v $(pwd):/app:rw -t ghcr.io/cyclonedx
238
238
 
239
239
  Use curl or your favorite tool to pass arguments to the `/sbom` route.
240
240
 
241
+ ### Server arguments
242
+
243
+ Arguments can be passed either via the query string or as a JSON body. The following arguments are supported.
244
+
245
+ | Argument | Description |
246
+ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
247
+ | type | Project type |
248
+ | multiProject | [boolean] |
249
+ | requiredOnly | Include only the packages with required scope on the SBoM. [boolean] |
250
+ | noBabel | Do not use babel to perform usage analysis for JavaScript/TypeScript projects. [boolean] |
251
+ | installDeps | Install dependencies automatically for some projects. Defaults to true but disabled for containers and oci scans. [boolean] [default: true] |
252
+ | project | |
253
+ | projectName | Dependency track project name. Default use the directory name |
254
+ | projectGroup | Dependency track project group |
255
+ | projectVersion | Dependency track project version [default: ""] |
256
+
241
257
  ### Scanning a local path
242
258
 
243
259
  ```shell
package/index.js CHANGED
@@ -686,7 +686,6 @@ function addComponent(
686
686
  encodeForPurl(pkg.subpath)
687
687
  );
688
688
  let purlString = purl.toString();
689
- purlString = decodeURIComponent(purlString);
690
689
  let description = { "#cdata": pkg.description };
691
690
  if (format === "json") {
692
691
  description = pkg.description || undefined;
@@ -2681,7 +2680,9 @@ export const createGoBom = async (path, options) => {
2681
2680
  }
2682
2681
  } else {
2683
2682
  shouldManuallyParse = true;
2684
- console.error("go unexpectedly didn't return any output");
2683
+ console.error(
2684
+ "go unexpectedly didn't return any output. Check if the correct version of golang is installed."
2685
+ );
2685
2686
  options.failOnError && process.exit(1);
2686
2687
  }
2687
2688
  }
@@ -4419,7 +4420,12 @@ export const createMultiXBom = async (pathList, options) => {
4419
4420
  );
4420
4421
  }
4421
4422
  bomData = await createCsharpBom(path, options, parentComponent);
4422
- if (bomData && bomData.bomJson && bomData.bomJson.components) {
4423
+ if (
4424
+ bomData &&
4425
+ bomData.bomJson &&
4426
+ bomData.bomJson.components &&
4427
+ bomData.bomJson.components.length
4428
+ ) {
4423
4429
  if (DEBUG_MODE) {
4424
4430
  console.log(
4425
4431
  `Found ${bomData.bomJson.components.length} csharp packages at ${path}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyclonedx/cdxgen",
3
- "version": "9.8.3",
3
+ "version": "9.8.5",
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>",
@@ -38,6 +38,7 @@
38
38
  "cdx-verify": "./bin/verify.js"
39
39
  },
40
40
  "scripts": {
41
+ "docs": "docsify serve docs",
41
42
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --inject-globals false docker.test.js utils.test.js display.test.js",
42
43
  "watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch --inject-globals false",
43
44
  "lint": "eslint *.js *.test.js bin/*.js",
@@ -99,6 +100,7 @@
99
100
  ],
100
101
  "devDependencies": {
101
102
  "caxa": "^3.0.1",
103
+ "docsify-cli": "^4.4.4",
102
104
  "eslint": "^8.49.0",
103
105
  "jest": "^29.7.0",
104
106
  "prettier": "3.0.3"
package/server.js CHANGED
@@ -6,7 +6,7 @@ import { spawnSync } from "node:child_process";
6
6
  import os from "node:os";
7
7
  import fs from "node:fs";
8
8
  import path from "node:path";
9
- import { createBom } from "./index.js";
9
+ import { createBom, submitBom } from "./index.js";
10
10
  import compression from "compression";
11
11
 
12
12
  // Timeout milliseconds. Default 10 mins
@@ -42,33 +42,37 @@ const parseQueryString = (q, body, options = {}) => {
42
42
  if (body && Object.keys(body).length) {
43
43
  options = Object.assign(options, body);
44
44
  }
45
- if (q.type) {
46
- options.projectType = q.type;
47
- }
48
- if (q.multiProject && q.multiProject !== "false") {
49
- options.multiProject = true;
50
- }
51
- if (q.requiredOnly && q.requiredOnly !== "false") {
52
- options.requiredOnly = true;
53
- }
54
- if (q.noBabel) {
55
- options.noBabel = q.noBabel;
56
- }
57
- if (q.installDeps) {
58
- options.installDeps = q.installDeps;
59
- }
60
- if (q.project) {
61
- options.project = q.project;
62
- }
63
- if (q.projectName) {
64
- options.projectName = q.projectName;
65
- }
66
- if (q.projectGroup) {
67
- options.projectGroup = q.projectGroup;
45
+
46
+ const queryParams = [
47
+ "type",
48
+ "multiProject",
49
+ "requiredOnly",
50
+ "noBabel",
51
+ "installDeps",
52
+ "project",
53
+ "projectName",
54
+ "projectGroup",
55
+ "projectVersion",
56
+ "parentUUID",
57
+ "serverUrl",
58
+ "apiKey",
59
+ "specVersion"
60
+ ];
61
+
62
+ for (const param of queryParams) {
63
+ if (q[param]) {
64
+ options[param] = q[param];
65
+ }
68
66
  }
69
- if (q.projectVersion) {
70
- options.projectVersion = q.projectVersion;
67
+
68
+ // To help dependency track users, we downgrade the spec version to 1.4 automatically
69
+ if (options.serverUrl || options.apiKey) {
70
+ options.specVersion = 1.4;
71
71
  }
72
+
73
+ options.projectType == options.type;
74
+ delete options.type;
75
+
72
76
  return options;
73
77
  };
74
78
 
@@ -114,6 +118,10 @@ const start = (options) => {
114
118
  res.write(JSON.stringify(bomNSData.bomJson, null, 2));
115
119
  }
116
120
  }
121
+ if (options.serverUrl && options.apiKey) {
122
+ console.log("Publishing SBoM to Dependency Track");
123
+ submitBom(options, bomNSData.bomJson);
124
+ }
117
125
  res.end("\n");
118
126
  if (cleanup && srcDir && srcDir.startsWith(os.tmpdir()) && fs.rmSync) {
119
127
  console.log(`Cleaning up ${srcDir}`);
package/utils.test.js CHANGED
@@ -1143,7 +1143,7 @@ test("parse github actions workflow data", async () => {
1143
1143
  dep_list = parseGitHubWorkflowData(
1144
1144
  readFileSync("./.github/workflows/repotests.yml", { encoding: "utf-8" })
1145
1145
  );
1146
- expect(dep_list.length).toEqual(6);
1146
+ expect(dep_list.length).toEqual(7);
1147
1147
  expect(dep_list[0]).toEqual({
1148
1148
  group: "actions",
1149
1149
  name: "checkout",