T09 · Insecure Skill Coding Practices
- Location
scripts/task_manager.py:164- Finding
Shell Command Injection in MCP Command Execution
- Content
View full analysis
Vulnerability Details
File Location:
scripts/task_manager.py, lines 164-168 and 423-426
Vulnerability Type: OS command injection through unsafe shell interpolation
Risk Level: HighVulnerable Code
python def run_mcporter(command: str, args_dict: dict) -> Optional[dict]: args_json = json.dumps(args_dict, ensure_ascii=False) cmd = f'{MCPORTER_PATH} call wecom-doc.{command} --args \'{args_json}\' --output json' result = subprocess.run(cmd, shell=True, capture_output=True, text=True)The retry implementation repeats the same vulnerable pattern:
python args_json = json.dumps(args_dict, ensure_ascii=False) cmd = f'{MCPORTER_PATH} call wecom-doc.{command} --args \'{args_json}\' --output json' result = subprocess.run(cmd, shell=True, capture_output=True, text=True)Technical Analysis
The implementation serializes MCP arguments as JSON, embeds that JSON inside a single-quoted shell command, and executes the resulting string with
shell=True.JSON serialization does not make data safe for use in a shell command. In particular, a single quote in an attacker-controlled value is preserved by
json.dumps()and can terminate the shell's single-quoted argument. Subsequent shell metacharacters can then be interpreted as commands.Values reaching
args_dictinclude task identifiers, names, descriptions, remarks, blockers, output URLs, owners, arbitrary edited fields, and data read back from WeCom records. Consequently, both direct input and previously stored task data may reach this execution sink.The
commandargument is also interpolated into the shell command without validation. Although current internal call sites use predefined MCP method names, the helper is public and can be imported and invoked directly.Attack Path
- An attacker obtains a path to invoke a task mutation API, either directly through the Python module, through the CLI, or by influencing an a ...[truncated 1440 chars]
- Remediation
View remediation
Remediation Suggestions
Eliminate shell interpretation and pass every command component as a separate argument:
python def run_mcporter(command: str, args_dict: dict) -> Optional[dict]: allowed_commands = { "smartsheet_get_records", "smartsheet_add_records", "smartsheet_update_records", "smartsheet_delete_records", "smartsheet_get_fields", } if command not in allowed_commands: raise ValueError("Unsupported MCP command") args_json = json.dumps(args_dict, ensure_ascii=False) result = subprocess.run( [ MCPORTER_PATH, "call", f"wecom-doc.{command}", "--args", args_json, "--output", "json", ], shell=False, capture_output=True, text=True, check=False, timeout=30, )Apply the same correction to
run_mcporter_with_retry().Additional hardening should include:
- Centralizing MCP execution in one safe helper rather than duplicating command construction.
- Allowlisting supported MCP method names.
- Adding maximum lengths and type validation for task fields.
- Running the Skill under a minimally privileged operating-system account.
- Adding regression tests containing quotes, newlines, command substitutions, and shell metacharacters.
- Avoiding logging raw process output when it may contain credentials or sensitive remote data.
