GHSA-3q26-f695-pp76: @cyanheads/git-mcp-server vulnerable to command injection in several tools
SummaryA command injection vulnerability exists in the `git-mcp-server` MCP Server. The vulnerability is caused by the unsanitized use of input parameters within a call to `child_process.exec`, enabling an attacker to inject arbitrary system commands. Successful exploitation can lead to remote code execution under the server process's privileges.The server constructs and executes shell commands using unvalidated user input directly within command-line strings. This introduces the possibility of shell metacharacter injection (`|`, `>`, `&&`, etc.).DetailsThe MCP Server exposes tools (`git_add`, `git_init`, `git_logs`, etcc) to perform several git operations.  An MCP Client can be instructed to execute additional actions for example via indirect prompt injection when asked to read git logs. Below some example of vulnerable code and different ways to test this vulnerability including a real example of indirect prompt injection that can lead to arbitrary command injection.Vulnerable codeThe following snippet illustrates the vulnerable code pattern used in the MCP Server’s tooling. **Note**: These are only some instances, but similar patterns may exist elsewhere in the codebase.`git_init``git_add`PoCRealistic Example - Indirect prompt injection via git logsAn MCP Client can be instructed to execute additional actions for example via indirect prompt injection in git logs. The following PoC shows how reading git logs can lead to execution of additional tools vulnerable to command injection.When the client reads Git history as part of its contextual input, it may inadvertently interpret injected instructions embedded in commit messages as legitimate commands or follow-up instructions.This behavior can be exploited to cause the model to execute unintended actions, leading to an arbitrary command execution on the host where the MCP server is running.Setup a local git repository with a malicious git commit messageUse an MCP Client - I used CursorAdd and enable the `git-mcp-server``.cursor/mcp.json`Verify the file `/tmp/TEST3` does **not** exist:open the chat and use the following prompt (it's just an example):run the `git_log` tool - if you have `Auto-Run` mode enabled skip this stepObserve that the response will contain the git logs but will also trigger the `git_add` tool execution with a malicious payload that can lead to command injection. The following tool will be called (without user request but just following the instructions in the git log):run the `git_init` tool - if you have `Auto-Run` mode enabled skip this stepConfirm that the injected command executed:Using MCP InspectorStart the MCP server:Open the MCP Inspector:In MCP Inspector:set transport type: `Streamable HTTP`set the url to `http://127.0.0.1:3010/mcp`click Connectgo to the **Tools** tab and click **List Tools**select the `git_add` toolVerify the file `/tmp/TEST` does **not** exist:In the **path** field, input:Click **Run Tool**Observe the request being sent:the server will log the following:Confirm that the injected command executed:Using an IDE (I used Cursor)add and enable the `git-mcp-server``.cursro/mcp.json`check il the file `/tmp/TEST2` existsopen the chat and use the following prompt (it's just an example):the command executed will be `git init -b "$(id>/tmp/TEST2)" "/tmp/REPO"`run the `git_init` tool - if you have `Auto-Run` mode enabled skip this stepcheck that the file `/tmp/TEST2` is createdRemediationTo mitigate this vulnerability, I suggest to avoid using `child_process.exec` with untrusted input. Instead, use a safer API such as [`child_process.execFile`](https://nodejs.org/api/child_process.html#child_processexecfilefile-args-options-callback), which allows you to pass arguments as a separate array — avoiding shell interpretation entirely.ImpactCommand Injection / Remote Code Execution (RCE)Referenceshttps://equixly.com/blog/2025/03/29/mcp-server-new-security-nightmare/https://invariantlabs.ai/blog/mcp-github-vulnerability
CVSS v3.1: 7.5