@cyclonedx/cdxgen 10.1.0 → 10.1.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/README.md +7 -0
- package/analyzer.js +21 -18
- package/bin/cdxgen.js +4 -4
- package/bin/evinse.js +2 -2
- package/bin/repl.js +4 -4
- package/bin/verify.js +1 -1
- package/binary.js +3 -3
- package/db.js +1 -1
- package/docker.js +8 -8
- package/docker.test.js +5 -5
- package/envcontext.js +6 -6
- package/envcontext.test.js +7 -7
- package/evinser.js +25 -25
- package/index.js +170 -148
- package/package.json +15 -11
- package/protobom.test.js +2 -2
- package/server.js +2 -2
- package/types/analyzer.d.ts +5 -0
- package/types/analyzer.d.ts.map +1 -0
- package/types/binary.d.ts +13 -0
- package/types/binary.d.ts.map +1 -0
- package/types/cbomutils.d.ts +2 -0
- package/types/cbomutils.d.ts.map +1 -0
- package/types/db.d.ts +19 -0
- package/types/db.d.ts.map +1 -0
- package/types/display.d.ts +8 -0
- package/types/display.d.ts.map +1 -0
- package/types/docker.d.ts +44 -0
- package/types/docker.d.ts.map +1 -0
- package/types/envcontext.d.ts +61 -0
- package/types/envcontext.d.ts.map +1 -0
- package/types/evinser.d.ts +728 -0
- package/types/evinser.d.ts.map +1 -0
- package/types/index.d.ts +48 -0
- package/types/index.d.ts.map +1 -0
- package/types/jest.config.d.ts +10 -0
- package/types/jest.config.d.ts.map +1 -0
- package/types/piptree.d.ts +2 -0
- package/types/piptree.d.ts.map +1 -0
- package/types/postgen.d.ts +3 -0
- package/types/postgen.d.ts.map +1 -0
- package/types/protobom.d.ts +3 -0
- package/types/protobom.d.ts.map +1 -0
- package/types/server.d.ts +3 -0
- package/types/server.d.ts.map +1 -0
- package/types/utils.d.ts +517 -0
- package/types/utils.d.ts.map +1 -0
- package/types/validator.d.ts +5 -0
- package/types/validator.d.ts.map +1 -0
- package/utils.js +222 -74
- package/utils.test.js +91 -67
- package/validator.js +2 -2
package/README.md
CHANGED
|
@@ -540,11 +540,18 @@ Refer to the [permissions document](./docs/PERMISSIONS.md)
|
|
|
540
540
|
Follow the usual PR process, but before raising a PR, run the following commands.
|
|
541
541
|
|
|
542
542
|
```bash
|
|
543
|
+
# Generate types using jsdoc syntax
|
|
544
|
+
npm run gen-types
|
|
545
|
+
# Run eslint with auto fix
|
|
543
546
|
npm run lint
|
|
547
|
+
# Run prettier
|
|
544
548
|
npm run pretty
|
|
549
|
+
# Run jest tests
|
|
545
550
|
npm test
|
|
546
551
|
```
|
|
547
552
|
|
|
553
|
+
If you are completely new to contributing to open-source projects, then look for [issues](https://github.com/CycloneDX/cdxgen/issues) with the labels "good first issue" or "help wanted".
|
|
554
|
+
|
|
548
555
|
## Enterprise support
|
|
549
556
|
|
|
550
557
|
Enterprise support, including custom development and integration services, is available via [AppThreat Ltd](https://www.appthreat.com). Free community support is also available via [Discord](https://discord.gg/tmmtjCEHNV).
|
package/analyzer.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { parse } from "@babel/parser";
|
|
2
2
|
import traverse from "@babel/traverse";
|
|
3
|
-
import { join } from "node:path";
|
|
4
3
|
import process from "node:process";
|
|
5
|
-
import {
|
|
6
|
-
import { basename,
|
|
4
|
+
import { lstatSync, readFileSync, readdirSync } from "node:fs";
|
|
5
|
+
import { basename, isAbsolute, join, relative, resolve } from "node:path";
|
|
7
6
|
|
|
8
7
|
const IGNORE_DIRS = process.env.ASTGEN_IGNORE_DIRS
|
|
9
8
|
? process.env.ASTGEN_IGNORE_DIRS.split(",")
|
|
@@ -190,21 +189,25 @@ const fileToParseableCode = (file) => {
|
|
|
190
189
|
let code = readFileSync(file, "utf-8");
|
|
191
190
|
if (file.endsWith(".vue") || file.endsWith(".svelte")) {
|
|
192
191
|
code = code
|
|
193
|
-
.replace(vueCommentRegex,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
192
|
+
.replace(vueCommentRegex, (match) => match.replaceAll(/\S/g, " "))
|
|
193
|
+
.replace(
|
|
194
|
+
vueCleaningRegex,
|
|
195
|
+
(match) => match.replaceAll(/\S/g, " ").substring(1) + ";"
|
|
196
|
+
)
|
|
197
|
+
.replace(
|
|
198
|
+
vueBindRegex,
|
|
199
|
+
(match, grA, grB, grC) =>
|
|
200
|
+
grA.replaceAll(/\S/g, " ") + grB + grC.replaceAll(/\S/g, " ")
|
|
201
|
+
)
|
|
202
|
+
.replace(
|
|
203
|
+
vuePropRegex,
|
|
204
|
+
(match, grA, grB) => " " + grA.replace(/[.:@]/g, " ") + grB
|
|
205
|
+
)
|
|
206
|
+
.replace(
|
|
207
|
+
vueTemplateRegex,
|
|
208
|
+
(match, grA, grB, grC) =>
|
|
209
|
+
grA + grB.replaceAll("{{", "{ ").replaceAll("}}", " }") + grC
|
|
210
|
+
);
|
|
208
211
|
}
|
|
209
212
|
return code;
|
|
210
213
|
};
|
package/bin/cdxgen.js
CHANGED
|
@@ -7,16 +7,16 @@ import { tmpdir } from "node:os";
|
|
|
7
7
|
import { basename, dirname, join, resolve } from "node:path";
|
|
8
8
|
import jws from "jws";
|
|
9
9
|
import crypto from "node:crypto";
|
|
10
|
-
import {
|
|
10
|
+
import { URL, fileURLToPath } from "node:url";
|
|
11
11
|
import globalAgent from "global-agent";
|
|
12
12
|
import process from "node:process";
|
|
13
13
|
import {
|
|
14
14
|
printCallStack,
|
|
15
|
+
printDependencyTree,
|
|
15
16
|
printOccurrences,
|
|
16
|
-
printServices,
|
|
17
17
|
printReachables,
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
printServices,
|
|
19
|
+
printTable
|
|
20
20
|
} from "../display.js";
|
|
21
21
|
import { findUpSync } from "find-up";
|
|
22
22
|
import { load as _load } from "js-yaml";
|
package/bin/evinse.js
CHANGED
|
@@ -10,8 +10,8 @@ import { validateBom } from "../validator.js";
|
|
|
10
10
|
import {
|
|
11
11
|
printCallStack,
|
|
12
12
|
printOccurrences,
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
printReachables,
|
|
14
|
+
printServices
|
|
15
15
|
} from "../display.js";
|
|
16
16
|
import { ATOM_DB } from "../utils.js";
|
|
17
17
|
import { findUpSync } from "find-up";
|
package/bin/repl.js
CHANGED
|
@@ -11,11 +11,11 @@ import { createBom } from "../index.js";
|
|
|
11
11
|
import { validateBom } from "../validator.js";
|
|
12
12
|
import {
|
|
13
13
|
printCallStack,
|
|
14
|
-
printOccurrences,
|
|
15
|
-
printOSTable,
|
|
16
|
-
printTable,
|
|
17
14
|
printDependencyTree,
|
|
18
|
-
|
|
15
|
+
printOSTable,
|
|
16
|
+
printOccurrences,
|
|
17
|
+
printServices,
|
|
18
|
+
printTable
|
|
19
19
|
} from "../display.js";
|
|
20
20
|
|
|
21
21
|
const options = {
|
package/bin/verify.js
CHANGED
|
@@ -5,7 +5,7 @@ import { hideBin } from "yargs/helpers";
|
|
|
5
5
|
import fs from "node:fs";
|
|
6
6
|
import jws from "jws";
|
|
7
7
|
import process from "node:process";
|
|
8
|
-
import {
|
|
8
|
+
import { URL, fileURLToPath } from "node:url";
|
|
9
9
|
import { dirname, join } from "node:path";
|
|
10
10
|
|
|
11
11
|
let url = import.meta.url;
|
package/binary.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { arch as _arch, platform as _platform, homedir, tmpdir } from "node:os";
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import { Buffer } from "node:buffer";
|
|
4
4
|
import {
|
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
readFileSync,
|
|
9
9
|
rmSync
|
|
10
10
|
} from "node:fs";
|
|
11
|
-
import {
|
|
11
|
+
import { basename, dirname, join } from "node:path";
|
|
12
12
|
import { spawnSync } from "node:child_process";
|
|
13
13
|
import { PackageURL } from "packageurl-js";
|
|
14
14
|
import { DEBUG_MODE, TIMEOUT_MS, findLicenseId } from "./utils.js";
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import { URL, fileURLToPath } from "node:url";
|
|
17
17
|
|
|
18
18
|
let url = import.meta.url;
|
|
19
19
|
if (!url.startsWith("file://")) {
|
package/db.js
CHANGED
package/docker.js
CHANGED
|
@@ -5,21 +5,21 @@ import stream from "node:stream/promises";
|
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { Buffer } from "node:buffer";
|
|
7
7
|
import {
|
|
8
|
+
createReadStream,
|
|
8
9
|
existsSync,
|
|
9
|
-
readdirSync,
|
|
10
|
-
statSync,
|
|
11
10
|
lstatSync,
|
|
12
|
-
readFileSync,
|
|
13
|
-
createReadStream,
|
|
14
|
-
mkdtempSync,
|
|
15
11
|
mkdirSync,
|
|
16
|
-
|
|
12
|
+
mkdtempSync,
|
|
13
|
+
readFileSync,
|
|
14
|
+
readdirSync,
|
|
15
|
+
rmSync,
|
|
16
|
+
statSync
|
|
17
17
|
} from "node:fs";
|
|
18
18
|
import { join } from "node:path";
|
|
19
19
|
import {
|
|
20
|
+
platform as _platform,
|
|
20
21
|
userInfo as _userInfo,
|
|
21
22
|
homedir,
|
|
22
|
-
platform as _platform,
|
|
23
23
|
tmpdir
|
|
24
24
|
} from "node:os";
|
|
25
25
|
import { x } from "tar";
|
|
@@ -1196,7 +1196,7 @@ export const addSkippedSrcFiles = (skippedImageSrcs, components) => {
|
|
|
1196
1196
|
for (const co of components) {
|
|
1197
1197
|
const srcFileValues = [];
|
|
1198
1198
|
let srcImageValue;
|
|
1199
|
-
co.properties.forEach(
|
|
1199
|
+
co.properties.forEach((property) => {
|
|
1200
1200
|
if (property.name === "oci:SrcImage") {
|
|
1201
1201
|
srcImageValue = property.value;
|
|
1202
1202
|
}
|
package/docker.test.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
+
addSkippedSrcFiles,
|
|
3
|
+
exportImage,
|
|
2
4
|
getConnection,
|
|
3
|
-
parseImageName,
|
|
4
5
|
getImage,
|
|
5
|
-
removeImage,
|
|
6
|
-
exportImage,
|
|
7
6
|
isWin,
|
|
8
|
-
|
|
7
|
+
parseImageName,
|
|
8
|
+
removeImage
|
|
9
9
|
} from "./docker.js";
|
|
10
|
-
import {
|
|
10
|
+
import { beforeEach, describe, expect, test } from "@jest/globals";
|
|
11
11
|
|
|
12
12
|
test("docker connection", async () => {
|
|
13
13
|
if (!(isWin && process.env.CI === "true")) {
|
package/envcontext.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
PYTHON_CMD,
|
|
5
|
-
JAVA_CMD,
|
|
3
|
+
CARGO_CMD,
|
|
6
4
|
DOTNET_CMD,
|
|
7
|
-
NODE_CMD,
|
|
8
|
-
NPM_CMD,
|
|
9
5
|
GCC_CMD,
|
|
10
6
|
GO_CMD,
|
|
7
|
+
JAVA_CMD,
|
|
8
|
+
NODE_CMD,
|
|
9
|
+
NPM_CMD,
|
|
10
|
+
PYTHON_CMD,
|
|
11
11
|
RUSTC_CMD,
|
|
12
|
-
|
|
12
|
+
isWin
|
|
13
13
|
} from "./utils.js";
|
|
14
14
|
import process from "node:process";
|
|
15
15
|
import { Buffer } from "node:buffer";
|
package/envcontext.test.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { expect, test } from "@jest/globals";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
getBranch,
|
|
5
|
-
getOriginUrl,
|
|
6
|
-
listFiles,
|
|
7
|
-
collectJavaInfo,
|
|
8
4
|
collectDotnetInfo,
|
|
9
|
-
collectPythonInfo,
|
|
10
|
-
collectNodeInfo,
|
|
11
5
|
collectGccInfo,
|
|
6
|
+
collectGoInfo,
|
|
7
|
+
collectJavaInfo,
|
|
8
|
+
collectNodeInfo,
|
|
9
|
+
collectPythonInfo,
|
|
12
10
|
collectRustInfo,
|
|
13
|
-
|
|
11
|
+
getBranch,
|
|
12
|
+
getOriginUrl,
|
|
13
|
+
listFiles
|
|
14
14
|
} from "./envcontext.js";
|
|
15
15
|
|
|
16
16
|
test("git tests", () => {
|
package/evinser.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DEBUG_MODE,
|
|
3
|
+
collectGradleDependencies,
|
|
4
|
+
collectMvnDependencies,
|
|
2
5
|
executeAtom,
|
|
3
6
|
getAllFiles,
|
|
4
7
|
getGradleCommand,
|
|
5
|
-
getMavenCommand
|
|
6
|
-
collectGradleDependencies,
|
|
7
|
-
collectMvnDependencies,
|
|
8
|
-
DEBUG_MODE
|
|
8
|
+
getMavenCommand
|
|
9
9
|
} from "./utils.js";
|
|
10
10
|
import { tmpdir } from "node:os";
|
|
11
11
|
import path from "node:path";
|
|
@@ -20,7 +20,7 @@ const typePurlsCache = {};
|
|
|
20
20
|
/**
|
|
21
21
|
* Function to create the db for the libraries referred in the sbom.
|
|
22
22
|
*
|
|
23
|
-
* @param {
|
|
23
|
+
* @param {Object} Command line options
|
|
24
24
|
*/
|
|
25
25
|
export const prepareDB = async (options) => {
|
|
26
26
|
if (!options.dbPath.includes("memory") && !fs.existsSync(options.dbPath)) {
|
|
@@ -318,8 +318,8 @@ export const initFromSbom = (components, language) => {
|
|
|
318
318
|
/**
|
|
319
319
|
* Function to analyze the project
|
|
320
320
|
*
|
|
321
|
-
* @param {
|
|
322
|
-
* @param {
|
|
321
|
+
* @param {Object} dbObjMap DB and model instances
|
|
322
|
+
* @param {Object} Command line options
|
|
323
323
|
*/
|
|
324
324
|
export const analyzeProject = async (dbObjMap, options) => {
|
|
325
325
|
const dirPath = options._[0] || ".";
|
|
@@ -479,11 +479,11 @@ export const parseObjectSlices = async (
|
|
|
479
479
|
* https://github.com/AppThreat/atom/blob/main/specification/docs/slices.md#use
|
|
480
480
|
*
|
|
481
481
|
* @param {string} language Application language
|
|
482
|
-
* @param {
|
|
483
|
-
* @param {
|
|
484
|
-
* @param {
|
|
485
|
-
* @param {
|
|
486
|
-
* @param {
|
|
482
|
+
* @param {Object} userDefinedTypesMap User Defined types in the application
|
|
483
|
+
* @param {Array} usages Usages array for each objectSlice
|
|
484
|
+
* @param {Object} dbObjMap DB Models
|
|
485
|
+
* @param {Object} purlLocationMap Object to track locations where purls are used
|
|
486
|
+
* @param {Object} purlImportsMap Object to track package urls and their import aliases
|
|
487
487
|
* @returns
|
|
488
488
|
*/
|
|
489
489
|
export const parseSliceUsages = async (
|
|
@@ -764,8 +764,8 @@ export const isFilterableType = (
|
|
|
764
764
|
* Method to detect services from annotation objects in the usage slice
|
|
765
765
|
*
|
|
766
766
|
* @param {string} language Application language
|
|
767
|
-
* @param {
|
|
768
|
-
* @param {
|
|
767
|
+
* @param {Array} usages Usages array for each objectSlice
|
|
768
|
+
* @param {Object} servicesMap Existing service map
|
|
769
769
|
*/
|
|
770
770
|
export const detectServicesFromUsages = (language, slice, servicesMap = {}) => {
|
|
771
771
|
const usages = slice.usages;
|
|
@@ -830,8 +830,8 @@ export const detectServicesFromUsages = (language, slice, servicesMap = {}) => {
|
|
|
830
830
|
* Method to detect services from user defined types in the usage slice
|
|
831
831
|
*
|
|
832
832
|
* @param {string} language Application language
|
|
833
|
-
* @param {
|
|
834
|
-
* @param {
|
|
833
|
+
* @param {Array} userDefinedTypes User defined types
|
|
834
|
+
* @param {Object} servicesMap Existing service map
|
|
835
835
|
*/
|
|
836
836
|
export const detectServicesFromUDT = (
|
|
837
837
|
language,
|
|
@@ -962,8 +962,8 @@ export const extractEndpoints = (language, code) => {
|
|
|
962
962
|
/**
|
|
963
963
|
* Method to create the SBOM with evidence file called evinse file.
|
|
964
964
|
*
|
|
965
|
-
* @param {
|
|
966
|
-
* @param {
|
|
965
|
+
* @param {Object} sliceArtefacts Various artefacts from the slice operation
|
|
966
|
+
* @param {Object} options Command line options
|
|
967
967
|
* @returns
|
|
968
968
|
*/
|
|
969
969
|
export const createEvinseFile = (sliceArtefacts, options) => {
|
|
@@ -1085,11 +1085,11 @@ export const createEvinseFile = (sliceArtefacts, options) => {
|
|
|
1085
1085
|
* Implemented based on the logic proposed here - https://github.com/AppThreat/atom/blob/main/specification/docs/slices.md#data-flow-slice
|
|
1086
1086
|
*
|
|
1087
1087
|
* @param {string} language Application language
|
|
1088
|
-
* @param {
|
|
1089
|
-
* @param {
|
|
1090
|
-
* @param {
|
|
1091
|
-
* @param {
|
|
1092
|
-
* @param {
|
|
1088
|
+
* @param {Object} userDefinedTypesMap User Defined types in the application
|
|
1089
|
+
* @param {Object} dataFlowSlice Data flow slice object from atom
|
|
1090
|
+
* @param {Object} dbObjMap DB models
|
|
1091
|
+
* @param {Object} purlLocationMap Object to track locations where purls are used
|
|
1092
|
+
* @param {Object} purlImportsMap Object to track package urls and their import aliases
|
|
1093
1093
|
*/
|
|
1094
1094
|
export const collectDataFlowFrames = async (
|
|
1095
1095
|
language,
|
|
@@ -1212,7 +1212,7 @@ export const collectDataFlowFrames = async (
|
|
|
1212
1212
|
* Implemented based on the logic proposed here - https://github.com/AppThreat/atom/blob/main/specification/docs/slices.md#data-flow-slice
|
|
1213
1213
|
*
|
|
1214
1214
|
* @param {string} language Application language
|
|
1215
|
-
* @param {
|
|
1215
|
+
* @param {Object} reachablesSlice Reachables slice object from atom
|
|
1216
1216
|
*/
|
|
1217
1217
|
export const collectReachableFrames = (language, reachablesSlice) => {
|
|
1218
1218
|
const reachableNodes = reachablesSlice?.reachables || [];
|
|
@@ -1253,7 +1253,7 @@ export const collectReachableFrames = (language, reachablesSlice) => {
|
|
|
1253
1253
|
/**
|
|
1254
1254
|
* Method to pick a callstack frame as an evidence. This method is required since CycloneDX 1.5 accepts only a single frame as evidence.
|
|
1255
1255
|
*
|
|
1256
|
-
* @param {
|
|
1256
|
+
* @param {Array} dfFrames Data flow frames
|
|
1257
1257
|
* @returns
|
|
1258
1258
|
*/
|
|
1259
1259
|
export const framePicker = (dfFrames) => {
|