Composer loaded PHP files from the project's own vendor/composer directory each time it ran. If someone could change those files, their code ran as whoever ran Composer next. With sudo, that means root.

The files are vendor/composer/InstalledVersions.php and vendor/composer/installed.php. Every Composer command was affected, including composer self-update. See the Composer advisory and the fixes for 2.7 and 2.2 LTS.

Who is affected

Anyone running composer/composer where someone else could have changed those files. The Composer team calls these setups high risk:

  • Running Composer with sudo.
  • CI pipelines that may run Composer on untrusted projects.
  • Shared environments where several developers run Composer on the same project.

What to do

Update Composer to 2.7.0, or to 2.2.23 if you're on the 2.2 LTS line. If you can't update yet, the Composer team advises:

  • Remove the right to run Composer with sudo for all users.
  • Don't run Composer in a directory you don't trust, or first check those two files for code you didn't expect.
  • Reset the two files by deleting them and running composer install --no-scripts --no-plugins.

Reported by edonsec.