{"id":"CVE-2026-40261","aliases":["CVE-2026-40261","GHSA-gqw4-4w2p-838q","BIT-COMPOSER-2026-40261"],"related":[],"kind":"vulnerability","state":"published","title":"Composer has Command Injection via Malicious Perforce Reference","summary":"Composer is a dependency manager for PHP. Versions 1.0 through 2.2.26 and 2.3 through 2.9.5 contain a command injection vulnerability in the Perforce::syncCodeBase() method, which appends the $sourceReference parameter to a shell command without proper escaping, and additionally in the Perforce::generateP4Command() method as in GHSA-wg36-wvj6-r67p / CVE-2026-40176, which interpolates user-supplied Perforce connection parameters (port, user, client) from the source url field without proper escaping. An attacker can inject arbitrary commands through crafted source reference or source url values containing shell metacharacters, even if Perforce is not installed. Unlike CVE-2026-40176, the source reference and url are provided as part of package metadata, meaning any compromised or malicious Composer repository can serve package metadata declaring perforce as a source type with malicious values. This vulnerability is exploitable when installing or updating dependencies from source, including the default behavior when installing dev-prefixed versions. This issue has been fixed in Composer 2.2.27 (2.2 LTS) and 2.9.6 (mainline). If developers are unable to immediately update, they can avoid installing dependencies from source by using --prefer-dist or the preferred-install: dist config setting, and only use trusted Composer repositories as a workaround.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Composer is a dependency manager for PHP. Versions 1.0 through 2.2.26 and 2.3 through 2.9.5 contain a command injection vulnerability in the Perforce::syncCodeBase() method, which appends the $sourceReference parameter to a shell command without proper escaping, and additionally in the Perforce::generateP4Command() method as in GHSA-wg36-wvj6-r67p / CVE-2026-40176, which interpolates user-supplied Perforce connection parameters (port, user, client) from the source url field without proper escaping. An attacker can inject arbitrary commands through crafted source reference or source url values containing shell metacharacters, even if Perforce is not installed. Unlike CVE-2026-40176, the source reference and url are provided as part of package metadata, meaning any compromised or malicious Composer repository can serve package metadata declaring perforce as a source type with malicious values. This vulnerability is exploitable when installing or updating dependencies from source, including the default behavior when installing dev-prefixed versions. This issue has been fixed in Composer 2.2.27 (2.2 LTS) and 2.9.6 (mainline). If developers are unable to immediately update, they can avoid installing dependencies from source by using --prefer-dist or the preferred-install: dist config setting, and only use trusted Composer repositories as a workaround.","source":"cvelist"},{"lang":"en","text":"### Impact\nThe `Perforce::syncCodeBase()` method appended the `$sourceReference` parameter to a shell command without proper escaping, allowing an attacker to inject arbitrary commands through a crafted source reference containing shell metacharacters. Further as in GHSA-wg36-wvj6-r67p / CVE-2026-40176 the `Perforce::generateP4Command()` method constructed shell commands by interpolating user-supplied Perforce connection parameters (port, user, client) without proper escaping from the source url field. Composer would execute these injected commands even if Perforce is not installed.\n\nThe source reference and url are provided as part of package metadata. Any Composer package repository can serve package metadata declaring perforce as a source type with a malicious source reference or source url. This means the vulnerability can be exploited through any package served by a compromised or malicious Composer repository. An attack does not require Perforce to be installed on the client, as Composer will attempt to execute the constructed command regardless.\n\nThis vulnerability is exploitable when installing or updating dependencies from source (`--prefer-source`, default when installing dev prefixed versions), even if you do not use Perforce.\n\n### Patches\nFixed in Composer 2.2.27 (2.2 LTS) and 2.9.6 (mainline)\n\nNote, the fix for the source url in the `Perforce::generateP4Command()` was addressed as part of the patches for GHSA-wg36-wvj6-r67p / CVE-2026-40176 in the same versions.\n\n### Workarounds\n\n- Avoid installing dependencies from source by using `--prefer-dist` or the `preferred-install: dist` config setting.\n- Only use trusted Composer repositories.","format":"markdown","source":"ghsa"}],"published":"2026-04-14T20:01:42.000Z","modified":"2026-09-10T03:51:01.816Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H","score":8.8,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H","score":8.8,"rating":"HIGH"},{"scorer":"redhat-SADP","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H","score":8.8,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H","score":8.8,"rating":"HIGH"},{"scorer":"Bitnami Vulnerability Database","scheme":"rating","rating":"HIGH"}],"cwes":["CWE-20","CWE-78"],"affected":[{"ranges":[{"version":">= 2.3.0, < 2.9.6","status":"affected"},{"version":">= 1.0.0, < 2.2.27","status":"affected"}],"vendor":"composer","product":"composer","source":"cvelist"},{"ranges":[{"type":"rpm","introduced":"2.9.7-1.hum1","fixed":"*","status":"unaffected"}],"vendor":"Red Hat","product":"Red Hat Hardened Images","package":"composer-main","cpe":"cpe:/a:redhat:hummingbird:1","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"2.3.0","status":"affected","fixed":"2.9.6"}],"ecosystem":"Packagist","package":"composer/composer","purl":"pkg:composer/composer/composer","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"1.0.0","status":"affected","fixed":"2.2.27"}],"ecosystem":"Packagist","package":"composer/composer","purl":"pkg:composer/composer/composer","source":"ghsa"},{"ranges":[{"status":"affected","introduced":"1.0.0","lastAffected":"2.2.26"},{"status":"affected","introduced":"2.3.0","lastAffected":"2.9.5"}],"vendor":"getcomposer","product":"composer","cpe":"cpe:2.3:a:getcomposer:composer:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"semver","introduced":"1.0.0","status":"affected","fixed":"2.2.27"},{"type":"semver","introduced":"2.3.0","status":"affected","fixed":"2.9.6"}],"ecosystem":"Bitnami","package":"composer","purl":"pkg:bitnami/composer","source":"bitnami"}],"references":[{"url":"https://github.com/composer/composer/security/advisories/GHSA-gqw4-4w2p-838q","tags":["advisory","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","bitnami"]},{"url":"https://github.com/composer/composer/releases/tag/2.9.6","tags":["article","release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","bitnami"]},{"url":"https://access.redhat.com/security/cve/CVE-2026-40261","tags":["vdb-entry","web","x-refsource-redhat"],"sources":["cvelist","ghsa","nvd","bitnami"]},{"url":"https://bugzilla.redhat.com/show_bug.cgi?id=2458841","tags":["issue-tracking","web","x-refsource-redhat"],"sources":["cvelist","ghsa","nvd","bitnami"]},{"url":"https://security.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-40261.json","tags":["web","x-sadp-csaf-vex"],"sources":["cvelist","ghsa","nvd","bitnami"]},{"url":"https://access.redhat.com/errata/RHSA-2026:8165","tags":["vendor-advisory","web","x-refsource-redhat"],"sources":["cvelist","ghsa","nvd","bitnami"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40261","tags":["advisory","web"],"sources":["ghsa","bitnami"]},{"url":"https://github.com/FriendsOfPHP/security-advisories/blob/master/composer/composer/CVE-2026-40261.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/composer/composer","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"none","automatable":"no","technicalImpact":"total","date":"2026-04-16T13:41:03.354Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-40261","url":"https://www.cve.org/CVERecord?id=CVE-2026-40261","licence":"CVE Terms of Use","modified":"2026-07-15T01:01:10.106Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-gqw4-4w2p-838q","url":"https://github.com/advisories/GHSA-gqw4-4w2p-838q","licence":"CC-BY-4.0","modified":"2026-09-10T03:51:01.816Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-40261","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40261","licence":"Public domain","modified":"2026-07-15T02:21:05.167Z"},{"source":"bitnami","name":"Bitnami Vulnerability Database","id":"BIT-COMPOSER-2026-40261","url":"https://osv.dev/vulnerability/BIT-COMPOSER-2026-40261","licence":"Apache-2.0","modified":"2026-09-08T08:45:58.208Z"}],"updatedAt":"2026-11-25T22:59:18.878Z","epss":{"score":0.01755,"percentile":0.78629,"date":"2026-12-02T12:00:21.000Z"}}