Gathering detailed insights and metrics for @cyclonedx/cdxgen
Gathering detailed insights and metrics for @cyclonedx/cdxgen
Gathering detailed insights and metrics for @cyclonedx/cdxgen
Gathering detailed insights and metrics for @cyclonedx/cdxgen
Creates CycloneDX Bill of Materials (BOM) for your projects from source and container images. Supports many languages and package managers. Integrate in your CI/CD pipeline with automatic submission to Dependency Track server. GPT: https://chatgpt.com/g/g-673bfeb4037481919be8a2cd1bf868d2-cdxgen
npm install @cyclonedx/cdxgen
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
588 Stars
1,414 Commits
157 Forks
18 Watching
41 Branches
71 Contributors
Updated on 28 Nov 2024
JavaScript (89.25%)
CMake (4.37%)
Python (2.18%)
Roff (1.42%)
Dockerfile (0.77%)
Meson (0.45%)
Elixir (0.38%)
Java (0.34%)
Shell (0.24%)
Clojure (0.22%)
Ruby (0.15%)
Makefile (0.13%)
Starlark (0.06%)
TypeScript (0.04%)
Cumulative downloads
Total Downloads
Last day
-17%
6,939
Compared to previous day
Last week
-6.2%
41,660
Compared to previous week
Last month
9.2%
189,579
Compared to previous month
Last year
56.3%
1,393,138
Compared to previous year
27
3
16
cdxgen is a CLI tool, library, REPL, and server to create a valid and compliant CycloneDX Bill of Materials (BOM) containing an aggregate of all project dependencies in JSON format. CycloneDX is a full-stack BOM specification that is easily created, human and machine-readable, and simple to parse. The tool supports CycloneDX specification versions from 1.4 - 1.6.
Supported BOM formats:
Most SBOM tools are like simple barcode scanners. For easy applications, they can parse a few package manifests and create a list of components only based on these files without any deep inspection. Further, a typical application might have several repos, components, and libraries with complex build requirements. Traditional techniques to generate an SBOM per language or package manifest either do not work in enterprise environments or don't provide the confidence required for both compliance and automated analysis. So we built cdxgen - the universal polyglot SBOM generator that is user-friendly, precise, and comprehensive!
Our philosophy:
Please visit our GPT app or the documentation site for detailed usage, tutorials, and support documentation.
Sections include:
1npm install -g @cyclonedx/cdxgen
If you are a Homebrew user, you can also install cdxgen via:
1$ brew install cdxgen
Deno and bun runtime can be used with limited support.
1deno install --allow-read --allow-env --allow-run --allow-sys=uid,systemMemoryInfo,gid,homedir --allow-write --allow-net -n cdxgen "npm:@cyclonedx/cdxgen/cdxgen"
You can also use the cdxgen container image with node, deno, or bun runtime versions.
The default version uses Node.js 22
1docker run --rm -e CDXGEN_DEBUG_MODE=debug -v /tmp:/tmp -v $(pwd):/app:rw -t ghcr.io/cyclonedx/cdxgen:master -r /app -o /app/bom.json
To use the deno version, use ghcr.io/cyclonedx/cdxgen-deno
as the image name.
1docker run --rm -e CDXGEN_DEBUG_MODE=debug -v /tmp:/tmp -v $(pwd):/app:rw -t ghcr.io/cyclonedx/cdxgen-deno:master -r /app -o /app/bom.json
For the bun version, use ghcr.io/cyclonedx/cdxgen-bun
as the image name.
1docker run --rm -e CDXGEN_DEBUG_MODE=debug -v /tmp:/tmp -v $(pwd):/app:rw -t ghcr.io/cyclonedx/cdxgen-bun:master -r /app -o /app/bom.json
In deno applications, cdxgen could be directly imported without any conversion. Please see the section on integration as a library
1import { createBom, submitBom } from "npm:@cyclonedx/cdxgen@^11.0.0";
1cdxgen [command] 2 3Commands: 4 cdxgen completion Generate bash/zsh completion 5 6Options: 7 -o, --output Output file. Default bom.json [default: "bom.json"] 8 -t, --type Project type. Please refer to https://cyclonedx.github.io/cdxgen/#/PROJECT_TYPES for supp 9 orted languages/platforms. [array] 10 --exclude-type Project types to exclude. Please refer to https://cyclonedx.github.io/cdxgen/#/PROJECT_TY 11 PES for supported languages/platforms. 12 -r, --recurse Recurse mode suitable for mono-repos. Defaults to true. Pass --no-recurse to disable. 13 [boolean] [default: true] 14 -p, --print Print the SBOM as a table with tree. [boolean] 15 -c, --resolve-class Resolve class names for packages. jars only for now. [boolean] 16 --deep Perform deep searches for components. Useful while scanning C/C++ apps, live OS and oci i 17 mages. [boolean] 18 --server-url Dependency track url. Eg: https://deptrack.cyclonedx.io 19 --skip-dt-tls-check Skip TLS certificate check when calling Dependency-Track. [boolean] [default: false] 20 --api-key Dependency track api key 21 --project-group Dependency track project group 22 --project-name Dependency track project name. Default use the directory name 23 --project-version Dependency track project version [string] [default: ""] 24 --project-id Dependency track project id. Either provide the id or the project name and version togeth 25 er [string] 26 --parent-project-id Dependency track parent project id [string] 27 --required-only Include only the packages with required scope on the SBOM. Would set compositions.aggrega 28 te to incomplete unless --no-auto-compositions is passed. [boolean] 29 --fail-on-error Fail if any dependency extractor fails. [boolean] 30 --no-babel Do not use babel to perform usage analysis for JavaScript/TypeScript projects. [boolean] 31 --generate-key-and-sign Generate an RSA public/private key pair and then sign the generated SBOM using JSON Web S 32 ignatures. [boolean] 33 --server Run cdxgen as a server [boolean] 34 --server-host Listen address [default: "127.0.0.1"] 35 --server-port Listen port [default: "9090"] 36 --install-deps Install dependencies automatically for some projects. Defaults to true but disabled for c 37 ontainers and oci scans. Use --no-install-deps to disable this feature. [boolean] 38 --validate Validate the generated SBOM using json schema. Defaults to true. Pass --no-validate to di 39 sable. [boolean] [default: true] 40 --evidence Generate SBOM with evidence for supported languages. [boolean] [default: false] 41 --spec-version CycloneDX Specification version to use. Defaults to 1.6 [number] [default: 1.6] 42 --filter Filter components containing this word in purl or component.properties.value. Multiple va 43 lues allowed. [array] 44 --only Include components only containing this word in purl. Useful to generate BOM with first p 45 arty components alone. Multiple values allowed. [array] 46 --author The person(s) who created the BOM. Set this value if you're intending the modify the BOM 47 and claim authorship. [array] [default: "OWASP Foundation"] 48 --profile BOM profile to use for generation. Default generic. 49 [choices: "appsec", "research", "operational", "threat-modeling", "license-compliance", "generic", "machine-learning", 50 "ml", "deep-learning", "ml-deep", "ml-tiny"] [default: "generic"] 51 --exclude Additional glob pattern(s) to ignore [array] 52 --include-formulation Generate formulation section with git metadata and build tools. Defaults to false. 53 [boolean] [default: false] 54 --include-crypto Include crypto libraries as components. [boolean] [default: false] 55 --standard The list of standards which may consist of regulations, industry or organizational-specif 56 ic standards, maturity models, best practices, or any other requirements which can be eva 57 luated against or attested to. 58 [array] [choices: "asvs-4.0.3", "bsimm-v13", "masvs-2.0.0", "nist_ssdf-1.1", "pcissc-secure-slc-1.1", "scvs-1.0.0", "s 59 saf-DRAFT-2023-11"] 60 --min-confidence Minimum confidence needed for the identity of a component from 0 - 1, where 1 is 100% con 61 fidence. [number] [default: 0] 62 --technique Analysis technique to use 63 [array] [choices: "auto", "source-code-analysis", "binary-analysis", "manifest-analysis", "hash-comparison", "instrume 64 ntation", "filename"] 65 --auto-compositions Automatically set compositions when the BOM was filtered. Defaults to true 66 [boolean] [default: true] 67 -h, --help Show help [boolean] 68 -v, --version Show version number [boolean]
All boolean arguments accept --no
prefix to toggle the behavior.
Minimal example.
1cdxgen -o bom.json
For a java project. cdxgen would automatically detect maven, gradle, or sbt and build bom accordingly
1cdxgen -t java -o bom.json
To print the SBOM as a table pass -p
argument.
1cdxgen -t java -o bom.json -p
To recursively generate a single BOM for all languages pass -r
argument.
1cdxgen -r -o bom.json
The default specification used by cdxgen is 1.5. To generate BOM for a different specification version, such as 1.6 or 1.4, pass the version number using the --spec-version
argument.
1# 1.6 is unsupported by most tools 2cdxgen -r -o bom.json --spec-version 1.6 3 4# 1.4 is supported by most tools 5cdxgen -r -o bom.json --spec-version 1.4
To generate SBOM for C or Python, ensure Java >= 21 is installed.
1# Install java >= 21 2cdxgen -t c -o bom.json
NOTE: cdxgen is known to freeze with Java 8 or 11, so ensure >= 21 is installed and JAVA_HOME environment variable is configured correctly. If in doubt, use the cdxgen container image.
By passing the type argument -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 a thousand components, thus requiring additional triaging before use with traditional SCA tools.
Invoke cdxgen with --server
argument to run it in server mode. By default, it listens to port 9090
, which can be customized with the arguments --server-host
and --server-port
.
1cdxgen --server
Or use the container image.
1docker run --rm -v /tmp:/tmp -p 9090:9090 -v $(pwd):/app:rw -t ghcr.io/cyclonedx/cdxgen -r /app --server --server-host 0.0.0.0
Use curl or your favorite tool to pass arguments to the /sbom
route.
Arguments can be passed either via the query string or as a JSON body. Please refer to Server Usage
Use the /health endpoint to check if the SBOM server is up and running.
1curl "http://127.0.0.1:9090/health"
1curl "http://127.0.0.1:9090/sbom?path=/Volumes/Work/sandbox/vulnerable-aws-koa-app&multiProject=true&type=js"
1curl "http://127.0.0.1:9090/sbom?url=https://github.com/HooliCorp/vulnerable-aws-koa-app.git&multiProject=true&type=js"
If you need to pass credentials to authenticate.
1curl "http://127.0.0.1:9090/sbom?url=https://<access_token>@github.com/some/repo.git&multiProject=true&type=js" 2curl "http://127.0.0.1:9090/sbom?url=https://<username>:<password>@bitbucket.org/some/repo.git&multiProject=true&type=js"
You can POST the arguments.
1curl -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"}'
1git clone https://github.com/cyclonedx/cdxgen.git 2docker compose up
cdxgen can generate a BOM file from a given war file.
1# cdxgen -t java app.war 2cdxgen app.war
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 to create a separate mapping file with the jar name (including the version) as the key and class names list as a value.
1cdxgen -t java --resolve-class -o bom.json
This would create a bom.json.map file with the jar - class name mapping. Refer to these examples to learn about the structure.
cdxgen can automatically query public registries such as maven, 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. Ensure that GITHUB_TOKEN
is set or provided by built-in GITHUB_TOKEN in GitHub Actions, otherwise rate limiting might prevent license resolving.
1export FETCH_LICENSE=true
cdxgen can retain the dependency tree under the dependencies
attribute for a small number of supported package manifests. These are currently limited to:
cdxgen could be extended with external binary plugins to support more SBOM use cases. These are now installed as an optional dependency.
1sudo npm install -g @cyclonedx/cdxgen-plugins-bin
docker
type is automatically detected based on the presence of values such as sha256
or docker.io
prefix etc in the path.
1cdxgen odoo@sha256:4e1e147f0e6714e8f8c5806d2b484075b4076ca50490577cdf9162566086d15e -o /tmp/bom.json
You can also pass -t docker
with repository names. Only the latest
tag would be pulled if none was specified.
1cdxgen shiftleft/scan-slim -o /tmp/bom.json -t docker
You can also pass the .tar file of a container image.
1docker pull shiftleft/scan-slim 2docker save -o /tmp/slim.tar shiftleft/scan-slim 3podman save -q --format oci-archive -o /tmp/slim.tar shiftleft/scan-slim 4cdxgen /tmp/slim.tar -o /tmp/bom.json -t docker
Setup podman in either rootless or remote mode
Do not forget to start the podman socket required for API access on Linux.
1systemctl --user enable --now podman.socket 2systemctl --user start podman.socket 3podman system service -t 0 &
You can use the obom
command to generate an OBOM for a live system or a VM for compliance and vulnerability management purposes. Windows and Linux operating systems are supported in this mode.
1# obom is an alias for cdxgen -t os 2obom 3# cdxgen -t os
This feature is powered by osquery, which is installed along with the binary plugins. cdxgen would opportunistically try to detect as many components, apps, and extensions as possible using the default queries. The process would take several minutes and result in an SBOM file with thousands of components of various types, such as operating-system, device-drivers, files, and data.
Use the cbom
alias to generate a CBOM. This is currently supported only for Java projects.
1cbom -t java 2# cdxgen -t java --include-crypto -o bom.json .
See evinse mode in the advanced documentation.
cdxgen can sign the generated BOM json file to increase authenticity and non-repudiation capabilities. To enable this, set the following environment variables.
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 is a known site that could be used for such signature validation.
Use the bundled cdx-verify
command, which supports verifying a single signature added at the bom level.
1npm install -g @cyclonedx/cdxgen 2cdx-verify -i bom.json --public-key public.key
There are many libraries available to validate JSON Web Tokens. Below is a javascript example.
1# npm install jws 2const jws = require("jws"); 3const fs = require("fs"); 4// Location of the SBOM json file 5const bomJsonFile = "bom.json"; 6// Location of the public key 7const publicKeyFile = "public.key"; 8const bomJson = JSON.parse(fs.readFileSync(bomJsonFile, "utf8")); 9// Retrieve the signature 10const bomSignature = bomJson.signature.value; 11const validationResult = jws.verify(bomSignature, bomJson.signature.algorithm, fs.readFileSync(publicKeyFile, "utf8")); 12if (validationResult) { 13 console.log("Signature is valid!"); 14} else { 15 console.log("SBOM signature is invalid :("); 16}
For node.js projects, lock files are parsed initially, so the SBOM would include all dependencies, including dev ones. 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 set their scope property to required
in the resulting SBOM. You can turn off this analysis by passing the argument --no-babel
. Scope property would then be set based on the dev
attribute in the lock file.
This attribute can be later used for various purposes. For example, dep-scan uses this attribute to prioritize vulnerabilities. Unfortunately, tools such as dependency track, do not include this feature and might over-report the CVEs.
With the argument --required-only
, you can limit the SBOM only to include packages with the scope "required", commonly called 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.
For go, go mod why
command is used to identify required packages. For php, composer lock file is parsed to distinguish required (packages) from optional (packages-dev).
cdxgen can automatically detect names of services from YAML manifests such as docker-compose, Kubernetes, or Skaffold manifests. These would be populated under the services
attribute in the generated SBOM. With evinse, additional services could be detected by parsing common annotations from the source code.
Use the CycloneDX CLI tool for advanced use cases such as conversion, diff and merging.
Global Assembly Cache (GAC) dependencies must be made available in the build output of the project for cdxgen in order for it to inspect and include in the results. A cdxgen scan with the --deep
flag will look for additional dependencies in the form of dll files. A simple way to have the dotnet build copy the GAC dependencies into the build directory is to place the file Directory.Build.props
into the root of the project and ensure the contents include the following:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<Reference>
<Private>True</Private>
</Reference>
</ItemDefinitionGroup>
</Project>
Permission to modify and redistribute is granted under the terms of the Apache 2.0 license. See the LICENSE file for the full license.
cdxgen is ESM only and could be imported and used with both deno and Node.js >= 20
Minimal example:
1import { createBom, submitBom } from "npm:@cyclonedx/cdxgen@^9.0.1";
See the Deno Readme for detailed instructions.
1import { createBom, submitBom } from "@cyclonedx/cdxgen"; 2// bomNSData would contain bomJson 3const bomNSData = await createBom(filePath, options); 4// Submission to dependency track server 5const dbody = await submitBom(args, bomNSData.bomJson);
Please check out our contribute to CycloneDX/cdxgen documentation if you are interested in helping.
Before raising a PR, please run the following commands.
1corepack enable pnpm 2pnpm install 3# Generate types using jsdoc syntax 4pnpm run gen-types 5# Run biomejs formatter and linter with auto fix 6pnpm run lint 7# Run jest tests 8pnpm test
The latest stable version of the package.
Stable Version
1
7.4/10
Summary
CycloneDX cdxgen may execute code contained within build-related files
Affected Versions
<= 10.10.7
Patched Versions
No security vulnerabilities found.