@trustify-da/trustify-da-javascript-client 0.3.0-ea.de62188 → 0.3.0-ea.e258fba
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 +176 -2
- package/dist/package.json +6 -2
- package/dist/src/cli.js +48 -1
- package/dist/src/cyclone_dx_sbom.d.ts +13 -0
- package/dist/src/cyclone_dx_sbom.js +39 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +9 -24
- package/dist/src/package_version.d.ts +8 -0
- package/dist/src/package_version.js +31 -0
- package/dist/src/providers/base_java.d.ts +53 -0
- package/dist/src/providers/base_java.js +64 -17
- package/dist/src/providers/base_javascript.d.ts +54 -0
- package/dist/src/providers/base_javascript.js +105 -3
- package/dist/src/providers/golang_gomodules.js +49 -7
- package/dist/src/providers/java_gradle.d.ts +48 -0
- package/dist/src/providers/java_gradle.js +196 -18
- package/dist/src/providers/java_maven.d.ts +28 -8
- package/dist/src/providers/java_maven.js +104 -10
- package/dist/src/providers/javascript_bun.d.ts +12 -0
- package/dist/src/providers/javascript_bun.js +42 -1
- package/dist/src/providers/javascript_npm.d.ts +13 -0
- package/dist/src/providers/javascript_npm.js +40 -1
- package/dist/src/providers/javascript_pnpm.d.ts +13 -0
- package/dist/src/providers/javascript_pnpm.js +47 -1
- package/dist/src/providers/javascript_yarn.d.ts +12 -0
- package/dist/src/providers/javascript_yarn.js +75 -2
- package/dist/src/providers/manifest.js +6 -3
- package/dist/src/providers/processors/yarn_berry_processor.d.ts +5 -1
- package/dist/src/providers/processors/yarn_berry_processor.js +3 -2
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +5 -1
- package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
- package/dist/src/providers/python_controller.js +4 -1
- package/dist/src/providers/requirements_parser.js +1 -1
- package/dist/src/providers/rust_cargo.js +70 -29
- 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 +11 -0
- package/dist/src/sbom.js +10 -0
- package/dist/src/tools.js +24 -1
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -103,14 +103,17 @@ Use as CLI Script
|
|
|
103
103
|
```shell
|
|
104
104
|
$ npx @trustify-da/trustify-da-javascript-client help
|
|
105
105
|
|
|
106
|
-
Usage: trustify-da-javascript-client {component|stack|image|validate-token|license}
|
|
106
|
+
Usage: trustify-da-javascript-client {component|stack|stack-batch|image|validate-token|license|sbom|remediate}
|
|
107
107
|
|
|
108
108
|
Commands:
|
|
109
109
|
trustify-da-javascript-client stack </path/to/manifest> [--workspace-dir <path>] [--html|--summary] produce stack report for manifest path
|
|
110
110
|
trustify-da-javascript-client stack-batch </path/to/workspace-root> [--html|--summary] produce stack report for all packages/crates in workspace
|
|
111
111
|
trustify-da-javascript-client component <path/to/manifest> [--workspace-dir <path>] produce component report for a manifest type and content
|
|
112
112
|
trustify-da-javascript-client image <image-refs..> [--html|--summary] produce image analysis report for OCI image references
|
|
113
|
+
trustify-da-javascript-client validate-token <token-provider> [--token-value <value>] validate input token if authentic and authorized
|
|
113
114
|
trustify-da-javascript-client license </path/to/manifest> display project license information from manifest and LICENSE file in JSON format
|
|
115
|
+
trustify-da-javascript-client sbom </path/to/manifest> [--output <file>] generate a CycloneDX SBOM from a manifest file
|
|
116
|
+
trustify-da-javascript-client remediate <path> [--dry-run] [--providers <list>] [--sources <list>] [--group-by <strategy>] scan and apply vulnerability remediations
|
|
114
117
|
|
|
115
118
|
Options:
|
|
116
119
|
--help Show help [boolean]
|
|
@@ -160,6 +163,27 @@ $ npx @trustify-da/trustify-da-javascript-client image httpd:2.4.49^^amd64
|
|
|
160
163
|
|
|
161
164
|
# get project license information
|
|
162
165
|
$ npx @trustify-da/trustify-da-javascript-client license /path/to/package.json
|
|
166
|
+
|
|
167
|
+
# generate a CycloneDX SBOM from a manifest file
|
|
168
|
+
$ npx @trustify-da/trustify-da-javascript-client sbom /path/to/pom.xml
|
|
169
|
+
|
|
170
|
+
# generate SBOM and write to a file
|
|
171
|
+
$ npx @trustify-da/trustify-da-javascript-client sbom /path/to/pom.xml --output sbom.json
|
|
172
|
+
|
|
173
|
+
# scan a manifest and apply vulnerability remediations
|
|
174
|
+
$ npx @trustify-da/trustify-da-javascript-client remediate /path/to/pom.xml
|
|
175
|
+
|
|
176
|
+
# preview remediations without modifying files
|
|
177
|
+
$ npx @trustify-da/trustify-da-javascript-client remediate /path/to/pom.xml --dry-run
|
|
178
|
+
|
|
179
|
+
# scan a directory for all supported manifests
|
|
180
|
+
$ npx @trustify-da/trustify-da-javascript-client remediate /path/to/project/
|
|
181
|
+
|
|
182
|
+
# filter by vulnerability providers (order determines priority)
|
|
183
|
+
$ npx @trustify-da/trustify-da-javascript-client remediate /path/to/pom.xml --providers provider1,provider2
|
|
184
|
+
|
|
185
|
+
# group report output by bundle instead of per-dependency
|
|
186
|
+
$ npx @trustify-da/trustify-da-javascript-client remediate /path/to/pom.xml --dry-run --group-by bundle
|
|
163
187
|
```
|
|
164
188
|
</li>
|
|
165
189
|
|
|
@@ -213,6 +237,27 @@ $ trustify-da-javascript-client image httpd:2.4.49^^amd64
|
|
|
213
237
|
|
|
214
238
|
# get project license information
|
|
215
239
|
$ trustify-da-javascript-client license /path/to/package.json
|
|
240
|
+
|
|
241
|
+
# generate a CycloneDX SBOM from a manifest file
|
|
242
|
+
$ trustify-da-javascript-client sbom /path/to/pom.xml
|
|
243
|
+
|
|
244
|
+
# generate SBOM and write to a file
|
|
245
|
+
$ trustify-da-javascript-client sbom /path/to/pom.xml --output sbom.json
|
|
246
|
+
|
|
247
|
+
# scan a manifest and apply vulnerability remediations
|
|
248
|
+
$ trustify-da-javascript-client remediate /path/to/pom.xml
|
|
249
|
+
|
|
250
|
+
# preview remediations without modifying files
|
|
251
|
+
$ trustify-da-javascript-client remediate /path/to/pom.xml --dry-run
|
|
252
|
+
|
|
253
|
+
# scan a directory for all supported manifests
|
|
254
|
+
$ trustify-da-javascript-client remediate /path/to/project/
|
|
255
|
+
|
|
256
|
+
# filter by vulnerability providers (order determines priority)
|
|
257
|
+
$ trustify-da-javascript-client remediate /path/to/pom.xml --providers provider1,provider2
|
|
258
|
+
|
|
259
|
+
# group report output by bundle instead of per-dependency
|
|
260
|
+
$ trustify-da-javascript-client remediate /path/to/pom.xml --dry-run --group-by bundle
|
|
216
261
|
```
|
|
217
262
|
</li>
|
|
218
263
|
</ul>
|
|
@@ -688,7 +733,7 @@ This increasing the chances and the probability that the automatic installation
|
|
|
688
733
|
###### Usage
|
|
689
734
|
A New setting is introduced - `TRUSTIFY_DA_PYTHON_INSTALL_BEST_EFFORTS` (as both env variable/key in `options` object)
|
|
690
735
|
1. `TRUSTIFY_DA_PYTHON_INSTALL_BEST_EFFORTS`="false" - install requirements.txt while respecting declared versions for all packages.
|
|
691
|
-
2. `TRUSTIFY_DA_PYTHON_INSTALL_BEST_EFFORTS`="true" - install all packages from requirements.txt, not respecting the declared version, but trying to install a version tailored for the used python version. When using this setting, you must set
|
|
736
|
+
2. `TRUSTIFY_DA_PYTHON_INSTALL_BEST_EFFORTS`="true" - install all packages from requirements.txt, not respecting the declared version, but trying to install a version tailored for the used python version. When using this setting, you must set `TRUSTIFY_DA_PYTHON_VIRTUAL_ENV` to 'true' and `MATCH_MANIFEST_VERSIONS` to 'false'.
|
|
692
737
|
|
|
693
738
|
##### Using `pipdeptree`
|
|
694
739
|
By default, The API algorithm will use native commands of PIP installer as data source to build the dependency tree.
|
|
@@ -705,6 +750,135 @@ For some ecosystems we support passing additional CLI arguments to the underlyin
|
|
|
705
750
|
|Maven |TRUSTIFY_DA_MVN_ARGS|
|
|
706
751
|
|
|
707
752
|
|
|
753
|
+
<h3>Remediation</h3>
|
|
754
|
+
<p>
|
|
755
|
+
The <code>remediate</code> command scans manifest files for known vulnerabilities and applies version upgrades to resolve them. By default, it modifies manifest files in place. Use <code>--dry-run</code> to preview changes without modifying any files.
|
|
756
|
+
</p>
|
|
757
|
+
|
|
758
|
+
<h4>Supported Manifest Formats</h4>
|
|
759
|
+
<ul>
|
|
760
|
+
<li><strong>Maven</strong> — <code>pom.xml</code> (single-module projects; updates dependency version elements and resolves property references)</li>
|
|
761
|
+
<li><strong>Gradle Version Catalog</strong> — <code>libs.versions.toml</code> or any <code>*.versions.toml</code> file (updates centralized version references and inline version declarations)</li>
|
|
762
|
+
</ul>
|
|
763
|
+
|
|
764
|
+
<h4>CLI Flags</h4>
|
|
765
|
+
<table>
|
|
766
|
+
<tr>
|
|
767
|
+
<th>Flag</th>
|
|
768
|
+
<th>Alias</th>
|
|
769
|
+
<th>Type</th>
|
|
770
|
+
<th>Default</th>
|
|
771
|
+
<th>Description</th>
|
|
772
|
+
</tr>
|
|
773
|
+
<tr>
|
|
774
|
+
<td><code><path></code></td>
|
|
775
|
+
<td>—</td>
|
|
776
|
+
<td>string (positional)</td>
|
|
777
|
+
<td><em>required</em></td>
|
|
778
|
+
<td>Path to a manifest file or directory to scan recursively</td>
|
|
779
|
+
</tr>
|
|
780
|
+
<tr>
|
|
781
|
+
<td><code>--dry-run</code></td>
|
|
782
|
+
<td><code>-d</code></td>
|
|
783
|
+
<td>boolean</td>
|
|
784
|
+
<td><code>false</code></td>
|
|
785
|
+
<td>Preview changes without modifying files</td>
|
|
786
|
+
</tr>
|
|
787
|
+
<tr>
|
|
788
|
+
<td><code>--providers</code></td>
|
|
789
|
+
<td>—</td>
|
|
790
|
+
<td>string</td>
|
|
791
|
+
<td>—</td>
|
|
792
|
+
<td>Comma-separated list of vulnerability providers (env: <code>TRUSTIFY_DA_PROVIDERS</code>)</td>
|
|
793
|
+
</tr>
|
|
794
|
+
<tr>
|
|
795
|
+
<td><code>--sources</code></td>
|
|
796
|
+
<td>—</td>
|
|
797
|
+
<td>string</td>
|
|
798
|
+
<td>—</td>
|
|
799
|
+
<td>Comma-separated list of vulnerability sources (env: <code>TRUSTIFY_DA_SOURCES</code>)</td>
|
|
800
|
+
</tr>
|
|
801
|
+
<tr>
|
|
802
|
+
<td><code>--group-by</code></td>
|
|
803
|
+
<td>—</td>
|
|
804
|
+
<td>string</td>
|
|
805
|
+
<td><code>dependency</code></td>
|
|
806
|
+
<td>Report grouping strategy (<code>dependency</code> or <code>bundle</code>)</td>
|
|
807
|
+
</tr>
|
|
808
|
+
</table>
|
|
809
|
+
|
|
810
|
+
<h4>Provider Priority Resolution</h4>
|
|
811
|
+
<p>
|
|
812
|
+
When multiple vulnerability providers suggest different remediation versions for the same dependency, the <code>--providers</code> flag determines priority. Providers listed first have the highest priority.
|
|
813
|
+
</p>
|
|
814
|
+
<ul>
|
|
815
|
+
<li>The provider ordering in <code>--providers</code> determines rank (first = highest priority).</li>
|
|
816
|
+
<li>Trustify vendor trusted packages always take precedence over non-trusted content at equal provider rank.</li>
|
|
817
|
+
<li>Two version selection strategies are used internally:
|
|
818
|
+
<ul>
|
|
819
|
+
<li><strong>Closest coverage</strong> (default) — prefers the remediation version closest to the current version within the same major version.</li>
|
|
820
|
+
<li><strong>Highest</strong> — always selects the highest available remediation version.</li>
|
|
821
|
+
</ul>
|
|
822
|
+
</li>
|
|
823
|
+
</ul>
|
|
824
|
+
|
|
825
|
+
<h4>Exit Codes</h4>
|
|
826
|
+
<ul>
|
|
827
|
+
<li><code>0</code> — no remediations needed, or remediations applied successfully</li>
|
|
828
|
+
<li><code>1</code> — error during execution</li>
|
|
829
|
+
<li><code>2</code> — remediations available (only returned in <code>--dry-run</code> mode when changes would be made; never returned when changes are applied)</li>
|
|
830
|
+
</ul>
|
|
831
|
+
|
|
832
|
+
<h4>Known Limitations</h4>
|
|
833
|
+
<ul>
|
|
834
|
+
<li>Gradle DSL files (<code>build.gradle</code>, <code>build.gradle.kts</code>) are not supported — only version catalog files (<code>*.versions.toml</code>).</li>
|
|
835
|
+
<li>Multi-module Maven projects with inherited dependency versions from parent POMs are not supported — only versions declared directly in the scanned <code>pom.xml</code> are updated.</li>
|
|
836
|
+
</ul>
|
|
837
|
+
|
|
838
|
+
<h4>Example: GitHub Action Workflow</h4>
|
|
839
|
+
<p>
|
|
840
|
+
The following workflow runs a scheduled remediation scan using the container image and opens a pull request with any version updates. Save this as <code>.github/workflows/trustify-da-remediation.yml</code> in your repository:
|
|
841
|
+
</p>
|
|
842
|
+
|
|
843
|
+
```yaml
|
|
844
|
+
name: Trustify DA Remediation Scan
|
|
845
|
+
|
|
846
|
+
on:
|
|
847
|
+
schedule:
|
|
848
|
+
# Run weekly on Monday at 08:00 UTC
|
|
849
|
+
- cron: '0 8 * * 1'
|
|
850
|
+
workflow_dispatch:
|
|
851
|
+
|
|
852
|
+
permissions:
|
|
853
|
+
contents: write
|
|
854
|
+
pull-requests: write
|
|
855
|
+
|
|
856
|
+
jobs:
|
|
857
|
+
remediate:
|
|
858
|
+
runs-on: ubuntu-latest
|
|
859
|
+
steps:
|
|
860
|
+
- uses: actions/checkout@v4
|
|
861
|
+
|
|
862
|
+
- name: Run remediation scan
|
|
863
|
+
uses: docker://ghcr.io/guacsec/trustify-da-javascript-client:latest
|
|
864
|
+
env:
|
|
865
|
+
TRUSTIFY_DA_BACKEND_URL: ${{ secrets.TRUSTIFY_DA_BACKEND_URL }}
|
|
866
|
+
with:
|
|
867
|
+
entrypoint: trustify-da-javascript-client
|
|
868
|
+
args: remediate . --providers provider1,provider2
|
|
869
|
+
|
|
870
|
+
- name: Create pull request
|
|
871
|
+
uses: peter-evans/create-pull-request@v7
|
|
872
|
+
with:
|
|
873
|
+
title: 'fix(deps): apply Trustify DA vulnerability remediations'
|
|
874
|
+
body: |
|
|
875
|
+
Automated dependency version updates from Trustify Dependency Analytics.
|
|
876
|
+
|
|
877
|
+
This PR was generated by a scheduled remediation scan.
|
|
878
|
+
branch: trustify-da-remediation
|
|
879
|
+
commit-message: 'fix(deps): apply Trustify DA vulnerability remediations'
|
|
880
|
+
```
|
|
881
|
+
|
|
708
882
|
<!-- Badge links -->
|
|
709
883
|
[0]: https://img.shields.io/github/v/release/guacsec/trustify-da-javascript-client?color=green&label=latest
|
|
710
884
|
[1]: https://img.shields.io/github/v/release/guacsec/trustify-da-javascript-client?color=yellow&include_prereleases&label=early-access
|
package/dist/package.json
CHANGED
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
"provenance": true
|
|
26
26
|
},
|
|
27
27
|
"type": "module",
|
|
28
|
-
"bin":
|
|
28
|
+
"bin": {
|
|
29
|
+
"trustify-da": "dist/src/cli.js"
|
|
30
|
+
},
|
|
29
31
|
"main": "dist/src/index.js",
|
|
30
32
|
"module": "dist/src/index.js",
|
|
31
33
|
"types": "dist/src/index.d.ts",
|
|
@@ -48,7 +50,7 @@
|
|
|
48
50
|
},
|
|
49
51
|
"dependencies": {
|
|
50
52
|
"@babel/core": "^7.23.2",
|
|
51
|
-
"@
|
|
53
|
+
"@yarnpkg/parsers": "^3.1.0",
|
|
52
54
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
53
55
|
"fast-glob": "^3.3.3",
|
|
54
56
|
"fast-xml-parser": "^5.3.4",
|
|
@@ -69,10 +71,12 @@
|
|
|
69
71
|
},
|
|
70
72
|
"devDependencies": {
|
|
71
73
|
"@babel/core": "^7.23.2",
|
|
74
|
+
"@cyclonedx/cyclonedx-library": "^10.2.0",
|
|
72
75
|
"@eslint/js": "^10.0.0",
|
|
73
76
|
"@trustify-da/trustify-da-api-model": "^2.0.12",
|
|
74
77
|
"@types/node": "^25.9.1",
|
|
75
78
|
"@types/which": "^3.0.4",
|
|
79
|
+
"ajv": "^8.20.0",
|
|
76
80
|
"babel-plugin-rewire": "^1.2.0",
|
|
77
81
|
"c8": "^11.0.0",
|
|
78
82
|
"chai": "^6.2.2",
|
package/dist/src/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import * as path from "path";
|
|
|
4
4
|
import yargs from 'yargs';
|
|
5
5
|
import { hideBin } from 'yargs/helpers';
|
|
6
6
|
import { getProjectLicense, getLicenseDetails } from './license/index.js';
|
|
7
|
+
import { runRemediation } from './remediate.js';
|
|
7
8
|
import client, { selectTrustifyDABackend, generateSbom } from './index.js';
|
|
8
9
|
// command for component analysis take manifest type and content
|
|
9
10
|
const component = {
|
|
@@ -430,9 +431,54 @@ const sbom = {
|
|
|
430
431
|
}
|
|
431
432
|
}
|
|
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
|
+
};
|
|
433
479
|
// parse and invoke the command
|
|
434
480
|
yargs(hideBin(process.argv))
|
|
435
|
-
.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}`)
|
|
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}`)
|
|
436
482
|
.command(stack)
|
|
437
483
|
.command(stackBatch)
|
|
438
484
|
.command(component)
|
|
@@ -440,6 +486,7 @@ yargs(hideBin(process.argv))
|
|
|
440
486
|
.command(validateToken)
|
|
441
487
|
.command(license)
|
|
442
488
|
.command(sbom)
|
|
489
|
+
.command(remediate)
|
|
443
490
|
.scriptName('')
|
|
444
491
|
.version(false)
|
|
445
492
|
.demandCommand(1)
|
|
@@ -26,6 +26,19 @@ export default class CycloneDxSbom {
|
|
|
26
26
|
alg: string;
|
|
27
27
|
content: string;
|
|
28
28
|
}>): CycloneDxSbom;
|
|
29
|
+
/**
|
|
30
|
+
* Attach hashes to already-added components by matching their PURL. This is a
|
|
31
|
+
* post-processing step so ecosystem-specific hash sources (e.g. Maven reading
|
|
32
|
+
* the local .m2 cache) can enrich the SBOM without threading their concern
|
|
33
|
+
* through the shared dependency-tree parser. Components without a matching
|
|
34
|
+
* entry, or whose hashes are already set, are left untouched.
|
|
35
|
+
* @param {Map<string, Array<{alg: string, content: string}>>} hashMap - PURL→hashes map
|
|
36
|
+
* @return {CycloneDxSbom} the updated SBOM
|
|
37
|
+
*/
|
|
38
|
+
attachHashes(hashMap: Map<string, Array<{
|
|
39
|
+
alg: string;
|
|
40
|
+
content: string;
|
|
41
|
+
}>>): CycloneDxSbom;
|
|
29
42
|
/** @param {{}} opts - various options, settings and configuration of application.
|
|
30
43
|
* @return String CycloneDx Sbom json object in a string format
|
|
31
44
|
*/
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { EOL } from "os";
|
|
2
2
|
import { PackageURL } from "packageurl-js";
|
|
3
|
+
import { getPackageVersion } from "./package_version.js";
|
|
4
|
+
/**
|
|
5
|
+
* This client's version, read once at module load, used to populate
|
|
6
|
+
* metadata.tools.components[].version in the generated SBOM.
|
|
7
|
+
* @type {string|undefined}
|
|
8
|
+
*/
|
|
9
|
+
const PACKAGE_VERSION = getPackageVersion();
|
|
3
10
|
/**
|
|
4
11
|
*
|
|
5
12
|
* @param component {PackageURL}
|
|
@@ -135,6 +142,30 @@ export default class CycloneDxSbom {
|
|
|
135
142
|
}
|
|
136
143
|
return this;
|
|
137
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Attach hashes to already-added components by matching their PURL. This is a
|
|
147
|
+
* post-processing step so ecosystem-specific hash sources (e.g. Maven reading
|
|
148
|
+
* the local .m2 cache) can enrich the SBOM without threading their concern
|
|
149
|
+
* through the shared dependency-tree parser. Components without a matching
|
|
150
|
+
* entry, or whose hashes are already set, are left untouched.
|
|
151
|
+
* @param {Map<string, Array<{alg: string, content: string}>>} hashMap - PURL→hashes map
|
|
152
|
+
* @return {CycloneDxSbom} the updated SBOM
|
|
153
|
+
*/
|
|
154
|
+
attachHashes(hashMap) {
|
|
155
|
+
if (!hashMap || hashMap.size === 0) {
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
for (const component of this.components) {
|
|
159
|
+
if (component.hashes) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const hashes = hashMap.get(component.purl);
|
|
163
|
+
if (hashes && hashes.length > 0) {
|
|
164
|
+
component.hashes = hashes;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
138
169
|
/** @param {{}} opts - various options, settings and configuration of application.
|
|
139
170
|
* @return String CycloneDx Sbom json object in a string format
|
|
140
171
|
*/
|
|
@@ -144,11 +175,18 @@ export default class CycloneDxSbom {
|
|
|
144
175
|
const rootPurl = this.rootComponent?.purl;
|
|
145
176
|
this.sbomObject = {
|
|
146
177
|
"bomFormat": "CycloneDX",
|
|
147
|
-
"specVersion": "1.
|
|
178
|
+
"specVersion": "1.6",
|
|
148
179
|
"version": 1,
|
|
149
180
|
"metadata": {
|
|
150
181
|
"timestamp": new Date(),
|
|
151
182
|
"component": this.rootComponent,
|
|
183
|
+
"tools": {
|
|
184
|
+
"components": [{
|
|
185
|
+
"type": "application",
|
|
186
|
+
"name": "trustify-da-javascript-client",
|
|
187
|
+
"version": PACKAGE_VERSION
|
|
188
|
+
}]
|
|
189
|
+
},
|
|
152
190
|
"properties": new Array()
|
|
153
191
|
},
|
|
154
192
|
"components": this.components.filter(c => c.purl !== rootPurl),
|
package/dist/src/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export function selectTrustifyDABackend(opts?: {
|
|
|
24
24
|
export function generateSbom(manifestPath: string, opts?: Options): Promise<object>;
|
|
25
25
|
export { parseImageRef } from "./oci_image/utils.js";
|
|
26
26
|
export { ImageRef } from "./oci_image/images.js";
|
|
27
|
+
export { extractRemediations } from "./remediation.js";
|
|
27
28
|
declare namespace _default {
|
|
28
29
|
export { componentAnalysis };
|
|
29
30
|
export { stackAnalysis };
|
|
@@ -266,3 +267,4 @@ import { resolveContinueOnError } from './batch_opts.js';
|
|
|
266
267
|
import { resolveBatchMetadata } from './batch_opts.js';
|
|
267
268
|
export { discoverMavenModules, discoverGradleSubprojects, discoverGoWorkspaceModules, discoverUvWorkspaceMembers, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata };
|
|
268
269
|
export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
|
|
270
|
+
export { generateReport, generateDeduplicationKey } from "./remediation_report.js";
|
package/dist/src/index.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { EOL } from "os";
|
|
3
4
|
import pLimit from 'p-limit';
|
|
4
|
-
import { availableProviders, match } from './provider.js';
|
|
5
5
|
import analysis from './analysis.js';
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import { getCustom } from "./tools.js";
|
|
8
6
|
import { resolveBatchMetadata, resolveContinueOnError } from './batch_opts.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
7
|
+
import { getPackageVersion } from './package_version.js';
|
|
8
|
+
import { availableProviders, match } from './provider.js';
|
|
11
9
|
import { discoverGoWorkspaceModules } from './providers/golang_gomodules.js';
|
|
10
|
+
import { discoverGradleSubprojects } from './providers/java_gradle.js';
|
|
11
|
+
import { discoverMavenModules } from './providers/java_maven.js';
|
|
12
12
|
import { discoverUvWorkspaceMembers } from './providers/python_uv.js';
|
|
13
|
+
import { getCustom } from "./tools.js";
|
|
13
14
|
import { discoverWorkspaceCrates, discoverWorkspacePackages, filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore, validatePackageJson, } from './workspace.js';
|
|
14
|
-
import.meta.dirname;
|
|
15
|
-
import * as url from 'url';
|
|
16
15
|
export { parseImageRef } from "./oci_image/utils.js";
|
|
17
16
|
export { ImageRef } from "./oci_image/images.js";
|
|
18
17
|
export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
|
|
18
|
+
export { extractRemediations } from "./remediation.js";
|
|
19
|
+
export { generateReport, generateDeduplicationKey } from './remediation_report.js';
|
|
19
20
|
export default { componentAnalysis, stackAnalysis, stackAnalysisBatch, imageAnalysis, validateToken, generateSbom };
|
|
20
21
|
export { discoverMavenModules, discoverGradleSubprojects, discoverGoWorkspaceModules, discoverUvWorkspaceMembers, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata, };
|
|
21
22
|
/**
|
|
@@ -93,23 +94,7 @@ function logOptionsAndEnvironmentsVariables(alongsideText, valueToBePrinted) {
|
|
|
93
94
|
* @private
|
|
94
95
|
*/
|
|
95
96
|
function readAndPrintVersionFromPackageJson() {
|
|
96
|
-
|
|
97
|
-
// new ESM way in nodeJS ( since node version 22 ) to bring module directory.
|
|
98
|
-
dirName = import.meta.dirname;
|
|
99
|
-
// old ESM way in nodeJS ( before node versions 22.00 to bring module directory)
|
|
100
|
-
if (!dirName) {
|
|
101
|
-
dirName = url.fileURLToPath(new URL('.', import.meta.url));
|
|
102
|
-
}
|
|
103
|
-
try {
|
|
104
|
-
if (__dirname) {
|
|
105
|
-
dirName = __dirname;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
catch (e) {
|
|
109
|
-
console.log("__dirname is not defined, continue with fileUrlPath");
|
|
110
|
-
}
|
|
111
|
-
let packageJson = JSON.parse(fs.readFileSync(path.join(dirName, "..", "package.json")).toString());
|
|
112
|
-
logOptionsAndEnvironmentsVariables("trustify-da-javascript-client analysis started, version: ", packageJson.version);
|
|
97
|
+
logOptionsAndEnvironmentsVariables("trustify-da-javascript-client analysis started, version: ", getPackageVersion());
|
|
113
98
|
}
|
|
114
99
|
/**
|
|
115
100
|
* This function is used to determine the Trustify DA backend URL.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads this package's version from package.json, resolving the path relative
|
|
3
|
+
* to this module. Works under ESM (node >= 22 import.meta.dirname, older via
|
|
4
|
+
* import.meta.url) and CommonJS (__dirname). Returns undefined if the file
|
|
5
|
+
* cannot be read, so callers never fail on a missing version.
|
|
6
|
+
* @return {string|undefined} the package version, or undefined
|
|
7
|
+
*/
|
|
8
|
+
export function getPackageVersion(): string | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import * as url from "url";
|
|
4
|
+
/**
|
|
5
|
+
* Reads this package's version from package.json, resolving the path relative
|
|
6
|
+
* to this module. Works under ESM (node >= 22 import.meta.dirname, older via
|
|
7
|
+
* import.meta.url) and CommonJS (__dirname). Returns undefined if the file
|
|
8
|
+
* cannot be read, so callers never fail on a missing version.
|
|
9
|
+
* @return {string|undefined} the package version, or undefined
|
|
10
|
+
*/
|
|
11
|
+
export function getPackageVersion() {
|
|
12
|
+
try {
|
|
13
|
+
let dirName = import.meta.dirname;
|
|
14
|
+
if (!dirName) {
|
|
15
|
+
dirName = url.fileURLToPath(new URL('.', import.meta.url));
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
if (__dirname) {
|
|
19
|
+
dirName = __dirname;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// __dirname not defined under ESM, continue with fileURLToPath
|
|
24
|
+
}
|
|
25
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(dirName, "..", "package.json")).toString());
|
|
26
|
+
return packageJson.version;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -10,6 +10,13 @@ export type ecosystem_maven = any;
|
|
|
10
10
|
export const ecosystem_maven: string;
|
|
11
11
|
export const ecosystem_gradle: "gradle";
|
|
12
12
|
export default class Base_Java {
|
|
13
|
+
/**
|
|
14
|
+
* Maven dependency scopes. Used to detect whether the trailing column of a
|
|
15
|
+
* dependency-tree line is a scope keyword — which in turn signals that an
|
|
16
|
+
* optional classifier column is present between the packaging and version.
|
|
17
|
+
* @type {string[]}
|
|
18
|
+
*/
|
|
19
|
+
static MAVEN_SCOPES: string[];
|
|
13
20
|
/**
|
|
14
21
|
*
|
|
15
22
|
* @param {string} globalBinary name of the global binary
|
|
@@ -40,6 +47,52 @@ export default class Base_Java {
|
|
|
40
47
|
* @protected
|
|
41
48
|
*/
|
|
42
49
|
protected _getDepth(line: string): number;
|
|
50
|
+
/**
|
|
51
|
+
* Parse a single dependency-tree line into its Maven coordinate parts.
|
|
52
|
+
*
|
|
53
|
+
* This is the single source of truth for interpreting a dependency-tree
|
|
54
|
+
* line. Both {@link parseDep} (used to build SBOM component PURLs) and the
|
|
55
|
+
* Maven hash-map builder rely on it, so the PURL key and the artifact file
|
|
56
|
+
* path can never drift from one another.
|
|
57
|
+
*
|
|
58
|
+
* A line has the shape `groupId:artifactId:packaging[:classifier]:version[:scope]`.
|
|
59
|
+
* The classifier column is only present when a sixth column holds a known
|
|
60
|
+
* Maven scope keyword; otherwise the fourth column is the version.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} line - line to parse from a dependency tree
|
|
63
|
+
* @returns {{groupId: string, artifactId: string, packaging: string, classifier: (string|null), version: string, scope: (string|null), overridden: boolean}}
|
|
64
|
+
* Parsed coordinate. `version` is the resolved concrete version — when the
|
|
65
|
+
* line carries a conflict override the override version replaces it and
|
|
66
|
+
* `overridden` is set, mirroring how Maven records the winning version.
|
|
67
|
+
*/
|
|
68
|
+
parseCoordinate(line: string): {
|
|
69
|
+
groupId: string;
|
|
70
|
+
artifactId: string;
|
|
71
|
+
packaging: string;
|
|
72
|
+
classifier: (string | null);
|
|
73
|
+
version: string;
|
|
74
|
+
scope: (string | null);
|
|
75
|
+
overridden: boolean;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Build the canonical PackageURL for a parsed coordinate.
|
|
79
|
+
*
|
|
80
|
+
* The classifier is folded into the version component (e.g.
|
|
81
|
+
* `4.1.0-linux-x86_64`) except when the version came from a conflict
|
|
82
|
+
* override, in which case the override version stands alone — matching the
|
|
83
|
+
* historical behavior of {@link parseDep}.
|
|
84
|
+
*
|
|
85
|
+
* @param {{groupId: string, artifactId: string, classifier: (string|null), version: string, overridden: boolean}} coord
|
|
86
|
+
* @returns {PackageURL} The canonical packageURL for the coordinate
|
|
87
|
+
* @protected
|
|
88
|
+
*/
|
|
89
|
+
protected _coordinateToPurl(coord: {
|
|
90
|
+
groupId: string;
|
|
91
|
+
artifactId: string;
|
|
92
|
+
classifier: (string | null);
|
|
93
|
+
version: string;
|
|
94
|
+
overridden: boolean;
|
|
95
|
+
}): PackageURL;
|
|
43
96
|
/**
|
|
44
97
|
* Create a PackageURL from any line in a Text Graph dependency tree for a manifest path.
|
|
45
98
|
* @param {string} line - line to parse from a dependencies.txt file
|