sparkfabrik / drupal-sbom
Builds a software bill of materials (SBOM) of a Drupal codebase, as SPDX 3.0.1, without running its code.
Requires
- php: >=8.1
- composer-runtime-api: ^2.2
- composer/spdx-licenses: ^1.5
- psr/log: ^2 || ^3
- symfony/yaml: ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- drupal/coder: ^8.3
- opis/json-schema: ^2.4
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^10.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Builds a software bill of materials (SBOM) of a Drupal codebase as an SPDX 3.0.1 JSON-LD document, without running any code of the codebase.
It is the inventory engine of DruBOM, extracted so that other tools can use it outside a Drupal site: DruBOM's module and scanner, and any agent that needs the dependency inventory of a Drupal site.
What it reads
- Composer:
composer.json,composer.lockandvendor/composer/installed.json. - Drupal: the
*.info.ymlfiles of modules, themes and profiles, and the*.libraries.ymlfiles. - npm, Yarn and pnpm lockfiles of themes and modules.
- PHP runtime: the version and extensions of the PHP running the scan, unless it is skipped.
It never loads settings.php, vendor/autoload.php or any other PHP file of the codebase, and never connects to a database. Sources it cannot read in full are listed as coverage gaps in the document.
Without vendor/, the scan works from composer.lock and the document is typed source; with it, build.
Requirements
PHP 8.1 or later. The codebase can be any Drupal from 8 to 12.
Command line
composer require sparkfabrik/drupal-sbom vendor/bin/drupal-sbom --root /path/to/project --skip php --output sbom.spdx.json
--rootis the Composer project root to inspect.--websets the web root, relative to the project root, when it is not the Drupal scaffold web root.--skip phpleaves out the PHP runtime, when the scan does not run on the site's PHP.--include-devkeeps packages used only for development.
Exit codes: 0 written; 2 written, but a source could not be fully read; 1 failed, nothing written.
As a library
use Sparkfabrik\DrupalSbom\Scan\ScanCommand; $code = ScanCommand::run(['--root', $projectRoot, '--skip', 'php', '--output', $file]);
The collectors, the inventory builder and the SPDX formatter are also usable on their own, from the Sparkfabrik\DrupalSbom\Inventory and Sparkfabrik\DrupalSbom\SbomFormatter namespaces. A tool that embeds the library names itself in the documents it produces: ScanCommand::run() and Spdx3Formatter take the producer name, and the scanner its version and command name.
Inside a running Drupal site, pass the library collector a LibraryDiscoveryInterface adapter over Drupal's library discovery and a YamlDecoderInterface over Drupal's YAML decoder. Outside a site, the collector reads *.libraries.yml with a decoder that rejects PHP constants (!php/const), and reports such a file as a coverage gap.
What a scan does not know
A scan sees only files. It cannot tell which extensions are enabled or which PHP serves the site, and it does not check vulnerabilities: give the document to a tool that reads SPDX 3.0.1, or use DruBOM on the site.
Both a scan and DruBOM describe package metadata. Neither proves that the files on disk are unmodified.
Development
composer install composer qa
composer qa runs the code style check (Drupal coding standards), PHPStan and the tests, as CI does on PHP 8.1 to 8.4.
Releases
Add the version's section to CHANGELOG.md, then push a tag such as 0.1.0. The release workflow publishes the GitHub release with that section as its notes.
Maintainers
Developed by SparkFabrik. Maintainers: Paolo Mainardi and Marco Primitivo.
License
GPL-2.0-or-later. See LICENSE.