Summary
A command injection vulnerability in mcp-shell allows a caller of the shell_exec MCP tool to bypass the intended executable allowlist by invoking Bash in command mode.
When the server accepts a command containing /bin/bash -c, an attacker may execute arbitrary operating-system commands with the privileges of the mcpuser account.
Affected context
The vulnerability occurs in mcp-shell deployments that use the affected command validation logic and a security configuration allowing /bin/bash. The validation checks only the first command token and does not reject Bash's command-mode flag, allowing a shell interpreter to process additional command text after the allowlisted executable is accepted.
Exploit preconditions
- Attack surface: The
shell_execMCP tool - Required access: Ability to invoke the MCP tool, subject to the deployment's authentication and authorization controls
- Trigger point: Command validation and execution of a request containing
/bin/bashwith the-coption - Why exploitation is possible: Validation evaluates only the first token and does not block shell command-mode arguments, so attacker-controlled text reaches the shell interpreter outside the intended executable allowlist
Why this happens
The underlying flaw is an incomplete command-validation boundary. The server treats the first token as sufficient evidence that a command is allowed, while permitting an allowlisted shell interpreter to receive arguments that change its behavior.
This maps primarily to CWE-78: Improper Neutralization of Special Elements used in an OS Command, because attacker-controlled input can influence operating-system command execution. It is also related to CWE-183: Permissive List of Allowed Inputs and CWE-1188: Initialization of a Resource with an Insecure Default, because the default policy permits a shell executable without accounting for its command-interpreter modes.
Potential impact
- An attacker may execute arbitrary commands as the
mcpuseraccount. - The application or container runtime could be compromised.
- Sensitive files, credentials, or environment data may be exposed.
- An attacker could modify application data or disrupt service operation.
- Additional compromise could occur if the process has excessive filesystem, network, or host permissions.
General mitigation guidance
Mitigation generally focuses on removing shell interpretation from command execution and making execution policies deny-by-default.
Common defensive patterns include:
- Avoiding shell interpreters for structured command execution whenever possible.
- Treating the complete executable and argument vector as policy input rather than validating only the first token.
- Rejecting shell command-mode flags and other interpreter options unless they are explicitly required and safely constrained.
- Using narrowly scoped executable and argument allowlists with secure defaults.
- Reducing input trust through typed command parameters and strict validation.
- Running the service with least-privilege filesystem, network, and process permissions.
- Preventing access to sensitive host resources and limiting container capabilities.
- Applying authorization and auditing controls to every command-execution request.
How teams detect issues like this
Detection approaches can include:
- Static analysis rules for shell execution APIs, command interpreters, and execution of user-controlled strings.
- Code review checks for validation that inspects only the first token of a command.
- Searches for allowlists containing shells such as Bash together with interpreter flags such as
-c. - Policy checks that require argument-aware command validation and deny-by-default executable configuration.
- Runtime monitoring for unexpected shell processes, command-line arguments, child processes, and access to sensitive paths.
- Automated security review tools that identify command construction and incomplete input-neutralization patterns.

