Summary
cli-mcp-server contains a command allowlist bypass when shell operators are enabled. Shell command substitution can cause non-allowlisted commands to be executed despite ALLOWED_COMMANDS validation, creating a high-severity command injection risk when attacker-controlled command input reaches the validator.
Affected context
The vulnerability occurs in deployments that enable ALLOW_SHELL_OPERATORS and use the command validation logic in cli-mcp-server 0.2.5. It becomes risky when an attacker can influence a command or command fragment that is processed by _validate_command_with_operators, particularly where validation checks the visible command structure without fully accounting for shell evaluation behavior.
Exploit preconditions
- Attack surface: Command-processing functionality exposed through the MCP server
- Required access: Ability to submit or influence command input accepted by the server
- Trigger point: Validation performed by _validate_command_with_operators when shell operators are enabled
- Why exploitation is possible: Shell substitution syntax may be evaluated by the command interpreter while bypassing the allowlist's command-name validation
Why this happens
The underlying bug is a mismatch between command allowlist validation and shell parsing semantics. The validator permits shell operators but does not comprehensively account for command-substitution constructs that can introduce additional executable commands. This maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, where attacker-controlled input reaches a shell execution path without enforcing an equivalent restricted execution model.
Potential impact
- Attackers may execute commands that are absent from the approved command list
- The service process or its host environment could be compromised
- Sensitive files, credentials, or environment variables may be exposed
- Attackers could alter data, disrupt operations, or establish persistence
- Downstream systems may be affected when the service has elevated permissions
General mitigation guidance
Mitigation generally focuses on avoiding shell interpretation and ensuring that authorization decisions match the actual execution behavior.
Common defensive patterns include:
- Prefer direct process execution with fixed argument arrays over shell-based execution
- Disable shell operators unless they are strictly required
- Apply command and argument allowlists after parsing into the exact execution model
- Treat all externally supplied command content as untrusted
- Use narrowly scoped service accounts and least-privilege operating-system permissions
- Isolate command-running components and restrict filesystem, network, and credential access
- Reject ambiguous or unsupported shell constructs rather than attempting partial validation
How teams detect issues like this
Organizations can identify similar risks through:
- Static analysis rules for shell execution APIs and dynamic command construction
- Code review checks for allowlists that validate command names without validating arguments and shell syntax
- Tests covering command substitution, nested operators, quoting, and parser-versus-shell behavior
- Runtime monitoring for unexpected child processes spawned by the MCP service
- Policy enforcement that prevents shell execution for services handling untrusted input
- Automated security review tools that flag command construction and incomplete neutralization controls

