@cyclonedx/cdxgen 9.1.1 → 9.2.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.
package/README.md CHANGED
@@ -8,7 +8,7 @@ When used with plugins, cdxgen could generate an SBoM for Linux docker images an
8
8
 
9
9
  NOTE:
10
10
 
11
- CycloneDX 1.5 specification is brand new and unsupported by many downstream tools. Use version 8.6.0 for 1.4 compatibility.
11
+ CycloneDX 1.5 specification is brand new and unsupported by many downstream tools. Use version 8.6.0 for 1.4 compatibility or pass the argument `--spec-version 1.4`.
12
12
 
13
13
  ## Supported languages and package format
14
14
 
@@ -80,7 +80,7 @@ For go, `go mod why` command is used to identify required packages. For php, com
80
80
  ```shell
81
81
  sudo npm install -g @cyclonedx/cdxgen
82
82
 
83
- # For CycloneDX 1.4 compatibility use version 8.6.0
83
+ # For CycloneDX 1.4 compatibility use version 8.6.0 or pass the argument `--spec-version 1.4`
84
84
  sudo npm install -g @cyclonedx/cdxgen@8.6.0
85
85
  ```
86
86
 
@@ -150,8 +150,10 @@ Options:
150
150
  cts. Defaults to true but disabled for containers
151
151
  and oci scans. Use --no-install-deps to disable
152
152
  this feature. [boolean] [default: true]
153
- --validate Validate the generated SBoM using json schema.
154
- [boolean] [default: false]
153
+ --validate Validate the generated SBoM using json schema. De
154
+ faults to true. [boolean] [default: true]
155
+ --spec-version CycloneDX Specification version to use. Defaults
156
+ to 1.5 [default: "1.5"]
155
157
  --version Show version number [boolean]
156
158
  -h Show help [boolean]
157
159
  ```
@@ -182,6 +184,12 @@ To recursively generate a single BoM for all languages pass `-r` argument.
182
184
  cdxgen -r -o bom.json
183
185
  ```
184
186
 
187
+ To generate SBoM for an older specification version such as 1.4, pass the version using the `--spec-version` argument.
188
+
189
+ ```shell
190
+ cdxgen -r -o bom.json --spec-version 1.4
191
+ ```
192
+
185
193
  ## Universal SBoM
186
194
 
187
195
  By passing the type `-t universal`, cdxgen could be forced to opportunistically collect as many components and services as possible by scanning all package, container and kubernetes manifests. The resulting SBoM could have over thousand components thus requiring additional triaging before use with traditional SCA tools.
package/bin/cdxgen.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { createBom, submitBom, validateBom } from "../index.js";
3
+ import { createBom, submitBom } from "../index.js";
4
+ import { validateBom } from "../validator.js";
4
5
  import fs from "node:fs";
5
6
  import { tmpdir } from "node:os";
6
7
  import { basename, dirname, join, resolve } from "node:path";
@@ -109,8 +110,13 @@ const args = yargs(hideBin(process.argv))
109
110
  })
110
111
  .option("validate", {
111
112
  type: "boolean",
112
- default: false,
113
- description: "Validate the generated SBoM using json schema."
113
+ default: true,
114
+ description:
115
+ "Validate the generated SBoM using json schema. Defaults to true."
116
+ })
117
+ .option("spec-version", {
118
+ description: "CycloneDX Specification version to use. Defaults to 1.5",
119
+ default: "1.5"
114
120
  })
115
121
  .scriptName("cdxgen")
116
122
  .version()
@@ -144,6 +150,11 @@ if (!args.projectName) {
144
150
  }
145
151
  }
146
152
 
153
+ // To help dependency track users, we downgrade the spec version to 1.4 automatically
154
+ if (args.serverUrl || args.apiKey) {
155
+ args.specVersion = 1.4;
156
+ }
157
+
147
158
  /**
148
159
  * projectType: python, nodejs, java, golang
149
160
  * multiProject: Boolean to indicate monorepo or multi-module projects
@@ -165,7 +176,8 @@ const options = {
165
176
  projectVersion: args.projectVersion,
166
177
  server: args.server,
167
178
  serverHost: args.serverHost,
168
- serverPort: args.serverPort
179
+ serverPort: args.serverPort,
180
+ specVersion: args.specVersion
169
181
  };
170
182
 
171
183
  /**
package/binary.js CHANGED
@@ -3,6 +3,7 @@ import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
3
3
  import { join, dirname, basename } from "node:path";
4
4
  import { spawnSync } from "node:child_process";
5
5
  import { PackageURL } from "packageurl-js";
6
+ import { DEBUG_MODE } from "./utils.js";
6
7
 
7
8
  import { fileURLToPath } from "node:url";
8
9
  import path from "node:path";
@@ -15,13 +16,6 @@ const dirName = import.meta ? path.dirname(fileURLToPath(url)) : __dirname;
15
16
 
16
17
  const isWin = _platform() === "win32";
17
18
 
18
- // Debug mode flag
19
- const DEBUG_MODE =
20
- process.env.CDXGEN_DEBUG_MODE === "debug" ||
21
- process.env.SCAN_DEBUG_MODE === "debug" ||
22
- process.env.SHIFTLEFT_LOGGING_LEVEL === "debug" ||
23
- process.env.NODE_ENV === "development";
24
-
25
19
  let platform = _platform();
26
20
  let extn = "";
27
21
  if (platform == "win32") {
@@ -388,7 +382,7 @@ export const getOSPackages = (src) => {
388
382
  purlObj.qualifiers,
389
383
  purlObj.subpath
390
384
  ).toString();
391
- comp["bom-ref"] = comp.purl;
385
+ comp["bom-ref"] = decodeURIComponent(comp.purl);
392
386
  }
393
387
  if (purlObj.type !== "none") {
394
388
  allTypes.add(purlObj.type);
@@ -430,7 +424,7 @@ export const getOSPackages = (src) => {
430
424
  purlObj.qualifiers,
431
425
  purlObj.subpath
432
426
  ).toString();
433
- comp["bom-ref"] = comp.purl;
427
+ comp["bom-ref"] = decodeURIComponent(comp.purl);
434
428
  }
435
429
  }
436
430
  } catch (err) {
@@ -474,7 +468,7 @@ export const getOSPackages = (src) => {
474
468
  purlObj.subpath
475
469
  ).toString();
476
470
  }
477
- newComp["bom-ref"] = newComp.purl;
471
+ newComp["bom-ref"] = decodeURIComponent(newComp.purl);
478
472
  pkgList.push(newComp);
479
473
  }
480
474
  }