← Security advisories

Claude MCP skill code injection — skill container orchestration and cluster management endpoints — SA-SKL-INJECTION42

SA-SKL-INJECTION42 documents four shell injection vulnerabilities in MCP skill registry container orchestration and cluster management endpoints. Container orchestration surfaces are particularly high-value injection targets because the shell commands they execute — kubectl, helm, docker-compose — run with cluster-level credentials and in environments that hold Kubernetes service account tokens, Helm KubeTokens, container registry push keys, and cloud provider IAM credentials. Shell metacharacter injection via namespace, release name, resource name, and service name parameters achieves command execution at the privilege level of the orchestration service, with exfiltration impact spanning cluster access, registry publish capability, and all environment secrets of the container process.

SA-SKL-INJECTION42 findings at a glance
CRITICALINJECTION42-001 — exec(`kubectl apply -f ${manifestPath} --namespace ${namespace}`); attacker namespace ; cat /var/run/secrets/kubernetes.io/serviceaccount/token exfiltrates Kubernetes service account token; fix: execFile() array; validate namespace against /^[a-z0-9][a-z0-9\-]{0,62}$/; realpathSync containment for manifestPath
CRITICALINJECTION42-002 — exec(`helm install ${releaseName} ${chartPath} --namespace ${namespace}`); attacker releaseName ; env > /tmp/out.txt exfiltrates all env vars including HELM_KUBETOKEN; fix: execFile() array; validate releaseName against /^[a-z0-9][a-z0-9\-]{0,52}$/; validate namespace; realpathSync containment for chartPath
CRITICALINJECTION42-003 — exec(`kubectl delete ${resourceType} ${resourceName} --namespace ${namespace}`); attacker resourceName with space-injected --all deletes all resources of that type in the namespace; fix: execFile() array; validate resourceType against allowlist; validate resourceName against /^[a-z0-9][a-z0-9\-\.]{0,252}$/; validate namespace
CRITICALINJECTION42-004 — exec(`docker-compose -f ${composePath} up -d --scale ${service}=${count}`); attacker service ; printenv exfiltrates all env vars including COMPOSE_HTTP_TIMEOUT and registry credentials; fix: execFile() array; realpathSync containment for composePath; validate service against /^[a-zA-Z0-9_\-]{1,64}$/; validate count against /^[0-9]{1,4}$/

INJECTION42-001 — kubectl apply namespace injection exfiltrates Kubernetes service account token

Severity: CRITICAL

The cluster management endpoint constructs a kubectl apply command using Node.js child_process.exec() with the user-supplied namespace parameter interpolated directly into the command string. The exec() function passes the entire string to /bin/sh -c, which interprets shell metacharacters. An attacker submits a namespace value containing ; cat /var/run/secrets/kubernetes.io/serviceaccount/token. The shell executes the original kubectl apply command followed by the cat command, and the service account token — a base64-encoded JWT granting cluster API access with the registry's service account permissions — is included in the command output returned to the caller.

The Kubernetes service account token is a long-lived credential that grants cluster API access beyond the registry's intended scope. Depending on the RBAC bindings of the registry's service account, the attacker may be able to list pods across namespaces, read secrets, or escalate to cluster-admin. The fix replaces exec() with execFile() using an argument array — which never invokes a shell — validates the namespace against the Kubernetes namespace naming regex, and applies realpathSync containment to the manifest path to prevent directory traversal.

Vulnerable
// POST /api/clusters/:clusterId/apply
router.post('/:clusterId/apply', requireSession, async (req, res) => {
  const { manifestPath, namespace } = req.body;
  const { stdout } = await execAsync(
    `kubectl apply -f ${manifestPath} --namespace ${namespace}`
    // namespace='; cat /var/run/secrets/kubernetes.io/serviceaccount/token'
  );
  return res.json({ output: stdout });
});
Fixed
// POST /api/clusters/:clusterId/apply
const NAMESPACE_RE = /^[a-z0-9][a-z0-9\-]{0,62}$/;
const MANIFEST_BASE = '/app/cluster-manifests';

router.post('/:clusterId/apply', requireSession, async (req, res) => {
  const { manifestPath, namespace } = ClusterApplySchema.parse(req.body);
  if (!NAMESPACE_RE.test(namespace)) {
    return res.status(400).json({ error: 'Invalid namespace' });
  }
  const safeManifest = realpathSync(path.join(MANIFEST_BASE, manifestPath));
  if (!safeManifest.startsWith(MANIFEST_BASE + '/')) {
    return res.status(400).json({ error: 'Invalid manifest path' });
  }
  const { stdout } = await execFileAsync('kubectl', [
    'apply', '-f', safeManifest, '--namespace', namespace
  ]); // no shell, no metacharacter expansion
  return res.json({ output: stdout });
});

INJECTION42-002 — helm install release name injection exfiltrates HELM_KUBETOKEN

Severity: CRITICAL

The chart deployment endpoint constructs a helm install command with exec() using user-supplied releaseName, chartPath, and namespace. An attacker submits a release name containing ; env > /tmp/out.txt. The shell executes the Helm install command (which may fail or succeed) followed by writing all environment variables to a world-readable file. The environment contains HELM_KUBETOKEN — the bearer token used by Helm to authenticate against the Kubernetes API — as well as cloud provider credentials, container registry passwords, and any other secrets mounted into the deployment service's environment.

The /tmp/out.txt file created by the injection is accessible to any process running in the same container, including subsequent requests that read file paths. Even without direct stdout exfiltration, the written file represents a persistent secret dump that can be read via a path traversal in an adjacent endpoint. The fix uses execFile() with an argument array, validates releaseName against the Helm release naming convention (lowercase alphanumeric and hyphens, max 53 characters), validates namespace independently, and constrains chartPath to a designated chart directory via realpathSync.

exec() with any user-supplied parameter is a shell injection by default. Node.js child_process.exec() always invokes /bin/sh -c with the full command string. Use execFile() with an argument array for every system command that accepts user input. The argument array form never spawns a shell and cannot interpret metacharacters, regardless of what the input contains.

INJECTION42-003 — kubectl delete resource name injection deletes all resources via --all flag

Severity: CRITICAL

The resource deletion endpoint constructs kubectl delete ${resourceType} ${resourceName} --namespace ${namespace} with exec(). This variant demonstrates a space-injection attack that does not require shell metacharacters: the attacker submits a resource name of my-service --all. When the shell splits the command string, --all becomes a valid kubectl flag that instructs the command to delete all resources of the specified type in the namespace — not just the named resource. An attacker targeting the registry's production namespace can delete all Deployments, Services, or ConfigMaps with a single request.

Space-injection attacks bypass sanitizers that block ;, |, `, $, and other metacharacters, because the injected payload consists only of valid flag syntax parsed by the target binary. The fix uses execFile() with an argument array, which passes each argument as a separate element and never allows an argument to be interpreted as a flag by another argument. Additional validation of resourceName against the Kubernetes resource naming regex prevents both space injection and other character-class attacks.

Vulnerable
// DELETE /api/clusters/:clusterId/resources
router.delete('/:clusterId/resources', requireSession, async (req, res) => {
  const { resourceType, resourceName, namespace } = req.body;
  const { stdout } = await execAsync(
    `kubectl delete ${resourceType} ${resourceName} --namespace ${namespace}`
    // resourceName='my-service --all' deletes ALL resources of that type
  );
  return res.json({ output: stdout });
});
Fixed
// DELETE /api/clusters/:clusterId/resources
const RESOURCE_TYPES = new Set(['deployment', 'service', 'configmap', 'pod', 'secret']);
const RESOURCE_NAME_RE = /^[a-z0-9][a-z0-9\-\.]{0,252}$/;

router.delete('/:clusterId/resources', requireSession, async (req, res) => {
  const { resourceType, resourceName, namespace } = ResourceDeleteSchema.parse(req.body);
  if (!RESOURCE_TYPES.has(resourceType)) {
    return res.status(400).json({ error: 'Invalid resource type' });
  }
  if (!RESOURCE_NAME_RE.test(resourceName)) {
    return res.status(400).json({ error: 'Invalid resource name' });
  }
  if (!NAMESPACE_RE.test(namespace)) {
    return res.status(400).json({ error: 'Invalid namespace' });
  }
  const { stdout } = await execFileAsync('kubectl', [
    'delete', resourceType, resourceName, '--namespace', namespace
  ]); // each argument is isolated — --all cannot be injected via resourceName
  return res.json({ output: stdout });
});

INJECTION42-004 — docker-compose service name injection exfiltrates all container environment secrets

Severity: CRITICAL

The container scaling endpoint constructs docker-compose -f ${composePath} up -d --scale ${service}=${count} with exec(). An attacker submits a service name containing ; printenv. The shell executes the docker-compose command (which scales the specified service) followed by printing all environment variables. The environment includes COMPOSE_HTTP_TIMEOUT, Docker registry authentication tokens (DOCKER_AUTH_CONFIG or equivalent), cloud provider credentials mounted into the container orchestration service, and any other secrets in the environment at the time the endpoint is invoked.

The fix uses execFile() with an argument array and the --scale flag constructed from validated component parts, applies realpathSync containment to restrict the compose file path to the designated compose directory, validates the service name against an alphanumeric-and-hyphen regex, and validates the count against a numeric-only regex to prevent both injection and resource exhaustion via extreme scale values.

Vulnerable
// POST /api/clusters/:clusterId/scale
router.post('/:clusterId/scale', requireSession, async (req, res) => {
  const { composePath, service, count } = req.body;
  const { stdout } = await execAsync(
    `docker-compose -f ${composePath} up -d --scale ${service}=${count}`
    // service='; printenv' exfiltrates all env vars
  );
  return res.json({ output: stdout });
});
Fixed
// POST /api/clusters/:clusterId/scale
const SERVICE_NAME_RE = /^[a-zA-Z0-9_\-]{1,64}$/;
const COUNT_RE = /^[0-9]{1,4}$/;
const COMPOSE_BASE = '/app/compose-files';

router.post('/:clusterId/scale', requireSession, async (req, res) => {
  const { composePath, service, count } = ScaleSchema.parse(req.body);
  if (!SERVICE_NAME_RE.test(service)) {
    return res.status(400).json({ error: 'Invalid service name' });
  }
  if (!COUNT_RE.test(String(count))) {
    return res.status(400).json({ error: 'Invalid count' });
  }
  const safeCompose = realpathSync(path.join(COMPOSE_BASE, composePath));
  if (!safeCompose.startsWith(COMPOSE_BASE + '/')) {
    return res.status(400).json({ error: 'Invalid compose path' });
  }
  const { stdout } = await execFileAsync('docker-compose', [
    '-f', safeCompose, 'up', '-d', '--scale', `${service}=${count}`
  ]);
  return res.json({ output: stdout });
});

Remediation summary

FindingSeverityPrimary remediationSecondary hardening
INJECTION42-001CriticalReplace exec() with execFile() array; validate namespace against /^[a-z0-9][a-z0-9\-]{0,62}$/; realpathSync for manifestPathMount service account token as projected volume with short TTL; least-privilege RBAC
INJECTION42-002CriticalReplace exec() with execFile() array; validate releaseName and namespace; realpathSync for chartPathHELM_KUBETOKEN rotation; least-privilege Kubernetes RBAC for Helm service account
INJECTION42-003CriticalReplace exec() with execFile() array; validate resourceType against allowlist; validate resourceName regexNamespace-scoped RBAC preventing deletion of cluster-critical resources
INJECTION42-004CriticalReplace exec() with execFile() array; validate service and count regex; realpathSync for composePathDocker credential store isolation; count ceiling to prevent resource exhaustion

Find code injection vulnerabilities like these before attackers do. SkillAudit scans your MCP skill registry container orchestration endpoints for all four SA-SKL-INJECTION42 patterns plus the broader injection advisory series. See the SA-SKL-INJECTION41 documentation generation advisory and the SA-SKL-INJECTION40 version pinning advisory for related findings. Connect your repository at skillaudit.dev.