MCP-for-Stata: Command injection via log_file_name parameter in Stata command wrapper
Date: 2026-06
Affected: pip/stata-mcp
Attack vector: command-injection
Category: vulnerability-disclosure
Severity: Critical
CVE: CVE-2026-47708
CWE: CWE-77

### Summary The `log_file_name` parameter in the `stata_do` API and CLI is directly interpolated into a Stata command string without sanitization. The security guard (`GuardValidator`) only scans the do-file content but does not validate this parameter. An attacker can inject arbitrary Stata commands (including `shell`, `python`, `erase`, etc.) by crafting a malicious `log_file_name` containing quotes, newlines, or Stata command separators. ### Details In `src/stata_mcp/stata/stata_do/do.py`, both `_execute_unix_like` and `_execute_windows` construct a Stata command string using Python f-strings: ```python commands = f""" capture log close {self.generate_log_command(log_file, is_replace)} ... do "{dofile_path}" ... """ ``` The `generate_log_command` method returns: ```python log_cmd = f'log using "{log_file.as_posix()}", {replace_clause} {log_type} name({log_type}_log)' ``` Where `log_file` is constructed from user-supplied `log_name`: ```python def generate_log_file(self, log_name: str, extension='log'): return self.log_file_path / f"{log_name}.{extension}" ``` The `log_name` parameter comes directly from user input (via MCP tool `stata_do` or CLI `stata-mcp tool do`) without any validation. Since the path is embedded inside double quotes in a Stata command string, an attacker can break out of the string context and inject arbitrary commands. Additionally, `generate_log_file` does not prevent path traversal via `log_name`, allowing arbitrary file write outside t


Mitigations:

Architectural layers (MAESTRO):