@trustify-da/trustify-da-javascript-client 0.3.0-ea.b68592e → 0.3.0-ea.b77d624

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.
Files changed (57) hide show
  1. package/README.md +189 -3
  2. package/dist/package.json +16 -7
  3. package/dist/src/analysis.d.ts +7 -0
  4. package/dist/src/analysis.js +29 -13
  5. package/dist/src/cli.js +106 -2
  6. package/dist/src/cyclone_dx_sbom.d.ts +13 -0
  7. package/dist/src/cyclone_dx_sbom.js +39 -1
  8. package/dist/src/index.d.ts +5 -1
  9. package/dist/src/index.js +12 -25
  10. package/dist/src/oci_image/images.js +15 -1
  11. package/dist/src/package_version.d.ts +8 -0
  12. package/dist/src/package_version.js +31 -0
  13. package/dist/src/provider.js +3 -1
  14. package/dist/src/providers/base_java.d.ts +53 -0
  15. package/dist/src/providers/base_java.js +64 -17
  16. package/dist/src/providers/base_javascript.d.ts +54 -0
  17. package/dist/src/providers/base_javascript.js +105 -3
  18. package/dist/src/providers/containerfile_parser.d.ts +5 -0
  19. package/dist/src/providers/containerfile_parser.js +20 -0
  20. package/dist/src/providers/golang_gomodules.js +49 -7
  21. package/dist/src/providers/java_gradle.d.ts +48 -0
  22. package/dist/src/providers/java_gradle.js +196 -18
  23. package/dist/src/providers/java_maven.d.ts +28 -8
  24. package/dist/src/providers/java_maven.js +104 -10
  25. package/dist/src/providers/javascript_bun.d.ts +12 -0
  26. package/dist/src/providers/javascript_bun.js +42 -1
  27. package/dist/src/providers/javascript_npm.d.ts +13 -0
  28. package/dist/src/providers/javascript_npm.js +40 -1
  29. package/dist/src/providers/javascript_pnpm.d.ts +13 -0
  30. package/dist/src/providers/javascript_pnpm.js +47 -1
  31. package/dist/src/providers/javascript_yarn.d.ts +12 -0
  32. package/dist/src/providers/javascript_yarn.js +75 -2
  33. package/dist/src/providers/manifest.js +6 -3
  34. package/dist/src/providers/oci_dockerfile.d.ts +51 -0
  35. package/dist/src/providers/oci_dockerfile.js +177 -0
  36. package/dist/src/providers/processors/yarn_berry_processor.d.ts +5 -1
  37. package/dist/src/providers/processors/yarn_berry_processor.js +3 -2
  38. package/dist/src/providers/processors/yarn_classic_processor.d.ts +5 -1
  39. package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
  40. package/dist/src/providers/python_controller.js +4 -1
  41. package/dist/src/providers/requirements_parser.js +1 -1
  42. package/dist/src/providers/rust_cargo.js +70 -29
  43. package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
  44. package/dist/src/remediate.d.ts +21 -0
  45. package/dist/src/remediate.js +149 -0
  46. package/dist/src/remediation.d.ts +57 -0
  47. package/dist/src/remediation.js +436 -0
  48. package/dist/src/remediation_report.d.ts +40 -0
  49. package/dist/src/remediation_report.js +159 -0
  50. package/dist/src/sbom.d.ts +11 -0
  51. package/dist/src/sbom.js +10 -0
  52. package/dist/src/tools.js +24 -1
  53. package/dist/src/updaters/maven_updater.d.ts +26 -0
  54. package/dist/src/updaters/maven_updater.js +322 -0
  55. package/dist/src/updaters/toml_updater.d.ts +33 -0
  56. package/dist/src/updaters/toml_updater.js +244 -0
  57. package/package.json +17 -8
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>
@@ -230,6 +275,18 @@ $ trustify-da-javascript-client license /path/to/package.json
230
275
  <li><a href="https://www.rust-lang.org/">Rust</a> - <a href="https://doc.rust-lang.org/cargo/">Cargo</a></li>
231
276
  </ul>
232
277
 
278
+ <h3>Dockerfile Analysis Prerequisites</h3>
279
+ <p>
280
+ OCI image and <code>Dockerfile</code>/<code>Containerfile</code> analysis require the following external tools to be installed and available on your <code>PATH</code>:
281
+ </p>
282
+ <ul>
283
+ <li><a href="https://github.com/anchore/syft">Syft</a> — generates the image SBOM.</li>
284
+ <li><a href="https://github.com/containers/skopeo">skopeo</a> — resolves the image digest and manifest from the registry.</li>
285
+ </ul>
286
+ <p>
287
+ <strong>Dockerfile analysis is not supported on Windows</strong>, because <code>skopeo</code> provides no native Windows binary.
288
+ </p>
289
+
233
290
  <h3>License Detection</h3>
234
291
  <p>
235
292
  The client automatically detects your project's license with intelligent fallback:
@@ -688,14 +745,14 @@ This increasing the chances and the probability that the automatic installation
688
745
  ###### Usage
689
746
  A New setting is introduced - `TRUSTIFY_DA_PYTHON_INSTALL_BEST_EFFORTS` (as both env variable/key in `options` object)
690
747
  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 setting `MATCH_MANIFEST_VERSIONS` to 'false'.
748
+ 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
749
 
693
750
  ##### Using `pipdeptree`
694
751
  By default, The API algorithm will use native commands of PIP installer as data source to build the dependency tree.
695
752
  It's also possible to use the lightweight Python PIP utility [pipdeptree](https://pypi.org/project/pipdeptree/) as data source instead. In order to activate this, you need to set the environment variable/option `TRUSTIFY_DA_PIP_USE_DEP_TREE` to 'true'.
696
753
 
697
754
  #### Toggle Red Hat Trusted Content recommendations
698
- Both the HTML-based report and JSON response will by default contain recommendations for migrating to Red Hat-based Trusted Content repositories. This feature can be disabled by setting `TRUSTIFY_DA_RECOMMENDATIONS_ENABLED` to 'false' via environment variables or options.
755
+ Both the HTML-based report and JSON response will by default contain recommendations for migrating to Red Hat-based Trusted Content repositories. This feature can be disabled by setting `TRUSTIFY_DA_RECOMMEND` to 'false' via environment variables or options.
699
756
 
700
757
  #### Additional CLI arguments
701
758
  For some ecosystems we support passing additional CLI arguments to the underlying tools. The following table outlines the supported ecosystems and the environment variable/option that configures this. Note that the arguments are expected to be in the format of a JSON array.
@@ -705,6 +762,135 @@ For some ecosystems we support passing additional CLI arguments to the underlyin
705
762
  |Maven |TRUSTIFY_DA_MVN_ARGS|
706
763
 
707
764
 
765
+ <h3>Remediation</h3>
766
+ <p>
767
+ 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.
768
+ </p>
769
+
770
+ <h4>Supported Manifest Formats</h4>
771
+ <ul>
772
+ <li><strong>Maven</strong> — <code>pom.xml</code> (single-module projects; updates dependency version elements and resolves property references)</li>
773
+ <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>
774
+ </ul>
775
+
776
+ <h4>CLI Flags</h4>
777
+ <table>
778
+ <tr>
779
+ <th>Flag</th>
780
+ <th>Alias</th>
781
+ <th>Type</th>
782
+ <th>Default</th>
783
+ <th>Description</th>
784
+ </tr>
785
+ <tr>
786
+ <td><code>&lt;path&gt;</code></td>
787
+ <td>—</td>
788
+ <td>string (positional)</td>
789
+ <td><em>required</em></td>
790
+ <td>Path to a manifest file or directory to scan recursively</td>
791
+ </tr>
792
+ <tr>
793
+ <td><code>--dry-run</code></td>
794
+ <td><code>-d</code></td>
795
+ <td>boolean</td>
796
+ <td><code>false</code></td>
797
+ <td>Preview changes without modifying files</td>
798
+ </tr>
799
+ <tr>
800
+ <td><code>--providers</code></td>
801
+ <td>—</td>
802
+ <td>string</td>
803
+ <td>—</td>
804
+ <td>Comma-separated list of vulnerability providers (env: <code>TRUSTIFY_DA_PROVIDERS</code>)</td>
805
+ </tr>
806
+ <tr>
807
+ <td><code>--sources</code></td>
808
+ <td>—</td>
809
+ <td>string</td>
810
+ <td>—</td>
811
+ <td>Comma-separated list of vulnerability sources (env: <code>TRUSTIFY_DA_SOURCES</code>)</td>
812
+ </tr>
813
+ <tr>
814
+ <td><code>--group-by</code></td>
815
+ <td>—</td>
816
+ <td>string</td>
817
+ <td><code>dependency</code></td>
818
+ <td>Report grouping strategy (<code>dependency</code> or <code>bundle</code>)</td>
819
+ </tr>
820
+ </table>
821
+
822
+ <h4>Provider Priority Resolution</h4>
823
+ <p>
824
+ 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.
825
+ </p>
826
+ <ul>
827
+ <li>The provider ordering in <code>--providers</code> determines rank (first = highest priority).</li>
828
+ <li>Trustify vendor trusted packages always take precedence over non-trusted content at equal provider rank.</li>
829
+ <li>Two version selection strategies are used internally:
830
+ <ul>
831
+ <li><strong>Closest coverage</strong> (default) — prefers the remediation version closest to the current version within the same major version.</li>
832
+ <li><strong>Highest</strong> — always selects the highest available remediation version.</li>
833
+ </ul>
834
+ </li>
835
+ </ul>
836
+
837
+ <h4>Exit Codes</h4>
838
+ <ul>
839
+ <li><code>0</code> — no remediations needed, or remediations applied successfully</li>
840
+ <li><code>1</code> — error during execution</li>
841
+ <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>
842
+ </ul>
843
+
844
+ <h4>Known Limitations</h4>
845
+ <ul>
846
+ <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>
847
+ <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>
848
+ </ul>
849
+
850
+ <h4>Example: GitHub Action Workflow</h4>
851
+ <p>
852
+ 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:
853
+ </p>
854
+
855
+ ```yaml
856
+ name: Trustify DA Remediation Scan
857
+
858
+ on:
859
+ schedule:
860
+ # Run weekly on Monday at 08:00 UTC
861
+ - cron: '0 8 * * 1'
862
+ workflow_dispatch:
863
+
864
+ permissions:
865
+ contents: write
866
+ pull-requests: write
867
+
868
+ jobs:
869
+ remediate:
870
+ runs-on: ubuntu-latest
871
+ steps:
872
+ - uses: actions/checkout@v4
873
+
874
+ - name: Run remediation scan
875
+ uses: docker://ghcr.io/guacsec/trustify-da-javascript-client:latest
876
+ env:
877
+ TRUSTIFY_DA_BACKEND_URL: ${{ secrets.TRUSTIFY_DA_BACKEND_URL }}
878
+ with:
879
+ entrypoint: trustify-da-javascript-client
880
+ args: remediate . --providers provider1,provider2
881
+
882
+ - name: Create pull request
883
+ uses: peter-evans/create-pull-request@v7
884
+ with:
885
+ title: 'fix(deps): apply Trustify DA vulnerability remediations'
886
+ body: |
887
+ Automated dependency version updates from Trustify Dependency Analytics.
888
+
889
+ This PR was generated by a scheduled remediation scan.
890
+ branch: trustify-da-remediation
891
+ commit-message: 'fix(deps): apply Trustify DA vulnerability remediations'
892
+ ```
893
+
708
894
  <!-- Badge links -->
709
895
  [0]: https://img.shields.io/github/v/release/guacsec/trustify-da-javascript-client?color=green&label=latest
710
896
  [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": "dist/src/cli.js",
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",
@@ -40,15 +42,15 @@
40
42
  "test": "c8 npm run tests",
41
43
  "tests": "mocha --config .mocharc.json",
42
44
  "tests:rep": "mocha --reporter-option maxDiffSize=0 --reporter json > unit-tests-result.json",
43
- "pretest": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm src/providers/tree-sitter-gomod.wasm",
45
+ "pretest": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm src/providers/tree-sitter-gomod.wasm && cp node_modules/tree-sitter-containerfile/tree-sitter-containerfile.wasm src/providers/tree-sitter-containerfile.wasm",
44
46
  "precompile": "rm -rf dist",
45
47
  "compile": "tsc -p tsconfig.json",
46
48
  "compile:dev": "tsc -p tsconfig.dev.json",
47
- "postcompile": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm dist/src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm dist/src/providers/tree-sitter-gomod.wasm"
49
+ "postcompile": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm dist/src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm dist/src/providers/tree-sitter-gomod.wasm && cp node_modules/tree-sitter-containerfile/tree-sitter-containerfile.wasm dist/src/providers/tree-sitter-containerfile.wasm"
48
50
  },
49
51
  "dependencies": {
50
52
  "@babel/core": "^7.23.2",
51
- "@cyclonedx/cyclonedx-library": "^10.0.0",
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",
@@ -61,6 +63,7 @@
61
63
  "p-limit": "^7.3.0",
62
64
  "packageurl-js": "~1.0.2",
63
65
  "smol-toml": "^1.6.0",
66
+ "tree-sitter-containerfile": "^0.8.1",
64
67
  "tree-sitter-gomod": "github:strum355/tree-sitter-go-mod#56326f2ad478892ace58ff247a97d492a3cbcdda",
65
68
  "tree-sitter-requirements": "github:Strum355/tree-sitter-requirements#d0261ee76b84253997fe70d7d397e78c006c3801",
66
69
  "web-tree-sitter": "^0.26.7",
@@ -68,18 +71,20 @@
68
71
  },
69
72
  "devDependencies": {
70
73
  "@babel/core": "^7.23.2",
71
- "@trustify-da/trustify-da-api-model": "^2.0.8",
74
+ "@cyclonedx/cyclonedx-library": "^10.2.0",
75
+ "@eslint/js": "^10.0.0",
76
+ "@trustify-da/trustify-da-api-model": "^2.0.12",
72
77
  "@types/node": "^25.9.1",
73
78
  "@types/which": "^3.0.4",
79
+ "ajv": "^8.20.0",
74
80
  "babel-plugin-rewire": "^1.2.0",
75
81
  "c8": "^11.0.0",
76
82
  "chai": "^6.2.2",
77
- "@eslint/js": "^10.0.0",
78
83
  "eslint": "^10.4.1",
79
84
  "eslint-import-resolver-typescript": "^4.4.4",
80
85
  "eslint-plugin-import-x": "^4.16.2",
81
- "globals": "^17.6.0",
82
86
  "esmock": "^2.6.2",
87
+ "globals": "^17.6.0",
83
88
  "mocha": "^11.7.6",
84
89
  "msw": "^2.12.7",
85
90
  "sinon": "^22.0.0",
@@ -113,9 +118,13 @@
113
118
  "reporter": [
114
119
  "html",
115
120
  "json",
121
+ "lcov",
116
122
  "text"
117
123
  ]
118
124
  },
125
+ "overrides": {
126
+ "tree-sitter": "0.22.4"
127
+ },
119
128
  "resolutions": {
120
129
  "@hapi/joi": "17.1.1"
121
130
  }
@@ -6,6 +6,7 @@ declare namespace _default {
6
6
  export { requestStackBatch };
7
7
  export { requestImages };
8
8
  export { validateToken };
9
+ export { appendAnalysisQueryParams };
9
10
  }
10
11
  export default _default;
11
12
  /**
@@ -57,3 +58,9 @@ declare function requestImages(imageRefs: Array<string>, url: string, html?: boo
57
58
  * @return {Promise<number>} return the HTTP status Code of the response from the validate token request.
58
59
  */
59
60
  declare function validateToken(url: any, opts?: any): Promise<number>;
61
+ /**
62
+ * Append common analysis query parameters (recommend, providers, sources) to a URL.
63
+ * @param {URL} url - the URL object to append query parameters to
64
+ * @param {import("index.js").Options} [opts={}] - options containing parameter overrides
65
+ */
66
+ declare function appendAnalysisQueryParams(url: URL, opts?: any): void;
@@ -6,7 +6,7 @@ import { generateImageSBOM, parseImageRef } from "./oci_image/utils.js";
6
6
  import { addProxyAgent, getCustom, getTokenHeaders, TRUSTIFY_DA_OPERATION_TYPE_HEADER, TRUSTIFY_DA_PACKAGE_MANAGER_HEADER } from "./tools.js";
7
7
  /** Media type for CycloneDX JSON batch payloads (batch-analysis API). */
8
8
  export const CYCLONEDX_JSON_MEDIA_TYPE = 'application/vnd.cyclonedx+json';
9
- export default { requestComponent, requestStack, requestStackBatch, requestImages, validateToken };
9
+ export default { requestComponent, requestStack, requestStackBatch, requestImages, validateToken, appendAnalysisQueryParams };
10
10
  /**
11
11
  * Send a stack analysis request and get the report as 'text/html' or 'application/json'.
12
12
  * @param {import('./provider').Provider} provider - the provided data for constructing the request
@@ -20,6 +20,9 @@ async function requestStack(provider, manifest, url, html = false, opts = {}) {
20
20
  opts["source-manifest"] = Buffer.from(fs.readFileSync(manifest).toString()).toString('base64');
21
21
  opts["manifest-type"] = path.parse(manifest).base;
22
22
  let provided = await provider.provideStack(manifest, opts); // throws error if content providing failed
23
+ if (provided.batch) {
24
+ return requestStackBatch(JSON.parse(provided.content), url, html, opts);
25
+ }
23
26
  opts["source-manifest"] = "";
24
27
  opts[TRUSTIFY_DA_OPERATION_TYPE_HEADER.toUpperCase().replaceAll("-", "_")] = "stack-analysis";
25
28
  let startTime = new Date();
@@ -38,9 +41,7 @@ async function requestStack(provider, manifest, url, html = false, opts = {}) {
38
41
  body: provided.content
39
42
  }, opts);
40
43
  const finalUrl = new URL(`${url}/api/v5/analysis`);
41
- if (opts['TRUSTIFY_DA_RECOMMENDATIONS_ENABLED'] === 'false') {
42
- finalUrl.searchParams.append('recommend', 'false');
43
- }
44
+ appendAnalysisQueryParams(finalUrl, opts);
44
45
  let resp = await fetch(finalUrl, fetchOptions);
45
46
  let result;
46
47
  if (resp.status === 200) {
@@ -79,6 +80,9 @@ async function requestStack(provider, manifest, url, html = false, opts = {}) {
79
80
  async function requestComponent(provider, manifest, url, opts = {}) {
80
81
  opts["source-manifest"] = Buffer.from(fs.readFileSync(manifest).toString()).toString('base64');
81
82
  let provided = await provider.provideComponent(manifest, opts); // throws error if content providing failed
83
+ if (provided.batch) {
84
+ return requestStackBatch(JSON.parse(provided.content), url, false, opts);
85
+ }
82
86
  opts["source-manifest"] = "";
83
87
  opts[TRUSTIFY_DA_OPERATION_TYPE_HEADER.toUpperCase().replaceAll("-", "_")] = "component-analysis";
84
88
  if (process.env["TRUSTIFY_DA_DEBUG"] === "true") {
@@ -95,9 +99,7 @@ async function requestComponent(provider, manifest, url, opts = {}) {
95
99
  body: provided.content
96
100
  }, opts);
97
101
  const finalUrl = new URL(`${url}/api/v5/analysis`);
98
- if (opts['TRUSTIFY_DA_RECOMMENDATIONS_ENABLED'] === 'false') {
99
- finalUrl.searchParams.append('recommend', 'false');
100
- }
102
+ appendAnalysisQueryParams(finalUrl, opts);
101
103
  let resp = await fetch(finalUrl, fetchOptions);
102
104
  let result;
103
105
  if (resp.status === 200) {
@@ -136,9 +138,7 @@ async function requestComponent(provider, manifest, url, opts = {}) {
136
138
  */
137
139
  async function requestStackBatch(sbomByPurl, url, html = false, opts = {}) {
138
140
  const finalUrl = new URL(`${url}/api/v5/batch-analysis`);
139
- if (opts['TRUSTIFY_DA_RECOMMENDATIONS_ENABLED'] === 'false') {
140
- finalUrl.searchParams.append('recommend', 'false');
141
- }
141
+ appendAnalysisQueryParams(finalUrl, opts);
142
142
  const fetchOptions = addProxyAgent({
143
143
  method: 'POST',
144
144
  headers: {
@@ -186,9 +186,7 @@ async function requestImages(imageRefs, url, html = false, opts = {}) {
186
186
  imageSboms[parsedImageRef.getPackageURL().toString()] = generateImageSBOM(parsedImageRef, opts);
187
187
  }
188
188
  const finalUrl = new URL(`${url}/api/v5/batch-analysis`);
189
- if (opts['TRUSTIFY_DA_RECOMMENDATIONS_ENABLED'] === 'false') {
190
- finalUrl.searchParams.append('recommend', 'false');
191
- }
189
+ appendAnalysisQueryParams(finalUrl, opts);
192
190
  const fetchOptions = addProxyAgent({
193
191
  method: 'POST',
194
192
  headers: {
@@ -222,6 +220,24 @@ async function requestImages(imageRefs, url, html = false, opts = {}) {
222
220
  throw new Error(`Got error response from Trustify DA backend - http return code : ${resp.status}, ex-request-id: ${resp.headers.get("ex-request-id")} error message => ${await resp.text()}`);
223
221
  }
224
222
  }
223
+ /**
224
+ * Append common analysis query parameters (recommend, providers, sources) to a URL.
225
+ * @param {URL} url - the URL object to append query parameters to
226
+ * @param {import("index.js").Options} [opts={}] - options containing parameter overrides
227
+ */
228
+ function appendAnalysisQueryParams(url, opts = {}) {
229
+ if (getCustom('TRUSTIFY_DA_RECOMMEND', 'true', opts) === 'false') {
230
+ url.searchParams.append('recommend', 'false');
231
+ }
232
+ const providers = getCustom('TRUSTIFY_DA_PROVIDERS', null, opts);
233
+ if (providers) {
234
+ url.searchParams.append('providers', providers);
235
+ }
236
+ const sources = getCustom('TRUSTIFY_DA_SOURCES', null, opts);
237
+ if (sources) {
238
+ url.searchParams.append('sources', sources);
239
+ }
240
+ }
225
241
  /**
226
242
  *
227
243
  * @param url the backend url to send the request to
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 = {
@@ -19,11 +20,25 @@ const component = {
19
20
  desc: 'Workspace root directory (for monorepos; lock file is expected here)',
20
21
  type: 'string',
21
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',
22
31
  }
23
32
  }),
24
33
  handler: async (args) => {
25
34
  let manifestName = args['/path/to/manifest'];
26
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
+ }
27
42
  let res = await client.componentAnalysis(manifestName, opts);
28
43
  console.log(JSON.stringify(res, null, 2));
29
44
  }
@@ -72,6 +87,14 @@ const image = {
72
87
  desc: 'For JSON report, get only the \'summary\'',
73
88
  type: 'boolean',
74
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',
75
98
  }
76
99
  }),
77
100
  handler: async (args) => {
@@ -81,7 +104,14 @@ const image = {
81
104
  }
82
105
  let html = args['html'];
83
106
  let summary = args['summary'];
84
- let res = await client.imageAnalysis(imageRefs, html);
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);
85
115
  if (summary && !html) {
86
116
  let summaries = {};
87
117
  for (let [imageRef, report] of Object.entries(res)) {
@@ -132,6 +162,14 @@ const stack = {
132
162
  desc: 'Workspace root directory (for monorepos; lock file is expected here)',
133
163
  type: 'string',
134
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',
135
173
  }
136
174
  }),
137
175
  handler: async (args) => {
@@ -139,6 +177,12 @@ const stack = {
139
177
  let html = args['html'];
140
178
  let summary = args['summary'];
141
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
+ }
142
186
  let theProvidersSummary = new Map();
143
187
  let theProvidersObject = {};
144
188
  let res = await client.stackAnalysis(manifest, html, opts);
@@ -201,6 +245,14 @@ const stackBatch = {
201
245
  desc: 'Stop on first invalid package.json or SBOM error (env: TRUSTIFY_DA_CONTINUE_ON_ERROR=false)',
202
246
  type: 'boolean',
203
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',
204
256
  }
205
257
  }),
206
258
  handler: async (args) => {
@@ -221,6 +273,12 @@ const stackBatch = {
221
273
  if (args.failFast) {
222
274
  opts.continueOnError = false;
223
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
+ }
224
282
  let res = await client.stackAnalysisBatch(workspaceRoot, html, opts);
225
283
  const batchAnalysis = res && typeof res === 'object' && res != null && 'analysis' in res ? res.analysis : res;
226
284
  if (summary && !html && typeof batchAnalysis === 'object') {
@@ -373,9 +431,54 @@ const sbom = {
373
431
  }
374
432
  }
375
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
+ };
376
479
  // parse and invoke the command
377
480
  yargs(hideBin(process.argv))
378
- .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}`)
379
482
  .command(stack)
380
483
  .command(stackBatch)
381
484
  .command(component)
@@ -383,6 +486,7 @@ yargs(hideBin(process.argv))
383
486
  .command(validateToken)
384
487
  .command(license)
385
488
  .command(sbom)
489
+ .command(remediate)
386
490
  .scriptName('')
387
491
  .version(false)
388
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
  */