# CVE-2026-40261: Composer has Command Injection via Malicious Perforce Reference

> Archived entry. Full-text search covers entries since 2026-11-10; exact IDs work for all years.

- **Severity:** HIGH 8.8
- **CVSS:** 8.8 (v3.1, CNA) `CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H`
- **CVSS metrics:** Attack vector: Network; Attack complexity: Low; Privileges required: None; User interaction: Required; Scope: Unchanged; Confidentiality impact: High; Integrity impact: High; Availability impact: High
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Remote, no login needed
- **EPSS:** 1.98% (percentile 81, 2026-11-26)
- **CWE:** CWE-78, CWE-20
- **Aliases:** BIT-composer-2026-40261, GHSA-gqw4-4w2p-838q
- **Published:** 2026-04-14T20:01:42.000Z
- **Modified:** 2026-09-10T03:51:01.816Z

## Who should check

- Projects that depend on Packagist package composer/composer (\>= 2.3.0, \< 2.9.6)
- Anyone running composer \>= 2.3.0, \< 2.9.6; \>= 1.0.0, \< 2.2.27

## Description

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.

## Affected and fixed versions

- Packagist `composer/composer`: affected \>= 2.3.0, \< 2.9.6; fixed 2.9.6, 2.2.27 (osv)
- composer: \>= 2.3.0, \< 2.9.6; \>= 1.0.0, \< 2.2.27 (cvelist)

## Mitigation

- Upgrade composer/composer to one of 2.9.6, 2.2.27 (or later in the same release line).

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by CVE-2026-40261. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2026-40261.md
Affected: composer/composer >= 2.3.0, < 2.9.6
Fixed in: 2.9.6, 2.2.27

Steps:
1. Search this machine and project for composer/composer (Packagist), composer: dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is CVE-2026-40261 being exploited?

There is no confirmed exploitation: CVE-2026-40261 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known. EPSS estimates a 1.98% chance of exploitation in the next 30 days (as of 2026-11-26).

### How serious is CVE-2026-40261?

High: CVSS 8.8 (v3.1, scored by CNA). Remote, no login needed. A user has to take an action, such as opening a link, for the attack to work.

### Which versions are affected by CVE-2026-40261?

composer/composer \>= 2.3.0, \< 2.9.6.

### Is there a fix for CVE-2026-40261?

Yes. Fixed in 2.9.6, 2.2.27. Upgrade composer/composer to one of 2.9.6, 2.2.27 (or later in the same release line).

### How do I check if I'm affected by CVE-2026-40261?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- vendor: <https://github.com/composer/composer/security/advisories/GHSA-gqw4-4w2p-838q>
- vendor: <https://access.redhat.com/errata/RHSA-2026:8165>
- vendor: <https://nvd.nist.gov/vuln/detail/CVE-2026-40261>
- other: <https://github.com/composer/composer/releases/tag/2.9.6>
- other: <https://access.redhat.com/security/cve/CVE-2026-40261>
- other: <https://bugzilla.redhat.com/show_bug.cgi?id=2458841>
- other: <https://security.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-40261.json>
- other: <https://github.com/FriendsOfPHP/security-advisories/blob/master/composer/composer/CVE-2026-40261.yaml>
- other: <https://github.com/composer/composer>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- NVD: This product uses data from the NVD API but is not endorsed or certified by the NVD. <https://nvd.nist.gov/vuln/detail/CVE-2026-40261>
- OSV: CC-BY 4.0 <https://osv.dev/vulnerability/GHSA-gqw4-4w2p-838q> (license: <https://creativecommons.org/licenses/by/4.0/>)

HTML: <https://flawdb.com/CVE-2026-40261> · JSON: <https://flawdb.com/api/v1/entries/CVE-2026-40261>
