---
id: "CVE-2026-40176"
kind: "vulnerability"
aliases: ["CVE-2026-40176", "GHSA-wg36-wvj6-r67p"]
title: "Composer has a command injection via malicious perforce repository"
severity: "high"
cvss: 7.8
epss: 0.01045
exploited: false
status: "open"
category: "package"
products: [{"name": "composer/composer", "fixed": ["2.9.6"], "affected": ">= 2.3.0, < 2.9.6", "ecosystem": "composer"}, {"name": "composer/composer", "fixed": ["2.2.27"], "affected": ">= 1.0.0, < 2.2.27", "ecosystem": "composer"}, {"name": "getcomposer composer", "fixed": [], "affected": ">= 1.0.0, <= 2.2.26", "ecosystem": "vendor"}, {"name": "getcomposer composer", "fixed": [], "affected": ">= 2.3.0, <= 2.9.5", "ecosystem": "vendor"}]
ecosystems: ["composer", "vendor"]
tags: ["ci", "composer", "cwe-20", "cwe-78", "developers", "package", "php"]
not_affected_if: ["dependencies-only", "no-perforce-repositories", "trusted-projects-only"]
published_at: "2026-04-14T20:03:08+00:00"
first_seen_at: "2026-11-02T23:04:40+00:00"
updated_at: "2026-11-02T23:06:16+00:00"
sources: [{"source": "ghsa", "url": "https://github.com/advisories/GHSA-wg36-wvj6-r67p", "first_seen_at": "2026-11-02T23:04:40+00:00"}, {"source": "nvd", "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-40176", "first_seen_at": "2026-11-02T23:06:16+00:00"}]
---

# Composer has a command injection via malicious perforce repository

Composer builds a shell command from Perforce connection values (port, user, client) in composer.json without escaping them. A project whose composer.json declares a Perforce repository can run arbitrary commands as the user running Composer, even if Perforce is not installed.

_Summary, check and fix written by a model from the sources; labelled as such._

## Affected

- composer:composer/composer affected >= 2.3.0, < 2.9.6 fixed 2.9.6
- composer:composer/composer affected >= 1.0.0, < 2.2.27 fixed 2.2.27
- vendor:getcomposer composer affected >= 1.0.0, <= 2.2.26 fixed ?
- vendor:getcomposer composer affected >= 2.3.0, <= 2.9.5 fixed ?

## How to check

- Run `composer --version` and compare against the fixed versions below.
- Search project and global composer.json files (root project and `~/.config/composer/composer.json`) for Perforce repository entries.

## Fix

- Composer `2.9.6` (mainline)
- Composer `2.2.27` (2.2 LTS)

## Timeline

- 2026-11-02T23:04:40+00:00 ghsa https://github.com/advisories/GHSA-wg36-wvj6-r67p
- 2026-11-02T23:06:16+00:00 nvd https://nvd.nist.gov/vuln/detail/CVE-2026-40176

## Documents

- [advisory] Maintainer's advisory: api.github.com https://api.github.com/repos/composer/composer/security-advisories/GHSA-wg36-wvj6-r67p
- [advisory] Maintainer's advisory: github.com https://github.com/composer/composer/security/advisories/GHSA-wg36-wvj6-r67p
- [fix] Release: github.com https://github.com/composer/composer/releases/tag/2.9.6
- [fix] Release: github.com https://github.com/composer/composer/releases/tag/2.2.27

## From the sources

### Impact
The `Perforce::generateP4Command()` method constructed shell commands by interpolating user-supplied Perforce connection parameters (port, user, client) without proper escaping. An attacker controlling a repository configuration in a malicious composer.json declaring a Perforce VCS repository could inject arbitrary commands through these values, leading to command execution in the context of the user running Composer. Composer would execute these injected commands even if Perforce is not installed.

VCS repositories are only loaded from the root composer.json file located in the directory you execute Composer commands in and from the composer config directory (e.g. `~/.config/composer/composer.json`). So this vulnerability cannot be exploited through composer.json files of packages installed as dependencies.

You are at risk of command execution if you run Composer commands on untrusted projects with attacker supplied composer.json files, regardless of whether you or any of your dependencies use Perforce.

### Patches
Fixed in Composer 2.2.27 (2.2 LTS) and 2.9.6 (mainline)

### Workarounds
- Carefully inspect composer.json files before running Composer on them. Verify that Perforce-related fields contain valid values.
- Only run Composer commands on projects from trusted sources.

---

_Free to read at a human pace. An API with keys and an MCP server are in preparation; early access: hello@infrastack.ai_
