sbomtruth checks a CycloneDX SBOM against the Python environment it claims to describe. It reads a
site-packages directory as data, never importing anything, verifies every installed file against the
hashes in its wheel RECORD, and reports components that are missing from the SBOM, listed but not
installed, at a different version, vendored inside another package, or modified after installation. It can
also write a CycloneDX 1.6 SBOM from the environment, so that an SBOM and the files it describes agree by
construction.
The bundled environment and SBOM are synthetic: every package, version and file in them is invented.
A maker of medical devices ships a Python imaging workstation and has to include an SBOM with each premarket submission (FDA section 524B), then keep it current so that new vulnerabilities in its components reach the field team. The SBOM is usually generated from requirements files at build time, so it records what was requested, not what shipped. It goes wrong in ordinary ways: a transitive package was installed at a different version from a wheel cache, a library is vendored inside another package, a module was patched in place after installation, a test-only package is listed as shipped. Each of those is a vulnerability notice that never reaches anyone.
The installed files are the ground truth, and they can be verified by hash. sbomtruth therefore checks the SBOM against what will run, instead of against another manifest.
flowchart LR
A["site-packages<br/>METADATA, RECORD, files"] --> B["env.scan<br/>hash and size check,<br/>orphans, vendored copies<br/>(nothing is imported)"]
C["CycloneDX 1.5 / 1.6 JSON"] --> D["cyclonedx.parse_sbom<br/>purl parser, scopes,<br/>nested components"]
B --> E["names<br/>PEP 503 / PEP 440<br/>normalisation"]
D --> E
E --> F["check<br/>component by component,<br/>edge by edge"]
F --> G["findings<br/>Markdown or JSON,<br/>exit code"]
B --> H["emit<br/>CycloneDX 1.6 with<br/>nested vendored components"]
H -->|"checks clean"| F
sbomtruth.envwalks*.dist-info, readsMETADATA(name, version,Requires-Dist) andRECORD(path,sha256=<urlsafe base64, no padding>, size). Each distribution isintact,modified(a hash or size differs; the files are listed) orincomplete(listed files are missing). RECORD's own row and hashless.pycrows are tolerated. Files under site-packages that no RECORD claims are orphans (__pycache__is ignored). A symlink that points outside the tree is reported and never followed.sbomtruth.vendoredlooks for_vendorandvendordirectories inside a distribution. A version comes fromvendor.txt(name==version) or from a static__version__ = "x.y.z"read withast. A child directory counts only if Python code sits beneath it, so a JS or asset tree such asstatic/vendor/jquery/is not reported.sbomtruth.cyclonedxreads components (nested ones included) withpurl,scope,bom-refanddependencies. Onlypkg:pypicomponents are compared; every other purl type, a missing purl and a malformed purl are listed asunchecked.sbomtruth.checkproduces these finding kinds:missing-from-sbom,phantom(scoperequired, not installed),version-drift,vendored-undeclared(a vendored copy with no nested component, or with one declared at a different version),modified-files(modified or incomplete),orphan-files(a warning),missing-edgeandextra-edge. The exit code is 1 when any finding is an error.sbomtruth.emitwrites the SBOM. Vendored packages become nested components, thedependenciesgraph comes fromRequires-Dist, and each component carriessbomtruth:record-sha256, the sha256 of its RECORD file.
Notes are printed for a purl whose version differs from the component's version field (the purl
wins) and for a package with more than one *.dist-info directory (versions are compared for the
highest, files are verified for every copy).
Conventions: a nested pkg:pypi component under a distribution is read as a vendored copy of that
package, and is never compared with the top-level installation of the same name. Dependency edges are
compared only between components that are both in the SBOM, and Requires-Dist markers are evaluated
for the --python and --platform you give, with no extras.
python3 -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"
sbomtruth demo --out demo-out # build the fixtures, check, repair, emit, check again
# (replaces demo-out/site-packages only if a demo wrote it)
sbomtruth inventory --site-packages demo-out/site-packages
sbomtruth check --sbom demo-out/sbom.json --site-packages demo-out/site-packages \
--python 3.12 --platform linux # add --format json for JSON
sbomtruth emit --site-packages demo-out/site-packages --timestamp 2026-11-20T00:00:00Z \
--output emitted.jsoncheck exits 1 when any finding is an error, 0 otherwise, and 2 for unreadable input. To check a real
environment, point --site-packages at the lib/python3.x/site-packages directory of a virtual
environment (or at an extracted wheelhouse) and --sbom at your SBOM.
sbomtruth demo --out demo-out, run from a clean checkout:
$ sbomtruth inventory --site-packages demo-out/site-packages
Distributions: 27 (intact 26, modified 1, incomplete 0)
Vendored packages: 1
Orphan files: 1
Symlinks pointing outside the tree: 0
pip 24.0: intact; vendors urllib3 1.26.18
pynetdicom 2.0.2: modified
orphan: pydicom/_hotfix.py
$ sbomtruth check --sbom demo-out/sbom.json --site-packages demo-out/site-packages
## sbomtruth check (linux, Python 3.12)
10 findings: 9 errors, 1 warning.
| Kind | Severity | Subject | Detail |
| --- | --- | --- | --- |
| version-drift | error | pillow | the SBOM lists 10.2.0 but 10.3.0 is installed |
| version-drift | error | urllib3 | the SBOM lists 1.26.18 but 2.2.1 is installed |
| missing-from-sbom | error | charset-normalizer | charset_normalizer 3.3.2 is installed but the SBOM does not list it |
| missing-from-sbom | error | idna | idna 3.7 is installed but the SBOM does not list it |
| missing-from-sbom | error | typing-extensions | typing_extensions 4.11.0 is installed but the SBOM does not list it |
| phantom | error | pytest | the SBOM lists pytest 8.1.1 as required but it is not installed |
| vendored-undeclared | error | pip/urllib3 | pip vendors urllib3 1.26.18 in pip/_vendor/ but the SBOM lists no such component under it |
| modified-files | error | pynetdicom | pynetdicom is modified (changed: pynetdicom/core.py) |
| orphan-files | warning | pydicom/_hotfix.py | file is not listed in any RECORD |
| missing-edge | error | scikit-image -> tifffile | scikit-image requires tifffile but the SBOM has no such dependency edge |
Counts: version-drift 2, missing-from-sbom 3, phantom 1, vendored-undeclared 1, modified-files 1, orphan-files 1, missing-edge 1
Unchecked components:
- @cornerstonejs/core 1.77.0 (pkg:npm/%40cornerstonejs/core@1.77.0): purl type 'npm' is not compared
Exit code: 1
Repaired the environment: restored the patched module, removed the orphan file.
$ sbomtruth emit --site-packages demo-out/site-packages --timestamp 2026-11-20T00:00:00Z
wrote demo-out/emitted.json
$ sbomtruth check --sbom demo-out/emitted.json --site-packages demo-out/site-packages
## sbomtruth check (linux, Python 3.12)
0 findings: 0 errors, 0 warnings.
Exit code: 0
emit nests the urllib3 copy under pip, so the check above comes back clean. An excerpt of the
emitted document (sbomtruth emit ... --timestamp 2026-11-20T00:00:00Z):
{
"type": "library",
"bom-ref": "pkg:pypi/pip@24.0",
"name": "pip",
"version": "24.0",
"purl": "pkg:pypi/pip@24.0",
"scope": "required",
"properties": [
{
"name": "sbomtruth:record-sha256",
"value": "58c3360bce5d61d67dda95cc2eaf8a6b4853ac0cea4daad74d8d8956b0793e17"
}
],
"components": [
{
"type": "library",
"bom-ref": "pkg:pypi/pip@24.0#vendored/urllib3",
"name": "urllib3",
"scope": "required",
"purl": "pkg:pypi/urllib3@1.26.18",
"version": "1.26.18",
"properties": [
{
"name": "sbomtruth:vendored-in",
"value": "pip/_vendor"
}
]
}
]
},
...- Hashes over manifests. The RECORD hash is the evidence that a file is what the wheel installed.
A patched module shows up as
modified-fileseven when the SBOM andMETADATAagree. The trade-off is that a RECORD rewritten to match tampered files is not detected; thesbomtruth:record-sha256property is recorded byemitso a later comparison can catch it, butcheckdoes not use it yet. - Nothing is imported. Versions of vendored code come from
vendor.txtor anastparse, never from running the module. A test plants a top-levelraise SystemExitand a file write in a vendored module and shows the scanner reads the version without executing either. The cost is that a version computed at import time is reported as unknown. - Nested means vendored. A vendored copy counts as declared only when the SBOM lists it nested under
its parent. Matching by name alone would let the top-level
urllib3hide an older copy insidepip, which is exactly the case that causes missed notices. - Markers are evaluated for a stated target.
--pythonand--platformreplace the running interpreter, so the same environment gives the same findings on any machine. A requirement guarded bysys_platform == "win32"is a missing edge only for--platform win32. Extras are never assumed. - Edges are compared only between listed components. A dependency on a package the SBOM does not
list is already reported as
missing-from-sbom; reporting an edge to it as well would count one problem twice. An SBOM with nodependenciessection skips the edge checks and says so, and a component that has no entry in the section is treated as having unknown dependencies, so its edges are not compared. - Total, clock-free ordering. Findings are sorted by kind, subject and message, and
emittakes its timestamp as an argument, so output is identical across runs, machines and time zones.
pip install -e ".[dev]"
pytest -q
ruff check . && ruff format --check .93 tests pass offline. They cover RECORD verification (intact, one changed byte, one deleted file,
RECORD's own row and hashless .pyc rows), symlinks that point outside the tree, vendored detection
without importing, the purl parser (including percent-decoding and malformed input), the exact set of
findings on the demo fixture (10 findings, by kind and subject), PEP 503 and PEP 440 matching, marker
evaluation per platform, emit determinism, the emit then check round trip, five single mutations
that each produce exactly one finding of the expected kind, and the command line.
src/sbomtruth/
names.py PEP 503 and PEP 440 normalisation
purl.py package-URL parser
fsutil.py path handling that never follows a link out of the tree
env.py site-packages scan, RECORD verification, orphans
vendored.py vendored package detection (vendor.txt, ast)
requirements.py Requires-Dist marker evaluation for a target
cyclonedx.py CycloneDX 1.5 / 1.6 reader
check.py SBOM against environment, findings
emit.py CycloneDX 1.6 writer
report.py Markdown, JSON and text rendering
fixtures.py synthetic environment and SBOM
cli.py typer commands: demo, inventory, check, emit
tests/ pytest suite
.github/workflows/ci.yml
MIT. See LICENSE.
