GHSA-gjv4-ghm7-q58q MCP Server Kubernetes vulnerable to command injection in several tools
SummaryA command injection vulnerability exists in the `mcp-server-kubernetes` MCP Server. The vulnerability is caused by the unsanitized use of input parameters within a call to `child_process.execSync`, enabling an attacker to inject arbitrary system commands. Successful exploitation can lead to remote code execution under the server process's privileges.The server constructs and executes shell commands using unvalidated user input directly within command-line strings. This introduces the possibility of shell metacharacter injection (`|`, `>`, `&&`, etc.).DetailsThe MCP Server exposes tools (`kubectl_scale`, `kubectl_patch` , `explain_resource`, etc) to perform several kubernetes operations.  An MCP Client can be instructed to execute additional actions for example via prompt injection when asked to read pod logs. Below some example of vulnerable code and different ways to test this vulnerability including a real example of indirect prompt injection that can lead to arbitrary command injection.Vulnerable codeThe following snippet illustrates the vulnerable code pattern used in the MCP Server’s tooling. **Note**: These is only one instance, but similar patterns may exist elsewhere in the codebase.`kubectl_scale` toolPoCIndirect prompt injection via pod logsAn MCP Client can be instructed to execute additional actions for example via indirect prompt injection in pod logs. The following PoC shows how reading pod logs can lead to execution of additional tools vulnerable to command injection.When the client reads pod logs as part of its contextual input, it may inadvertently interpret injected instructions embedded in log messages as legitimate commands or follow-up instructions.This behavior can be exploited to cause the model to execute unintended actions, leading to an arbitrary command execution on the host where the MCP server is running.start `minikube`create a pod that contains instructions in logs`poc-pod.yaml`apply the podobserve the logscheck il the file `/tmp/TEST1` existsUse an MCP Client IDEAdd and enable the `mcp-server-kubernetes`open the chat and use the following prompt (it's just an example):run the `kubectl_logs` toolObserve that the response will contain the pod logs but will also trigger the `kubectl_scale` tool execution with a malicious payload that can lead to command injection. The following tool will be called (without user request but just following the instructions in the pod log):run the `kubectl_scale` toolConfirm that the injected command executed:Using MCP InspectorOpen the MCP Inspector:In MCP Inspector:set transport type: `STDIO`set the `command` to `npx`set the arguments to `mcp-server-kubernetes`click Connectgo to the **Tools** tab and click **List Tools**select the `kubectl_scale` toolVerify the file `/tmp/TEST` does **not** exist:In the **namespace** field, input:while in field `name` input `test` and in `replicas` field input `1`Click **Run Tool**Observe the request being sent:Confirm that the injected command executed:Use an MCP Client IDEadd and enable the `mcp-server-kubernetes`check il the file `/tmp/TEST3` existsopen the chat and use the following prompt (it's just an example):run the `kubectl_scale` toolcheck that the file `/tmp/TEST3` is createdRemediationTo mitigate this vulnerability, I suggest to avoid using `child_process.execSync` with untrusted input. Instead, use a safer API such as [`child_process.execFileSync`](https://nodejs.org/api/child_process.html#child_processexecfilesyncfile-args-options), which allows you to pass arguments as a separate array — avoiding shell interpretation entirely.ImpactCommand Injection / Remote Code Execution (RCE)Referenceshttps://equixly.com/blog/2025/03/29/mcp-server-new-security-nightmare/https://invariantlabs.ai/blog/mcp-github-vulnerabilitySimilar Issueshttps://github.com/cyanheads/git-mcp-server/commit/0dbd6995ccdf76ab770b58013034365b2d06c4d9
CVSS v3.1 score: 7.5