MCP05
- Location
dist/index.js:89- Finding
Command Prefix Allowlist Bypass Enables Arbitrary Shell Execution ## Remediation Suggestions 1. **Remove shell interpretation from restricted execution.** Replace the free-form command string with structured executable and argument fields. Execute using `execFile` or `spawn` with `shell: false`. 2. **Authorize exact executable identities.** Resolve approved executables to trusted paths and compare exact identities rather than string prefixes. Do not rely on whitespace trimming or command-name boundaries as shell security controls. 3. **Validate arguments per operation.** Restrict flags, subcommands, paths, and execution-related options. Git, npm, and similar build tools can themselves execute programs, so executable allowlisting alone is insufficient. 4. **Separate unrestricted execution from restricted operations.** Expose narrowly scoped operations for routine workloads. Require explicit authorization for a separate unrestricted shell capability, and use `allowExec: false` when execution is unnecessary. 5. **Isolate execution from the gateway.** Run commands under a dedicated low-privilege identity or sandbox with a minimal environment, restricted workspace access, controlled network egress, and no unnecessary access to credentials or transcripts. Validate `cwd` against approved directories. 6. **Add regression tests.** Cover appended commands, pipelines, substitutions, redirections, prefix-boundary confusion, and execution-capable arguments. Verify that restricted operations cannot launch an unapproved second command.
- Content
View full analysis
Vulnerability Details
File Location:
plugin/dist/index.js:89–96, 119–129, 132–142
Vulnerability Type: CWE-78 — Improper Restriction of Shell Commands
Risk Level: HighVulnerable Code
The allowlist validates only the beginning of the complete shell expression:
javascript const allow = Array.isArray(c.allowedCommands) ? c.allowedCommands.filter((x) => typeof x === "string" && x.trim().length > 0) : []; if (allow.length > 0 && !allow.some((prefix) => command.trim().startsWith(prefix.trim()))) { return { allowed: false, reason: "command is outside the configured allowedCommands allowlist", rule: "allowlist" }; } return { allowed: true };The model-facing tool forwards accepted commands to the execution function:
javascript execute: async ({ command, cwd, max_result_chars }, // The SDK hands plugin config through as an opaque record; validate it // inside checkCommand rather than casting it at the call site. config) => { const verdict = checkCommand(command, config); if (!verdict.allowed) { return textResult(`exec-juice refused: ${verdict.reason}`, { ok: false, refused: verdict.rule ?? "policy" }); } return compactExec(command, cwd || undefined, clampBudget(max_result_chars)); },The execution function invokes a shell with the entire accepted expression:
javascript async function compactExec(command, cwd, budget) { const t0 = Date.now(); const shell = shellForPlatform(); const options = { cwd, timeout: TIMEOUT_MS, maxBuffer: MAX_BUFFER, ...(shell ? { shell } : {}), }; try { const { stdout, stderr } = await execAsync(command, options);Technical Analysis
checkCommandtreats a matching string prefix as authorization for the entire command. However,child_process.execinterprets that command as shell syntax rather than as a single executable with isolated arguments.For example, when
allowedCommandscontains `"git ...[truncated 2891 chars]
