-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Harden install commands against special characters #2371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add shell escaping to claude-code and gemini-cli install commands.
WalkthroughThis pull request adds shell injection protection to two CLI installation modules. The Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
tests/cli/test_install.pyis excluded by none and included by none
📒 Files selected for processing (2)
src/fastmcp/cli/install/claude_code.py(2 hunks)src/fastmcp/cli/install/gemini_cli.py(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/fastmcp/cli/install/gemini_cli.py (1)
src/fastmcp/server/server.py (1)
name(360-361)
src/fastmcp/cli/install/claude_code.py (1)
src/fastmcp/server/server.py (1)
name(360-361)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: label-issue-or-pr
- GitHub Check: Run tests: Python 3.10 on windows-latest
| @@ -1,5 +1,6 @@ | |||
| """Claude Code integration for FastMCP install using Cyclopts.""" | |||
|
|
|||
| import shlex | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary and incorrect shlex.quote() usage.
The use of shlex.quote() is incorrect here. Since subprocess.run() is called with a list argument (line 142) and shell=True is not set, Python passes each list element directly to the executable without shell interpretation. In this context:
- Special characters in the
nameare already safe—no shell parsing occurs shlex.quote()adds literal quote characters that become part of the argument value- The Claude CLI would receive a name like
'my-server'(with quotes) instead ofmy-server
The shlex.quote() function is only needed when constructing command strings that will be interpreted by a shell.
Apply this diff to remove the incorrect escaping:
-import shlex
import shutil- # Build claude mcp add command (escape name to prevent shell injection)
- cmd_parts = [claude_cmd, "mcp", "add", shlex.quote(name)]
+ # Build claude mcp add command
+ cmd_parts = [claude_cmd, "mcp", "add", name]Also applies to: 128-129
🤖 Prompt for AI Agents
In src/fastmcp/cli/install/claude_code.py around lines 3, 128-129 (and the
invocation at ~142), remove the unnecessary use of shlex.quote(): delete the
import "import shlex" at line 3 and replace any shlex.quote(name) (and similar
calls) with the raw variable (e.g., name) so the argument list passed to
subprocess.run remains unmodified; ensure no shell=True usage relies on quoting
and run subprocess with the list of plain arguments.
| @@ -1,5 +1,6 @@ | |||
| """Gemini CLI integration for FastMCP install using Cyclopts.""" | |||
|
|
|||
| import shlex | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary and incorrect shlex.quote() usage.
The use of shlex.quote() is incorrect here for the same reason as in claude_code.py. Since subprocess.run() is called with a list argument (line 139) without shell=True, no shell interpretation occurs. The shlex.quote() will add literal quote characters that become part of the server name, potentially breaking the Gemini CLI command.
Apply this diff to remove the incorrect escaping:
-import shlex
import shutil- # Add server name and command (escape name to prevent shell injection)
- cmd_parts.extend([shlex.quote(name), full_command[0], "--"])
+ # Add server name and command
+ cmd_parts.extend([name, full_command[0], "--"])Also applies to: 133-134
🤖 Prompt for AI Agents
In src/fastmcp/cli/install/gemini_cli.py around lines 3 and 133-134, remove the
incorrect use of shlex.quote() that is wrapping server/name arguments (and
remove the now-unused import at line 3); because subprocess.run(...) is invoked
with a list (no shell=True), the server name should be passed as the raw string
elements in the argument list rather than quoted, so replace calls like
shlex.quote(server) with server (or the original unescaped variable) and delete
the shlex import.
Apply shell escaping to server names in claude-code and gemini-cli install commands to prevent issues with special characters.