-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| """Gemini CLI integration for FastMCP install using Cyclopts.""" | ||
|
|
||
| import shlex | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unnecessary and incorrect The use of 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 |
||
| import shutil | ||
| import subprocess | ||
| import sys | ||
|
|
@@ -129,8 +130,8 @@ def install_gemini_cli( | |
| for key, value in env_vars.items(): | ||
| cmd_parts.extend(["-e", f"{key}={value}"]) | ||
|
|
||
| # Add server name and command | ||
| cmd_parts.extend([name, full_command[0], "--"]) | ||
| # Add server name and command (escape name to prevent shell injection) | ||
| cmd_parts.extend([shlex.quote(name), full_command[0], "--"]) | ||
| cmd_parts.extend(full_command[1:]) | ||
|
|
||
| try: | ||
|
|
||
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. Sincesubprocess.run()is called with a list argument (line 142) andshell=Trueis not set, Python passes each list element directly to the executable without shell interpretation. In this context:nameare already safe—no shell parsing occursshlex.quote()adds literal quote characters that become part of the argument value'my-server'(with quotes) instead ofmy-serverThe
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 shutilAlso applies to: 128-129
🤖 Prompt for AI Agents