From 93b12c7ac753fb751a1dc4612dcb15df8d073742 Mon Sep 17 00:00:00 2001 From: YAMIN Al-Shahwan Date: Sat, 31 Oct 2026 22:57:03 +0300 Subject: [PATCH] fix(mcp-server): use execFileAsync for Python venv/pip setup in runPoc poc.ts's .py code path built eight shell commands for venv creation and pip installation via template-literal interpolation into execAsync() (shell-backed child_process.exec), using values derived from the caller-supplied filePath/pocDir. The existing containment check only validates that the resolved path is inside POC_DIR; it never validates which characters the path may contain, so a filePath whose directory segment includes a quote followed by a shell separator breaks out of the surrounding quoting at each of these call sites. This mirrors the exact pattern already fixed in 60d826a for the main PoC execution call (execAsync -> execFileAsync), but these eight sites were added afterward by f8c3d6a/7bb0a63 and never revisited. Switch all eight call sites to execFileAsync with array-form arguments, matching the existing main execution call. No shell is invoked, so no quoting/escaping concern exists regardless of path content. Verified against the real compiled function: the same crafted filePath that previously created a marker file via shell injection now fails safely, with the malicious string passed through as a single inert argument (python -m venv even refuses it for containing a PATH separator, demonstrating no shell interpretation occurs). --- mcp-server/src/poc.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mcp-server/src/poc.ts b/mcp-server/src/poc.ts index 2f4198d..8e13c42 100644 --- a/mcp-server/src/poc.ts +++ b/mcp-server/src/poc.ts @@ -69,9 +69,9 @@ export async function runPoc( await dependencies.fs.access(pythonBin); } catch { try { - await dependencies.execAsync(`python3 -m venv "${venvDir}"`); + await dependencies.execFileAsync('python3', ['-m', 'venv', venvDir]); } catch { - await dependencies.execAsync(`python -m venv "${venvDir}"`); + await dependencies.execFileAsync('python', ['-m', 'venv', venvDir]); } } @@ -86,19 +86,19 @@ export async function runPoc( const hasProjectRequirements = await checkExists(dependencies.path.join(projectRoot, 'requirements.txt')); if (hasProjectPyproject) { - await dependencies.execAsync(`"${pythonBin}" -m pip install -e "${projectRoot}"`).catch(() => { }); + await dependencies.execFileAsync(pythonBin, ['-m', 'pip', 'install', '-e', projectRoot]).catch(() => { }); } else if (hasProjectRequirements) { - await dependencies.execAsync(`"${pythonBin}" -m pip install -r "${dependencies.path.join(projectRoot, 'requirements.txt')}"`).catch(() => { }); + await dependencies.execFileAsync(pythonBin, ['-m', 'pip', 'install', '-r', dependencies.path.join(projectRoot, 'requirements.txt')]).catch(() => { }); } const hasPocPyproject = await checkExists(dependencies.path.join(pocDir, 'pyproject.toml')); const hasPocRequirements = await checkExists(dependencies.path.join(pocDir, 'requirements.txt')); if (hasPocPyproject) { - await dependencies.execAsync(`"${pythonBin}" -m pip install .`, { cwd: pocDir }).catch(() => { }); + await dependencies.execFileAsync(pythonBin, ['-m', 'pip', 'install', '.'], { cwd: pocDir }).catch(() => { }); } if (hasPocRequirements) { - await dependencies.execAsync(`"${pythonBin}" -m pip install -r requirements.txt`, { cwd: pocDir }).catch(() => { }); + await dependencies.execFileAsync(pythonBin, ['-m', 'pip', 'install', '-r', 'requirements.txt'], { cwd: pocDir }).catch(() => { }); } } else if (ext === '.go') { runCmd = 'go'; @@ -153,9 +153,9 @@ export async function runPoc( const venvDir = dependencies.path.join(pocDir, '.venv'); // Update the venv to include system site packages try { - await dependencies.execAsync(`python3 -m venv --system-site-packages "${venvDir}"`); + await dependencies.execFileAsync('python3', ['-m', 'venv', '--system-site-packages', venvDir]); } catch { - await dependencies.execAsync(`python -m venv --system-site-packages "${venvDir}"`); + await dependencies.execFileAsync('python', ['-m', 'venv', '--system-site-packages', venvDir]); } output = (await dependencies.execFileAsync(runCmd, runArgs, execOptions)) as unknown as { stdout: string; stderr: string };