GrepBoard/Manuals
605 manuals ·

Check PHP Dependencies for CVEs with composer audit

·Tested on Composer 2.10.3 · PHP 8.3.6 (Ubuntu 24.04 package unpacked, nothing installed system-wide)·Test scope ↓·6 steps

Use composer audit to check PHP packages pinned in composer.lock against known security advisories: output formats, exit codes and a re-check after the fix.

composer audit --locked compares the packages pinned in composer.lock with the security advisories on Packagist. It does not need the packages installed, so it fits a pre-deploy check or a CI job. Reference: Composer CLI – audit.

[1] Check the Composer version first. Composer itself had two command-injection flaws in its Perforce driver (CVE-2026-40176 and CVE-2026-40261), fixed in 2.9.6 and 2.2.27 (announcement). The version below is newer than both.

console
$ composer --version
output
$ composer --versionComposer version 2.10.3 2026-08-27 13:34:23

[2] Run the audit in the project directory against the lock file. With --locked, only the contents of composer.lock count, whether or not vendor/ exists. Start with the summary.

console
$ composer audit --locked --format summary
output
$ composer audit --locked --format summaryFound 16 security vulnerability advisories affecting 2 packages.Run "composer audit" for a full list of advisories.

The test project's lock pins guzzlehttp/guzzle 7.4.0 and symfony/http-foundation 5.4.0. The count grows as advisories are added, so the same lock gives different numbers on different dates.

[3] Switch formats for details. The default (table) draws one table per advisory; plain is line-oriented and easy to grep. This is the first advisory in plain.

console
$ composer audit --locked --format plain
output
$ composer audit --locked --format plainFound 16 security vulnerability advisories affecting 2 packages:Package: guzzlehttp/guzzleSeverity: highAdvisory ID: PKSA-gcrk-3vtt-1r14CVE: CVE-2026-69246Title: Guzzle: Noncanonical host can bypass host-based checksURL: https://github.com/advisories/GHSA-v5mv-p594-2x33Affected versions: >=8.0.0,<8.0.1|<7.15.2Reported at: 2026-08-03T21:07:26+00:00--------

<7.15.2 in Affected versions means 7.15.2 is the fixed release. For programs, use --format json; in testing its top-level keys were advisories, abandoned and filter, and advisories is grouped by package name, so one package can be pulled out like this.

console
$ composer audit --locked --format json | python3 -c 'import json,sys; j=json.load(sys.stdin); print(list(j)); [print(p, a["severity"], a["cve"]) for p,l in j["advisories"].items() for a in l if p=="symfony/http-foundation"]'
output
['advisories', 'abandoned', 'filter']symfony/http-foundation high CVE-2025-64500symfony/http-foundation low CVE-2024-50345

[4] Fail the CI job on the exit code. Per the documentation, 0 means no issues and 1 means packages matched the dependency policies (or the command failed because required packages were missing).

console
$ composer audit --locked --format summary > /dev/null; echo $?
output
$ echo $?1

Dev packages (require-dev) do not ship to production, so leave them out of a production check with --no-dev. On the same lock, symfony/http-foundation (dev) dropped out and 16 advisories became 14.

output
$ composer audit --locked --no-dev --format summaryFound 14 security vulnerability advisories affecting 1 package.Run "composer audit" for a full list of advisories.

[5] Fix it. Read Affected versions and move to the fixed release or later. To update only the named packages and their dependencies:

console
$ composer update guzzlehttp/guzzle symfony/http-foundation --with-dependencies

This Composer drops versions with advisories from the candidates during update. Pinning a vulnerable version exactly in composer.json therefore fails to resolve.

output
$ composer update --no-install  Problem 1    - Root composer.json requires guzzlehttp/guzzle 7.4.0 (exact version match: 7.4.0 or 7.4.0.0), found guzzlehttp/guzzle[7.4.0] but these were not loaded, because they are affected by security advisories ("PKSA-…").  Problem 2    - Root composer.json requires symfony/http-foundation 5.4.0 (exact version match: 5.4.0 or 5.4.0.0), found symfony/http-foundation[v5.4.0] but these were not loaded, because they are affected by security advisories ("PKSA-…").

[6] Re-run the same command. After widening the constraints to ^7.4 and ~5.4.0 and running update, guzzlehttp/guzzle 7.16.0 and symfony/http-foundation v5.4.54 were locked and the audit passed.

output
$ composer audit --lockedNo security vulnerability advisories found.$ echo $?0

If composer.lock changed, commit it so deployments install the same versions.

Where the check gets confusing

  • Without --locked, the audit reads what is installed in vendor/. If the lock was updated but nothing was installed, the results can differ.
  • The count is the number of advisories, not packages. Above, 16 advisories fell on 2 packages.
  • The test environment had no PHP curl extension, so Composer warned that it was slower than normal. The audit result was unaffected.
  • By default composer audit matches advisories from the Packagist.org API, plus those served by repositories listed in the repositories section of composer.json (documentation). A vulnerability absent from those sources is not reported. A clean result means "no known advisory", not "no vulnerability".

#composer#php#advisory