The vulnerability exists in the mcp-kubernetes-server because of improper input validation in the functions that handle kubectl and helm commands. The core of the issue lies in the kubectl and helm wrapper functions within src/mcp_kubernetes_server/main.py. These functions are designed to restrict certain subcommands when the server is started with --disable-write or --disable-delete flags.
The security mechanism in place splits the incoming command string by whitespace and only checks the very first word (or the first two, in the case of some helm commands) against a blocklist of disallowed operations. This creates a classic command injection vulnerability. An attacker can bypass the filter by providing a command that starts with a harmless, allowed operation, followed by a semicolon (;) or other shell command separator, and then the malicious command. For example, a command like kubectl version; kubectl delete pod critical-pod will pass the validation because the check only sees version, which is a read-only operation. The entire string is then passed to a shell for execution, leading to the deletion of the pod, bypassing the intended security control.
The same flaw exists in the helm command wrapper. Both functions fail to properly sanitize or validate the entire command string before execution, making them vulnerable to command chaining and injection.