fix(mcp-server): use platform default shell for execShell to support … - #10
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Updates execShell in the MCP server toolkit to use the platform-appropriate default shell so shell execution works on Windows (instead of hard-coding /bin/sh).
Changes:
- Detect Windows at runtime and route
execShellthroughcmd.exe-style invocation. - Add
node:processimport to support platform/env access for shell selection.
Suppressed comments (2)
apps/mcp-server/src/tools/kit.ts:143
- On Windows, selecting the shell from COMSPEC/ComSpec makes the actual executable depend on the server environment rather than the policy-screened command line. That can undermine the allowlist/denylist intent (e.g., a safe-looking
git …command could still be executed by a replaced COMSPEC program). Also, invokingcmd.exewithout/dcan run AutoRun commands from the registry, which is undesirable in a sandboxed tool runner.
Prefer invoking cmd.exe directly and disable AutoRun via /d (and /s for standard cmd parsing).
const isWin = process.platform === 'win32';
const shell = isWin ? process.env.COMSPEC || process.env.ComSpec || 'cmd.exe' : '/bin/sh';
const shellArgs = isWin ? ['/c', screened] : ['-c', screened];
return execFile(shell, shellArgs, options);
apps/mcp-server/src/tools/kit.ts:143
- This change introduces OS-dependent behavior (
cmd.exevs/bin/sh) but there are no unit tests exercisingexecShell’s platform selection and argument construction. Adding a small test would prevent regressions (e.g., accidentally using the wrong flags on Windows).
const isWin = process.platform === 'win32';
const shell = isWin ? process.env.COMSPEC || process.env.ComSpec || 'cmd.exe' : '/bin/sh';
const shellArgs = isWin ? ['/c', screened] : ['-c', screened];
return execFile(shell, shellArgs, options);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
139
to
+140
| const screened = security.commands.check(commandLine); | ||
| return execFile('/bin/sh', ['-c', screened], options); | ||
| const isWin = process.platform === 'win32'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…Windows