A malicious package can run commands on your machine during composer install or composer update, with the rights of the user or CI account running Composer. Composer handed a package's Perforce source address to the p4 client without checking it, and p4 accepts addresses that start a local command.
Who is affected
The Composer advisory says you're only exposed when all of these are true:
- The Perforce
p4command line client is installed and on thePATHwhere Composer runs. - An attacker controls a package's Perforce source details. Packagist.org doesn't allow those, so this needs another Composer repository, an inline
packagerepository, or acomposer.lockfrom a source you don't trust. - The package is installed from source, because it has no dist archive or you use
--prefer-source.
Machines without p4, and projects that only use Packagist.org, aren't affected.
What to do
Update composer/composer to 2.10.3, or to 2.2.30 if you stay on 2.2 or older. Composer says upgrading is the only complete fix. Until you can, remove p4 from the PATH on machines that don't use Perforce, and only use repositories and lock files you trust.
The fix only accepts real network addresses for Perforce. An unusual P4PORT value that isn't a plain host and port is now rejected.
Reported by Saku0512.