CVE-2026-47708: MCP-for-Stata: Command injection via log_file_name parameter in Stata command wrapper
The stata-mcp package before 1.17.3 builds a Stata command from the log_file_name parameter of the stata_do tool without sanitizing it. Crafted input injects Stata commands such as shell, giving code execution on the host and bypassing the built-in guard. Upgrade to stata-mcp 1.17.3.
Published Jun 4, 2026 · Analysis Oct 26, 2026
What an attacker can do
In src/stata_mcp/stata/stata_do/do.py, the functions _execute_unix_like and _execute_windows build a Stata script with Python f-strings. generate_log_command puts the log path inside double quotes in a log using line, and generate_log_file builds that path from the caller's log name with no validation.
A log_file_name holding quotes, newlines or Stata command separators breaks out of the string. The advisory's proof of concept uses a value starting with a quote and a semicolon, followed by shell echo pwned > /tmp/pwned.txt. Stata then runs the shell command. The same input can traverse paths, so it can write or overwrite files outside the log directory.
GuardValidator, the security check, only scans the do-file content. It never sees this parameter, so the guard is bypassed completely.
The attacker needs to supply tool arguments. That can be anyone who reaches the MCP tool or the stata-mcp tool do CLI, or an AI agent steered by prompt injection into passing a hostile log_file_name. The CVSS 4.0 vector lists network access with no privileges or user interaction. The result is code execution as the user who runs the MCP server, usually a researcher's workstation with data and credentials.
Who is affected
pip package stata-mcp before 1.17.3. Every setup that exposes the stata_do tool or the stata-mcp tool do command is affected. The advisory also suggests that dofile_path is embedded in command strings without sanitization.
Check the installed version:
pip show stata-mcpstata-mcp
- Ecosystem
- PyPI
- Affected
- < 1.17.3
- Fixed in
- 1.17.3
- Check
pip show stata-mcp
How to fix it
Upgrade to stata-mcp 1.17.3:
pip install -U "stata-mcp>=1.17.3"The advisory's remediation guidance is an allowlist for log names (letters, digits, underscore, dot, hyphen, at most 128 characters), a check that the resolved log path stays inside the log directory, generated internal filenames such as UUIDs, and similar sanitization for dofile_path. The advisory does not say exactly which of these the fix commit applies. It names no workaround, so until you upgrade, do not expose the tool to untrusted callers or agents that read untrusted content.
How to tell if you were hit
Look in your MCP or CLI logs for stata_do calls where log_file_name contains quotes, semicolons, newlines, shell, python, erase or path separators like ../. Check the Stata log directory for files outside the expected name pattern, and the filesystem for files written by Stata outside it. On the host, look for shell processes spawned by the Stata process. Beam records agent shell commands and file access, so its activity view can show what an agent did after it called this tool.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
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:
commands = f"""
capture log close
{self.generate_log_command(log_file, is_replace)}
...
do "{dofile_path}"
...
"""The generate_log_command method returns:
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:
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 the intended log directory.
Proof of Concept
When calling stata_do via MCP tool with:
{
"dofile_path": "test.do",
"log_file_name": "'; shell echo pwned > /tmp/pwned.txt; '"
}The generated Stata commands become:
log using "<log_dir>/'; shell echo pwned > /tmp/pwned.txt; '.log", replace text name(text_log)Stata interprets this as multiple commands, with shell echo pwned > /tmp/pwned.txt; executed as an arbitrary shell command.
Impact
- Remote Code Execution via
shellcommand injection - Arbitrary file write/overwrite via path traversal in
log_name - Complete bypass of the security guard, as the guard only validates do-file content, not wrapper parameters
Remediation / Fix
- Apply strict allowlist validation to
log_name(only alphanumeric, underscore, dot, hyphen; max 128 chars) - Resolve and verify the constructed log path remains within the intended log directory
- Consider generating safe internal filenames (e.g., UUIDs) instead of accepting user-defined log names for command construction
- Apply similar sanitization to
dofile_pathbefore embedding it into Stata command strings
References
- Issue: #74
- Fix commit: https://github.com/SepineTam/stata-mcp/commit/e6f945941ae0c7cf5e74a428e0b3dc82b396382f
Credited to SepineTam.
Questions
- Which stata-mcp version fixes CVE-2026-47708?
1.17.3. Earlier versions are listed as vulnerable.
- Does the guard stop this?
No. GuardValidator checks only the do-file content, not the log_file_name parameter, so the injection passes through it.
- Can this also write files?
Yes. The advisory says log_name allows path traversal and arbitrary file write or overwrite outside the log directory.
- Is CVE-2026-47708 exploited in the wild?
No source says so. It is not in CISA's KEV catalog and the EPSS score is 0.0053.
References
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology
More Other MCP servers and tools vulnerabilities
All Other MCP servers and tools entriesCVE-2026-102943
Dagu MCP DAG specification read bypasses path containment and workspace isolation
medium6.5Nov 10, 2026CVE-2026-102610
fast-agent: `fast-agent serve` binds HTTP to 0.0.0.0 with no authentication by default; with --shell this is unauthenticated remote command execution
medium6.4Nov 9, 2026CVE-2026-63655
tsParticles: Unbounded HTTP Request Body Buffering in @tsparticles/mcp-server Leads to Remote DoS
high7.5Nov 9, 2026CVE-2026-76892
tsParticles: Malformed JSON requests can terminate the @tsparticles/mcp-server HTTP process
high8.7Nov 9, 2026CVE-2026-76893
tsParticles: A single anonymous MCP session can monopolize HTTP mode and deny new clients
medium6.9Nov 9, 2026CVE-2026-77604
Code Graph RAG: MCP paginated read_file path traversal / arbitrary file read
high7.5Nov 9, 2026
