SBOMs for PHP and Composer
Composer has no built-in SBOM command. sbombox generate detects composer.json and uses cdxgen or syft. The CycloneDX Composer plugin is the do-it-yourself option.
At a glance
| Package manager | Built-in SBOM command | What sbombox generate runs | Lockfile to commit |
|---|---|---|---|
| Composer | No (CycloneDX Composer plugin) | cdxgen, then syft | composer.lock |
Generate with SBOMBox
curl -fsSL https://sbombox.com/install.sh | sh
sbombox generate -o sbom.json
sbombox score sbom.jsoncdxgen separates required packages from packages-dev in composer.lock. Install it with the CLI:
curl -fsSL https://sbombox.com/install.sh | SBOMBOX_GENERATORS=syft,cdxgen shTo pin the choice, set SBOMBOX_GENERATOR to one or more generator names, comma-separated. SBOMBox tries them in that order and skips any that are not installed. An unknown name fails with the list of valid names.
SBOMBOX_GENERATOR=cdxgen sbombox generate -o sbom.jsonUse the CycloneDX Composer plugin
--omit=dev leaves dev packages out. Without --output-file, the plugin writes to stdout.
composer require --dev cyclonedx/cyclonedx-php-composer
composer CycloneDX:make-sbom --output-format=JSON --omit=dev --output-file=sbom.json# See what lowers the score
sbombox score sbom.json --format detailed
# Check a ruleset, e.g. EU Cyber Resilience Act readiness
sbombox compliance sbom.json -p cra-readiness
# Upload it to the active project, labelled with the release
sbombox push sbom.json --version v1.4.0Monorepos
- Each app with its own
composer.lockis a separate SBOM. Runsbombox generate --dir path/to/appfor each. - Upload each to its own SBOMBox project with
sbombox push FILE --project ID.
Known gaps
- Composer has no SBOM command, and SBOMBox has no native PHP generator. A universal tool is used.
- Without
composer.lock, versions are guessed from the ranges incomposer.json.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
No lockfile for composer: transitive dependencies may be missing and versions may be guessed. | composer.lock not committed | Run composer install, commit composer.lock |
No SBOM generator found for ecosystems [...]. Install one with: curl -fsSL https://sbombox.com/install.sh | sh | Neither cdxgen nor syft is installed | Run curl -fsSL https://sbombox.com/install.sh | sh |
| PHPUnit in the SBOM | Dev packages included | Use the Composer plugin with --omit=dev, or cdxgen |
In CI, run the same commands. See GitHub Actions, GitLab CI, Jenkins, Azure Pipelines, Bitbucket Pipelines or CircleCI, or use the GitHub Action.