@cyclonedx/cdxgen 8.0.0
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/.eslintrc.js +15 -0
- package/LICENSE +201 -0
- package/README.md +354 -0
- package/analyzer.js +189 -0
- package/bin/cdxgen +316 -0
- package/binary.js +507 -0
- package/docker.js +769 -0
- package/docker.test.js +72 -0
- package/index.js +4292 -0
- package/jest.config.js +181 -0
- package/known-licenses.json +27 -0
- package/lic-mapping.json +294 -0
- package/package.json +94 -0
- package/queries.json +68 -0
- package/server.js +110 -0
- package/spdx-licenses.json +500 -0
- package/utils.js +4284 -0
- package/utils.test.js +1660 -0
- package/vendor-alias.json +10 -0
package/.eslintrc.js
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
# CycloneDX Generator
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This tool creates a valid and compliant CycloneDX Software Bill-of-Materials (SBOM) containing an aggregate of all project dependencies for c/c++, node.js, php, python, ruby, rust, java, .Net, dart, haskell, elixir, and Go projects in XML and JSON format. CycloneDX 1.4 is a lightweight SBOM specification that is easily created, human and machine-readable, and simple to parse.
|
|
6
|
+
|
|
7
|
+
When used with plugins, cdxgen could generate an SBoM for Linux docker images and even VMs running Linux or Windows operating system.
|
|
8
|
+
|
|
9
|
+
## Supported languages and package format
|
|
10
|
+
|
|
11
|
+
| Language/Platform | Package format | Transitive dependencies |
|
|
12
|
+
| ------------------------------------------------------ | ----------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
13
|
+
| node.js | npm-shrinkwrap.json, package-lock.json, pnpm-lock.yaml, yarn.lock, rush.js, bower.json, .min.js | Yes except .min.js |
|
|
14
|
+
| java | maven (pom.xml [1]), gradle (build.gradle, .kts), scala (sbt), bazel | Yes unless pom.xml is manually parsed due to unavailability of maven or errors |
|
|
15
|
+
| php | composer.lock | Yes |
|
|
16
|
+
| python | setup.py, requirements.txt [2], Pipfile.lock, poetry.lock, bdist_wheel, .whl, .egg-info | Only with Pipfile.lock and poetry.lock |
|
|
17
|
+
| go | binary, go.mod, go.sum, Gopkg.lock | Yes except binary |
|
|
18
|
+
| ruby | Gemfile.lock, gemspec | Only for Gemfile.lock |
|
|
19
|
+
| rust | binary, Cargo.toml, Cargo.lock | Only for Cargo.lock |
|
|
20
|
+
| .Net | .csproj, packages.config, project.assets.json [3], packages.lock.json, .nupkg | Only for project.assets.json, packages.lock.json |
|
|
21
|
+
| dart | pubspec.lock, pubspec.yaml | Only for pubspec.lock |
|
|
22
|
+
| haskell | cabal.project.freeze | Yes |
|
|
23
|
+
| elixir | mix.lock | Yes |
|
|
24
|
+
| c/c++ | conan.lock, conanfile.txt | Yes only for conan.lock |
|
|
25
|
+
| clojure | Clojure CLI (deps.edn), Leiningen (project.clj) | Yes unless the files are parsed manually due to lack of clojure cli or leiningen command |
|
|
26
|
+
| docker / oci image | All supported languages. Linux OS packages with plugins [4] | Best effort based on lock files |
|
|
27
|
+
| GitHub Actions | .github/workflows/\*.yml | N/A |
|
|
28
|
+
| Linux | All supported languages. Linux OS packages with plugins [5] | Best effort based on lock files |
|
|
29
|
+
| Windows | All supported languages. OS packages with best effort [5] | Best effort based on lock files |
|
|
30
|
+
| Jenkins Plugins | .hpi files | |
|
|
31
|
+
| Helm Charts | .yaml | N/A |
|
|
32
|
+
| Skaffold | .yaml | N/A |
|
|
33
|
+
| kustomization | .yaml | N/A |
|
|
34
|
+
| Tekton tasks | .yaml | N/A |
|
|
35
|
+
| Kubernetes | .yaml | N/A |
|
|
36
|
+
| Maven Cache | $HOME/.m2/repository/\*\*/\*.jar | N/A |
|
|
37
|
+
| SBT Cache | $HOME/.ivy2/cache/\*\*/\*.jar | N/A |
|
|
38
|
+
| Gradle Cache | $HOME/caches/modules-2/files-2.1/\*\*/\*.jar | N/A |
|
|
39
|
+
| Helm Index | $HOME/.cache/helm/repository/\*\*/\*.yaml | N/A |
|
|
40
|
+
| Docker compose | docker-compose\*.yml. Images would also be scanned. | N/A |
|
|
41
|
+
| Google CloudBuild configuration | cloudbuild.yaml | N/A |
|
|
42
|
+
| OpenAPI | openapi\*.json, openapi\*.yaml | N/A |
|
|
43
|
+
| [Privado](https://www.privado.ai?utm_source=cyclonedx) | privado.json | Data and service information will be included. Use with universal mode. |
|
|
44
|
+
|
|
45
|
+
NOTE:
|
|
46
|
+
|
|
47
|
+
- Apache maven 3.x is required for parsing pom.xml
|
|
48
|
+
- gradle or gradlew is required to parse gradle projects
|
|
49
|
+
- sbt is required for parsing scala sbt projects. Only scala 2.10 + sbt 0.13.6+ and 2.12 + sbt 1.0+ is supported for now.
|
|
50
|
+
- Alternatively, create a lock file using sbt-dependency-lock [plugin](https://github.com/stringbean/sbt-dependency-lock)
|
|
51
|
+
|
|
52
|
+
Footnotes:
|
|
53
|
+
|
|
54
|
+
- [1] - For multi-module application, the BoM file could include components that may not be included in the packaged war or ear file.
|
|
55
|
+
- [2] - Use pip freeze to improve the accuracy for requirements.txt based parsing. `python -m pip freeze > requirements.txt`
|
|
56
|
+
- [3] - Perform dotnet or nuget restore to generate project.assets.json. Without this file cdxgen would not include indirect dependencies.
|
|
57
|
+
- [4] - See section on plugins
|
|
58
|
+
- [5] - Powered by osquery. See section on plugins
|
|
59
|
+
|
|
60
|
+
### Automatic usage detection
|
|
61
|
+
|
|
62
|
+
For node.js projects, lock files are parsed initially so the SBoM would include all dependencies including dev dependencies. An AST parser powered by babel-parser is then used to detect packages that are imported and used by non-test code. Such imported packages would automatically have their `scope` property set to `required` in the resulting SBoM. By passing the argument `--no-babel`, you can disable this analysis. Scope property would then be set based on the `dev` attribute in the lock file.
|
|
63
|
+
|
|
64
|
+
This attribute can be later used for various purposes. For example, [dep-scan](https://github.com/cyclonedx/dep-scan) use this attribute to prioritize vulnerabilities. Tools such dependency track, unfortunately, do not include this feature and hence might over-report the CVEs.
|
|
65
|
+
|
|
66
|
+
By passing the argument `--required-only`, you can limit the SBoM to only include packages with the scope "required", commonly referred to as production or non-dev dependencies. Combine with `--no-babel` to limit this list to only non-dev dependencies based on the `dev` attribute being false in the lock files.
|
|
67
|
+
|
|
68
|
+
For go, `go mod why` command is used to identify required packages. For php, composer lock file is used to distinguish required (packages) from optional (packages-dev).
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
## Installing
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
sudo npm install -g @cyclonedx/cdxgen
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
You can also use the cdxgen container image
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
docker run --rm -it -v /tmp:/tmp -v $(pwd):/app:rw -t ghcr.io/cyclonedx/cdxgen -r /app
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Getting Help
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
$ cdxgen -h
|
|
88
|
+
Options:
|
|
89
|
+
-o, --output Output file for bom.xml or bom.json. Default console
|
|
90
|
+
-t, --type Project type
|
|
91
|
+
-r, --recurse Recurse mode suitable for mono-repos [boolean]
|
|
92
|
+
-p, --print Print the SBoM as a table [boolean]
|
|
93
|
+
-c, --resolve-class Resolve class names for packages. jars only for now.
|
|
94
|
+
[boolean]
|
|
95
|
+
--deep Perform deep searches for components. Useful while
|
|
96
|
+
scanning live OS and oci images. [boolean]
|
|
97
|
+
--server-url Dependency track url. Eg:
|
|
98
|
+
https://deptrack.cyclonedx.io
|
|
99
|
+
--api-key Dependency track api key
|
|
100
|
+
--project-group Dependency track project group
|
|
101
|
+
--project-name Dependency track project name. Default use
|
|
102
|
+
the directory name
|
|
103
|
+
--project-version Dependency track project version
|
|
104
|
+
--project-id Dependency track project id. Either
|
|
105
|
+
provide the id or the project name and version together
|
|
106
|
+
--required-only Include only the packages with required scope on the
|
|
107
|
+
SBoM. [boolean]
|
|
108
|
+
--fail-on-error Fail if any dependency extractor fails. [boolean]
|
|
109
|
+
--no-babel Do not use babel to perform usage analysis for
|
|
110
|
+
JavaScript/TypeScript projects. [boolean]
|
|
111
|
+
--generate-key-and-sign Generate an RSA public/private key pair and then
|
|
112
|
+
sign the generated SBoM using JSON Web
|
|
113
|
+
Signatures. [boolean]
|
|
114
|
+
--server Run cdxgen as a server [boolean]
|
|
115
|
+
--server-host Listen address [default: "127.0.0.1"]
|
|
116
|
+
--server-port Listen port [default: "9090"]
|
|
117
|
+
--version Show version number [boolean]
|
|
118
|
+
-h Show help [boolean]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Example
|
|
122
|
+
|
|
123
|
+
Minimal example.
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
cdxgen -o bom.json
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
NOTE:
|
|
130
|
+
|
|
131
|
+
cdxgen would always produce bom in both xml and json format as per CycloneDX 1.4 specification. json is the recommended format.
|
|
132
|
+
|
|
133
|
+
For a java project. This would automatically detect maven, gradle or sbt and build bom accordingly
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
cdxgen -t java -o bom.json
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
To print the SBoM as a table pass `-p` argument.
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
cdxgen -t java -o bom.json -p
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
To recursively generate a single BoM for all languages pass `-r` argument.
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
cdxgen -r -o bom.json
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Universal SBoM
|
|
152
|
+
|
|
153
|
+
By passing the type `-t universal`, cdxgen could be forced to opportunistically collect as many components and services as possible by scanning all package, container and kubernetes manifests. The resulting SBoM could have over thousand components thus requiring additional triaging before use with traditional SCA tools.
|
|
154
|
+
|
|
155
|
+
## SBoM server
|
|
156
|
+
|
|
157
|
+
Invoke cdxgen with `--server` argument to run it in a server mode. By default, it listens to port `9090` which can be customized with the arguments `--server-host` and `--server-port`.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
cdxgen --server
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Or use the container image.
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
docker run --rm -it -v /tmp:/tmp -p 9090:9090 -v $(pwd):/app:rw -t ghcr.io/cyclonedx/cdxgen -r /app --server
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Use curl or your favourite tool to pass arguments to the `/sbom` route.
|
|
170
|
+
|
|
171
|
+
### Scanning a local path
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
curl "http://127.0.0.1:9090/sbom?path=/Volumes/Work/sandbox/vulnerable-aws-koa-app&multiProject=true&type=js"
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Scanning a git repo
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
curl "http://127.0.0.1:9090/sbom?url=https://github.com/HooliCorp/vulnerable-aws-koa-app.git&multiProject=true&type=js"
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
You can POST the arguments.
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
curl -H "Content-Type: application/json" http://localhost:9090/sbom -XPOST -d $'{"url": "https://github.com/HooliCorp/vulnerable-aws-koa-app.git", "type": "nodejs", "multiProject": "true"}'
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Docker compose
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
git clone https://github.com/cyclonedx/cdxgen.git
|
|
193
|
+
docker compose up
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Privado.ai support
|
|
197
|
+
|
|
198
|
+
In universal mode, cdxgen can look for any [Privado](https://www.privado.ai?utm_source=cyclonedx) scan reports and enrich the SBoM with data (flow and classification), endpoints, and leakage information. Such an SBoM would help with privacy compliance and use cases.
|
|
199
|
+
|
|
200
|
+
Invoke privado scan first to generate this report followed by an invocation of cdxgen in universal mode as shown.
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
privado scan --enable-javascript <directory>
|
|
204
|
+
cdxgen -t universal <directory> -o bom.json
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## War file support
|
|
208
|
+
|
|
209
|
+
cdxgen can generate a BoM file from a given war file.
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# cdxgen -t java app.war
|
|
213
|
+
cdxgen app.war
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Resolving class names
|
|
217
|
+
|
|
218
|
+
Sometimes it is necessary to resolve class names contained in jar files. By passing an optional argument `--resolve-class`, it is possible to get cdxgen create a separate mapping file with the jar name (including the version) as the key and class names list as a value.
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
cdxgen -t java --resolve-class -o bom.json
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
This would create a bom.json.map file with the jar - class name mapping. Refer to [these](test/data/bom-maven.json.map) [examples](test/data/bom-gradle.json.map) to learn about the structure.
|
|
225
|
+
|
|
226
|
+
## Resolving licenses
|
|
227
|
+
|
|
228
|
+
cdxgen can automatically query the public registries such as maven or npm or nuget to resolve the package licenses. This is a time consuming operation and is disabled by default. To enable, set the environment variable `FETCH_LICENSE` to `true` as shown.
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
export FETCH_LICENSE=true
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Dependency Tree
|
|
235
|
+
|
|
236
|
+
cdxgen can retain the dependency tree under the `dependencies` attribute for a small number of supported package manifests. These are currently limited to:
|
|
237
|
+
|
|
238
|
+
- package-lock.json
|
|
239
|
+
- yarn.lock
|
|
240
|
+
- pnpm-lock.yaml
|
|
241
|
+
- Maven (pom.xml)
|
|
242
|
+
- Gradle
|
|
243
|
+
|
|
244
|
+
## Environment variables
|
|
245
|
+
|
|
246
|
+
| Variable | Description |
|
|
247
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
248
|
+
| SCAN_DEBUG_MODE | Set to debug to enable debug messages |
|
|
249
|
+
| GITHUB_TOKEN | Specify GitHub token to prevent traffic shaping while querying license and repo information |
|
|
250
|
+
| MVN_CMD | Set to override maven command |
|
|
251
|
+
| MVN_ARGS | Set to pass additional arguments such as profile or settings to maven |
|
|
252
|
+
| MAVEN_HOME | Specify maven home |
|
|
253
|
+
| GRADLE_CACHE_DIR | Specify gradle cache directory. Useful for class name resolving |
|
|
254
|
+
| GRADLE_MULTI_PROJECT_MODE | Set this variable for gradle multi-project applications. Do not use this with recurse mode. |
|
|
255
|
+
| GRADLE_ARGS | Set to pass additional arguments such as profile or settings to gradle. Eg: --configuration runtimeClassPath |
|
|
256
|
+
| GRADLE_HOME | Specify gradle home |
|
|
257
|
+
| GRADLE_CMD | Set to override gradle command |
|
|
258
|
+
| GRADLE_DEPENDENCY_TASK | By default cdxgen use the task "dependencies" to collect packages. Set to override the task name. |
|
|
259
|
+
| SBT_CACHE_DIR | Specify sbt cache directory. Useful for class name resolving |
|
|
260
|
+
| FETCH_LICENSE | Set to true to fetch license information from the registry. npm and golang only |
|
|
261
|
+
| USE_GOSUM | Set to true to generate BOMs for golang projects using go.sum as the dependency source of truth, instead of go.mod |
|
|
262
|
+
| CDXGEN_TIMEOUT_MS | Default timeout for known execution involving maven, gradle or sbt |
|
|
263
|
+
| BAZEL_TARGET | Bazel target to build. Default :all (Eg: //java-maven) |
|
|
264
|
+
| CLJ_CMD | Set to override the clojure cli command |
|
|
265
|
+
| LEIN_CMD | Set to override the leiningen command |
|
|
266
|
+
| SBOM_SIGN_ALGORITHM | Signature algorithm. Some valid values are RS256, RS384, RS512, PS256, PS384, PS512, ES256 etc |
|
|
267
|
+
| SBOM_SIGN_PRIVATE_KEY | Private key to use for signing |
|
|
268
|
+
| SBOM_SIGN_PUBLIC_KEY | Optional. Public key to include in the SBoM signature |
|
|
269
|
+
|
|
270
|
+
## Plugins
|
|
271
|
+
|
|
272
|
+
cdxgen could be extended with external binary plugins to support more SBoM use cases. These are now installed as an optional dependency.
|
|
273
|
+
|
|
274
|
+
```
|
|
275
|
+
sudo npm install -g @cyclonedx/cdxgen-plugins-bin
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Docker / OCI container support
|
|
279
|
+
|
|
280
|
+
`docker` type is automatically detected based on the presence of values such as `sha256` or `docker.io` prefix etc in the path.
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
cdxgen odoo@sha256:4e1e147f0e6714e8f8c5806d2b484075b4076ca50490577cdf9162566086d15e -o /tmp/bom.json
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
You can also pass `-t docker` for simple labels. Only the `latest` tag would be pulled if none was specified.
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
cdxgen shiftleft/scan-slim -o /tmp/bom.json -t docker
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
You can also pass the .tar file of a container image.
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
docker save -o /tmp/slim.tar shiftleft/scan-slim
|
|
296
|
+
podman save -q --format oci-archive -o /tmp/slim.tar shiftleft/scan-slim
|
|
297
|
+
cdxgen /tmp/slim.tar -o /tmp/bom.json -t docker
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
NOTE:
|
|
301
|
+
|
|
302
|
+
- Only application related packages are collected by cdxgen. Support for OS installed packages is coming soon.
|
|
303
|
+
|
|
304
|
+
### Podman in rootless mode
|
|
305
|
+
|
|
306
|
+
Setup podman in either [rootless](https://github.com/containers/podman/blob/master/docs/tutorials/rootless_tutorial.md) or [remote](https://github.com/containers/podman/blob/master/docs/tutorials/mac_win_client.md) mode
|
|
307
|
+
|
|
308
|
+
On Linux, do not forget to start the podman socket which is required for API access.
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
systemctl --user enable --now podman.socket
|
|
312
|
+
systemctl --user start podman.socket
|
|
313
|
+
podman system service -t 0 &
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Generate SBoM for a live system
|
|
317
|
+
|
|
318
|
+
You can use cdxgen to generate SBoM for a live system or a VM for compliance and vulnerability management purposes by passing the argument `-t os`.
|
|
319
|
+
|
|
320
|
+
```
|
|
321
|
+
cdxgen -t os
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
This feature is powered by osquery which is [installed](https://github.com/cyclonedx/cdxgen-plugins-bin/blob/main/build.sh#L8) along with the binary plugins. cdxgen would opportunistically try to detect as many components, apps and extensions as possible using the [default queries](queries.json). The process would take several minutes and result in an SBoM file with thousands of components.
|
|
325
|
+
|
|
326
|
+
## SBoM signing
|
|
327
|
+
|
|
328
|
+
cdxgen can sign the generated SBoM json file to increase authenticity and non-repudiation capabilities. To enable this, set the following environment variables.
|
|
329
|
+
|
|
330
|
+
- SBOM_SIGN_ALGORITHM: Algorithm. Example: RS512
|
|
331
|
+
- SBOM_SIGN_PRIVATE_KEY: Location to the RSA private key
|
|
332
|
+
- SBOM_SIGN_PUBLIC_KEY: Optional. Location to the RSA public key
|
|
333
|
+
|
|
334
|
+
To generate test public/private key pairs, you can run cdxgen by passing the argument `--generate-key-and-sign`. The generated json file would have an attribute called `signature` which could be used for validation. [jwt.io](jwt.io) is a known site that could be used for such signature validation.
|
|
335
|
+
|
|
336
|
+

|
|
337
|
+
|
|
338
|
+
## Automatic services detection
|
|
339
|
+
|
|
340
|
+
cdxgen could automatically detect names of services from YAML manifests such as docker-compose or Kubernetes or Skaffold manifests. These would be populated under the `services` attribute in the generated SBoM. Please help improve this feature by filing issues for any inaccurate detection.
|
|
341
|
+
|
|
342
|
+
## Conversion to SPDX format
|
|
343
|
+
|
|
344
|
+
Use the [CycloneDX CLI](https://github.com/CycloneDX/cyclonedx-cli) tool for advanced use cases such as conversion, diff and merging.
|
|
345
|
+
|
|
346
|
+
## License
|
|
347
|
+
|
|
348
|
+
Permission to modify and redistribute is granted under the terms of the Apache 2.0 license. See the [LICENSE](LICENSE) file for the full license.
|
|
349
|
+
|
|
350
|
+
[license]: https://github.com/cyclonedx/cdxgen/blob/master/LICENSE
|
|
351
|
+
|
|
352
|
+
## Discord support
|
|
353
|
+
|
|
354
|
+
The developers could be reached via the [discord](https://discord.gg/DCNxzaeUpd) channel.
|