Skip to content

fix(mcp-server): use execFileAsync for Python venv/pip setup in runPoc - #178

Open
Cwvv7 wants to merge 1 commit into
gemini-cli-extensions:mainfrom
Cwvv7:fix/poc-python-venv-command-injection
Open

Cwvv7 wants to merge 1 commit into
gemini-cli-extensions:mainfrom
Cwvv7:fix/poc-python-venv-command-injection

Conversation

@Cwvv7

@Cwvv7 Cwvv7 commented Oct 31, 2026

Copy link
Copy Markdown

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).

Testing

  • tsc build: clean, no errors.
  • npx vitest run src/poc.test.ts: updated the Python test's assertions to match the new execFileAsync call shape (it previously asserted the old, vulnerable execAsync string-command call), and added a new regression test asserting a filePath containing shell metacharacters reaches execFileAsync as a single literal array argument rather than being interpolated into a shell command string.
  • Note for reviewers: on this Windows development machine, 4 pre-existing tests in poc.test.ts (unrelated to the .py branch) fail due to what looks like a path-separator mismatch between the test's hand-rolled mockPath helper (POSIX-style, forward-slash) and the real path module's output for POC_DIR on Windows (backslash-separated). I confirmed via git stash that these exact same 4 tests fail identically before this change, so they are a pre-existing, Windows-specific test-environment issue, not a regression introduced here. I'd expect them to pass on the project's actual Linux CI.
  • Manually verified against the real compiled dist/poc.js (built, unmodified, from this fix): the exact crafted filePath that previously created a marker file via shell injection now fails safely with no injection, and python -m venv itself rejects the malicious string outright for containing a PATH separator -- direct confirmation that no shell interpretation of the path occurs anymore.

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).
@google-cla

google-cla Bot commented Oct 31, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant