Skip to content

fix: avoid shell interpolation of user-supplied paths in deployment (command injection) - #329

Open
yogikortisa wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
yogikortisa:fix/deploy-path-command-injection
Open

yogikortisa wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
yogikortisa:fix/deploy-path-command-injection

Conversation

@yogikortisa

@yogikortisa yogikortisa commented Oct 14, 2026 •

Copy link
Copy Markdown

Summary

prepareSourceDirectory() (lib/deployment/source-processor.js) and runUniversalMaker() (lib/deployment/universal-maker.js) build shell commands by string-interpolating user-controlled filesystem paths and run them via child_process.exec, which executes the string through /bin/sh -c.

The folderPath argument of the deploy_local_folder tool flows unsanitized into these commands (files: [folderPath] → prepareSourceDirectory → exec(`cp -R "${file}/." "${tempDir}/"`)). A path containing shell metacharacters therefore results in OS command execution on the host running the MCP server.

Fix

  • source-processor.js: replace the cp -R shell call with fs.promises.cp(file, tempDir, { recursive: true }) — no subprocess, no shell. Removed the now-unused exec/util imports.
  • universal-maker.js: replace the interpolated exec command with execFile(binPath, [...]) — argv array, no shell.

Both changes are behavior-preserving and remove the shell entirely from these code paths, eliminating the command-injection vector.

@google-cla

google-cla Bot commented Oct 14, 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses potential OS command injection vulnerabilities by replacing shell-based command executions with safer alternatives. In lib/deployment/source-processor.js, the shell command cp -R is replaced with fsp.cp, and in lib/deployment/universal-maker.js, exec is replaced with execFile to run the binary with an arguments array. Feedback on these changes suggests adding dereference: true to the fsp.cp options to ensure symlinks are dereferenced and do not become broken in the deployed container environment.

Comment thread lib/deployment/source-processor.js Outdated
@yogikortisa

Copy link
Copy Markdown
Author

@googlebot I signed it!

…ion)

prepareSourceDirectory() and runUniversalMaker() interpolated user-controlled
filesystem paths (notably the deploy_local_folder tool's folderPath) into
shell commands executed via child_process.exec (/bin/sh -c), allowing OS
command injection via paths containing shell metacharacters.

Replace with fs.promises.cp (no subprocess) and execFile (argv, no shell).
Behavior-preserving; removes the shell from these code paths.
@yogikortisa
yogikortisa force-pushed the fix/deploy-path-command-injection branch from bbf19de to efd1fd1 Compare October 15, 2026 02:08
Address review feedback: fsp.cp defaults to dereference:false, copying symlinks as-is; their targets would be absent in the deployed Cloud Run container. Set dereference:true so the real files are packaged.
@shruti-mantri shruti-mantri added the kokoro:force-run This will force trigger a run for presubmit tests label Oct 19, 2026
@kokoro-team kokoro-team removed the kokoro:force-run This will force trigger a run for presubmit tests label Oct 19, 2026
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.

3 participants