T09 · Insecure Skill Coding Practices
- Location
scripts/exa_search/exa_search.py:18- Finding
OS Command Injection Through Exa Search Queries
- Content
View full analysis
Dict[str, Any]: """执行 mcporter 命令并返回结果""" try: # 需要用反斜杠转义内部双引号 escaped_arg = call_arg.replace('"', '\\"') cmd_str = f'mcporter call "exa.{escaped_arg}"' result = subprocess.run( cmd_str, shell=True, capture_output=True, text=True, timeout=120 ) ``` Attacker-controlled values are inserted into `call_arg` by functions such as: ```python def search_web(query: str, num_results: int = 8, search_type: str = "auto") -> Dict[str, Any]: """网页搜索""" call_arg = f'web_search_exa(query: "{query}", numResults: {num_results}, type: "{search_type}")' return run_mcporter(call_arg) def search_code(query: str, tokens: int = 5000) -> Dict[str, Any]: """代码搜索""" call_arg = f'get_code_context_exa(query: "{query}", tokensNum: {tokens})' return run_mcporter(call_arg) ``` The value originates from an unrestricted positional CLI argument: ```python parser.add_argument("query", help="搜索关键词/URL/研究ID") ``` ### Technical Analysis The implementation converts an argument containing user-controlled search text into a shell command string and invokes it with `shell=True`. Replacing double quotation marks with `\"` is not sufficient shell escaping. Shell substitutions such as `$(command)` and backtick substitution are still evaluated inside double-quoted shell strings. Shell metacharacters can consequently cause the shell to run commands before or while invoking `mcporter`. The issue affects all operations routed through `run_mcporter()`, including web searches, code searches, company a ...[truncated 1418 chars]- Remediation
View remediation
