Scan a folder and write a software bill of materials (SBOM) as
sbom.json, in CycloneDX 1.6 JSON, then check it for known vulnerabilities.
It finds the dependency manifests and lock files in a folder and its subfolders, and lists every package with its version and a package URL (purl). osv_check.py then looks up every package in OSV.dev, the free open source vulnerability database, and lists known CVEs and the versions that fix them. Python standard library only, no installs.
- Python 3.11+
- Clone the repo, or download
sbom.pyandosv_check.py. - That's it: there are no tokens, settings or packages to install.
python sbom.py path/to/projectThis writes path/to/project/sbom.json. To write it somewhere else:
python sbom.py path/to/project -o reports/sbom.jsonWith no folder, it scans the current one.
| Ecosystem | Files |
|---|---|
| Python | requirements*.txt, pyproject.toml, poetry.lock, uv.lock |
| JavaScript | package-lock.json, package.json |
| Ruby | Gemfile.lock |
| Go | go.mod |
| Rust | Cargo.lock |
| PHP | composer.lock |
| Swift | Package.resolved (Swift Package Manager and Xcode) |
| CocoaPods | Podfile.lock |
Where a lock file sits next to its manifest (package-lock.json beside package.json, or poetry.lock or uv.lock beside pyproject.toml), only the lock file is read, because it holds the exact versions. A package with no pinned version is listed without one.
It skips .git, node_modules, virtual environments, vendor, Pods, build output and similar folders. A file it can't read is reported and skipped, and the scan carries on.
Each component records the files it was found in, as sbom:source properties, so a package used in two places is listed once.
python osv_check.py path/to/project/sbom.jsonIt prints a Markdown report: a count by severity, then a table of each vulnerable package with its CVE (linked to OSV.dev), severity, the versions that fix it and a summary. Most severe come first. Where OSV lists one issue under several IDs, such as a GitHub advisory and a PyPI one, it's shown once.
-o report.mdalso writes the report to a file.--json findings.jsonalso writes the findings as JSON.--no-failexits with 0 even when vulnerabilities are found. Otherwise it exits with 1, so it can fail a CI job.
Packages without a pinned version can't be checked, so they're listed as not checked. Only the package names and versions are sent to OSV.dev.
- uses: actions/checkout@v7
- run: curl -sSLO https://raw.githubusercontent.com/SecOpsNews/script_sbom.py/main/sbom.py
- run: curl -sSLO https://raw.githubusercontent.com/SecOpsNews/script_sbom.py/main/osv_check.py
- run: python sbom.py . -o sbom.json
- run: python osv_check.py sbom.json -o vulnerabilities.md
- uses: actions/upload-artifact@v7
if: always()
with:
name: sbom
path: |
sbom.json
vulnerabilities.mdThe check step fails the job when it finds a known vulnerability. Add --no-fail to report without failing.
It reads what your manifests and lock files declare. It doesn't inspect installed packages, container images or binaries. For those, use a scanner such as OSV-Scanner or Grype.
python -m venv .venv
.venv/bin/pip install -r requirements-dev.txt
.venv/bin/pytest testsIncrement the package.json version, using SemVer, when committing changes to the scripts, and keep VERSION in sbom.py and osv_check.py in step. The GitHub action creates a new release using the last commit message as the release note.
Made by thechelsuk for SecOpsNews: security news, advisories and critical CVEs on one dashboard. MIT licensed: see LICENSE.