Creating a software bill of materials and detecting vulnerabilities in Python dependency packages
Published on October 21, 2020 by Dai Tran
howto devsecops sbom supply-chain-security python dependency-vulnerabilities blog
2 min READ
The software bill of materials (SBOM) and supply chain (package dependency) security risks have been discussed a lot in the wake of the notorious Log4j vulnerability. My question was how to generate the SBOM, scan and report the dependency packages used by my Python code for vulnerabilities. Fortunately, I have found two tools that help me accomplish this:
Install cyclonedx-bom
from the Visual Studio Code Integrated Powershell terminal using pip
:
pip install cyclonedx-bom
As bomber
at the time of writing does not support Windows, I have to run a Debian based Docker container that have a volume mounted to the project root directory of my Python code, download the latest release and install it from there using the following command:
dpkg -i bomber_<version_number>_linux_arm64.deb
In the Visual Studio Code Integrated Powershell terminal, run the following command to create the JSON SBOM file called pycyber.cyclonedxsbom.json
in the sub directory sbom
of the project root directory.
cyclonedx-py --format json -o ./sbom/pycyber.cyclonedxsbom.json -e
In the Debian based Docker container, cd
into the sbom
directory and run the following command to create a HTML dependency package vulnerability report there using the pycyber.cyclonedxsbom.json
as the input.
root# cd sbom
root# bomber scan pycyber.cyclonedxsbom.json --output=html
The report name follows this naming convention yyyymmdd-hh-mm-ss-bomber-results.html
and looks like as follows.
The report show the vulnerable dependency packages and their versions. The pipdeptree tool can be used to identify the packages that require them using the following command.
pipdeptree -r -p MarkupSafe,numpy
I then update version numbers of the identified packages in the requirements.txt
to the latest or the ones that do not use the vulnerable versions of the dependency packages. Finally, I regenerate SBOM and vulnerability report again to make sure that no vulnerabilities are reported.