Skip to content

Commit f7b9f72

Browse files
committed
[Security] Fix potential command injection on Windows in CLI dev command
1 parent 3dc8b72 commit f7b9f72

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/mcp/cli/cli.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import importlib.metadata
44
import importlib.util
55
import os
6+
import shlex
67
import subprocess
78
import sys
89
from pathlib import Path
@@ -275,8 +276,15 @@ def dev(
275276

276277
# Run the MCP Inspector command with shell=True on Windows
277278
shell = sys.platform == "win32"
279+
cmd_args = [npx_cmd, "@modelcontextprotocol/inspector"] + uv_cmd
280+
281+
if shell:
282+
# On Windows with shell=True, I need to quote arguments to prevent injection
283+
# and join them into a single string, as passing a list with shell=True is unsafe/undefined behavior
284+
cmd_args = " ".join(shlex.quote(arg) for arg in cmd_args)
285+
278286
process = subprocess.run(
279-
[npx_cmd, "@modelcontextprotocol/inspector"] + uv_cmd,
287+
cmd_args,
280288
check=True,
281289
shell=shell,
282290
env=dict(os.environ.items()), # Convert to list of tuples for env update

0 commit comments

Comments
 (0)