Skip to content

fix: remove shell=True from subprocess calls in mcp dev#2190

Open
Br1an67 wants to merge 2 commits intomodelcontextprotocol:mainfrom
Br1an67:fix/issue-1257-shell-injection
Open

fix: remove shell=True from subprocess calls in mcp dev#2190
Br1an67 wants to merge 2 commits intomodelcontextprotocol:mainfrom
Br1an67:fix/issue-1257-shell-injection

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

Summary

Fixes #1257

mcp dev used shell=True when running npx on Windows, exposing a command injection risk via shell metacharacters in file paths (e.g., server&calc.py).

Changes

  • src/mcp/cli/cli.py:
    • Remove shell=True from both subprocess.run calls (_get_npx_command and the Inspector invocation).
    • _get_npx_command() already resolves to npx.cmd/npx.exe on Windows, so shell=True is unnecessary.
    • Add FileNotFoundError to the exception handler for robustness when the command is not found without shell expansion.

Test

uv run ruff check src/mcp/cli/cli.py  # All checks passed

Br1an67 added 2 commits March 2, 2026 01:12
…ction risk)

Remove shell=True from _get_npx_command() and the MCP Inspector
subprocess.run() call. On Windows, _get_npx_command() already resolves
to the correct .cmd/.exe extension, so shell=True is unnecessary and
exposes a command injection risk via shell metacharacters in file paths.

Also catch FileNotFoundError in _get_npx_command() for robustness when
the command is not found without shell expansion.
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.

Don’t use shell=True in mcp dev subprocess on Windows (command injection risk)

1 participant