modelcontextprotocol / modelcontextprotocol/python-sdk

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

Ouverte Adaptée aux débutants
#1,257 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

bug fix proposed P1 ready for work
Langage dominant
Python
Étoiles
24.3k
Forks
4k
Merge moyen
1 j 1 h
PR mergées (30 j)
31

Description

Initial Checks
Description

What’s happening:

When you run the mcp dev command on Windows, it starts another program using a method (subprocess.run with shell=True) that lets the Windows command prompt (cmd.exe) handle the command. This is risky because if any part of the command includes special characters (like &, |, %, etc.), Windows might run something you didn’t expect — even another program, if the file path or arguments are weirdly named or crafted.

Why this is a real problem:

  • This isn’t just a theory — it’s a well-known risk with shell=True in Python. If anyone (or any script) can control part of the file path or arguments, they might be able to run extra commands on your computer.
  • The Python documentation says to avoid shell=True when possible for exactly this reason.
  • The fix is easy: use shell=False and make sure the right Windows executable is picked (like npx.cmd).
  • This keeps things safe and works the same on all systems.

What should happen instead:

  • The command should be run without shell=True on Windows, just like it is on Linux/Mac.
  • File paths and arguments should always be passed as a list, not a single string.

How this could be abused:

  • If someone manages to sneak a file or argument with a shell special character into your project, running mcp dev could run extra commands (for example, opening Calculator if the file had &calc in its name).

Please fix:

  • Remove shell=True from the subprocess.run call in src/mcp/cli/cli.py (Windows part).
  • Make sure the command and its arguments are always passed as a list.
  • Make sure it works on Windows by using the right executable (like npx.cmd).

Thanks!

Example Code
# Example of risky situation on Windows:
# If a file is named "server&calc.py" and you run:
#   mcp dev path\to\server&calc.py
# Windows might run Calculator because of the &

# Please see src/mcp/cli/cli.py (mcp dev command) for the subprocess.run([npx_cmd, ...], shell=True, ...)
Python & MCP Python SDK
Python 3.11, Windows 11, latest MCP Python SDK (main branch, August 2025)

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez dans src/mcp/cli/cli.py, au niveau de l’appel subprocess.run de mcp dev pour Windows. Vérifiez comment la commande et les arguments sont assemblés, puis vérifiez que l’exécutable est sélectionné de manière appropriée pour Windows et que les arguments sont transmis sous forme de liste sans shell=True. C’est terminé lorsque mcp dev s’exécute sous Windows et que les métacaractères du shell présents dans les chemins ou les arguments ne sont pas interprétés comme des commandes supplémentaires.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
cli, security
Type d'issue
Bug
Difficulté
2/5
Temps estimé
1-3 heures
Activité
Calme
Clarté
Clairement spécifiée
Accessibilité débutants
72/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.