Summary
sf-mcp-server constructs Salesforce CLI commands using user-controlled input and passes them directly to child_process.exec, allowing shell metacharacters to be interpreted.
In environments where an attacker can influence these command arguments, this flaw can be used to execute arbitrary shell commands with the privileges of the MCP server process.
Affected context
This vulnerability affects deployments of sf-mcp-server that:
- Expose Salesforce-related command functionality via MCP to clients (e.g., Claude for Desktop)
- Build Salesforce CLI command strings from user-supplied or indirectly-controlled input
- Execute those commands through
child_process.execor equivalent shell-invoking APIs
The risk is highest when the MCP server is reachable by untrusted or semi-trusted users and runs under a privileged account or on sensitive infrastructure.
Exploit preconditions
- Attack surface: MCP server interface that accepts input used to construct Salesforce CLI commands.
- Required access: Ability to issue requests or actions through the MCP interface that influence CLI parameters (e.g., org names, flags, target paths, or arbitrary argument fields).
- Trigger point: Invocation of a Salesforce CLI command where user-controlled data is concatenated into a shell command string passed to
child_process.exec. - Why exploitation is possible: The server does not properly sanitize or safely handle shell metacharacters, allowing user-controlled data to break out of intended arguments and inject additional commands.
Why this happens
The core bug is the use of child_process.exec with command strings constructed via string concatenation or interpolation that directly include user-controlled values.
Because exec invokes a shell, special characters (such as ;, &&, |, backticks, and others) are interpreted by the shell, turning data into executable syntax.
This behavior maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, where untrusted input is not properly constrained before being incorporated into a system command.
At an abstract level, the pattern is: user input → string-built shell command → shell execution, without robust argument separation, validation, or escaping.
Potential impact
- Attackers could execute arbitrary shell commands with the privileges of the sf-mcp-server process.
- Local files or environment variables (including credentials, API keys, or tokens) could be read or exfiltrated.
- Additional software could be downloaded and executed, potentially establishing persistence or backdoors.
- Data associated with Salesforce development workflows could be modified, corrupted, or deleted.
- The host system could be used as a pivot point for further network compromise.
General mitigation guidance
Effective mitigation focuses on preventing untrusted input from being interpreted as shell syntax and reducing the impact of any command execution paths:
- Prefer non-shell APIs such as
child_process.execFileorspawnwith argument arrays, so the shell is not invoked at all. - Avoid constructing command strings via concatenation; treat all user-influenced values as data, not as part of the command line.
- Introduce strict input validation and allowlists for parameters (e.g., known command names, flags, and org identifiers), rejecting or normalizing unexpected characters.
- Separate responsibilities so that only a minimal, well-audited subset of commands is exposed through the MCP server.
- Run the MCP server with least privilege, restricting filesystem and network access to what is strictly necessary, and consider sandboxing or containerization to limit blast radius.
- Centralize command-execution utilities in a small module that enforces safe patterns, making it easier to audit and maintain.
How teams detect issues like this
Detection is best approached through both code-centric and operational perspectives:
- Static analysis: Configure rules to flag uses of
child_process.exec,execSync, or similar APIs where arguments are derived from request parameters, MCP messages, or other user inputs. - Code review: Look for any string concatenation or template literals that build shell commands, especially around Salesforce CLI invocations and user-facing features.
- Security testing: Use dynamic application security testing (DAST) or manual penetration testing to inject shell metacharacters in CLI-related parameters and observe unexpected behavior.
- Logging and monitoring: Enable detailed logging for command execution paths and alert on anomalous or multi-part shell commands, unexpected utilities being invoked, or outbound network connections from the MCP server.
- Automated code review tools and CI checks can enforce policies that prohibit unsafe shell invocation patterns and require safer alternatives.

