Miggo Logo

CVE-2025-53107:
@cyanheads/git-mcp-server vulnerable to command injection in several tools

7.5

CVSS Score
3.1

Basic Information

EPSS Score
0.36757%
Published
6/30/2025
Updated
6/30/2025
KEV Status
No
Technology
TechnologyJavaScript

Technical Details

CVSS Vector
CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:H
Package NameEcosystemVulnerable VersionsFirst Patched Version
@cyanheads/git-mcp-servernpm<= 2.1.42.1.5

Vulnerability Intelligence
Miggo AIMiggo AI

Miggo AIRoot Cause Analysis

The core of the vulnerability lies in the widespread use of child_process.exec throughout the git-mcp-server codebase. The application constructs git commands as simple strings, concatenating user-provided input directly into these strings. This is a classic command injection vulnerability. An attacker can provide malicious input containing shell metacharacters (e.g., |, &&, ;, $()) to break out of the intended git command and execute arbitrary commands on the server's operating system. The vulnerability is present in almost every tool (git_add, git_init, etc.) that the server exposes, as they all follow this insecure pattern of command construction and execution. The provided patch systematically replaces all calls to exec with execFile. The execFile function is inherently safer because it accepts command-line arguments as an array of strings, ensuring that user input is treated as data rather than executable code by the shell. My analysis of the patch commit confirmed that a large number of functions were modified, and each of these functions represents a potential vector for exploitation. The PoC in the description demonstrates how even indirect input, like a git log message, can be used to trigger this vulnerability, highlighting the severity and pervasive nature of the issue.

Vulnerable functions

addGitFiles
src/mcp-server/tools/gitAdd/logic.ts
The function constructs a git command by embedding unsanitized `targetPath` and `filesArg` variables into a string, which is then executed via `execAsync`. This allows for command injection if a malicious path or file argument is provided.
gitBranchLogic
src/mcp-server/tools/gitBranch/logic.ts
The function builds a git command string using user-provided inputs like `targetPath`, `branchName`, and `startPoint` without proper sanitization, making it vulnerable to command injection via the `execAsync` call.
checkoutGit
src/mcp-server/tools/gitCheckout/logic.ts
The function constructs a git checkout command by concatenating user-controlled inputs such as `targetPath` and `branchOrPath` into a command string executed by `execAsync`, which is susceptible to command injection.
gitCherryPickLogic
src/mcp-server/tools/gitCherryPick/logic.ts
The function is vulnerable to command injection as it constructs a git command string with user-supplied data like `targetPath` and `commitRef` and executes it using `execAsync`.
gitCleanLogic
src/mcp-server/tools/gitClean/logic.ts
The function constructs a git command string with user-controlled `targetPath` and other flags, which is then executed by `execAsync`, creating a command injection vulnerability.
gitCloneLogic
src/mcp-server/tools/gitClone/logic.ts
The function is vulnerable to command injection because it builds a git clone command by embedding a sanitized but still potentially dangerous `sanitizedRepoUrl` and `sanitizedTargetPath` into a command string for `execAsync`.
commitGitChanges
src/mcp-server/tools/gitCommit/logic.ts
The function uses `execAsync` to run a git commit command constructed with user input, including the commit message. Despite an attempt to escape the message, the use of `exec` with concatenated strings is inherently unsafe and can be exploited.
diffGitChanges
src/mcp-server/tools/gitDiff/logic.ts
The function constructs a git diff command with user-provided `targetPath`, `safeCommit1`, `safeCommit2`, and `safeFile`, and executes it with `execAsync`, which allows for command injection.
fetchGitRemote
src/mcp-server/tools/gitFetch/logic.ts
The function is vulnerable as it constructs a git fetch command with user-controlled `targetPath` and `safeRemote` and executes it with `execAsync`, leading to a command injection vulnerability.
gitInitLogic
src/mcp-server/tools/gitInit/logic.ts
This function is vulnerable to command injection because it constructs a git init command by concatenating user-provided `initialBranch` and `targetPath` into a command string that is executed by `execAsync`.
logGitHistory
src/mcp-server/tools/gitLog/logic.ts
The function constructs a git log command with user-controlled inputs like `targetPath`, `author`, `since`, `until`, and `branchOrFile`, and executes it with `execAsync`, making it vulnerable to command injection.
gitMergeLogic
src/mcp-server/tools/gitMerge/logic.ts
The function is vulnerable because it constructs a git merge command with user-supplied `targetPath`, `commitMessage`, and `branch` and executes it with `execAsync`, which can lead to command injection.
pullGitChanges
src/mcp-server/tools/gitPull/logic.ts
The function constructs a git pull command with user-provided `targetPath`, `remote`, and `branch` and executes it with `execAsync`, creating a command injection vulnerability.
pushGitChanges
src/mcp-server/tools/gitPush/logic.ts
The function is vulnerable to command injection as it constructs a git push command with user-controlled `targetPath`, `remote`, `branch`, and `remoteBranch` and executes it with `execAsync`.
gitRebaseLogic
src/mcp-server/tools/gitRebase/logic.ts
The function constructs a git rebase command with user-supplied `targetPath`, `onto`, `upstream`, and `branch` and executes it with `execAsync`, which is insecure.
gitRemoteLogic
src/mcp-server/tools/gitRemote/logic.ts
The function is vulnerable as it constructs git remote commands with user-provided `targetPath`, `name`, and `url` and executes them with `execAsync`.
resetGitState
src/mcp-server/tools/gitReset/logic.ts
The function constructs a git reset command with user-controlled `targetPath` and `commit` and executes it with `execAsync`, leading to a command injection vulnerability.
gitSetWorkingDirLogic
src/mcp-server/tools/gitSetWorkingDir/logic.ts
The function uses `execAsync` to initialize a git repository. Although the command is static, the `cwd` option is derived from user input (`sanitizedPath`), which could potentially be manipulated in some environments to cause issues, although the primary vulnerability is the use of `exec` itself.
gitShowLogic
src/mcp-server/tools/gitShow/logic.ts
The function is vulnerable because it constructs a git show command with user-supplied `targetPath` and `refSpec` (which includes `ref` and `filePath`) and executes it with `execAsync`.
gitStashLogic
src/mcp-server/tools/gitStash/logic.ts
The function constructs git stash commands with user-provided `targetPath`, `stashRef`, and `message` and executes them with `execAsync`, making it vulnerable to command injection.
getGitStatus
src/mcp-server/tools/gitStatus/logic.ts
The function is vulnerable as it constructs a git status command with user-controlled `targetPath` and executes it with `execAsync`.
gitTagLogic
src/mcp-server/tools/gitTag/logic.ts
The function constructs git tag commands with user-supplied `targetPath`, `tagName`, `message`, and `commitRef` and executes them with `execAsync`, which is insecure.
gitWorktreeLogic
src/mcp-server/tools/gitWorktree/logic.ts
The function constructs git worktree commands with various user-provided inputs like paths and branch names and executes them with `execAsync`, making it vulnerable to command injection.

WAF Protection Rules

WAF Rule

### Summ*ry * *omm*n* inj**tion vuln*r**ility *xists in t** `*it-m*p-s*rv*r` M*P S*rv*r. T** vuln*r**ility is **us** *y t** uns*nitiz** us* o* input p*r*m*t*rs wit*in * **ll to `**il*_pro**ss.*x**`, *n**lin* *n *tt**k*r to inj**t *r*itr*ry syst*m *o

Reasoning

T** *or* o* t** vuln*r**ility li*s in t** wi**spr*** us* o* `**il*_pro**ss.*x**` t*rou**out t** `*it-m*p-s*rv*r` *o****s*. T** *ppli**tion *onstru*ts *it *omm*n*s *s simpl* strin*s, *on**t*n*tin* us*r-provi*** input *ir**tly into t**s* strin*s. T*is