Summary
A command injection vulnerability in mcp-shell allows a caller of the shell_exec MCP tool to execute arbitrary operating-system commands through Git command-line options.
The issue becomes risky when MCP connectivity is available and the server permits /usr/bin/git without enforcing executable-specific argument restrictions.
Affected context
The vulnerability affects mcp-shell deployments that:
- Enable the shell_exec MCP tool
- Permit /usr/bin/git through the default security configuration
- Rely on generic shell metacharacter and dangerous-construct checks
- Do not apply a per-executable policy to Git arguments
In the default containerized deployment, Git is installed and the service runs as the mcpuser account. Exploitation depends on an attacker being able to connect to the MCP server and invoke the relevant tool.
Exploit preconditions
- Attack surface: The shell_exec MCP tool exposed through MCP connectivity
- Required access: Ability to invoke the tool; separate operating-system authentication may not be required if MCP access is already authorized
- Trigger point: Processing a permitted Git command and its arguments
- Why exploitation is possible: Git options can define shell-backed aliases, while the security checks do not adequately recognize the relevant metacharacter or enforce a safe argument policy for Git
Why this happens
The root cause is an incomplete command-safety model combined with insufficient validation of arguments for an allowed executable.
The security logic omits an important shell metacharacter and treats executable allowlisting as sufficient, even though Git accepts configuration options that can cause command execution. This maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, because attacker-controlled command data reaches an execution-capable processing path without complete neutralization or contextual validation.
Potential impact
- Arbitrary commands could execute with the privileges of the mcp-shell process
- The service environment and accessible files could be compromised
- Credentials, tokens, or other sensitive data could be exposed
- The container or connected workloads could be altered
- Attackers could potentially use the service as a foothold for lateral movement
General mitigation guidance
Mitigation generally focuses on reducing shell exposure and treating every executable's arguments as untrusted input.
Common defensive patterns include:
- Prefer dedicated, non-shell APIs for approved operations
- Apply strict per-executable argument schemas and reject unsupported Git options
- Use positive allowlists for commands, subcommands, flags, and values
- Implement complete, context-aware neutralization of shell metacharacters
- Avoid relying solely on generic string filters or executable allowlists
- Run the service with the least privilege and isolate its filesystem and network access
- Keep sensitive credentials and host interfaces unavailable to the service where possible
- Require authenticated, authorized MCP access and log tool invocations
These controls reduce the impact of command-injection defects and limit the trust placed in caller-supplied command strings.
How teams detect issues like this
Detection can combine:
- Static analysis for shell execution APIs, string-based command construction, and incomplete metacharacter filters
- Code review checks for executable allowlists without argument-level policies
- Tests using special characters and tool-specific configuration options across all permitted executables
- Policy enforcement that blocks unrestricted shell tools or requires explicit command schemas
- Runtime monitoring for unusual Git options, unexpected child processes, and commands launched by the MCP service
- Audit review of MCP tool calls and process execution telemetry
Automated security scanning and code-review tools may help identify unsafe command construction, but coverage should be supplemented with executable-specific tests.

