Guides / Languages and packages

Check PHP dependencies with composer audit

beginnerUpdated 26 Nov 2026992 words

Composer has a built-in audit. composer audit checks the packages of a project against the security advisories that Packagist publishes, and Composer also refuses to add a version with a known advisory during composer require and composer update. Neither needs a plugin.

Check your Composer version

composer --version

The commands and output below come from Composer 2.11.3 with PHP 8.5, the current Composer release as of November 2026. Older 2.x releases have composer audit too, but the blocking and the policy settings described here may be missing or named differently. Update with composer self-update, or use a newer composer image in Docker builds.

Run the audit

composer audit checks the packages installed in vendor/. To check the lockfile, which is what a deploy installs, add --locked:

composer audit --locked

For a project locked at guzzlehttp/guzzle 7.4.4 (one of eleven entries):

Found 11 security vulnerability advisories affecting 1 package:
+-------------------+----------------------------------------------------------------------------------+
| Package           | guzzlehttp/guzzle                                                                |
| Severity          | high                                                                             |
| Advisory ID       | PKSA-k1b4-kshy-xgbh                                                              |
| CVE               | CVE-2022-31090                                                                   |
| Title             | CURLOPT_HTTPAUTH option not cleared on change of origin                          |
| URL               | https://github.com/guzzle/guzzle/security/advisories/GHSA-25mq-v84q-4j7r         |
| Affected versions | >=7,<7.4.5|>=4,<6.5.8                                                            |
| Reported at       | 2022-06-20T22:16:07+00:00                                                        |
+-------------------+----------------------------------------------------------------------------------+

Each entry has the Packagist advisory ID (PKSA-…), the CVE, the affected version ranges and a link. --format=summary prints only the count, --format=json the full list for scripts. --no-dev leaves out the packages of require-dev, which do not run in production when you deploy with composer install --no-dev.

composer audit exits with 0 when it finds nothing and with 1 when it finds an advisory, so it can gate a CI job as it is. Abandoned packages also fail the audit by default (since Composer 2.7); --abandoned=report lists them without failing.

Versions with advisories are blocked on update

When you add or update a package, Composer leaves out versions that have a security advisory:

composer require guzzlehttp/guzzle:7.4.4
  Problem 1
    - Root composer.json requires guzzlehttp/guzzle 7.4.4 (exact version match: 7.4.4 or 7.4.4.0),
      found guzzlehttp/guzzle[7.4.4] but these were not loaded, because they are affected by
      security advisories ("PKSA-cnw1-2ytm-cgr8", ...). Go to https://packagist.org/security-advisories/
      to find advisory details. To ignore the advisories, add their IDs to the
      "policy.advisories.ignore-id" config or add the package to "policy.advisories.ignore".
      To turn the feature off entirely, you can set "policy.advisories.block" to false.

Installation failed, reverting ./composer.json to its original content.

The setting is policy.advisories.block, on by default. It protects new installs and updates. An existing composer.lock with a vulnerable version stays as it is until someone updates it, which is why the audit is still needed.

To install a blocked version on purpose, for example to reproduce a bug, pass --no-blocking to that one require, update or install command.

Fix findings

Update the package and its dependencies within the constraints of composer.json:

composer update guzzlehttp/guzzle --with-dependencies
composer audit --locked

If the constraint excludes the fixed version (an exact 7.4.4, as in the example), raise it. When the new version needs newer dependencies than the lockfile has, add -W (--with-all-dependencies):

composer require guzzlehttp/guzzle:^7.10 -W
  - Upgrading guzzlehttp/guzzle (7.4.4 => 7.17.0)
  - Upgrading guzzlehttp/promises (1.5.3 => 2.6.2)
Writing lock file
No security vulnerability advisories found.

When the vulnerable package is a dependency of a dependency, composer why shows which package requires it and with which constraint:

composer why guzzlehttp/psr7 --locked
guzzlehttp/guzzle 7.4.4 requires guzzlehttp/psr7 (^1.8.3 || ^2.1)

Ignore an advisory

When an advisory does not apply to you, record it in composer.json with the reason, so that the next person sees it:

{
  "config": {
    "policy": {
      "advisories": {
        "ignore-id": {
          "CVE-2022-31090": "We do not use the curl handler with CURLOPT_HTTPAUTH."
        }
      }
    }
  }
}

The audit then lists the advisory under Found 1 ignored security vulnerability advisory and no longer counts it. CVE, GHSA and PKSA IDs work. The older config.audit.ignore key with the same content still works in 2.11.3, and the Composer documentation marks it as deprecated.

Deploy from the lockfile

Commit composer.lock. On the server or in the image build, install the versions it lists:

composer install --no-dev --no-interaction --optimize-autoloader

composer install never changes the lockfile. When composer.json was changed without an update, it warns:

Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. ...

In a Dockerfile, copy the two files first so that the dependency layer is cached:

COPY composer.json composer.lock ./
RUN composer install --no-dev --no-interaction --no-scripts --no-autoloader
COPY . .
RUN composer dump-autoload --optimize --no-dev

Run it in CI

A GitHub Actions job with a schedule, so that new advisories show up on days without commits:

name: composer audit
on:
  push:
  pull_request:
  schedule:
    - cron: "41 6 * * *"
jobs:
  audit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: shivammathur/setup-php@v2
        with:
          php-version: "8.5"
          tools: composer:v2
      - run: composer audit --locked --no-dev

In GitLab CI, the composer image is enough:

composer-audit:
  image: composer:2.11.3
  script:
    - composer audit --locked --no-dev

What it does not cover

composer audit knows the packages of composer.lock. PHP itself, its extensions and the web server come from the operating system or the container base image and get their fixes there. WordPress, Drupal and other applications installed outside Composer keep their own lists of plugins and themes, which composer audit does not see.

The Patchbrief agent can read the composer.lock of the app paths you configure and checks it against new advisories every day.

Sources

Check your servers every day

The agent of Patchbrief reports the packages and settings of a server once a day; the digest names what to fix first.

Start free