T09 · Insecure Skill Coding Practices
- Location
scripts/search_module.py:58- Finding
Shell Command Injection in the EXA Search Fallback
- Content
View full analysis
Vulnerability Details
File Location:
scripts/search_module.py, lines 58–59
Vulnerability Type: Shell command injection
Risk Level: HighVulnerable Code:
python cmd = f"mcporter call exa.web_search_exa query='{query}' numResults={num_results}" result = subprocess.run(cmd, shell=True, capture_output=True, text=True)Technical Analysis
The fallback implementation interpolates
queryandnum_resultsinto a command string that is executed withshell=True. Thequeryvalue can be assembled from caller-controlled location and recommendation-type values bymulti_round_search().Enclosing
queryin single quotes does not make the command safe. An input containing a single quote can terminate the quoted argument and append shell operators or additional commands. The system shell then interprets the injected syntax becauseshell=Trueis enabled.The vulnerable path is used when the
skill_orchestratorimport is unavailable and the code falls back to invokingmcporterthroughsubprocess.Attack Path
- An attacker supplies a crafted location or recommendation type containing a single quote followed by shell syntax.
multi_round_search()incorporates the supplied value into a search query.search_exa()receives that query.- If the orchestrator-backed search interface is unavailable, the fallback constructs a shell command using the untrusted query.
- The injected single quote terminates the intended quoted argument.
subprocess.run(..., shell=True)causes the shell to interpret and execute the appended command.- The injected command runs with the operating-system privileges of the Agent or Skill process.
Impact Assessment
Successful exploitation permits arbitrary local command execution under the account running the Skill. Depending on that account's permissions, an attacker could read or modify accessible files, steal environment-based credential ...[truncated 273 chars]
- Remediation
View remediation
Remediation Suggestions
Remove shell interpretation and pass arguments directly to
subprocess.run():python result = subprocess.run( [ "mcporter", "call", "exa.web_search_exa", f"query={query}", f"numResults={int(num_results)}", ], capture_output=True, text=True, check=True, )Additionally:
- Validate that
num_resultsis an integer within an expected range. - Avoid attempting to secure this implementation solely through manual shell escaping.
- Handle
subprocess.CalledProcessErrorand command timeouts explicitly. - Prefer the structured Python search API whenever available.
- Add regression tests using queries containing apostrophes, semicolons, command substitutions, and newline characters to confirm they are treated only as data.
- Validate that
