CVE-2024-24821: Composer/composer Composer Code Execution And Possible Vulnerability

HIGH
Advisory Identifier: GHSA-7c6p-848j-wh5h
CVSS 8.8
CWE-829
Published
Advisory Summary

CVE-2024-24821 is a HIGH (CVSS 8.8) composer code execution and possible vulnerability (CWE-829: Inclusion of Functionality from Untrusted Control Sphere) affecting Composer/composer libraries in the Packagist ecosystem. The issue involves composer code execution and possible privilege escalation via compromised installedversions.php or installed.php. Remediation is available by upgrading affected packages to version 2.2.23, 2.7.0.

CVE-2024-24821 at a Glance

CVE Identifier CVE-2024-24821
GHSA Identifier GHSA-7c6p-848j-wh5h
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-829: Inclusion of Functionality from Untrusted Control Sphere
Affected Product Composer/composer
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 8.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H).

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2024-24821

To remediate this vulnerability, upgrade all affected Composer/composer dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

composer/composer fixed: 2.2.23
Upgrade composer/composer to 2.2.23
composer/composer fixed: 2.7.0
Upgrade composer/composer to 2.7.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for composer/composer

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-24821, inspect your project dependencies for Composer/composer:

inspect dependencies for composer/composer

Analyze the terminal output to locate any version of Composer/composer in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.2.23), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-829: Inclusion of Functionality from Untrusted Control Sphere, where the product imports, requires, or includes executable functionality (such as a library) from a source that is outside of the intended control sphere. In Composer/composer, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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 ```

CVE-2024-24821 Affected Composer/composer Versions

2 component(s)
Fixed Versions:
2.2.232.7.0
Product / Package Ecosystem Affected Versions Fixed Version
composer/composer
Packagist
≥ 2.0.0-alpha1
< 2.2.23
2.2.23
composer/composer
Packagist
≥ 2.3.0-rc1
< 2.7.0
2.7.0

References

Frequently Asked Questions

What is CVE-2024-24821?
CVE-2024-24821 is a security vulnerability in Composer/composer involving Composer code execution and possible privilege escalation via compromised InstalledVersions.php or installed.php under CWE-829: Inclusion of Functionality from Untrusted Control Sphere.
Which Composer/composer versions are affected?
Affected versions include releases prior to 2.2.23, 2.7.0 across affected packages: composer/composer.
What version fixes CVE-2024-24821?
Upgrading to 2.2.23, 2.7.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is composer/composer affected?
Yes, composer/composer is affected in releases prior to 2.2.23, 2.7.0. Upgrade your dependency to 2.2.23, 2.7.0 or later.
What is the CVSS score of CVE-2024-24821?
CVE-2024-24821 has a CVSS v3.1 base score of 8.8 (HIGH) with vector string CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H.
What CWE is associated with CVE-2024-24821?
CVE-2024-24821 is classified under CWE-829: Inclusion of Functionality from Untrusted Control Sphere (The product imports, requires, or includes executable functionality (such as a library) from a source that is outside of the intended control sphere.).
How can I check Packagist dependencies for CVE-2024-24821?
Run the dependency tree command: 'inspect dependencies for composer/composer'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-7c6p-848j-wh5h",
  "modified" : "2024-02-09T17:49:02Z",
  "published" : "2024-02-08T15:06:38Z",
  "aliases" : [ "CVE-2024-24821" ],
  "summary" : "Composer code execution and possible privilege escalation via compromised InstalledVersions.php or installed.php",
  "details" : "### Impact\n\nSeveral files within the local working directory are included during the invocation of Composer and in the context of the executing user.\n\nAs 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.\n\nAll Composer CLI commands are affected, including composer.phar's self-update.\n\nThe following are of high risk:\n\n- Composer being run with sudo.\n- Pipelines which may execute Composer on untrusted projects.\n- Shared environments with developers who run Composer individually on the same project.\n\n### Patches\n\n2.7.0, 2.2.23\n\n### Workarounds\n\n- It is advised that the patched versions are applied at the earliest convenience.\n\nWhere not possible, the following should be addressed:\n- Remove all sudo composer privileges for all users to mitigate root privilege escalation.  \n- 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. \n\nA reset can also be done on these files by the following:\n\n```sh\nrm vendor/composer/installed.php vendor/composer/InstalledVersions.php\ncomposer install --no-scripts --no-plugins\n```",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "composer/composer"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.0-alpha1"
      }, {
        "fixed" : "2.2.23"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "composer/composer"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.3.0-rc1"
      }, {
        "fixed" : "2.7.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/composer/composer/security/advisories/GHSA-7c6p-848j-wh5h"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-24821"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/composer/composer/commit/64e4eb356b159a30c766cd1ea83450a38dc23bf5"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/composer/composer/commit/77e3982918bc1d886843dc3d5e575e7e871b27b7"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/composer/composer"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-829" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-02-08T15:06:38Z",
    "nvd_published_at" : "2024-02-09T00:15:08Z"
  }
}