Skip to content

Commit 93d26b6

Browse files
committed
fix(security): harden CLI dev command against injection on Windows
Switched from shlex.quote to subprocess.list2cmdline for proper argument escaping on Windows when shell=True is required for npx. This ensures security and reliability when file paths contain special characters.
1 parent 1b5287c commit 93d26b6

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
@@ -273,8 +273,16 @@ def dev(
273273

274274
# Run the MCP Inspector command with shell=True on Windows
275275
shell = sys.platform == "win32"
276+
cmd_args = [npx_cmd, "@modelcontextprotocol/inspector"] + uv_cmd
277+
278+
if shell:
279+
# On Windows with shell=True, I need to quote arguments to prevent injection
280+
# and join them into a single string, as passing a list with shell=True is unsafe/undefined behavior
281+
# Using list2cmdline as it's the correct way to escape for cmd.exe
282+
cmd_args = subprocess.list2cmdline(cmd_args)
283+
276284
process = subprocess.run(
277-
[npx_cmd, "@modelcontextprotocol/inspector"] + uv_cmd,
285+
cmd_args,
278286
check=True,
279287
shell=shell,
280288
env=dict(os.environ.items()), # Convert to list of tuples for env update

0 commit comments

Comments
 (0)