Loading...
Skip to main content

CVE-2026-40261 — Vulnerability in composer/composer — CVE Details

HIGH

Composer has a command injection via malicious perforce reference

Published April 14, 2026Updated September 10, 2026Source: osv

Summary

### Impact The `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. The 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. This 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. ### Patches Fixed in Composer 2.2.27 (2.2 LTS) and 2.9.6 (mainline) Note, 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. ### Workarounds - Avoid installing dependencies from source by using `--prefer-dist` or the `preferred-install: dist` config setting. - Only use trusted Composer repositories.

Advisory Timeline

  • First published April 14, 2026 (181 days ago).
  • Last revised September 10, 2026 — 148 days after initial publication.

Remediation

Upgrade to the fixed version using your package manager.

Composer
Update composer/composer to 2.9.6 or later
composer require "composer/composer:^2.9.6"
Composer
Update composer/composer to 2.2.27 or later
composer require "composer/composer:^2.2.27"

After upgrading, run your dependency scanner again to confirm the vulnerability is resolved.

Affected Packages (2)

Affects 1 ecosystem: packagist (1).

PackageEcosystemAffectedFixed In
composer/composer
packagist
2.3.0, 2.3.1, 2.3.10, 2.3.2 (+59 more)2.9.6
composer/composer
packagist
1.0.0, 1.0.1, 1.0.2, 1.0.3 (+143 more)2.2.27

Vulnerability Classification

Common Weakness Enumeration (CWE) identifiers for this vulnerability type.

  • CWE-20
    Improper Input ValidationMITRE
  • CWE-78
    OS Command InjectionMITRE

CVSS Score Breakdown

What the CVSS (Common Vulnerability Scoring System) 8.8 score means for each attack dimension.

Attack Vector
Network
Attack Complexity
Low
Privileges Required
None
User Interaction
Required
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H

Frequently Asked Questions

What is CVE-2026-40261?
Composer has a command injection via malicious perforce reference This vulnerability has been assigned a severity rating of HIGH (CVSS score: 8.8/10).
How do I check if my project is affected by CVE-2026-40261?
CVE-2026-40261 affects composer/composer. Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2026-40261 and 200,000+ other known vulnerabilities.

Severity & Exploitability

CVSS Score
8.8

High exploitability or significant impact. Prioritize remediation within days.

Also Known As

GHSA-gqw4-4w2p-838q
BIT-composer-2026-40261

Related CVEs

  • CVE-2024-35241
    HIGH

    Composer has a command injection via malicious git branch name

  • CVE-2026-65954
    HIGH

    PHPCSUtils: Remote code execution via eval() in AbstractArrayDeclarationSniff::getActualArrayKey()

  • CVE-2026-84361
    HIGH

    Composer arbitrary command execution via a malicious package's Perforce source URL

  • CVE-2024-35242
    HIGH

    Composer has multiple command injections via malicious git/hg branch names

  • CVE-2026-61825
    HIGH

    code16/sharp has a stored XSS via data-html-content Sanitizer Bypass

Check if you're affected

Scan your dependencies to see if this vulnerability affects your projects.

Scan Your Dependencies