{"id":"CVE-2026-47708","aliases":["CVE-2026-47708","GHSA-4p62-hqp5-g644","PYSEC-2026-544"],"related":[],"kind":"vulnerability","state":"published","title":"MCP-for-Stata: Command injection via log_file_name parameter in Stata command wrapper","summary":"MCP-for-Stata is an MCP server for Stata to integrate Stata into an agent. Prior to version 1.17.3, 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. Version 1.17.3 contains a patch for the issue.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"MCP-for-Stata is an MCP server for Stata to integrate Stata into an agent. Prior to version 1.17.3, 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. Version 1.17.3 contains a patch for the issue.","source":"cvelist"},{"lang":"en","text":"### Summary\nThe `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.\n\n### Details\n\nIn `src/stata_mcp/stata/stata_do/do.py`, both `_execute_unix_like` and `_execute_windows` construct a Stata command string using Python f-strings:\n\n```python\ncommands = f\"\"\"\ncapture log close\n{self.generate_log_command(log_file, is_replace)}\n...\ndo \"{dofile_path}\"\n...\n\"\"\"\n```\n\nThe `generate_log_command` method returns:\n\n```python\nlog_cmd = f'log using \"{log_file.as_posix()}\", {replace_clause} {log_type} name({log_type}_log)'\n```\n\nWhere `log_file` is constructed from user-supplied `log_name`:\n\n```python\ndef generate_log_file(self, log_name: str, extension='log'):\n    return self.log_file_path / f\"{log_name}.{extension}\"\n```\n\nThe `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.\n\nAdditionally, `generate_log_file` does not prevent path traversal via `log_name`, allowing arbitrary file write outside the intended log directory.\n\n### Proof of Concept\n\nWhen calling `stata_do` via MCP tool with:\n\n```json\n{\n  \"dofile_path\": \"test.do\",\n  \"log_file_name\": \"'; shell echo pwned > /tmp/pwned.txt; '\"\n}\n```\n\nThe generated Stata commands become:\n\n```stata\nlog using \"<log_dir>/'; shell echo pwned > /tmp/pwned.txt; '.log\", replace text name(text_log)\n```\n\nStata interprets this as multiple commands, with `shell echo pwned > /tmp/pwned.txt;` executed as an arbitrary shell command.\n\n### Impact\n\n- **Remote Code Execution** via `shell` command injection\n- **Arbitrary file write/overwrite** via path traversal in `log_name`\n- Complete bypass of the security guard, as the guard only validates do-file content, not wrapper parameters\n\n### Remediation / Fix\n\n1. Apply strict allowlist validation to `log_name` (only alphanumeric, underscore, dot, hyphen; max 128 chars)\n2. Resolve and verify the constructed log path remains within the intended log directory\n3. Consider generating safe internal filenames (e.g., UUIDs) instead of accepting user-defined log names for command construction\n4. Apply similar sanitization to `dofile_path` before embedding it into Stata command strings\n\n### References\n\n- Issue: #74\n- Fix commit: https://github.com/SepineTam/stata-mcp/commit/e6f945941ae0c7cf5e74a428e0b3dc82b396382f","format":"markdown","source":"ghsa"},{"lang":"es","text":"MCP-for-Stata es un servidor MCP para Stata para integrar Stata en un agente. Antes de la versión 1.17.3, el parámetro ’log_file_name’ en la API ’stata_do’ y la CLI se interpola directamente en una cadena de comandos de Stata sin sanitización. El guardia de seguridad (’GuardValidator’) solo escanea el contenido del do-file pero no valida este parámetro. Un atacante puede inyectar comandos arbitrarios de Stata (incluyendo ’shell’, ’python’, ’erase’, etc.) mediante la creación de un ’log_file_name’ malicioso que contenga comillas, saltos de línea o separadores de comandos de Stata. La versión 1.17.3 contiene un parche para el problema.","source":"nvd"}],"published":"2026-06-04T21:00:42.000Z","modified":"2026-10-24T19:10:00.127Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N","score":9.3,"rating":"CRITICAL"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N","score":9.3,"rating":"CRITICAL"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N","rating":"CRITICAL"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N"}],"cwes":["CWE-77"],"affected":[{"ranges":[{"version":"< 1.17.3","status":"affected"}],"vendor":"SepineTam","product":"stata-mcp","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.17.3"}],"ecosystem":"PyPI","package":"stata-mcp","purl":"pkg:pypi/stata-mcp","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.17.3"}],"ecosystem":"PyPI","package":"stata-mcp","purl":"pkg:pypi/stata-mcp","source":"pysec"}],"references":[{"url":"https://github.com/SepineTam/mcp-for-stata/security/advisories/GHSA-4p62-hqp5-g644","tags":["exploit","x-refsource-confirm"],"sources":["cvelist","nvd"]},{"url":"https://github.com/SepineTam/mcp-for-stata/issues/74","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/SepineTam/mcp-for-stata/commit/e6f945941ae0c7cf5e74a428e0b3dc82b396382f","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/SepineTam/stata-mcp/security/advisories/GHSA-4p62-hqp5-g644","tags":["web"],"sources":["ghsa","pysec"]},{"url":"https://github.com/SepineTam/stata-mcp","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/stata-mcp","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-4p62-hqp5-g644","tags":["advisory"],"sources":["pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-47708","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"total","date":"2026-07-22T15:08:59.330Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-47708","url":"https://www.cve.org/CVERecord?id=CVE-2026-47708","licence":"CVE Terms of Use","modified":"2026-07-22T15:10:36.426Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-4p62-hqp5-g644","url":"https://github.com/advisories/GHSA-4p62-hqp5-g644","licence":"CC-BY-4.0","modified":"2026-06-29T12:26:16.888Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-47708","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-47708","licence":"Public domain","modified":"2026-10-24T19:10:00.127Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-544","url":"https://osv.dev/vulnerability/PYSEC-2026-544","licence":"CC-BY-4.0","modified":"2026-07-01T20:23:05.367Z"}],"updatedAt":"2026-11-25T22:59:29.409Z","epss":{"score":0.00384,"percentile":0.34601,"date":"2026-12-01T12:00:22.000Z"}}