🧩
Security

Checking Composer packages for security: a guide for PHP project owners

22.11.2026
← All articles

Almost every modern PHP project is managed with Composer. Whether it is Laravel, Symfony or your own framework, the vendor folder holds dozens or hundreds of packages, most of which arrived as dependencies of other packages. Each one runs on your server with the same privileges as your own code, so a vulnerability in any of them is a vulnerability in your site.

composer audit

Since Composer 2.4 the audit command checks the exact versions in composer.lock against public advisory databases and lists vulnerable packages with severity and affected versions. Update Composer itself first, since it also receives security fixes.

composer self-update
composer audit
composer audit --no-dev
composer audit --format=plain

It exits with a non-zero code when it finds something, which makes it easy to add to CI so a vulnerable build never ships. composer update and composer require also print a short audit summary at the end.

Commit composer.lock

composer.json holds ranges such as ^10.0; composer.lock pins the exact version, commit and archive hash. Without the lock file, every composer install on the server pulls whatever is newest that day, so production drifts away from what you tested, and a brand-new, unreviewed release can slip in without anyone noticing. Update only locally or in staging with composer update, commit the lock file, and run only composer install on the server.

Outdated and abandoned packages

composer outdated --direct
composer why vendor/package
composer show --tree
composer validate --strict

A package can be risky even without a registered advisory if nobody has maintained it for years, because bugs simply stop getting fixed. Packages several major versions behind deserve attention, and packages marked "abandoned" should be replaced with the suggested alternative as soon as practical.

Scripts and plugins run code

The scripts section and Composer plugins execute code during install and update. Since Composer 2.2, allow-plugins blocks any plugin not explicitly listed. Keep secure-http enabled, and for an unfamiliar project start with composer install --no-scripts --no-plugins and read the scripts first.

{
    "config": {
        "allow-plugins": { "pestphp/pest-plugin": true },
        "secure-http": true
    }
}

Adding roave/security-advisories as a dev dependency makes Composer refuse to install known vulnerable versions at all:

composer require --dev roave/security-advisories:dev-latest

Deploy cleanly

Install without dev tools and point the document root at the project's public folder so vendor, .env and composer.json are not reachable from a browser:

composer install --no-dev --optimize-autoloader --no-interaction
curl -I https://example.uz/.env
curl -I https://example.uz/vendor/autoload.php

A private clinic in Namangan ran its online booking on Laravel with the whole project in public_html, so .env was readable in the browser, and composer audit reported several known issues in a years-old lock file. The fix was moving the document root to public, rotating every secret in .env, updating packages in staging and only then deploying with --no-dev.

Make it routine

Run composer audit at least monthly and ideally before every deploy, and enable automated dependency update pull requests in your repository. If you have questions about SSH and Composer on sayt.uz hosting, ask through your cabinet or support; without Composer on the server, build locally with --no-dev and upload the ready vendor folder.

Related articles

🈲 Japanese SEO spam hack: strange pages from your site appear in Google 🐘 Critical PHP vulnerabilities: why you should not delay updating 📚 Securing an OJS Journal Site: Updates, File Storage and Bot Load 🧪 Exposed phpinfo() and leftover test files: why they matter
🌐 Language
🇺🇿 O⁠'zbek 🇺🇿 Özbek (yangi) 🇺🇿 Ўзбек 🇷🇺 Русский 🇬🇧 English ✓