Skip to content

Commit 2fd686b

Browse files
committed
fix(shell_executor.py): update _create_shell_command to preserve wildcards for shell expansion while escaping other arguments to prevent shell injection
1 parent 358ccda commit 2fd686b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/mcp_shell_server/shell_executor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,21 @@ def _clean_command(self, command: List[str]) -> List[str]:
4444
def _create_shell_command(self, command: List[str]) -> str:
4545
"""
4646
Create a shell command string from a list of arguments.
47-
Properly escapes all arguments to prevent shell injection.
47+
Wildcards (*?[]) are preserved for shell expansion.
4848
4949
Args:
5050
command (List[str]): Command and its arguments
5151
5252
Returns:
5353
str: Shell-safe command string
5454
"""
55-
return " ".join(shlex.quote(arg) for arg in command)
55+
escaped_args = []
56+
for arg in command:
57+
if any(char in arg for char in "*?[]"):
58+
escaped_args.append(arg)
59+
else:
60+
escaped_args.append(shlex.quote(arg))
61+
return " ".join(escaped_args)
5662

5763
def _validate_command(self, command: List[str]) -> None:
5864
"""

0 commit comments

Comments
 (0)