@trustify-da/trustify-da-javascript-client 0.3.0-ea.2ea1d77 → 0.3.0-ea.328523e
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 +272 -19
- package/dist/package.json +33 -28
- package/dist/src/analysis.d.ts +52 -22
- package/dist/src/analysis.js +77 -22
- package/dist/src/cli.js +238 -7
- package/dist/src/config.d.ts +120 -0
- package/dist/src/config.js +260 -0
- package/dist/src/cyclone_dx_sbom.d.ts +27 -1
- package/dist/src/cyclone_dx_sbom.js +82 -9
- package/dist/src/index.d.ts +97 -22
- package/dist/src/index.js +115 -42
- package/dist/src/license/index.d.ts +4 -4
- package/dist/src/license/index.js +13 -7
- package/dist/src/license/license_utils.js +4 -1
- package/dist/src/license/licenses_api.d.ts +3 -3
- package/dist/src/license/licenses_api.js +1 -1
- package/dist/src/oci_image/images.d.ts +1 -1
- package/dist/src/oci_image/images.js +15 -1
- package/dist/src/oci_image/utils.d.ts +5 -5
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/package_version.d.ts +8 -0
- package/dist/src/package_version.js +31 -0
- package/dist/src/provider.d.ts +4 -3
- package/dist/src/provider.js +12 -2
- package/dist/src/providers/base_java.d.ts +67 -12
- package/dist/src/providers/base_java.js +82 -61
- package/dist/src/providers/base_javascript.d.ts +90 -15
- package/dist/src/providers/base_javascript.js +206 -24
- package/dist/src/providers/base_pyproject.d.ts +158 -0
- package/dist/src/providers/base_pyproject.js +322 -0
- package/dist/src/providers/containerfile_parser.d.ts +5 -0
- package/dist/src/providers/containerfile_parser.js +20 -0
- package/dist/src/providers/golang_gomodules.d.ts +23 -13
- package/dist/src/providers/golang_gomodules.js +208 -120
- package/dist/src/providers/gomod_parser.d.ts +4 -0
- package/dist/src/providers/gomod_parser.js +16 -0
- package/dist/src/providers/java_gradle.d.ts +67 -0
- package/dist/src/providers/java_gradle.js +320 -22
- package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
- package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
- package/dist/src/providers/java_maven.d.ts +37 -9
- package/dist/src/providers/java_maven.js +269 -11
- package/dist/src/providers/javascript_bun.d.ts +22 -0
- package/dist/src/providers/javascript_bun.js +141 -0
- package/dist/src/providers/javascript_npm.d.ts +19 -0
- package/dist/src/providers/javascript_npm.js +61 -1
- package/dist/src/providers/javascript_pnpm.d.ts +13 -0
- package/dist/src/providers/javascript_pnpm.js +53 -3
- package/dist/src/providers/javascript_yarn.d.ts +12 -0
- package/dist/src/providers/javascript_yarn.js +75 -2
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +28 -7
- package/dist/src/providers/marker_evaluator.d.ts +14 -0
- package/dist/src/providers/marker_evaluator.js +191 -0
- package/dist/src/providers/oci_dockerfile.d.ts +51 -0
- package/dist/src/providers/oci_dockerfile.js +177 -0
- package/dist/src/providers/processors/yarn_berry_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_berry_processor.js +91 -7
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
- package/dist/src/providers/python_controller.d.ts +5 -1
- package/dist/src/providers/python_controller.js +69 -8
- package/dist/src/providers/python_pip.d.ts +5 -0
- package/dist/src/providers/python_pip.js +6 -6
- package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
- package/dist/src/providers/python_pip_pyproject.js +146 -0
- package/dist/src/providers/python_poetry.d.ts +98 -0
- package/dist/src/providers/python_poetry.js +286 -0
- package/dist/src/providers/python_uv.d.ts +46 -0
- package/dist/src/providers/python_uv.js +275 -0
- package/dist/src/providers/requirements_parser.js +1 -1
- package/dist/src/providers/rust_cargo.d.ts +6 -2
- package/dist/src/providers/rust_cargo.js +101 -33
- package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/remediate.d.ts +107 -0
- package/dist/src/remediate.js +244 -0
- package/dist/src/remediation.d.ts +81 -0
- package/dist/src/remediation.js +475 -0
- package/dist/src/remediation_report.d.ts +23 -0
- package/dist/src/remediation_report.js +180 -0
- package/dist/src/sbom.d.ts +25 -1
- package/dist/src/sbom.js +23 -2
- package/dist/src/tools.d.ts +37 -13
- package/dist/src/tools.js +92 -13
- package/dist/src/updaters/maven_updater.d.ts +58 -0
- package/dist/src/updaters/maven_updater.js +345 -0
- package/dist/src/updaters/toml_updater.d.ts +62 -0
- package/dist/src/updaters/toml_updater.js +276 -0
- package/dist/src/workspace.d.ts +11 -1
- package/dist/src/workspace.js +3 -2
- package/package.json +34 -29
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Converts a Subresource Integrity (SRI) string to a CycloneDX hash object.
|
|
3
|
+
* SRI is formatted as `<alg>-<base64>` (e.g. `sha512-Ab3d...`). CycloneDX
|
|
4
|
+
* expects an uppercased algorithm label (e.g. `SHA-512`) and a hex-encoded
|
|
5
|
+
* digest. When the SRI string contains multiple space-separated hashes, only
|
|
6
|
+
* the first is used.
|
|
7
|
+
* @param {string} integrity - SRI string from a lock file
|
|
8
|
+
* @returns {{alg: string, content: string}|null} CycloneDX hash, or null when unparseable
|
|
9
|
+
*/
|
|
10
|
+
export function sriToHash(integrity: string): {
|
|
11
|
+
alg: string;
|
|
12
|
+
content: string;
|
|
13
|
+
} | null;
|
|
14
|
+
export type purlType = any;
|
|
2
15
|
/** @typedef {import('../provider').Provider} */
|
|
3
16
|
/** @typedef {import('../provider').Provided} Provided */
|
|
4
17
|
/**
|
|
@@ -19,7 +32,7 @@ export default class Base_javascript {
|
|
|
19
32
|
* @param {Object} opts - Configuration options for the provider
|
|
20
33
|
* @protected
|
|
21
34
|
*/
|
|
22
|
-
protected _setUp(manifestPath: string, opts:
|
|
35
|
+
protected _setUp(manifestPath: string, opts: Object): void;
|
|
23
36
|
/**
|
|
24
37
|
* Gets the current manifest object
|
|
25
38
|
* @returns {Manifest} The manifest object
|
|
@@ -47,6 +60,11 @@ export default class Base_javascript {
|
|
|
47
60
|
*/
|
|
48
61
|
protected _cmdName(): string;
|
|
49
62
|
/**
|
|
63
|
+
* Returns the package manager name (e.g. npm, yarn, pnpm, bun)
|
|
64
|
+
* @returns {string} The package manager name
|
|
65
|
+
*/
|
|
66
|
+
packageManagerName(): string;
|
|
67
|
+
/**
|
|
50
68
|
* Returns the command arguments for listing dependencies
|
|
51
69
|
* @returns {Array<string>} The command arguments
|
|
52
70
|
* @abstract
|
|
@@ -60,6 +78,47 @@ export default class Base_javascript {
|
|
|
60
78
|
* @protected
|
|
61
79
|
*/
|
|
62
80
|
protected _updateLockFileCmdArgs(): Array<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Parses the provider's lock file into a hash map keyed by `name@version`.
|
|
83
|
+
* Subclasses override this (accepting the lock directory) to support their
|
|
84
|
+
* lock file format. The default implementation returns an empty map so
|
|
85
|
+
* providers without lock parsing (or without a lock file present) gracefully
|
|
86
|
+
* omit hashes.
|
|
87
|
+
* @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
|
|
88
|
+
* @protected
|
|
89
|
+
*/
|
|
90
|
+
protected _parseLockFileHashes(): Map<string, Array<{
|
|
91
|
+
alg: string;
|
|
92
|
+
content: string;
|
|
93
|
+
}>>;
|
|
94
|
+
/**
|
|
95
|
+
* Loads lock-file hashes for the given directory into internal state.
|
|
96
|
+
* Parsing failures degrade gracefully to an empty map (no hashes emitted).
|
|
97
|
+
* @param {string} lockDir - Directory containing the lock file
|
|
98
|
+
* @protected
|
|
99
|
+
*/
|
|
100
|
+
protected _loadHashes(lockDir: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* Looks up CycloneDX hashes for a package by name and resolved version.
|
|
103
|
+
* @param {string} name - The package name (including scope, e.g. `@hapi/joi`)
|
|
104
|
+
* @param {string} version - The resolved package version
|
|
105
|
+
* @returns {Array<{alg: string, content: string}>|undefined} Hashes, or undefined
|
|
106
|
+
* @protected
|
|
107
|
+
*/
|
|
108
|
+
protected _hashesFor(name: string, version: string): Array<{
|
|
109
|
+
alg: string;
|
|
110
|
+
content: string;
|
|
111
|
+
}> | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Looks up CycloneDX hashes for a package described by a PackageURL.
|
|
114
|
+
* @param {PackageURL} purl - The package URL
|
|
115
|
+
* @returns {Array<{alg: string, content: string}>|undefined} Hashes, or undefined
|
|
116
|
+
* @protected
|
|
117
|
+
*/
|
|
118
|
+
protected _hashesForPurl(purl: PackageURL): Array<{
|
|
119
|
+
alg: string;
|
|
120
|
+
content: string;
|
|
121
|
+
}> | undefined;
|
|
63
122
|
/**
|
|
64
123
|
* Checks if the provider supports the given manifest name
|
|
65
124
|
* @param {string} manifestName - The manifest name to check
|
|
@@ -67,30 +126,40 @@ export default class Base_javascript {
|
|
|
67
126
|
*/
|
|
68
127
|
isSupported(manifestName: string): boolean;
|
|
69
128
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
129
|
+
* Walks up the directory tree from manifestDir looking for the lock file.
|
|
130
|
+
* Stops when the lock file is found, when a package.json with a "workspaces"
|
|
131
|
+
* field is encountered without a lock file (workspace root boundary), or
|
|
132
|
+
* when the filesystem root is reached.
|
|
133
|
+
*
|
|
134
|
+
* When TRUSTIFY_DA_WORKSPACE_DIR is set, checks only that directory (no walk-up).
|
|
135
|
+
*
|
|
136
|
+
* @param {string} manifestDir - The directory to start searching from
|
|
137
|
+
* @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
|
|
138
|
+
* @returns {string|null} The directory containing the lock file, or null
|
|
139
|
+
* @protected
|
|
140
|
+
*/
|
|
141
|
+
protected _isWorkspaceRoot(dir: any): string | null;
|
|
142
|
+
_findLockFileDir(manifestDir: any, opts?: {}): string | null;
|
|
143
|
+
/**
|
|
73
144
|
* @param {string} manifestDir - The base directory where the manifest is located
|
|
74
|
-
* @param {
|
|
145
|
+
* @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
|
|
75
146
|
* @returns {boolean} True if the lock file exists
|
|
76
147
|
*/
|
|
77
|
-
validateLockFile(manifestDir: string, opts?:
|
|
78
|
-
TRUSTIFY_DA_WORKSPACE_DIR?: string;
|
|
79
|
-
}): boolean;
|
|
148
|
+
validateLockFile(manifestDir: string, opts?: Object): boolean;
|
|
80
149
|
/**
|
|
81
150
|
* Provides content and content type for stack analysis
|
|
82
151
|
* @param {string} manifestPath - The manifest path or name
|
|
83
152
|
* @param {Object} [opts={}] - Optional configuration options
|
|
84
153
|
* @returns {Provided} The provided data for stack analysis
|
|
85
154
|
*/
|
|
86
|
-
provideStack(manifestPath: string, opts?:
|
|
155
|
+
provideStack(manifestPath: string, opts?: Object): Provided;
|
|
87
156
|
/**
|
|
88
157
|
* Provides content and content type for component analysis
|
|
89
158
|
* @param {string} manifestPath - Path to package.json for component report
|
|
90
159
|
* @param {Object} [opts={}] - Optional configuration options
|
|
91
160
|
* @returns {Provided} The provided data for component analysis
|
|
92
161
|
*/
|
|
93
|
-
provideComponent(manifestPath: string, opts?:
|
|
162
|
+
provideComponent(manifestPath: string, opts?: Object): Provided;
|
|
94
163
|
/**
|
|
95
164
|
* Read license from manifest (package.json). Reused by npm, pnpm, yarn.
|
|
96
165
|
* @param {string} manifestPath - path to package.json
|
|
@@ -104,21 +173,21 @@ export default class Base_javascript {
|
|
|
104
173
|
* @returns {Object} The dependency tree
|
|
105
174
|
* @protected
|
|
106
175
|
*/
|
|
107
|
-
protected _buildDependencyTree(includeTransitive: boolean, opts?:
|
|
176
|
+
protected _buildDependencyTree(includeTransitive: boolean, opts?: Object): Object;
|
|
108
177
|
/**
|
|
109
178
|
* Recursively builds the Sbom from the JSON that npm listing returns
|
|
110
179
|
* @param {Sbom} sbom - The SBOM object to add dependencies to
|
|
111
180
|
* @param {Object} depTree - The current dependency tree
|
|
112
181
|
* @protected
|
|
113
182
|
*/
|
|
114
|
-
protected _addDependenciesToSbom(sbom: Sbom, depTree:
|
|
183
|
+
protected _addDependenciesToSbom(sbom: Sbom, depTree: Object): void;
|
|
115
184
|
/**
|
|
116
185
|
* Extracts root dependencies from the dependency tree
|
|
117
186
|
* @param {Object} depTree - The dependency tree object
|
|
118
187
|
* @returns {Map<string, PackageURL>} Map of dependency names to their PackageURL objects
|
|
119
188
|
* @protected
|
|
120
189
|
*/
|
|
121
|
-
protected _getRootDependencies(depTree:
|
|
190
|
+
protected _getRootDependencies(depTree: Object): Map<string, PackageURL>;
|
|
122
191
|
/**
|
|
123
192
|
* Gets the version of the package manager
|
|
124
193
|
* @returns {string} The version string of the package manager
|
|
@@ -126,6 +195,12 @@ export default class Base_javascript {
|
|
|
126
195
|
*/
|
|
127
196
|
protected _version(): string;
|
|
128
197
|
/**
|
|
198
|
+
* Creates or updates the lock file for the package manager
|
|
199
|
+
* @param {string} manifestDir - Directory containing the manifest file
|
|
200
|
+
* @protected
|
|
201
|
+
*/
|
|
202
|
+
protected _createLockFile(manifestDir: string): void;
|
|
203
|
+
/**
|
|
129
204
|
* Parses the dependency tree output
|
|
130
205
|
* @param {string} output - The output to parse
|
|
131
206
|
* @returns {string} The parsed output
|
|
@@ -134,6 +209,6 @@ export default class Base_javascript {
|
|
|
134
209
|
protected _parseDepTreeOutput(output: string): string;
|
|
135
210
|
#private;
|
|
136
211
|
}
|
|
137
|
-
export type Provided =
|
|
212
|
+
export type Provided = any;
|
|
138
213
|
import Manifest from './manifest.js';
|
|
139
214
|
import Sbom from '../sbom.js';
|
|
@@ -12,6 +12,49 @@ import Manifest from './manifest.js';
|
|
|
12
12
|
* @type {string}
|
|
13
13
|
*/
|
|
14
14
|
export const purlType = 'npm';
|
|
15
|
+
/**
|
|
16
|
+
* Maps a Subresource Integrity (SRI) algorithm token to its CycloneDX label.
|
|
17
|
+
* @type {Object<string, string>}
|
|
18
|
+
*/
|
|
19
|
+
const SRI_ALG_LABELS = {
|
|
20
|
+
sha1: 'SHA-1',
|
|
21
|
+
sha256: 'SHA-256',
|
|
22
|
+
sha384: 'SHA-384',
|
|
23
|
+
sha512: 'SHA-512',
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Converts a Subresource Integrity (SRI) string to a CycloneDX hash object.
|
|
27
|
+
* SRI is formatted as `<alg>-<base64>` (e.g. `sha512-Ab3d...`). CycloneDX
|
|
28
|
+
* expects an uppercased algorithm label (e.g. `SHA-512`) and a hex-encoded
|
|
29
|
+
* digest. When the SRI string contains multiple space-separated hashes, only
|
|
30
|
+
* the first is used.
|
|
31
|
+
* @param {string} integrity - SRI string from a lock file
|
|
32
|
+
* @returns {{alg: string, content: string}|null} CycloneDX hash, or null when unparseable
|
|
33
|
+
*/
|
|
34
|
+
export function sriToHash(integrity) {
|
|
35
|
+
if (typeof integrity !== 'string') {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const first = integrity.trim().split(/\s+/)[0];
|
|
39
|
+
if (!first) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const dash = first.indexOf('-');
|
|
43
|
+
if (dash < 0) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const alg = SRI_ALG_LABELS[first.slice(0, dash).toLowerCase()];
|
|
47
|
+
// Strip any SRI options (e.g. "?foo") that may follow the base64 payload
|
|
48
|
+
const base64 = first.slice(dash + 1).split('?')[0];
|
|
49
|
+
if (!alg || !base64) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const content = Buffer.from(base64, 'base64').toString('hex');
|
|
53
|
+
if (!content) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return { alg, content };
|
|
57
|
+
}
|
|
15
58
|
/**
|
|
16
59
|
* Base class for JavaScript package manager providers.
|
|
17
60
|
* This class provides common functionality for different JavaScript package managers
|
|
@@ -25,6 +68,11 @@ export default class Base_javascript {
|
|
|
25
68
|
#cmd;
|
|
26
69
|
/** @type {string} */
|
|
27
70
|
#ecosystem;
|
|
71
|
+
/**
|
|
72
|
+
* Lock-file hashes keyed by `name@version`.
|
|
73
|
+
* @type {Map<string, Array<{alg: string, content: string}>>}
|
|
74
|
+
*/
|
|
75
|
+
#hashes = new Map();
|
|
28
76
|
/**
|
|
29
77
|
* Sets up the provider with the manifest path and options
|
|
30
78
|
* @param {string} manifestPath - Path to the package.json manifest file
|
|
@@ -71,6 +119,13 @@ export default class Base_javascript {
|
|
|
71
119
|
throw new TypeError("_cmdName must be implemented");
|
|
72
120
|
}
|
|
73
121
|
/**
|
|
122
|
+
* Returns the package manager name (e.g. npm, yarn, pnpm, bun)
|
|
123
|
+
* @returns {string} The package manager name
|
|
124
|
+
*/
|
|
125
|
+
packageManagerName() {
|
|
126
|
+
return this._cmdName();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
74
129
|
* Returns the command arguments for listing dependencies
|
|
75
130
|
* @returns {Array<string>} The command arguments
|
|
76
131
|
* @abstract
|
|
@@ -88,6 +143,58 @@ export default class Base_javascript {
|
|
|
88
143
|
_updateLockFileCmdArgs() {
|
|
89
144
|
throw new TypeError("_updateLockFileCmdArgs must be implemented");
|
|
90
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Parses the provider's lock file into a hash map keyed by `name@version`.
|
|
148
|
+
* Subclasses override this (accepting the lock directory) to support their
|
|
149
|
+
* lock file format. The default implementation returns an empty map so
|
|
150
|
+
* providers without lock parsing (or without a lock file present) gracefully
|
|
151
|
+
* omit hashes.
|
|
152
|
+
* @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
|
|
153
|
+
* @protected
|
|
154
|
+
*/
|
|
155
|
+
_parseLockFileHashes() {
|
|
156
|
+
return new Map();
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Loads lock-file hashes for the given directory into internal state.
|
|
160
|
+
* Parsing failures degrade gracefully to an empty map (no hashes emitted).
|
|
161
|
+
* @param {string} lockDir - Directory containing the lock file
|
|
162
|
+
* @protected
|
|
163
|
+
*/
|
|
164
|
+
_loadHashes(lockDir) {
|
|
165
|
+
try {
|
|
166
|
+
this.#hashes = this._parseLockFileHashes(lockDir) || new Map();
|
|
167
|
+
}
|
|
168
|
+
catch (_) {
|
|
169
|
+
this.#hashes = new Map();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Looks up CycloneDX hashes for a package by name and resolved version.
|
|
174
|
+
* @param {string} name - The package name (including scope, e.g. `@hapi/joi`)
|
|
175
|
+
* @param {string} version - The resolved package version
|
|
176
|
+
* @returns {Array<{alg: string, content: string}>|undefined} Hashes, or undefined
|
|
177
|
+
* @protected
|
|
178
|
+
*/
|
|
179
|
+
_hashesFor(name, version) {
|
|
180
|
+
if (!name || !version) {
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
return this.#hashes.get(`${name}@${version}`);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Looks up CycloneDX hashes for a package described by a PackageURL.
|
|
187
|
+
* @param {PackageURL} purl - The package URL
|
|
188
|
+
* @returns {Array<{alg: string, content: string}>|undefined} Hashes, or undefined
|
|
189
|
+
* @protected
|
|
190
|
+
*/
|
|
191
|
+
_hashesForPurl(purl) {
|
|
192
|
+
if (!purl) {
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
const name = purl.namespace ? `${purl.namespace}/${purl.name}` : purl.name;
|
|
196
|
+
return this._hashesFor(name, purl.version);
|
|
197
|
+
}
|
|
91
198
|
/**
|
|
92
199
|
* Checks if the provider supports the given manifest name
|
|
93
200
|
* @param {string} manifestName - The manifest name to check
|
|
@@ -97,18 +204,63 @@ export default class Base_javascript {
|
|
|
97
204
|
return 'package.json' === manifestName;
|
|
98
205
|
}
|
|
99
206
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
207
|
+
* Walks up the directory tree from manifestDir looking for the lock file.
|
|
208
|
+
* Stops when the lock file is found, when a package.json with a "workspaces"
|
|
209
|
+
* field is encountered without a lock file (workspace root boundary), or
|
|
210
|
+
* when the filesystem root is reached.
|
|
211
|
+
*
|
|
212
|
+
* When TRUSTIFY_DA_WORKSPACE_DIR is set, checks only that directory (no walk-up).
|
|
213
|
+
*
|
|
214
|
+
* @param {string} manifestDir - The directory to start searching from
|
|
215
|
+
* @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
|
|
216
|
+
* @returns {string|null} The directory containing the lock file, or null
|
|
217
|
+
* @protected
|
|
218
|
+
*/
|
|
219
|
+
_isWorkspaceRoot(dir) {
|
|
220
|
+
if (fs.existsSync(path.join(dir, 'pnpm-workspace.yaml'))) {
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
const pkgJsonPath = path.join(dir, 'package.json');
|
|
224
|
+
if (fs.existsSync(pkgJsonPath)) {
|
|
225
|
+
try {
|
|
226
|
+
const content = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
|
|
227
|
+
if (content.workspaces) {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
catch (_) {
|
|
232
|
+
// ignore parse errors
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
_findLockFileDir(manifestDir, opts = {}) {
|
|
238
|
+
const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts);
|
|
239
|
+
if (workspaceDir) {
|
|
240
|
+
const dir = path.resolve(workspaceDir);
|
|
241
|
+
return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
|
|
242
|
+
}
|
|
243
|
+
let dir = path.resolve(manifestDir);
|
|
244
|
+
let parent = dir;
|
|
245
|
+
do {
|
|
246
|
+
dir = parent;
|
|
247
|
+
if (fs.existsSync(path.join(dir, this._lockFileName()))) {
|
|
248
|
+
return dir;
|
|
249
|
+
}
|
|
250
|
+
if (this._isWorkspaceRoot(dir)) {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
parent = path.dirname(dir);
|
|
254
|
+
} while (parent !== dir);
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
103
258
|
* @param {string} manifestDir - The base directory where the manifest is located
|
|
104
|
-
* @param {
|
|
259
|
+
* @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
|
|
105
260
|
* @returns {boolean} True if the lock file exists
|
|
106
261
|
*/
|
|
107
262
|
validateLockFile(manifestDir, opts = {}) {
|
|
108
|
-
|
|
109
|
-
const dirToCheck = workspaceDir ? path.resolve(workspaceDir) : manifestDir;
|
|
110
|
-
const lock = path.join(dirToCheck, this._lockFileName());
|
|
111
|
-
return fs.existsSync(lock);
|
|
263
|
+
return this._findLockFileDir(manifestDir, opts) !== null;
|
|
112
264
|
}
|
|
113
265
|
/**
|
|
114
266
|
* Provides content and content type for stack analysis
|
|
@@ -171,9 +323,9 @@ export default class Base_javascript {
|
|
|
171
323
|
_buildDependencyTree(includeTransitive, opts = {}) {
|
|
172
324
|
this._version();
|
|
173
325
|
const manifestDir = path.dirname(this.#manifest.manifestPath);
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
this
|
|
326
|
+
const cmdDir = this._findLockFileDir(manifestDir, opts) || manifestDir;
|
|
327
|
+
this._createLockFile(cmdDir);
|
|
328
|
+
this._loadHashes(cmdDir);
|
|
177
329
|
let output = this.#executeListCmd(includeTransitive, cmdDir);
|
|
178
330
|
output = this._parseDepTreeOutput(output);
|
|
179
331
|
return JSON.parse(output);
|
|
@@ -191,9 +343,32 @@ export default class Base_javascript {
|
|
|
191
343
|
let sbom = new Sbom();
|
|
192
344
|
sbom.addRoot(mainComponent, license);
|
|
193
345
|
this._addDependenciesToSbom(sbom, depsObject);
|
|
346
|
+
this.#ensurePeerAndOptionalDeps(sbom);
|
|
194
347
|
sbom.filterIgnoredDeps(this.#manifest.ignored);
|
|
195
348
|
return sbom.getAsJsonString(opts);
|
|
196
349
|
}
|
|
350
|
+
/**
|
|
351
|
+
* Ensures peer and optional dependencies declared in the manifest are
|
|
352
|
+
* present in the SBOM, even when the package manager does not resolve them
|
|
353
|
+
* (e.g. yarn does not include peer deps in its dependency listing).
|
|
354
|
+
* @param {Sbom} sbom - The SBOM to supplement
|
|
355
|
+
* @private
|
|
356
|
+
*/
|
|
357
|
+
#ensurePeerAndOptionalDeps(sbom) {
|
|
358
|
+
const rootPurl = toPurl(purlType, this.#manifest.name, this.#manifest.version);
|
|
359
|
+
const depSources = [this.#manifest.peerDependencies, this.#manifest.optionalDependencies];
|
|
360
|
+
for (const source of depSources) {
|
|
361
|
+
for (const [name, version] of Object.entries(source)) {
|
|
362
|
+
// Build the purl prefix for exact matching (e.g. "pkg:npm/minimist@"
|
|
363
|
+
// or "pkg:npm/%40hapi/joi@") to avoid substring false positives
|
|
364
|
+
const probe = toPurl(purlType, name, version);
|
|
365
|
+
const purlPrefix = probe.toString().replace(/@[^@]*$/, '@');
|
|
366
|
+
if (!sbom.checkDependsOnByPurlPrefix(rootPurl, purlPrefix)) {
|
|
367
|
+
sbom.addDependency(rootPurl, probe);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
197
372
|
/**
|
|
198
373
|
* Recursively builds the Sbom from the JSON that npm listing returns
|
|
199
374
|
* @param {Sbom} sbom - The SBOM object to add dependencies to
|
|
@@ -201,13 +376,16 @@ export default class Base_javascript {
|
|
|
201
376
|
* @protected
|
|
202
377
|
*/
|
|
203
378
|
_addDependenciesToSbom(sbom, depTree) {
|
|
204
|
-
const dependencies =
|
|
379
|
+
const dependencies = {
|
|
380
|
+
...depTree["dependencies"],
|
|
381
|
+
...depTree["optionalDependencies"],
|
|
382
|
+
};
|
|
205
383
|
Object.entries(dependencies)
|
|
206
384
|
.forEach(entry => {
|
|
207
385
|
const [name, artifact] = entry;
|
|
208
386
|
const target = toPurl(purlType, name, artifact.version);
|
|
209
387
|
const rootPurl = toPurl(purlType, this.#manifest.name, this.#manifest.version);
|
|
210
|
-
sbom.addDependency(rootPurl, target);
|
|
388
|
+
sbom.addDependency(rootPurl, target, undefined, this._hashesFor(name, artifact.version));
|
|
211
389
|
this.#addDependenciesOf(sbom, target, artifact);
|
|
212
390
|
});
|
|
213
391
|
}
|
|
@@ -225,7 +403,7 @@ export default class Base_javascript {
|
|
|
225
403
|
const [name, depArtifact] = entry;
|
|
226
404
|
if (depArtifact.version !== undefined) {
|
|
227
405
|
const target = toPurl(purlType, name, depArtifact.version);
|
|
228
|
-
sbom.addDependency(from, target);
|
|
406
|
+
sbom.addDependency(from, target, undefined, this._hashesFor(name, depArtifact.version));
|
|
229
407
|
this.#addDependenciesOf(sbom, target, depArtifact);
|
|
230
408
|
}
|
|
231
409
|
});
|
|
@@ -249,8 +427,10 @@ export default class Base_javascript {
|
|
|
249
427
|
.sort();
|
|
250
428
|
for (const key of sortedDepsKeys) {
|
|
251
429
|
const rootPurl = toPurlFromString(sbom.getRoot().purl);
|
|
252
|
-
|
|
430
|
+
const targetPurl = rootDeps.get(key);
|
|
431
|
+
sbom.addDependency(rootPurl, targetPurl, undefined, this._hashesForPurl(targetPurl));
|
|
253
432
|
}
|
|
433
|
+
this.#ensurePeerAndOptionalDeps(sbom);
|
|
254
434
|
sbom.filterIgnoredDeps(this.#manifest.ignored);
|
|
255
435
|
return sbom.getAsJsonString(opts);
|
|
256
436
|
}
|
|
@@ -261,10 +441,14 @@ export default class Base_javascript {
|
|
|
261
441
|
* @protected
|
|
262
442
|
*/
|
|
263
443
|
_getRootDependencies(depTree) {
|
|
264
|
-
|
|
444
|
+
const allDeps = {
|
|
445
|
+
...depTree.dependencies,
|
|
446
|
+
...depTree.optionalDependencies,
|
|
447
|
+
};
|
|
448
|
+
if (Object.keys(allDeps).length === 0) {
|
|
265
449
|
return new Map();
|
|
266
450
|
}
|
|
267
|
-
return new Map(Object.entries(
|
|
451
|
+
return new Map(Object.entries(allDeps).map(([key, value]) => [key, toPurl(purlType, key, value.version)]));
|
|
268
452
|
}
|
|
269
453
|
/**
|
|
270
454
|
* Executes the list command to get dependencies
|
|
@@ -275,7 +459,7 @@ export default class Base_javascript {
|
|
|
275
459
|
*/
|
|
276
460
|
#executeListCmd(includeTransitive, manifestDir) {
|
|
277
461
|
const listArgs = this._listCmdArgs(includeTransitive, manifestDir);
|
|
278
|
-
return this.#invokeCommand(listArgs);
|
|
462
|
+
return this.#invokeCommand(listArgs, { cwd: manifestDir });
|
|
279
463
|
}
|
|
280
464
|
/**
|
|
281
465
|
* Gets the version of the package manager
|
|
@@ -288,19 +472,17 @@ export default class Base_javascript {
|
|
|
288
472
|
/**
|
|
289
473
|
* Creates or updates the lock file for the package manager
|
|
290
474
|
* @param {string} manifestDir - Directory containing the manifest file
|
|
291
|
-
* @
|
|
475
|
+
* @protected
|
|
292
476
|
*/
|
|
293
|
-
|
|
477
|
+
_createLockFile(manifestDir) {
|
|
294
478
|
const originalDir = process.cwd();
|
|
295
479
|
const isWindows = os.platform() === 'win32';
|
|
296
480
|
if (isWindows) {
|
|
297
|
-
// On Windows, --prefix flag doesn't work as expected
|
|
298
|
-
// Instead of installing from the prefix folder, it installs from current working directory
|
|
299
481
|
process.chdir(manifestDir);
|
|
300
482
|
}
|
|
301
483
|
try {
|
|
302
484
|
const args = this._updateLockFileCmdArgs(manifestDir);
|
|
303
|
-
this.#invokeCommand(args);
|
|
485
|
+
this.#invokeCommand(args, { cwd: manifestDir });
|
|
304
486
|
}
|
|
305
487
|
finally {
|
|
306
488
|
if (isWindows) {
|
|
@@ -350,7 +532,7 @@ export default class Base_javascript {
|
|
|
350
532
|
}
|
|
351
533
|
}
|
|
352
534
|
// Try to find the command in the following order:
|
|
353
|
-
// 1. Custom path from environment
|
|
535
|
+
// 1. Custom path from opts/environment (via getCustomPath)
|
|
354
536
|
// 2. Local node_modules/.bin
|
|
355
537
|
// 3. Global installation
|
|
356
538
|
let cmd = this.#cmd;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/** @typedef {{name: string, version: string, children: string[], hashes?: Array<{alg: string, content: string}>}} GraphEntry */
|
|
2
|
+
/** @typedef {{name: string, version: string, dependencies: DepTreeEntry[]}} DepTreeEntry */
|
|
3
|
+
/** @typedef {{directDeps: string[], graph: Map<string, GraphEntry>}} DependencyData */
|
|
4
|
+
/** @typedef {{ecosystem: string, content: string, contentType: string}} Provided */
|
|
5
|
+
export default class Base_pyproject {
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} manifestName
|
|
8
|
+
* @returns {boolean}
|
|
9
|
+
*/
|
|
10
|
+
isSupported(manifestName: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} manifestDir
|
|
13
|
+
* @param {Object} [opts={}]
|
|
14
|
+
* @returns {boolean}
|
|
15
|
+
*/
|
|
16
|
+
validateLockFile(manifestDir: string, opts?: Object): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Walk up from manifestDir to find the directory containing the lock file.
|
|
19
|
+
* Follows the same pattern as Base_javascript._findLockFileDir().
|
|
20
|
+
* @param {string} manifestDir
|
|
21
|
+
* @param {Object} [opts={}]
|
|
22
|
+
* @returns {string|null}
|
|
23
|
+
* @protected
|
|
24
|
+
*/
|
|
25
|
+
protected _findLockFileDir(manifestDir: string, opts?: Object): string | null;
|
|
26
|
+
/**
|
|
27
|
+
* Detect workspace root boundaries.
|
|
28
|
+
* Currently only uv has native workspace support ([tool.uv.workspace] in pyproject.toml).
|
|
29
|
+
* Poetry has no workspace/monorepo support (python-poetry/poetry#2270), so each
|
|
30
|
+
* poetry project is treated independently — see Python_poetry._findLockFileDir().
|
|
31
|
+
* @param {string} dir
|
|
32
|
+
* @returns {boolean}
|
|
33
|
+
* @protected
|
|
34
|
+
*/
|
|
35
|
+
protected _isWorkspaceRoot(dir: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Read project license from pyproject.toml, with fallback to LICENSE file.
|
|
38
|
+
* @param {string} manifestPath
|
|
39
|
+
* @returns {string|null}
|
|
40
|
+
*/
|
|
41
|
+
readLicenseFromManifest(manifestPath: string): string | null;
|
|
42
|
+
/**
|
|
43
|
+
* @param {string} manifest - path to pyproject.toml
|
|
44
|
+
* @param {Object} [opts={}]
|
|
45
|
+
* @returns {Promise<Provided>}
|
|
46
|
+
*/
|
|
47
|
+
provideStack(manifest: string, opts?: Object): Promise<Provided>;
|
|
48
|
+
/**
|
|
49
|
+
* @param {string} manifest - path to pyproject.toml
|
|
50
|
+
* @param {Object} [opts={}]
|
|
51
|
+
* @returns {Promise<Provided>}
|
|
52
|
+
*/
|
|
53
|
+
provideComponent(manifest: string, opts?: Object): Promise<Provided>;
|
|
54
|
+
/**
|
|
55
|
+
* @returns {string}
|
|
56
|
+
* @protected
|
|
57
|
+
*/
|
|
58
|
+
protected _lockFileName(): string;
|
|
59
|
+
/**
|
|
60
|
+
* @returns {string}
|
|
61
|
+
* @protected
|
|
62
|
+
*/
|
|
63
|
+
protected _cmdName(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the package manager name (e.g. pip, poetry, uv)
|
|
66
|
+
* @returns {string}
|
|
67
|
+
*/
|
|
68
|
+
packageManagerName(): string;
|
|
69
|
+
/**
|
|
70
|
+
* Resolve dependencies using the tool-specific command and parser.
|
|
71
|
+
*
|
|
72
|
+
* @param {string} manifestDir - directory containing the target pyproject.toml
|
|
73
|
+
* @param {string} workspaceDir - workspace root (where the lock file lives);
|
|
74
|
+
* only used by providers that need workspace-level resolution (e.g. uv)
|
|
75
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
76
|
+
* @param {Object} opts
|
|
77
|
+
* @returns {Promise<DependencyData>}
|
|
78
|
+
* @protected
|
|
79
|
+
*/
|
|
80
|
+
protected _getDependencyData(manifestDir: string, workspaceDir: string, parsed: object, opts: Object): Promise<DependencyData>;
|
|
81
|
+
/**
|
|
82
|
+
* Canonicalize a Python package name per PEP 503.
|
|
83
|
+
* @param {string} name
|
|
84
|
+
* @returns {string}
|
|
85
|
+
* @protected
|
|
86
|
+
*/
|
|
87
|
+
protected _canonicalize(name: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Get the project name from pyproject.toml.
|
|
90
|
+
* @param {object} parsed
|
|
91
|
+
* @returns {string|null}
|
|
92
|
+
* @protected
|
|
93
|
+
*/
|
|
94
|
+
protected _getProjectName(parsed: object): string | null;
|
|
95
|
+
/**
|
|
96
|
+
* Get the project version from pyproject.toml.
|
|
97
|
+
* @param {object} parsed
|
|
98
|
+
* @returns {string|null}
|
|
99
|
+
* @protected
|
|
100
|
+
*/
|
|
101
|
+
protected _getProjectVersion(parsed: object): string | null;
|
|
102
|
+
/**
|
|
103
|
+
* Scan raw pyproject.toml text for dependencies with ignore markers.
|
|
104
|
+
* @param {string} manifestPath
|
|
105
|
+
* @returns {Set<string>}
|
|
106
|
+
* @protected
|
|
107
|
+
*/
|
|
108
|
+
protected _getIgnoredDeps(manifestPath: string): Set<string>;
|
|
109
|
+
/**
|
|
110
|
+
* Compute the set of graph nodes reachable from direct deps, excluding ignored.
|
|
111
|
+
* @param {Map<string, GraphEntry>} graph
|
|
112
|
+
* @param {string[]} directDeps
|
|
113
|
+
* @param {Set<string>} ignoredDeps
|
|
114
|
+
* @returns {Set<string>}
|
|
115
|
+
* @protected
|
|
116
|
+
*/
|
|
117
|
+
protected _reachableNodes(graph: Map<string, GraphEntry>, directDeps: string[], ignoredDeps: Set<string>): Set<string>;
|
|
118
|
+
/**
|
|
119
|
+
* @param {string} name
|
|
120
|
+
* @param {string} version
|
|
121
|
+
* @returns {PackageURL}
|
|
122
|
+
* @protected
|
|
123
|
+
*/
|
|
124
|
+
protected _toPurl(name: string, version: string): PackageURL;
|
|
125
|
+
/**
|
|
126
|
+
* Create SBOM json string for a pyproject.toml project.
|
|
127
|
+
* @param {string} manifest - path to pyproject.toml
|
|
128
|
+
* @param {Object} opts
|
|
129
|
+
* @param {boolean} includeTransitive
|
|
130
|
+
* @returns {Promise<string>}
|
|
131
|
+
* @private
|
|
132
|
+
*/
|
|
133
|
+
private _createSbom;
|
|
134
|
+
}
|
|
135
|
+
export type GraphEntry = {
|
|
136
|
+
name: string;
|
|
137
|
+
version: string;
|
|
138
|
+
children: string[];
|
|
139
|
+
hashes?: Array<{
|
|
140
|
+
alg: string;
|
|
141
|
+
content: string;
|
|
142
|
+
}>;
|
|
143
|
+
};
|
|
144
|
+
export type DepTreeEntry = {
|
|
145
|
+
name: string;
|
|
146
|
+
version: string;
|
|
147
|
+
dependencies: DepTreeEntry[];
|
|
148
|
+
};
|
|
149
|
+
export type DependencyData = {
|
|
150
|
+
directDeps: string[];
|
|
151
|
+
graph: Map<string, GraphEntry>;
|
|
152
|
+
};
|
|
153
|
+
export type Provided = {
|
|
154
|
+
ecosystem: string;
|
|
155
|
+
content: string;
|
|
156
|
+
contentType: string;
|
|
157
|
+
};
|
|
158
|
+
import { PackageURL } from 'packageurl-js';
|