@trustify-da/trustify-da-javascript-client 0.3.0-ea.e12bc82 → 0.3.0-ea.e348975
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 +193 -13
- package/dist/package.json +43 -27
- package/dist/src/analysis.d.ts +28 -5
- package/dist/src/analysis.js +99 -89
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +346 -9
- package/dist/src/cyclone_dx_sbom.d.ts +17 -3
- package/dist/src/cyclone_dx_sbom.js +56 -8
- package/dist/src/index.d.ts +202 -12
- package/dist/src/index.js +361 -9
- package/dist/src/license/index.d.ts +28 -0
- package/dist/src/license/index.js +103 -0
- package/dist/src/license/license_utils.d.ts +40 -0
- package/dist/src/license/license_utils.js +137 -0
- package/dist/src/license/licenses_api.d.ts +34 -0
- package/dist/src/license/licenses_api.js +98 -0
- package/dist/src/license/project_license.d.ts +20 -0
- package/dist/src/license/project_license.js +62 -0
- package/dist/src/oci_image/images.d.ts +4 -5
- package/dist/src/oci_image/images.js +15 -1
- package/dist/src/oci_image/utils.d.ts +7 -7
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/provider.d.ts +18 -5
- package/dist/src/provider.js +33 -5
- package/dist/src/providers/base_java.d.ts +15 -15
- package/dist/src/providers/base_java.js +18 -44
- package/dist/src/providers/base_javascript.d.ts +45 -12
- package/dist/src/providers/base_javascript.js +138 -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 +30 -13
- package/dist/src/providers/golang_gomodules.js +176 -121
- 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 +28 -3
- package/dist/src/providers/java_gradle.js +128 -4
- 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 +20 -5
- package/dist/src/providers/java_maven.js +198 -6
- package/dist/src/providers/javascript_bun.d.ts +10 -0
- package/dist/src/providers/javascript_bun.js +100 -0
- package/dist/src/providers/javascript_npm.d.ts +6 -0
- package/dist/src/providers/javascript_npm.js +21 -0
- package/dist/src/providers/javascript_pnpm.d.ts +1 -1
- package/dist/src/providers/javascript_pnpm.js +8 -4
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +22 -4
- 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 +2 -2
- package/dist/src/providers/processors/yarn_berry_processor.js +88 -5
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +2 -2
- package/dist/src/providers/python_controller.d.ts +10 -3
- package/dist/src/providers/python_controller.js +122 -63
- package/dist/src/providers/python_pip.d.ts +16 -4
- package/dist/src/providers/python_pip.js +51 -58
- 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 +269 -0
- package/dist/src/providers/requirements_parser.d.ts +6 -0
- package/dist/src/providers/requirements_parser.js +24 -0
- package/dist/src/providers/rust_cargo.d.ts +56 -0
- package/dist/src/providers/rust_cargo.js +641 -0
- package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
- package/dist/src/remediate.d.ts +21 -0
- package/dist/src/remediate.js +149 -0
- package/dist/src/remediation.d.ts +57 -0
- package/dist/src/remediation.js +436 -0
- package/dist/src/remediation_report.d.ts +40 -0
- package/dist/src/remediation_report.js +159 -0
- package/dist/src/sbom.d.ts +17 -2
- package/dist/src/sbom.js +16 -4
- package/dist/src/tools.d.ts +48 -6
- package/dist/src/tools.js +114 -1
- package/dist/src/updaters/maven_updater.d.ts +26 -0
- package/dist/src/updaters/maven_updater.js +322 -0
- package/dist/src/updaters/toml_updater.d.ts +33 -0
- package/dist/src/updaters/toml_updater.js +244 -0
- package/dist/src/workspace.d.ts +70 -0
- package/dist/src/workspace.js +256 -0
- package/package.json +44 -28
package/dist/src/cli.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
2
3
|
import * as path from "path";
|
|
3
4
|
import yargs from 'yargs';
|
|
4
5
|
import { hideBin } from 'yargs/helpers';
|
|
5
|
-
import
|
|
6
|
+
import { getProjectLicense, getLicenseDetails } from './license/index.js';
|
|
7
|
+
import { runRemediation } from './remediate.js';
|
|
8
|
+
import client, { selectTrustifyDABackend, generateSbom } from './index.js';
|
|
6
9
|
// command for component analysis take manifest type and content
|
|
7
10
|
const component = {
|
|
8
11
|
command: 'component </path/to/manifest>',
|
|
@@ -11,10 +14,32 @@ const component = {
|
|
|
11
14
|
desc: 'manifest path for analyzing',
|
|
12
15
|
type: 'string',
|
|
13
16
|
normalize: true,
|
|
17
|
+
}).options({
|
|
18
|
+
workspaceDir: {
|
|
19
|
+
alias: 'w',
|
|
20
|
+
desc: 'Workspace root directory (for monorepos; lock file is expected here)',
|
|
21
|
+
type: 'string',
|
|
22
|
+
normalize: true,
|
|
23
|
+
},
|
|
24
|
+
providers: {
|
|
25
|
+
desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
|
|
26
|
+
type: 'string',
|
|
27
|
+
},
|
|
28
|
+
sources: {
|
|
29
|
+
desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
|
|
30
|
+
type: 'string',
|
|
31
|
+
}
|
|
14
32
|
}),
|
|
15
33
|
handler: async (args) => {
|
|
16
34
|
let manifestName = args['/path/to/manifest'];
|
|
17
|
-
|
|
35
|
+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
|
|
36
|
+
if (args.providers) {
|
|
37
|
+
opts.TRUSTIFY_DA_PROVIDERS = args.providers;
|
|
38
|
+
}
|
|
39
|
+
if (args.sources) {
|
|
40
|
+
opts.TRUSTIFY_DA_SOURCES = args.sources;
|
|
41
|
+
}
|
|
42
|
+
let res = await client.componentAnalysis(manifestName, opts);
|
|
18
43
|
console.log(JSON.stringify(res, null, 2));
|
|
19
44
|
}
|
|
20
45
|
};
|
|
@@ -22,9 +47,8 @@ const validateToken = {
|
|
|
22
47
|
command: 'validate-token <token-provider> [--token-value thevalue]',
|
|
23
48
|
desc: 'Validates input token if authentic and authorized',
|
|
24
49
|
builder: yargs => yargs.positional('token-provider', {
|
|
25
|
-
desc: 'the token provider',
|
|
26
|
-
type: 'string'
|
|
27
|
-
choices: ['snyk', 'oss-index'],
|
|
50
|
+
desc: 'the token provider name',
|
|
51
|
+
type: 'string'
|
|
28
52
|
}).options({
|
|
29
53
|
tokenValue: {
|
|
30
54
|
alias: 'value',
|
|
@@ -37,7 +61,7 @@ const validateToken = {
|
|
|
37
61
|
let opts = {};
|
|
38
62
|
if (args['tokenValue'] !== undefined && args['tokenValue'].trim() !== "") {
|
|
39
63
|
let tokenValue = args['tokenValue'].trim();
|
|
40
|
-
opts[`
|
|
64
|
+
opts[`TRUSTIFY_DA_PROVIDER_${tokenProvider}_TOKEN`] = tokenValue;
|
|
41
65
|
}
|
|
42
66
|
let res = await client.validateToken(opts);
|
|
43
67
|
console.log(res);
|
|
@@ -63,6 +87,14 @@ const image = {
|
|
|
63
87
|
desc: 'For JSON report, get only the \'summary\'',
|
|
64
88
|
type: 'boolean',
|
|
65
89
|
conflicts: 'html'
|
|
90
|
+
},
|
|
91
|
+
providers: {
|
|
92
|
+
desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
|
|
93
|
+
type: 'string',
|
|
94
|
+
},
|
|
95
|
+
sources: {
|
|
96
|
+
desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
|
|
97
|
+
type: 'string',
|
|
66
98
|
}
|
|
67
99
|
}),
|
|
68
100
|
handler: async (args) => {
|
|
@@ -72,7 +104,14 @@ const image = {
|
|
|
72
104
|
}
|
|
73
105
|
let html = args['html'];
|
|
74
106
|
let summary = args['summary'];
|
|
75
|
-
|
|
107
|
+
const opts = {};
|
|
108
|
+
if (args.providers) {
|
|
109
|
+
opts.TRUSTIFY_DA_PROVIDERS = args.providers;
|
|
110
|
+
}
|
|
111
|
+
if (args.sources) {
|
|
112
|
+
opts.TRUSTIFY_DA_SOURCES = args.sources;
|
|
113
|
+
}
|
|
114
|
+
let res = await client.imageAnalysis(imageRefs, html, opts);
|
|
76
115
|
if (summary && !html) {
|
|
77
116
|
let summaries = {};
|
|
78
117
|
for (let [imageRef, report] of Object.entries(res)) {
|
|
@@ -117,15 +156,36 @@ const stack = {
|
|
|
117
156
|
desc: 'For JSON report, get only the \'summary\'',
|
|
118
157
|
type: 'boolean',
|
|
119
158
|
conflicts: 'html'
|
|
159
|
+
},
|
|
160
|
+
workspaceDir: {
|
|
161
|
+
alias: 'w',
|
|
162
|
+
desc: 'Workspace root directory (for monorepos; lock file is expected here)',
|
|
163
|
+
type: 'string',
|
|
164
|
+
normalize: true,
|
|
165
|
+
},
|
|
166
|
+
providers: {
|
|
167
|
+
desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
|
|
168
|
+
type: 'string',
|
|
169
|
+
},
|
|
170
|
+
sources: {
|
|
171
|
+
desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
|
|
172
|
+
type: 'string',
|
|
120
173
|
}
|
|
121
174
|
}),
|
|
122
175
|
handler: async (args) => {
|
|
123
176
|
let manifest = args['/path/to/manifest'];
|
|
124
177
|
let html = args['html'];
|
|
125
178
|
let summary = args['summary'];
|
|
179
|
+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
|
|
180
|
+
if (args.providers) {
|
|
181
|
+
opts.TRUSTIFY_DA_PROVIDERS = args.providers;
|
|
182
|
+
}
|
|
183
|
+
if (args.sources) {
|
|
184
|
+
opts.TRUSTIFY_DA_SOURCES = args.sources;
|
|
185
|
+
}
|
|
126
186
|
let theProvidersSummary = new Map();
|
|
127
187
|
let theProvidersObject = {};
|
|
128
|
-
let res = await client.stackAnalysis(manifest, html);
|
|
188
|
+
let res = await client.stackAnalysis(manifest, html, opts);
|
|
129
189
|
if (summary) {
|
|
130
190
|
for (let provider in res.providers) {
|
|
131
191
|
if (res.providers[provider].sources !== undefined) {
|
|
@@ -143,13 +203,290 @@ const stack = {
|
|
|
143
203
|
console.log(html ? res : JSON.stringify(!html && summary ? theProvidersObject : res, null, 2));
|
|
144
204
|
}
|
|
145
205
|
};
|
|
206
|
+
// command for batch stack analysis (workspace)
|
|
207
|
+
const stackBatch = {
|
|
208
|
+
command: 'stack-batch </path/to/workspace-root> [--html|--summary] [--concurrency <n>] [--ignore <pattern>...] [--metadata] [--fail-fast]',
|
|
209
|
+
desc: 'produce stack report for all packages/crates in a workspace (Cargo or JS/TS)',
|
|
210
|
+
builder: yargs => yargs.positional('/path/to/workspace-root', {
|
|
211
|
+
desc: 'workspace root directory (containing Cargo.toml+Cargo.lock or package.json+lock file)',
|
|
212
|
+
type: 'string',
|
|
213
|
+
normalize: true,
|
|
214
|
+
}).options({
|
|
215
|
+
html: {
|
|
216
|
+
alias: 'r',
|
|
217
|
+
desc: 'Get the report as HTML instead of JSON',
|
|
218
|
+
type: 'boolean',
|
|
219
|
+
conflicts: 'summary'
|
|
220
|
+
},
|
|
221
|
+
summary: {
|
|
222
|
+
alias: 's',
|
|
223
|
+
desc: 'For JSON report, get only the \'summary\' per package',
|
|
224
|
+
type: 'boolean',
|
|
225
|
+
conflicts: 'html'
|
|
226
|
+
},
|
|
227
|
+
concurrency: {
|
|
228
|
+
alias: 'c',
|
|
229
|
+
desc: 'Max parallel SBOM generations (default: 10, env: TRUSTIFY_DA_BATCH_CONCURRENCY)',
|
|
230
|
+
type: 'number',
|
|
231
|
+
},
|
|
232
|
+
ignore: {
|
|
233
|
+
alias: 'i',
|
|
234
|
+
desc: 'Extra glob patterns excluded from workspace discovery (merged with defaults). Repeat flag per pattern. Env: TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE (comma-separated)',
|
|
235
|
+
type: 'string',
|
|
236
|
+
array: true,
|
|
237
|
+
},
|
|
238
|
+
metadata: {
|
|
239
|
+
alias: 'm',
|
|
240
|
+
desc: 'Return { analysis, metadata } with per-manifest errors (env: TRUSTIFY_DA_BATCH_METADATA=true)',
|
|
241
|
+
type: 'boolean',
|
|
242
|
+
default: false,
|
|
243
|
+
},
|
|
244
|
+
failFast: {
|
|
245
|
+
desc: 'Stop on first invalid package.json or SBOM error (env: TRUSTIFY_DA_CONTINUE_ON_ERROR=false)',
|
|
246
|
+
type: 'boolean',
|
|
247
|
+
default: false,
|
|
248
|
+
},
|
|
249
|
+
providers: {
|
|
250
|
+
desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
|
|
251
|
+
type: 'string',
|
|
252
|
+
},
|
|
253
|
+
sources: {
|
|
254
|
+
desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
|
|
255
|
+
type: 'string',
|
|
256
|
+
}
|
|
257
|
+
}),
|
|
258
|
+
handler: async (args) => {
|
|
259
|
+
const workspaceRoot = args['/path/to/workspace-root'];
|
|
260
|
+
const html = args['html'];
|
|
261
|
+
const summary = args['summary'];
|
|
262
|
+
const opts = {};
|
|
263
|
+
if (args.concurrency != null) {
|
|
264
|
+
opts.batchConcurrency = args.concurrency;
|
|
265
|
+
}
|
|
266
|
+
const extraIgnores = Array.isArray(args.ignore) ? args.ignore.filter(p => p != null && String(p).trim()) : [];
|
|
267
|
+
if (extraIgnores.length > 0) {
|
|
268
|
+
opts.workspaceDiscoveryIgnore = extraIgnores;
|
|
269
|
+
}
|
|
270
|
+
if (args.metadata) {
|
|
271
|
+
opts.batchMetadata = true;
|
|
272
|
+
}
|
|
273
|
+
if (args.failFast) {
|
|
274
|
+
opts.continueOnError = false;
|
|
275
|
+
}
|
|
276
|
+
if (args.providers) {
|
|
277
|
+
opts.TRUSTIFY_DA_PROVIDERS = args.providers;
|
|
278
|
+
}
|
|
279
|
+
if (args.sources) {
|
|
280
|
+
opts.TRUSTIFY_DA_SOURCES = args.sources;
|
|
281
|
+
}
|
|
282
|
+
let res = await client.stackAnalysisBatch(workspaceRoot, html, opts);
|
|
283
|
+
const batchAnalysis = res && typeof res === 'object' && res != null && 'analysis' in res ? res.analysis : res;
|
|
284
|
+
if (summary && !html && typeof batchAnalysis === 'object') {
|
|
285
|
+
const summaries = {};
|
|
286
|
+
for (const [purl, report] of Object.entries(batchAnalysis)) {
|
|
287
|
+
if (report?.providers) {
|
|
288
|
+
for (const provider of Object.keys(report.providers)) {
|
|
289
|
+
const sources = report.providers[provider]?.sources;
|
|
290
|
+
if (sources) {
|
|
291
|
+
for (const [source, data] of Object.entries(sources)) {
|
|
292
|
+
if (data?.summary) {
|
|
293
|
+
if (!summaries[purl]) {
|
|
294
|
+
summaries[purl] = {};
|
|
295
|
+
}
|
|
296
|
+
if (!summaries[purl][provider]) {
|
|
297
|
+
summaries[purl][provider] = {};
|
|
298
|
+
}
|
|
299
|
+
summaries[purl][provider][source] = data.summary;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (res && typeof res === 'object' && res != null && 'metadata' in res) {
|
|
307
|
+
res = { analysis: summaries, metadata: res.metadata };
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
res = summaries;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (html) {
|
|
314
|
+
const htmlContent = res && typeof res === 'object' && 'analysis' in res ? res.analysis : res;
|
|
315
|
+
console.log(htmlContent);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
console.log(JSON.stringify(res, null, 2));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
// command for license checking
|
|
323
|
+
const license = {
|
|
324
|
+
command: 'license </path/to/manifest>',
|
|
325
|
+
desc: 'Display project license information from manifest and LICENSE file in JSON format',
|
|
326
|
+
builder: yargs => yargs.positional('/path/to/manifest', {
|
|
327
|
+
desc: 'manifest path for license analysis',
|
|
328
|
+
type: 'string',
|
|
329
|
+
normalize: true,
|
|
330
|
+
}),
|
|
331
|
+
handler: async (args) => {
|
|
332
|
+
let manifestPath = args['/path/to/manifest'];
|
|
333
|
+
const opts = {}; // CLI options can be extended in the future
|
|
334
|
+
try {
|
|
335
|
+
selectTrustifyDABackend(opts);
|
|
336
|
+
}
|
|
337
|
+
catch (err) {
|
|
338
|
+
console.error(JSON.stringify({ error: err.message }, null, 2));
|
|
339
|
+
process.exit(1);
|
|
340
|
+
}
|
|
341
|
+
let localResult;
|
|
342
|
+
try {
|
|
343
|
+
localResult = getProjectLicense(manifestPath);
|
|
344
|
+
}
|
|
345
|
+
catch (err) {
|
|
346
|
+
console.error(JSON.stringify({ error: `Failed to read manifest: ${err.message}` }, null, 2));
|
|
347
|
+
process.exit(1);
|
|
348
|
+
}
|
|
349
|
+
const errors = [];
|
|
350
|
+
// Build LicenseInfo objects
|
|
351
|
+
const buildLicenseInfo = async (spdxId) => {
|
|
352
|
+
if (!spdxId) {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
const licenseInfo = { spdxId };
|
|
356
|
+
try {
|
|
357
|
+
const details = await getLicenseDetails(spdxId, opts);
|
|
358
|
+
if (details) {
|
|
359
|
+
// Check if backend recognized the license as valid
|
|
360
|
+
if (details.category === 'UNKNOWN') {
|
|
361
|
+
errors.push(`"${spdxId}" is not a valid SPDX license identifier. Please use a valid SPDX expression (e.g., "Apache-2.0", "MIT"). See https://spdx.org/licenses/`);
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
Object.assign(licenseInfo, details);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
errors.push(`No license details found for ${spdxId}`);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
catch (err) {
|
|
372
|
+
errors.push(`Failed to fetch details for ${spdxId}: ${err.message}`);
|
|
373
|
+
}
|
|
374
|
+
return licenseInfo;
|
|
375
|
+
};
|
|
376
|
+
const output = {
|
|
377
|
+
manifestLicense: await buildLicenseInfo(localResult.fromManifest),
|
|
378
|
+
fileLicense: await buildLicenseInfo(localResult.fromFile),
|
|
379
|
+
mismatch: localResult.mismatch
|
|
380
|
+
};
|
|
381
|
+
if (errors.length > 0) {
|
|
382
|
+
output.errors = errors;
|
|
383
|
+
}
|
|
384
|
+
console.log(JSON.stringify(output, null, 2));
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
const sbom = {
|
|
388
|
+
command: 'sbom </path/to/manifest> [--output]',
|
|
389
|
+
desc: 'generate a CycloneDX SBOM from a manifest file',
|
|
390
|
+
builder: yargs => yargs.positional('/path/to/manifest', {
|
|
391
|
+
desc: 'manifest path for SBOM generation',
|
|
392
|
+
type: 'string',
|
|
393
|
+
normalize: true,
|
|
394
|
+
}).options({
|
|
395
|
+
output: {
|
|
396
|
+
alias: 'o',
|
|
397
|
+
desc: 'Write SBOM JSON to a file instead of stdout',
|
|
398
|
+
type: 'string',
|
|
399
|
+
normalize: true,
|
|
400
|
+
},
|
|
401
|
+
workspaceDir: {
|
|
402
|
+
alias: 'w',
|
|
403
|
+
desc: 'Workspace root directory (for monorepos; lock file is expected here)',
|
|
404
|
+
type: 'string',
|
|
405
|
+
normalize: true,
|
|
406
|
+
}
|
|
407
|
+
}),
|
|
408
|
+
handler: async (args) => {
|
|
409
|
+
let manifest = args['/path/to/manifest'];
|
|
410
|
+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
|
|
411
|
+
let result;
|
|
412
|
+
try {
|
|
413
|
+
result = await generateSbom(manifest, opts);
|
|
414
|
+
}
|
|
415
|
+
catch (err) {
|
|
416
|
+
console.error(JSON.stringify({ error: `Failed to generate SBOM: ${err.message}` }, null, 2));
|
|
417
|
+
process.exit(1);
|
|
418
|
+
}
|
|
419
|
+
const json = JSON.stringify(result, null, 2);
|
|
420
|
+
if (args.output) {
|
|
421
|
+
try {
|
|
422
|
+
fs.writeFileSync(args.output, json);
|
|
423
|
+
}
|
|
424
|
+
catch (err) {
|
|
425
|
+
console.error(JSON.stringify({ error: `Failed to write output file: ${err.message}` }, null, 2));
|
|
426
|
+
process.exit(1);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
console.log(json);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
const remediate = {
|
|
435
|
+
command: 'remediate <path>',
|
|
436
|
+
desc: 'Scan and apply vulnerability remediations to manifest files',
|
|
437
|
+
builder: yargs => yargs.positional('path', {
|
|
438
|
+
desc: 'Path to manifest file or directory',
|
|
439
|
+
type: 'string',
|
|
440
|
+
normalize: true,
|
|
441
|
+
}).options({
|
|
442
|
+
'dry-run': {
|
|
443
|
+
alias: 'd',
|
|
444
|
+
type: 'boolean',
|
|
445
|
+
desc: 'Preview changes without modifying files',
|
|
446
|
+
},
|
|
447
|
+
providers: {
|
|
448
|
+
desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
|
|
449
|
+
type: 'string',
|
|
450
|
+
},
|
|
451
|
+
sources: {
|
|
452
|
+
desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
|
|
453
|
+
type: 'string',
|
|
454
|
+
},
|
|
455
|
+
'group-by': {
|
|
456
|
+
type: 'string',
|
|
457
|
+
choices: ['dependency', 'bundle'],
|
|
458
|
+
default: 'dependency',
|
|
459
|
+
desc: 'Report grouping strategy',
|
|
460
|
+
},
|
|
461
|
+
}),
|
|
462
|
+
handler: async (args) => {
|
|
463
|
+
try {
|
|
464
|
+
const result = await runRemediation(args.path, {
|
|
465
|
+
dryRun: args['dry-run'],
|
|
466
|
+
providers: args.providers,
|
|
467
|
+
sources: args.sources,
|
|
468
|
+
groupBy: args['group-by'],
|
|
469
|
+
});
|
|
470
|
+
console.log(result.output);
|
|
471
|
+
process.exit(result.exitCode);
|
|
472
|
+
}
|
|
473
|
+
catch (err) {
|
|
474
|
+
console.error(err.message);
|
|
475
|
+
process.exit(1);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
};
|
|
146
479
|
// parse and invoke the command
|
|
147
480
|
yargs(hideBin(process.argv))
|
|
148
|
-
.usage(`Usage: ${process.argv[0].includes("node") ? path.parse(process.argv[1]).base : path.parse(process.argv[0]).base} {component|stack|image|validate-token}`)
|
|
481
|
+
.usage(`Usage: ${process.argv[0].includes("node") ? path.parse(process.argv[1]).base : path.parse(process.argv[0]).base} {component|stack|stack-batch|image|validate-token|license|sbom|remediate}`)
|
|
149
482
|
.command(stack)
|
|
483
|
+
.command(stackBatch)
|
|
150
484
|
.command(component)
|
|
151
485
|
.command(image)
|
|
152
486
|
.command(validateToken)
|
|
487
|
+
.command(license)
|
|
488
|
+
.command(sbom)
|
|
489
|
+
.command(remediate)
|
|
153
490
|
.scriptName('')
|
|
154
491
|
.version(false)
|
|
155
492
|
.demandCommand(1)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="packageurl-js/src/package-url" />
|
|
2
1
|
export default class CycloneDxSbom {
|
|
3
2
|
sbomObject: any;
|
|
4
3
|
rootComponent: any;
|
|
@@ -7,9 +6,10 @@ export default class CycloneDxSbom {
|
|
|
7
6
|
sourceManifestForAuditTrail: any;
|
|
8
7
|
/**
|
|
9
8
|
* @param {PackageURL} root - add main/root component for sbom
|
|
9
|
+
* @param {string|Array} [licenses] - optional license(s) for the root component
|
|
10
10
|
* @return {CycloneDxSbom} the CycloneDxSbom Sbom Object
|
|
11
11
|
*/
|
|
12
|
-
addRoot(root: PackageURL): CycloneDxSbom;
|
|
12
|
+
addRoot(root: PackageURL, licenses?: string | any[]): CycloneDxSbom;
|
|
13
13
|
/**
|
|
14
14
|
* @return {{{"bom-ref": string, name, purl: string, type, version}}} root component of sbom.
|
|
15
15
|
*/
|
|
@@ -18,9 +18,14 @@ export default class CycloneDxSbom {
|
|
|
18
18
|
* Adds a dependency relationship between two components in the SBOM
|
|
19
19
|
* @param {PackageURL} sourceRef - The source component (parent)
|
|
20
20
|
* @param {PackageURL} targetRef - The target component (dependency)
|
|
21
|
+
* @param {string} [scope] - Scope of the dependency
|
|
22
|
+
* @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
|
|
21
23
|
* @return {CycloneDxSbom} The updated SBOM
|
|
22
24
|
*/
|
|
23
|
-
addDependency(sourceRef: PackageURL, targetRef: PackageURL, scope
|
|
25
|
+
addDependency(sourceRef: PackageURL, targetRef: PackageURL, scope?: string, targetHashes?: Array<{
|
|
26
|
+
alg: string;
|
|
27
|
+
content: string;
|
|
28
|
+
}>): CycloneDxSbom;
|
|
24
29
|
/** @param {{}} opts - various options, settings and configuration of application.
|
|
25
30
|
* @return String CycloneDx Sbom json object in a string format
|
|
26
31
|
*/
|
|
@@ -49,6 +54,8 @@ export default class CycloneDxSbom {
|
|
|
49
54
|
type: any;
|
|
50
55
|
version: any;
|
|
51
56
|
scope: any;
|
|
57
|
+
licenses?: any;
|
|
58
|
+
hashes?: any;
|
|
52
59
|
};
|
|
53
60
|
/**
|
|
54
61
|
* This method gets an array of dependencies to be ignored, and remove all of them from CycloneDx Sbom
|
|
@@ -69,6 +76,13 @@ export default class CycloneDxSbom {
|
|
|
69
76
|
* @return {boolean}
|
|
70
77
|
*/
|
|
71
78
|
checkIfPackageInsideDependsOnList(component: any, name: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
|
|
81
|
+
* @param {PackageURL} sourceRef - The source component
|
|
82
|
+
* @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
|
|
83
|
+
* @return {boolean}
|
|
84
|
+
*/
|
|
85
|
+
checkDependsOnByPurlPrefix(sourceRef: PackageURL, purlPrefix: string): boolean;
|
|
72
86
|
/** Removes the root component from the sbom
|
|
73
87
|
*/
|
|
74
88
|
removeRootComponent(): void;
|
|
@@ -5,10 +5,12 @@ import { PackageURL } from "packageurl-js";
|
|
|
5
5
|
* @param component {PackageURL}
|
|
6
6
|
* @param type type of package - application or library
|
|
7
7
|
* @param scope scope of the component - runtime or compile
|
|
8
|
-
* @
|
|
8
|
+
* @param licenses optional license string or array of licenses for the component
|
|
9
|
+
* @param hashes optional array of hash objects for the component, e.g. [{alg: "SHA-256", content: "..."}]
|
|
10
|
+
* @return {{"bom-ref": string, name, purl: string, type, version, scope, licenses?, hashes?}}
|
|
9
11
|
* @private
|
|
10
12
|
*/
|
|
11
|
-
function getComponent(component, type, scope) {
|
|
13
|
+
function getComponent(component, type, scope, licenses, hashes) {
|
|
12
14
|
let componentObject;
|
|
13
15
|
if (component instanceof PackageURL) {
|
|
14
16
|
if (component.namespace) {
|
|
@@ -36,6 +38,28 @@ function getComponent(component, type, scope) {
|
|
|
36
38
|
else {
|
|
37
39
|
componentObject = component;
|
|
38
40
|
}
|
|
41
|
+
// Add licenses if provided (CycloneDX format). Callers must provide valid SPDX identifiers.
|
|
42
|
+
if (licenses) {
|
|
43
|
+
const licenseArray = Array.isArray(licenses) ? licenses : [licenses];
|
|
44
|
+
const validLicenses = licenseArray
|
|
45
|
+
.map(lic => {
|
|
46
|
+
if (typeof lic === 'string') {
|
|
47
|
+
return { license: { id: lic } };
|
|
48
|
+
}
|
|
49
|
+
if (typeof lic === 'object' && lic !== null && ('license' in lic || 'expression' in lic)) {
|
|
50
|
+
return lic;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
})
|
|
54
|
+
.filter(Boolean);
|
|
55
|
+
if (validLicenses.length > 0) {
|
|
56
|
+
componentObject.licenses = validLicenses;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Add hashes if provided (CycloneDX 1.4 format).
|
|
60
|
+
if (hashes && hashes.length > 0) {
|
|
61
|
+
componentObject.hashes = hashes;
|
|
62
|
+
}
|
|
39
63
|
return componentObject;
|
|
40
64
|
}
|
|
41
65
|
function createDependency(dependency) {
|
|
@@ -56,11 +80,12 @@ export default class CycloneDxSbom {
|
|
|
56
80
|
}
|
|
57
81
|
/**
|
|
58
82
|
* @param {PackageURL} root - add main/root component for sbom
|
|
83
|
+
* @param {string|Array} [licenses] - optional license(s) for the root component
|
|
59
84
|
* @return {CycloneDxSbom} the CycloneDxSbom Sbom Object
|
|
60
85
|
*/
|
|
61
|
-
addRoot(root) {
|
|
86
|
+
addRoot(root, licenses) {
|
|
62
87
|
this.rootComponent =
|
|
63
|
-
getComponent(root, "application");
|
|
88
|
+
getComponent(root, "application", undefined, licenses);
|
|
64
89
|
this.components.push(this.rootComponent);
|
|
65
90
|
return this;
|
|
66
91
|
}
|
|
@@ -74,16 +99,24 @@ export default class CycloneDxSbom {
|
|
|
74
99
|
* Adds a dependency relationship between two components in the SBOM
|
|
75
100
|
* @param {PackageURL} sourceRef - The source component (parent)
|
|
76
101
|
* @param {PackageURL} targetRef - The target component (dependency)
|
|
102
|
+
* @param {string} [scope] - Scope of the dependency
|
|
103
|
+
* @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
|
|
77
104
|
* @return {CycloneDxSbom} The updated SBOM
|
|
78
105
|
*/
|
|
79
|
-
addDependency(sourceRef, targetRef, scope) {
|
|
106
|
+
addDependency(sourceRef, targetRef, scope, targetHashes) {
|
|
80
107
|
const sourcePurl = sourceRef.toString();
|
|
81
108
|
const targetPurl = targetRef.toString();
|
|
82
109
|
// Ensure both components exist in the components list
|
|
83
110
|
[sourceRef, targetRef].forEach((ref, index) => {
|
|
84
111
|
const purl = index === 0 ? sourcePurl : targetPurl;
|
|
85
|
-
|
|
86
|
-
|
|
112
|
+
const existingIndex = this.getComponentIndex(purl);
|
|
113
|
+
if (existingIndex < 0) {
|
|
114
|
+
const hashes = index === 1 ? targetHashes : undefined;
|
|
115
|
+
this.components.push(getComponent(ref, "library", scope, undefined, hashes));
|
|
116
|
+
}
|
|
117
|
+
else if (index === 1 && targetHashes && targetHashes.length > 0 && !this.components[existingIndex].hashes) {
|
|
118
|
+
// Update hashes if the component was first seen without them (e.g. as a source)
|
|
119
|
+
this.components[existingIndex].hashes = targetHashes;
|
|
87
120
|
}
|
|
88
121
|
});
|
|
89
122
|
// Ensure source dependency exists
|
|
@@ -108,6 +141,7 @@ export default class CycloneDxSbom {
|
|
|
108
141
|
getAsJsonString(opts) {
|
|
109
142
|
let manifestType = opts["manifest-type"];
|
|
110
143
|
this.setSourceManifest(opts["source-manifest"]);
|
|
144
|
+
const rootPurl = this.rootComponent?.purl;
|
|
111
145
|
this.sbomObject = {
|
|
112
146
|
"bomFormat": "CycloneDX",
|
|
113
147
|
"specVersion": "1.4",
|
|
@@ -117,7 +151,7 @@ export default class CycloneDxSbom {
|
|
|
117
151
|
"component": this.rootComponent,
|
|
118
152
|
"properties": new Array()
|
|
119
153
|
},
|
|
120
|
-
"components": this.components,
|
|
154
|
+
"components": this.components.filter(c => c.purl !== rootPurl),
|
|
121
155
|
"dependencies": this.dependencies
|
|
122
156
|
};
|
|
123
157
|
if (this.rootComponent === undefined) {
|
|
@@ -229,6 +263,20 @@ export default class CycloneDxSbom {
|
|
|
229
263
|
return false;
|
|
230
264
|
}
|
|
231
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
|
|
268
|
+
* @param {PackageURL} sourceRef - The source component
|
|
269
|
+
* @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
|
|
270
|
+
* @return {boolean}
|
|
271
|
+
*/
|
|
272
|
+
checkDependsOnByPurlPrefix(sourceRef, purlPrefix) {
|
|
273
|
+
const sourcePurl = sourceRef.toString();
|
|
274
|
+
const depIndex = this.getDependencyIndex(sourcePurl);
|
|
275
|
+
if (depIndex < 0) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
return this.dependencies[depIndex].dependsOn.some(dep => dep.startsWith(purlPrefix));
|
|
279
|
+
}
|
|
232
280
|
/** Removes the root component from the sbom
|
|
233
281
|
*/
|
|
234
282
|
removeRootComponent() {
|