{"id":"CVE-2026-40176","kind":"vulnerability","aliases":["CVE-2026-40176","GHSA-wg36-wvj6-r67p"],"related":[],"title":"Composer has a command injection via malicious perforce repository","description":"### Impact\nThe `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.\n\nVCS 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.\n\nYou 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.\n\n### Patches\nFixed in Composer 2.2.27 (2.2 LTS) and 2.9.6 (mainline)\n\n### Workarounds\n- Carefully inspect composer.json files before running Composer on them. Verify that Perforce-related fields contain valid values.\n- Only run Composer commands on projects from trusted sources.","summary":"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.","severity":"high","cvss":7.8,"epss":0.01045,"exploited":false,"exploited_at":null,"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"],"how_to_check":"- Run `composer --version` and compare against the fixed versions below.\n- Search project and global composer.json files (root project and `~/.config/composer/composer.json`) for Perforce repository entries.","fix":"- Composer `2.9.6` (mainline)\n- Composer `2.2.27` (2.2 LTS)","status":"open","published_at":"2026-04-14T20:03:08+00:00","first_seen_at":"2026-11-02T23:04:40+00:00","triaged_at":"2026-11-02T23:04:45+00:00","updated_at":"2026-11-02T23:06:16+00:00","category":"package","confidence":0.85,"triage":{"at":"2026-11-02T23:04:45Z","model":"claude-haiku-5-5","output":{"fix":"- Composer `2.9.6` (mainline)\n- Composer `2.2.27` (2.2 LTS)","reach":"local","title":"Composer: a malicious composer.json runs commands through Perforce settings","impact":"high","summary":"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.","audience":"developers","category":"package","nicknames":[],"who_cares":["composer","php","developers","ci"],"confidence":0.85,"fix_status":"available","needs_auth":"no","worst_case":"Arbitrary commands run as the user running Composer","analyst_note":"","how_to_check":"- Run `composer --version` and compare against the fixed versions below.\n- Search project and global composer.json files (root project and `~/.config/composer/composer.json`) for Perforce repository entries.","plain_action":"","needs_analyst":false,"not_affected_if":["trusted-projects-only","no-perforce-repositories","dependencies-only"],"who_is_affected":"Only Composer runs on untrusted projects are at risk, since VCS repositories are loaded only from the root composer.json and the global Composer config directory, not from dependencies' composer.json files. Teams that run Composer on projects from trusted sources can skip it; any system where Composer processes attacker-supplied composer.json files should be checked.","user_interaction":"yes","needs_special_setup":"no","severity_if_unknown":"high"},"cost_usd":0.000729,"input_tokens":4586,"output_tokens":541,"severity_before":"high"},"analyst_status":null,"analyst_note":null,"search":"'-20':30B '-2026':11A,19A '-40176':12A,20A '-78':32B '/.config/composer/composer.json':170C '2.2':221C '2.2.27':220C '2.9.6':224C 'arbitrari':63B,115C 'attack':99C,201C 'build':37B 'cannot':174C 'care':227C 'ci':27B 'client':47B,94C 'command':4A,40B,64B,83C,116C,122C,137C,161C,190C,196C,248C 'compos':1A,28B,36B,69B,131C,132C,160C,166C,195C,219C,233C,247C 'composer':24A,26A 'composer.json':49B,56B,107C,152C,178C,203C,229C 'composer/composer':21A,22A 'config':167C 'configur':103C 'connect':43B,90C 'construct':81C 'contain':242C 'context':126C 'control':100C 'could':113C 'cve':10A,18A 'cwe':29B,31B 'declar':57B,108C 'depend':184C,213C 'develop':33B 'directori':157C,168C 'e.g':169C 'escap':51B,97C 'even':70B,138C 'execut':123C,134C,159C,191C 'exploit':176C 'field':241C 'file':153C,179C,204C,230C 'fix':217C 'generatep4command':79C 'getcomposer':23A,25A 'ghsa':14A 'ghsa-wg36-wvj6-r67p':13A 'impact':76C 'inject':5A,114C,136C 'inspect':228C 'instal':75B,143C,182C 'interpol':85C 'lead':120C 'load':148C 'locat':154C 'lts':222C 'mainlin':225C 'malici':7A,106C 'method':80C 'packag':34B,181C 'paramet':91C 'patch':216C 'perforc':8A,42B,59B,72B,78C,89C,110C,140C,215C,239C 'perforce-rel':238C 'php':35B 'port':45B,92C 'project':54B,199C,250C 'proper':96C 'r67p':17A 'regardless':205C 'relat':240C 'repositori':9A,60B,102C,112C,145C 'risk':188C 'root':151C 'run':62B,68B,130C,194C,232C,246C 'shell':39B,82C 'sourc':253C 'suppli':88C,202C 'trust':252C 'untrust':198C 'use':214C 'user':46B,67B,87C,93C,129C 'user-suppli':86C 'valid':243C 'valu':44B,119C,244C 'vcs':111C,144C 'verifi':236C 'via':6A 'vulner':173C 'wg36':15A 'whether':207C 'whose':55B 'without':50B,95C 'workaround':226C 'would':133C 'wvj6':16A","nicknames":[],"mitigations":[],"who_affected":"Only Composer runs on untrusted projects are at risk, since VCS repositories are loaded only from the root composer.json and the global Composer config directory, not from dependencies' composer.json files. Teams that run Composer on projects from trusted sources can skip it; any system where Composer processes attacker-supplied composer.json files should be checked.","tier":"B","verified":{},"analyst_revisit_at":null,"fix_status":"available","audience":"developers","plain_action":null,"pkeys":["composer","composercomposer","getcomposercomposer"],"ptokens":["composer","getcomposer"],"labels":["ci","composer","cwe20","cwe78","developers","high","package","php","vendor"],"first_public_at":"2026-04-14T09:46:34+00:00","kev":null,"cvss_vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H","cvss_by":"GitHub","poc_count":0,"sources":[{"source":"ghsa","external_id":"GHSA-wg36-wvj6-r67p","url":"https://github.com/advisories/GHSA-wg36-wvj6-r67p","severity":"high","published_at":"2026-04-14T20:03:08+00:00","modified_at":"2026-11-02T23:03:50+00:00","first_seen_at":"2026-11-02T23:04:40+00:00","fetched_at":"2026-11-02T23:09:41+00:00","note":null},{"source":"nvd","external_id":"CVE-2026-40176","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40176","severity":null,"published_at":"2026-04-15T21:17:27+00:00","modified_at":"2026-07-15T02:21:04+00:00","first_seen_at":"2026-11-02T23:06:16+00:00","fetched_at":"2026-11-02T23:06:16+00:00","note":null}],"documents":[{"id":54288,"url":"https://api.github.com/repos/composer/composer/security-advisories/GHSA-wg36-wvj6-r67p","title":"Maintainer's advisory: api.github.com","kind":"vendor","source":"ghsa","publisher":"vendor","text":null,"published_at":null,"relation":"advisory","confidence":null,"note":"Maintainer's advisory: api.github.com"},{"id":54289,"url":"https://github.com/composer/composer/security/advisories/GHSA-wg36-wvj6-r67p","title":"Maintainer's advisory: github.com","kind":"vendor","source":"ghsa","publisher":"vendor","text":null,"published_at":"2026-04-14T09:46:34+00:00","relation":"advisory","confidence":null,"note":"Maintainer's advisory: github.com"},{"id":54290,"url":"https://github.com/composer/composer/releases/tag/2.9.6","title":"Release: github.com","kind":"release","source":"ghsa","publisher":"vendor","text":null,"published_at":null,"relation":"fix","confidence":null,"note":"Release: github.com"},{"id":54291,"url":"https://github.com/composer/composer/releases/tag/2.2.27","title":"Release: github.com","kind":"release","source":"ghsa","publisher":"vendor","text":null,"published_at":null,"relation":"fix","confidence":null,"note":"Release: github.com"}],"notice":"Free to read at a human pace. An API with keys and an MCP server are in preparation; early access: hello@infrastack.ai"}