Claude MCP skill code injection — skill container image build and push endpoints — SA-SKL-INJECTION38
SA-SKL-INJECTION38 documents four critical shell injection vulnerabilities in MCP skill registry container image build and push endpoints. These endpoints invoke container build tools — docker, buildah, and kaniko — by constructing shell command strings with unsanitized user-supplied arguments including image names, registry hosts, output tags, Dockerfiles, context paths, and push destinations. INJECTION38-001 injects a shell command through the imageName argument of a docker build invocation, exfiltrating Docker Hub push credentials. INJECTION38-002 injects through the registryHost parameter of a docker push invocation, dumping the entire process environment including OCI registry authentication tokens. INJECTION38-003 injects a space-separated build flag through outputTag in a buildah invocation, escaping container network isolation with --runtime-flag=net=host. INJECTION38-004 injects through the destination argument of a kaniko invocation, exfiltrating the full set of cloud provider credentials and Kaniko push tokens available in the build environment.
exec(`docker build -t ${imageName} --build-arg VERSION=${version} ${contextPath}`); attacker imageName with ; cat /run/secrets/DOCKER_HUB_TOKEN exfiltrates Docker Hub push credentialsexec(`docker push ${registryHost}/${imageName}:${tag}`); attacker registryHost with ; env > /tmp/out.txt exfiltrates all env vars including OCI registry tokens; fix: execFile() array; validate registryHost against allowlist; validate tag against /^[a-zA-Z0-9_.\-]{1,128}$/exec(`buildah bud --layers --tag ${outputTag} ${dockerfile}`); attacker outputTag with space-injected --runtime-flag=net=host escapes container network isolation; fix: execFile() array; validate outputTag; dockerfile realpathSync containmentexec(`kaniko --dockerfile ${dockerfile} --destination ${destination} --context ${context}`); attacker destination with ; printenv exfiltrates Kaniko credentials and cloud provider tokens; fix: execFile() array; validate destination against allowlist; dockerfile and context realpathSync containmentINJECTION38-001 — docker build shell injection via imageName exfiltrates Docker Hub push credentials
The container image build endpoint constructs a docker build command string using Node.js child_process.exec() with user-supplied template literal interpolation: exec(`docker build -t ${imageName} --build-arg VERSION=${version} ${contextPath}`). The exec() function passes the entire string to /bin/sh -c, which interprets shell metacharacters including semicolons, pipes, backticks, and command substitution syntax. An attacker who controls imageName can supply a value like myimage; cat /run/secrets/DOCKER_HUB_TOKEN, causing the shell to execute the Docker build command and then separately execute cat /run/secrets/DOCKER_HUB_TOKEN.
Container image build workers are among the most privileged components in a CI/CD pipeline. They typically run with Docker socket access, cloud registry push credentials, secrets mounted via Docker secrets or Kubernetes secrets, and sometimes cloud provider instance credentials to push to ECR, GCR, or ACR. The Docker Hub token available at /run/secrets/DOCKER_HUB_TOKEN allows an attacker to push arbitrary images to the registry's Docker Hub namespace, overwriting existing skill images with malicious content that will be pulled by all users who install the affected skills. The version and contextPath parameters are also injectable via the same mechanism if not separately validated.
Context path injection deserves particular attention: supplying a contextPath outside the designated build workspace — for example, ../../etc after bypassing basic path validation with URL encoding — allows the attacker to send arbitrary host filesystem directories as the Docker build context, leaking their contents through the build log output or through deliberate COPY instructions in a crafted Dockerfile.
INJECTION38-001 fix: Replace exec() with execFile('docker', ['build', '-t', imageName, '--build-arg', `VERSION=${version}`, contextPath]) — execFile passes arguments as an array to the OS, bypassing the shell entirely and making metacharacter injection impossible. Validate imageName against /^[a-z0-9.\-\/]{1,200}$/ before use. Run realpathSync(contextPath) and assert the result is within the designated workspace directory. Invoke the build process with a minimal environment object that excludes cloud provider credentials, container registry tokens, and secrets not needed for the build itself.
const { exec } = require('child_process');
async function buildImage(imageName, version, contextPath) {
// Shell metacharacters in imageName execute arbitrary commands
return new Promise((resolve, reject) => {
exec(
`docker build -t ${imageName} --build-arg VERSION=${version} ${contextPath}`,
(err, stdout, stderr) => err ? reject(err) : resolve(stdout)
);
});
}
const { execFile } = require('child_process');
const path = require('path');
const IMAGE_NAME_RE = /^[a-z0-9.\-\/]{1,200}$/;
const WORKSPACE = '/var/build/workspace';
async function buildImage(imageName, version, contextPath) {
if (!IMAGE_NAME_RE.test(imageName)) throw new Error('Invalid imageName');
const resolvedCtx = path.realpathSync(contextPath);
if (!resolvedCtx.startsWith(WORKSPACE + '/')) throw new Error('Path traversal');
return new Promise((resolve, reject) => {
execFile(
'docker',
['build', '-t', imageName, '--build-arg', `VERSION=${version}`, resolvedCtx],
{ env: minimalBuildEnv() }, // no registry tokens or cloud creds
(err, stdout, stderr) => err ? reject(err) : resolve(stdout)
);
});
}
INJECTION38-002 — docker push shell injection via registryHost dumps full process environment including OCI tokens
The container image push endpoint constructs a docker push command using exec(`docker push ${registryHost}/${imageName}:${tag}`). The registryHost parameter is intended to specify the target OCI registry hostname — values like registry.example.com or us-east1-docker.pkg.dev. Because the command is executed via the shell, an attacker who controls registryHost can inject ; env > /tmp/leak.txt, causing the shell to execute the push command against a malformed address (which fails harmlessly) and then write the entire process environment to a temporary file. The process environment of the image push worker contains OCI registry authentication credentials for every registry the service is configured to push to: Docker Hub tokens, ECR authentication tokens, GCR service account key JSON paths, and ACR client secret environment variables.
The tag parameter presents a subtler injection vector: tags that contain spaces followed by -- separated Docker CLI flags can inject additional push options, including --insecure to bypass TLS verification or --platform flags that alter push behavior. Validating only that the tag does not contain semicolons is insufficient — the full tag character set must be allowlisted to prevent argument injection attacks that do not require shell metacharacters.
INJECTION38-002 fix: Replace exec() with execFile('docker', ['push', `${registryHost}/${imageName}:${tag}`]). Validate registryHost against an allowlist of approved registry endpoints — do not attempt to construct an allowlist from hostname patterns, as subdomain and path manipulation can bypass regex-based checks. Validate tag against /^[a-zA-Z0-9_.\-]{1,128}$/. Validate imageName using the same pattern as INJECTION38-001. Pass a minimal environment to execFile that includes only the specific OCI credential helper configuration needed for the target registry, not all registry credentials simultaneously.
INJECTION38-003 — buildah bud shell injection via outputTag injects --runtime-flag to escape container network isolation
The buildah-based image build endpoint constructs exec(`buildah bud --layers --tag ${outputTag} ${dockerfile}`). The outputTag injection vector is distinct from the semicolon injection patterns in INJECTION38-001 and INJECTION38-002: rather than terminating the command and starting a new one, an attacker injects additional buildah CLI flags by supplying an outputTag value that contains a space followed by a flag. For example, myimage --runtime-flag=net=host expands to buildah bud --layers --tag myimage --runtime-flag=net=host /path/to/dockerfile, passing the --runtime-flag=net=host option to buildah, which forwards it to the container runtime. This instructs the runtime to run the build container with host network access rather than isolated network namespaces.
Escaping container network isolation during a build allows the attacker's Dockerfile instructions to access the host network directly — reaching the Docker daemon socket via TCP, connecting to internal services on localhost relative to the host, or accessing cloud provider metadata endpoints that are only accessible from the host's network namespace. Build workers in Kubernetes environments may have additional internal services reachable only from the host network, including the Kubernetes API server, etcd, and node-local DNS resolvers. The network isolation bypass also enables the attacker to exfiltrate build artifacts and secrets through arbitrary outbound connections, including connections to attacker-controlled external hosts.
INJECTION38-003 fix: Replace exec() with execFile('buildah', ['bud', '--layers', '--tag', outputTag, dockerfilePath]). Validate outputTag against /^[a-z0-9.\-\/]{1,200}$/ — this rejects spaces, so space-based flag injection is impossible regardless of shell interpretation. Run realpathSync(dockerfile) and assert containment within the workspace directory. Never pass user-supplied strings as a single concatenated argument to execFile — always use separate array elements for each argument.
INJECTION38-004 — kaniko shell injection via destination exfiltrates Kaniko credentials and cloud provider tokens
The kaniko-based build endpoint constructs exec(`kaniko --dockerfile ${dockerfile} --destination ${destination} --context ${context}`). Kaniko is typically used in environments where Docker socket access is unavailable — Kubernetes pods, CI runners, and sandboxed build environments — and runs with cloud provider credentials to push directly to managed container registries. The build worker's environment contains the full set of credentials needed to push to whatever registries the service is configured for: Google Application Default Credentials JSON, AWS credential files, Azure service principal environment variables, and sometimes Kaniko's own push token.
An attacker who controls destination can inject ; printenv > /workspace/env.txt, causing the shell to execute the kaniko command against an invalid destination (which fails) and then write the full environment to a file within the kaniko workspace directory. The kaniko workspace is typically mounted as a persistent volume or cloud storage bucket from which the build output is retrieved — meaning the exfiltrated environment file is accessible via the build artifact retrieval endpoint. The dockerfile and context parameters present path traversal vectors if not validated with realpathSync containment, allowing an attacker to point kaniko at arbitrary filesystem paths as the build context.
INJECTION38-004 fix: Replace exec() with execFile('/kaniko/executor', ['--dockerfile', dockerfilePath, '--destination', destination, '--context', contextPath]). Validate destination against an allowlist of approved registry endpoints — the destination specifies where the final image is pushed, so it must be a known approved registry. Run realpathSync on both dockerfile and context and assert workspace containment. Pass a minimal environment that includes only the cloud credential helper configuration for the specific target registry, not all credentials simultaneously.
SkillAudit scans your registry's container image build and push endpoints for all four INJECTION38 patterns, plus the other code injection families documented in the SA-SKL-INJECTION series. Get started free — 3 audits/month on public repos, results in 60 seconds.