CVE-2024-24821: Composer code execution and possible privilege escalation via compromised InstalledVersions.php or installed.php
Impact
Several files within the local working directory are included during the invocation of Composer and in the context of the executing user.
As such, under certain conditions arbitrary code execution may lead to local privilege escalation, provide lateral user movement or malicious code execution when Composer is invoked within a directory with tampered files.
All Composer CLI commands are affected, including composer.phar's self-update.
The following are of high risk:
- Composer being run with sudo. - Pipelines which may execute Composer on untrusted projects. - Shared environments with developers who run Composer individually on the same project.
Patches
2.7.0, 2.2.23
Workarounds
- It is advised that the patched versions are applied at the earliest convenience.
Where not possible, the following should be addressed: - Remove all sudo composer privileges for all users to mitigate root privilege escalation. - Avoid running Composer within an untrusted directory, or if needed, verify that the contents of vendor/composer/InstalledVersions.php and vendor/composer/installed.php do not include untrusted code.
A reset can also be done on these files by the following:
sh rm vendor/composer/installed.php vendor/composer/InstalledVersions.php composer install --no-scripts --no-plugins
Other sources
Composer code execution and possible privilege escalation via compromised InstalledVersions.php or installed.php
— Packagist
Composer is a dependency Manager for the PHP language. In affected versions several files within the local working directory are included during the invocation of Composer and in the context of the executing user. As such, under certain conditions arbitrary code execution may lead to local privilege escalation, provide lateral user movement or malicious code execution when Composer is invoked within a directory with tampered files. All Composer CLI commands are affected, including composer.phar's self-update. The following scenarios are of high risk: Composer being run with sudo, Pipelines which may execute Composer on untrusted projects, Shared environments with developers who run Composer individually on the same project. This vulnerability has been addressed in versions 2.7.0 and 2.2.23. It is advised that the patched versions are applied at the earliest convenience. Where not possible, the following should be addressed: Remove all sudo composer privileges for all users to mitigate root privilege escalation, and avoid running Composer within an untrusted directory, or if needed, verify that the contents of vendor/composer/InstalledVersions.php and vendor/composer/installed.php do not include untrusted code. A reset can also be done on these files by the following:sh rm vendor/composer/installed.php vendor/composer/InstalledVersions.php composer install --no-scripts --no-plugins
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
composer/composer/composerto a version that resolves this vulnerability.Fixed in 2.7.0 - Upgrade
Upgrade
composer/composer/composerto a version that resolves this vulnerability.Fixed in 2.2.23 - Upgrade
Upgrade
Composerto a version that resolves this vulnerability.Fixed in 2.7.0 - Upgrade
Upgrade
Composerto a version that resolves this vulnerability.Fixed in 2.2.23 - Configuration
Run composer install with --no-scripts --no-plugins.
Composer CLI install execution flags = --no-scripts --no-plugins - Compensating control
Remove all sudo Composer privileges for all users to mitigate root privilege escalation.
- Compensating control
Avoid running Composer within an untrusted directory; if this is necessary, verify that vendor/composer/InstalledVersions.php and vendor/composer/installed.php do not include untrusted code.
- Operational
Reset the potentially compromised Composer files by removing vendor/composer/installed.php and vendor/composer/InstalledVersions.php.
Event History
Frequently Asked Questions
What is the severity of CVE-2024-24821?
CVE-2024-24821 has a high severity due to the potential for arbitrary code execution and local privilege escalation.
How do I fix CVE-2024-24821?
To fix CVE-2024-24821, upgrade Composer to version 2.7.0 or 2.2.23 or later.
Which versions of Composer are affected by CVE-2024-24821?
CVE-2024-24821 affects Composer versions between 2.0.0-alpha1 and 2.2.23, as well as between 2.3.0-rc1 and 2.7.0.
What impact does CVE-2024-24821 have on system security?
CVE-2024-24821 can lead to local privilege escalation and lateral movement within the user environment.
Is CVE-2024-24821 exploitable remotely?
CVE-2024-24821 is not primarily a remote vulnerability, but it can be exploited locally under specific conditions.