T09 · Insecure Skill Coding Practices
- Location
scripts/search_module.py:59- Finding
OS Command Injection in Exa Search Fallback
- Content
View full analysis
Vulnerability Details
File Location:
scripts/search_module.py, lines 59–61
Vulnerability Type: OS command injection through user-controlled search input
Risk Level: HighVulnerable Code
python # 兜底实现 import subprocess cmd = f"mcporter call exa.web_search_exa query='{query}' numResults={num_results}" result = subprocess.run(cmd, shell=True, capture_output=True, text=True) return result.stdoutTechnical Analysis
The fallback search implementation embeds
querydirectly into a shell command and executes it withshell=True. The query is derived from location and recommendation-type values supplied to the Skill. Wrapping the value in single quotes does not make it safe because an attacker can include a single quote to terminate the quoted argument, followed by shell operators and an arbitrary command.This path is reachable when the preferred
skill_orchestratorintegration is unavailable andSEARCHis thereforeNone. No validation or shell escaping is performed before execution.Attack Path
- An attacker supplies a crafted location or recommendation type containing a closing quote, shell operators, and an operating-system command.
multi_round_search()incorporates that value into one or more search queries.search_exa()receives the resulting attacker-influenced query.- If
SEARCHis unavailable, the fallback constructs a command string using the query. subprocess.run(..., shell=True)passes that string to the system shell.- The shell interprets the injected operators and executes the attacker’s command with the privileges of the Agent process.
A conceptual malicious value could terminate the quoted
queryargument and append a command using;,&&, command substitution, or similar shell syntax.Impact Assessment
Successful exploitation permits arbitrary command execution under the account running the Skill. Depending on that account’s permissions, an attacker could:
- Read or modify ...[truncated 498 chars]
- Remediation
View remediation
Remediation Suggestions
Eliminate shell interpretation and pass each argument directly to the subprocess:
python result = subprocess.run( [ "mcporter", "call", "exa.web_search_exa", f"query={query}", f"numResults={num_results}", ], capture_output=True, text=True, check=True, timeout=30, ) return result.stdoutAdditional hardening should include:
- Validate that
queryis a string and impose a reasonable maximum length. - Constrain
num_resultsto an integer within an expected range. - Use an absolute, trusted path for
mcporterwhere practical to reduce executable path-hijacking risk. - Handle
subprocess.TimeoutExpiredandsubprocess.CalledProcessErrorwithout exposing sensitive process details. - Run the Skill under a least-privileged account with restricted filesystem and network access.
- Add regression tests containing quotes, semicolons, command substitutions, newlines, and other shell metacharacters to verify they remain literal argument content.
- Validate that
