INCIDENT MAP

Browse / MCP and Tool Server Flaws / CVE-2025-66404

mcp-server-kubernetes has potential security issue in exec_in_pod tool

CVE-2025-66404 ยท 2025-12-03 moderate

Class
MCP and Tool Server Flaws (filed by a model that read the advisory)
Technique
Code and command execution
Also involves
Indirect Prompt Injection
Affected
mcp-server-kubernetes (npm)
CVSS
CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:U/C:H/I:H/A:H
EPSS
1.5% chance of exploitation in 30 days

How it works, in short

String commands given to exec_in_pod are run through a shell without validation, so metacharacters inject extra commands into the pod. (Our summary, written by a model. The source text is below.)

Details

Summary

A security issue exists in the exec_in_pod tool of the mcp-server-kubernetes MCP Server. The tool accepts user-provided commands in both array and string formats. When a string format is provided, it is passed directly to shell interpretation (sh -c) without input validation, allowing shell metacharacters to be interpreted. This vulnerability can be exploited through direct command injection or indirect prompt injection attacks, where AI agents may execute commands without explicit user intent.

Details

The MCP Server exposes the exec_in_pod tool to execute commands inside Kubernetes pods. The tool supports both array and string command formats. The Kubernetes Exec API (via @kubernetes/client-node) accepts commands as an array of strings, which executes commands directly without shell interpretation. However, when a string format is provided, the code automatically wraps it in shell execution (sh -c), which interprets shell metacharacters without any input validation.

When string commands contain shell metacharacters (e.g., ;, &&, |, >, <, $), they are interpreted by the shell rather than being passed as literal arguments, allowing command injection. This vulnerability can be exploited in two ways:

Code pattern

The following snippet illustrates the code pattern used in the exec_in_pod tool:

File: src/tools/exec_in_pod.ts

export async function execInPod(
  k8sManager: KubernetesManager,
  input: {
    name: string;
    namespace?: string;
    command: string | string[];  // User-controlled input
    container?: string;
    shell?: string;
    timeout?: number;
    context?: string;
  }
): Promise<{ content: { type: string; text: string }[] }> {
  const namespace = input.namespace || "default";
  let commandArr: string[];
  
  if (Array.isArray(input.command)) {
    commandArr = input.command;
  } else {
    // User input passed to shell
    const shell = input.shell || "/bin/sh";
    commandArr = [shell, "-c", input.command];  // Shell metacharacters are interpreted
  }

  // ... Kubernetes Exec API call ...
  exec.exec(
    namespace,
    input.name,
    input.container ?? "",
    commandArr,  // Executed inside pod via shell
    stdoutStream,
    stderrStream,
    stdinStream,
    true,
    callback
  );
}

When input.command is a string, the code automatically wraps it in a shell command (/bin/sh -c), which interprets shell metacharacters. There is no input validation to detect or block shell metacharacters, allowing arbitrary command execution through command chaining (e.g., id>/tmp/TEST && echo done).

PoC

### Direct command injection via MCP Inspector

This demonstrates command injection through direct tool invocation:

The file /tmp/TEST was created, confirming that the injected command (id>/tmp/TEST) executed successfully, even though the intended command was only id.

Indirect prompt injection via pod logs

An MCP Client can be instructed to execute additional actions via indirect prompt injection in pod logs. When the client reads pod logs as part of its contextual input, it may interpret injected instructions embedded in log messages as legitimate commands or follow-up instructions.

Important: The KUBECONFIG environment variable must be explicitly set in the env section because mcp-server-kubernetes needs to connect to the Kubernetes API server (which requires authentication credentials stored in the kubeconfig file). The MCP server process may not inherit the user's shell environment variables. Replace /path/to/.kube/config with your actual kubeconfig path.

The file /tmp/TEST1 was created, confirming that the AI agent executed the command from the injected instructions in the pod logs, demonstrating indirect prompt injection.

Impact

Command injection allows arbitrary command execution within Kubernetes pods through shell metacharacter interpretation.

References

Source: GitHub Advisory Database, used under CC BY 4.0.