CVE-2021-29472: Composer/composer Remote Code Execution Vulnerability

HIGH
Advisory Identifier: GHSA-h5h8-pc6h-jvvx
CVSS 8.8
CWE-88 CWE-94
Published
Advisory Summary

CVE-2021-29472 is a HIGH (CVSS 8.8) remote code execution vulnerability (CWE-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection')) affecting Composer/composer libraries in the Packagist ecosystem. The issue involves composer's missing argument delimiter can lead to code execution via vcs repository urls or source download urls on systems with mercurial. Remediation is available by upgrading affected packages to version 1.10.22, 2.0.13.

CVE-2021-29472 at a Glance

CVE Identifier CVE-2021-29472
GHSA Identifier GHSA-h5h8-pc6h-jvvx
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection')
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:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H).

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

How to Fix CVE-2021-29472

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: 1.10.22
Upgrade composer/composer to 1.10.22
composer/composer fixed: 2.0.13
Upgrade composer/composer to 2.0.13
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-2021-29472, 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 1.10.22), 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-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection'), where the product constructs a string for a command to be executed by a separate component in another control sphere, but it does not properly delimit the intended arguments, options, or switches within that command string. 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

URLs for Mercurial repositories in the root composer.json and package source download URLs are not sanitized correctly. Specifically crafted URL values allow commands to be executed in the HgDriver if hg/Mercurial is installed on the system. ### Impact - The impact to Composer users directly is limited as the composer.json file is typically under their own control and source download URLs can only be supplied by third party Composer repositories they explicitly trust to download and execute source code from, e.g. Composer plugins. - The main impact is to services passing user input to Composer, including Packagist.org and Private Packagist. This allowed users to trigger remote command injection. The vulnerability has been patched on Packagist.org and Private Packagist within 12h of receiving the initial vulnerability report and based on a review of logs, to the best of our knowledge, was not abused by anyone. - Other services/tools using VcsRepository/VcsDriver or derivatives may also be vulnerable and should upgrade their composer/composer dependency immediately ### Patches 1.10.22 and 2.0.13 include patches for this issue.

CVE-2021-29472 Affected Composer/composer Versions

2 component(s)
Fixed Versions:
1.10.222.0.13
Product / Package Ecosystem Affected Versions Fixed Version
composer/composer
Packagist
< 1.10.22
1.10.22
composer/composer
Packagist
≥ 2.0.0-alpha1
< 2.0.13
2.0.13

References

Frequently Asked Questions

What is CVE-2021-29472?
CVE-2021-29472 is a security vulnerability in Composer/composer involving Composer's missing argument delimiter can lead to code execution via VCS repository URLs or source download URLs on systems with Mercurial under CWE-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection').
Which Composer/composer versions are affected?
Affected versions include releases prior to 1.10.22, 2.0.13 across affected packages: composer/composer.
What version fixes CVE-2021-29472?
Upgrading to 1.10.22, 2.0.13 (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 1.10.22, 2.0.13. Upgrade your dependency to 1.10.22, 2.0.13 or later.
What is the CVSS score of CVE-2021-29472?
CVE-2021-29472 has a CVSS v3.1 base score of 8.8 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2021-29472?
CVE-2021-29472 is classified under CWE-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection') (The product constructs a string for a command to be executed by a separate component in another control sphere, but it does not properly delimit the intended arguments, options, or switches within that command string.).
How can I check Packagist dependencies for CVE-2021-29472?
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-h5h8-pc6h-jvvx",
  "modified" : "2022-08-11T00:19:18Z",
  "published" : "2021-04-29T21:52:04Z",
  "aliases" : [ "CVE-2021-29472" ],
  "summary" : "Composer's missing argument delimiter can lead to code execution via VCS repository URLs or source download URLs on systems with Mercurial",
  "details" : "URLs for Mercurial repositories in the root composer.json and package source download URLs are not sanitized correctly. Specifically crafted URL values allow commands to be executed in the HgDriver if hg/Mercurial is installed on the system.\n\n### Impact\n- The impact to Composer users directly is limited as the composer.json file is typically under their own control and source download URLs can only be supplied by third party Composer repositories they explicitly trust to download and execute source code from, e.g. Composer plugins.\n- The main impact is to services passing user input to Composer, including Packagist.org and Private Packagist. This allowed users to trigger remote command injection. The vulnerability has been patched on Packagist.org and Private Packagist within 12h of receiving the initial vulnerability report and based on a review of logs, to the best of our knowledge, was not abused by anyone.\n- Other services/tools using VcsRepository/VcsDriver or derivatives may also be vulnerable and should upgrade their composer/composer dependency immediately\n\n### Patches\n1.10.22 and 2.0.13 include patches for this issue.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "composer/composer"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.10.22"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "composer/composer"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.0-alpha1"
      }, {
        "fixed" : "2.0.13"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/composer/composer/security/advisories/GHSA-h5h8-pc6h-jvvx"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-29472"
  }, {
    "type" : "WEB",
    "url" : "https://blog.sonarsource.com/php-supply-chain-attack-on-composer"
  }, {
    "type" : "WEB",
    "url" : "https://getcomposer.org"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/FriendsOfPHP/security-advisories/blob/master/composer/composer/CVE-2021-29472.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/composer/composer"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2021/05/msg00009.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/FAQUAMGO4Q4BLNZ2OH4CXQD7UK4IO2GE"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/KN3DMFH42BJW45VT6FYF2RXKC26D6VC2"
  }, {
    "type" : "WEB",
    "url" : "https://www.debian.org/security/2021/dsa-4907"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-88", "CWE-94" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-04-27T20:33:49Z",
    "nvd_published_at" : "2021-04-27T21:15:00Z"
  }
}