Composer has Command Injection via Malicious Perforce Reference
Key facts
- Attack vector
- Network
- Privileges required
- None
- User interaction
- Required
- Attack complexity
- Low
- Impact type
- Code execution
- Confidentiality · integrity · availability
- High · High · High
- Fix status
- Fixed
Attack profile from CVSS 3.1 · CNA. Fix status from CNA, GitHub and Red Hat. Impact type from CWE-78.
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.
Why it matters now
SSVC decision points
CISA ADP · SSVC 2.0.3
- Exploitation
- None
- Automatable
- No
- Technical impact
- Total
The decision (Track, Attend, Act) also depends on your mission and well-being impact; see CISA's SSVC guide.
Affected products
| Vendor | Product | Affected versions | Fixed in | Status | Source |
|---|---|---|---|---|---|
| composer | composer | 2.3.0 to before 2.9.6; 1.0.0 to before 2.2.27 | 2.9.6, 2.2.27 | Patch available | CNA |
| — | composer/composer (Packagist) | 2.3.0 to before 2.9.6 | 2.9.6 | Patch available | GHSA-gqw4-4w2p-838q |
| — | composer/composer (Packagist) | 1.0.0 to before 2.2.27 | 2.2.27 | Patch available | GHSA-gqw4-4w2p-838q |
- composer Vendorcomposer Affected 2.3.0 to before 2.9.6; 1.0.0 to before 2.2.27 Fixed in 2.9.6, 2.2.27 Patch available CNA
- composer/composer (Packagist) Vendor— Affected 2.3.0 to before 2.9.6 Fixed in 2.9.6 Patch available GHSA-gqw4-4w2p-838q
- composer/composer (Packagist) Vendor— Affected 1.0.0 to before 2.2.27 Fixed in 2.2.27 Patch available GHSA-gqw4-4w2p-838q
Remediation
- Fix · CNA composer (composer) Fixed in 2.9.6, 2.2.27
- Fix · GHSA-gqw4-4w2p-838q composer/composer (Packagist) Fixed in 2.9.6 Advisory →
- Fix · GHSA-gqw4-4w2p-838q composer/composer (Packagist) Fixed in 2.2.27 Advisory →
Red Hat 1 advisory
- RHSA-2026:8165 Released 2026-04-14 · Red Hat rating ImportantRed Hat Hardened Images RPMs bug fix and enhancement update
- Red Hat Hardened Images composer-2.9.7-1.hum1@noarch@public-hummingbird-aarch64-rpms, composer-2.9.7-1.hum1@noarch@public-hummingbird-x86_64-rpms, composer-2.9.7-1.hum1@src
Vendor assessments
Red Hat
Red Hat rating: Important. Red Hat's page for this CVE →
| Product | Status | Plan or fix |
|---|---|---|
| Red Hat Hardened Images | Fixed | RHSA-2026:8165 |
Timeline
- 2026-10-02 Threatist record created from CVE-2026-40261
- 2026-10-03 Alias added: GHSA-gqw4-4w2p-838q
References
Advisory 2
Other 7
- https://github.com/composer/composer/releases/tag/2.9.6
- https://access.redhat.com/errata/RHSA-2026:8165
- https://access.redhat.com/security/cve/CVE-2026-40261
- https://bugzilla.redhat.com/show_bug.cgi?id=2458841
- https://github.com/FriendsOfPHP/security-advisories/blob/master/composer/composer/CVE-2026-40261.yaml
- https://github.com/composer/composer
- https://security.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-40261.json
More Composer vulnerabilities
- TI-2015-06892 Composer before 2016-02-10 allows cache poisoning from other projects built on the same… CVSS 3.1HIGH 8.8
- TI-2021-17955 Command injection in composer on Windows CVSS 3.1CRITICAL 9.8
- TI-2021-10185 Code injection in composer CVSS 3.1HIGH 8.8
- TI-2022-08641 Missing input validation can lead to command execution in composer CVSS 3.1HIGH 8.8
- TI-2023-23380 Remote Code Execution via web-accessible composer.phar CVSS 3.1HIGH 8.8
- TI-2024-16338 Code execution and possible privilege escalation via compromised InstalledVersions.php or installed.php in Composer CVSS 3.1HIGH 8.8
Sources
- CVE-2026-40261 · CVE Program
- CVE-2026-40261 · NVD
- FIRST EPSS
- GHSA-gqw4-4w2p-838q · GitHub Advisory Database · CC BY 4.0
- CVE-2026-40261 · Red Hat security data · CC BY 4.0
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences