Safeguard
Supply Chain•

Do Composer scripts in dependencies run when you install them?

No. Composer runs only the scripts in your root composer.json, not those in dependencies. Plugins and autoload files can still run vendor code.

Safeguard Security Team
3 min read

No. According to the Composer documentation, only scripts defined in the root package's composer.json are executed. Scripts a dependency declares in its own composer.json do not run when you install it. Vendor code can still run through plugins and through autoloaded files, so those need review too.

Why people worry about this

Developers coming from other ecosystems know install time hooks that run arbitrary commands from any dependency. It is natural to ask whether PHP has the same exposure. For Composer scripts, the answer is better than many expect. Your own scripts, such as post-install-cmd or post-autoload-dump, run because you wrote them. A package you pull in cannot add its own.

What can still run vendor code

MechanismRuns whenWho controls it
Root scripts in composer.jsonInstall, update, autoload dumpYou
Dependency scriptsNever run by ComposerNot applicable
PluginsAs soon as installed and on later runsGated by allow-plugins
Autoload files entriesOn every request in your appPackage author
Normal class loadingWhen your code uses the classPackage author

The last two rows are the quiet ones. The docs say the files autoload mechanism requires listed files explicitly on every request. That is intended for helper functions. It also means a compromised release can execute code the first time your application boots, with no install step involved.

Steps to reduce exposure

  1. Keep the allow-plugins list short, and review additions.
  2. Read your own root scripts. A script that pipes a downloaded file into a shell is a risk of your own making.
  3. After an update, scan the composer.lock diff for packages you did not expect.
  4. For new packages, open composer.json and check the autoload section for files entries.
  5. Run installs in CI with no secrets in the environment where possible.
composer install --no-scripts --no-plugins

The no-scripts and no-plugins options are global Composer options. The first skips root scripts, the second disables installed plugins. They are handy when you are inspecting an unfamiliar project and do not want it to run anything yet.

A caution on pre-install scripts

The scripts page warns that Composer makes no assumptions about the state of your dependencies before an install or update. Do not rely on vendor packages inside pre-install-cmd or pre-update-cmd.

Try it yourself

Click through it at your own pace, or open it full screen. Compare a package that is merely present with one whose code path your application actually runs.

Where Safeguard fits

Safeguard's reachability analysis helps separate advisories your code can reach from those it cannot. You can try a free scan on your own lock file.

Quick check

Can a dependency run code when I run composer install?

Through scripts, no. Through an allowed plugin, yes. After install, any code your app loads can run, including autoload files entries.

Does no-scripts also stop plugins?

No. Plugins have their own option, no-plugins, and their own allow list.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.