This a simple script that takes a CycloneDX SBOM in JSON format and analyses it against certain quality factors. Namely,
- Correctness and presence of PURLs.
- Correctness and presence of licenses per purl. Note: it correlates against SPDX-license ids.
- Whether the SBOM entails the dependency tree
- The presence of an operating system
- Whether the SBOM contains information on the tool that was used to create it
- Install required libraries
pip install -r requirements.txt
Note: create a virtual env first
python -m env venv
source env/bin/activate
- Run CLI and generate a report you may pass a directory with many SBOM files or a single file.
python main.py test/ --report
- Example report
[
{
"filename": "test/cyclonedx-bom.json",
"purls": 378,
"percentage_valid_purl": 1.0,
"licenses": {
"valid_licenses": 372,
"percentage_valid_license_id": 0.98
},
"is_schema_compliant": true,
"operating_system": {
"has_os": false,
"os_found": null
},
"sbom_tool": {
"has_tool": true,
"tools": []
},
"has_dependency_tree": true,
"quality_score": 0.895
}
]
Note the ./test
folder contains CycloneDX SBOMs created for the vsm-webshop project with the CycloneDX python plugin, Syft, Trivy and ORT. Feel free to play with those.
You'll find that in analyser.py
the function grade_sbom
contains the weights for the above the factors:
weights = {
"has_dependency_tree": 0.2,
"valid_bom": 0.1,
"has_operating_system": 0.1,
"valid_licenses": 0.1,
"valid_purls": 0.5
}
and further down you'll also see the weighted scoring
score = (score_dep_tree * weights['has_dependency_tree']) + (score_valid_bom * weights['valid_bom']) + (
score_operating_systems * weights['has_operating_system']) + (score_licenses * weights['valid_licenses']) + (score_purls * weights['valid_purls'])
In simple words, the scoring looks at:
- whether the SBOM has a dependency tree
- the BOM file is of a valid CycloneDX schema
- Contains an operating system
- Has SPDX-valid license ids
- Has purls that conform with the spec.
Feel free to change the weights
array according to your needs. Ensure that all weights add up to 1 ;)
Feel free to contact me for any queries under vincent.groves@leanix.net or just open a issue or PR. Will try to get back to you in a timely manner.