Repository navigation
fix: avoid shell interpolation of user-supplied paths in deployment (command injection) - #329
yogikortisa wants to merge 2 commits into
Conversation
|
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. |
There was a problem hiding this comment.
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.
|
@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.
bbf19de to
efd1fd1
Compare
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.
Summary
prepareSourceDirectory()(lib/deployment/source-processor.js) andrunUniversalMaker()(lib/deployment/universal-maker.js) build shell commands by string-interpolating user-controlled filesystem paths and run them viachild_process.exec, which executes the string through/bin/sh -c.The
folderPathargument of thedeploy_local_foldertool 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 thecp -Rshell call withfs.promises.cp(file, tempDir, { recursive: true })— no subprocess, no shell. Removed the now-unusedexec/utilimports.universal-maker.js: replace the interpolatedexeccommand withexecFile(binPath, [...])— argv array, no shell.Both changes are behavior-preserving and remove the shell entirely from these code paths, eliminating the command-injection vector.