Severity by source
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/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
Unauthenticated injection via an exposed tool/CLI parameter (PR:N, AC:L) yields full OS command execution, so C/I/A:H; scope unchanged as the injected commands run within the server's own privilege context.
Primary rating from Vendor (https://github.com/SepineTam/stata-mcp).
CVSS VectorVendor: https://github.com/SepineTam/stata-mcp
Lifecycle Timeline
5DescriptionCVE.org
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
AnalysisAI
Command injection in the stata-mcp (MCP-for-Stata) server versions before 1.17.3 lets attackers execute arbitrary Stata and OS commands by supplying a malicious log_file_name to the stata_do MCP tool or stata-mcp tool do CLI. Because the value is interpolated unsanitized into a Stata log using command, an attacker can break out of the quoted string and invoke shell, python, or erase, achieving remote code execution and arbitrary file write while completely bypassing the GuardValidator, which only inspects do-file content. There is no public exploit identified at time of analysis, though the advisory includes a working proof-of-concept payload; EPSS is low at 0.63% (71st percentile).
Technical ContextAI
The affected component is stata-mcp, a Python (pip) Model Context Protocol server that wraps the Stata statistical package so AI agents and CLI users can run do-files. In src/stata_mcp/stata/stata_do/do.py, both _execute_unix_like and _execute_windows build a multi-line Stata command block with Python f-strings, embedding a log path derived from the user-supplied log_name inside a log using "..." statement. This is a textbook CWE-77 (Improper Neutralization of Special Elements used in a Command) flaw: Stata treats quotes, newlines, and separators as command boundaries, so an injected "; shell ... sequence is parsed as additional Stata commands. Stata's shell command then reaches the underlying OS, and on Windows the process is spawned with shell=True, compounding exposure. The same routine also lacks path-canonicalization, permitting ../ traversal to write log files outside the intended directory.
RemediationAI
Vendor-released patch: upgrade stata-mcp to version 1.17.3 or later (fix commit e6f945941ae0c7cf5e74a428e0b3dc82b396382f), which adds a strict allowlist LOG_FILE_NAME_PATTERN = ^[A-Za-z0-9_.-]{1,128}$ plus a _validate_log_name check that also rejects empty, ., and .. path parts to block traversal. See the advisory at https://github.com/SepineTam/stata-mcp/security/advisories/GHSA-4p62-hqp5-g644 and the patch at https://github.com/SepineTam/mcp-for-stata/commit/e6f945941ae0c7cf5e74a428e0b3dc82b396382f. If you cannot upgrade immediately, restrict who can invoke the stata_do tool and never expose the MCP server to untrusted clients or network interfaces (bind to localhost only), and validate or hard-code log_file_name upstream to alphanumeric/underscore/dot/hyphen values - trade-off: this constrains user-chosen log names but eliminates the injection primitive. Also treat dofile_path as untrusted, since the advisory notes it is embedded into the same command string; the maintainer recommends generating internal UUID-based log filenames rather than accepting user-defined names.
Wazuh SIEM platform versions 4.4.0 through 4.9.0 contain an unsafe deserialization vulnerability in the DistributedAPI t
BentoML version 1.4.2 and earlier contains an unauthenticated remote code execution vulnerability through insecure deser
pgAdmin 4 contains critical remote code execution vulnerabilities in the Query Tool download and Cloud Deployment endpoi
The renderLocalView function in render/views.py in graphite-web in Graphite 0.9.5 through 0.9.10 uses the pickle Python
BentoML is a Python library for building online serving systems optimized for AI apps and model inference. Rated critica
OpenSSL before 0.9.8za, 1.0.0 before 1.0.0m, and 1.0.1 before 1.0.1h does not properly restrict processing of ChangeCiph
pyLoad download manager version prior to 0.5.0b3.dev77 exposes the Flask SECRET_KEY through an unauthenticated endpoint.
Langflow (a visual LLM pipeline builder) contains a critical unauthenticated code execution vulnerability (CVE-2026-3301
In Mercurial before 4.1.3, "hg serve --stdio" allows remote authenticated users to launch the Python debugger, and conse
Unauthenticated remote code execution affects Kestra OSS (the open-source event-driven orchestration platform) prior to
Unauthenticated remote code execution in Marimo ≤0.20.4 allows attackers to execute arbitrary system commands via the `/
pyLoad is the free and open-source Download Manager written in pure Python. Rated medium severity (CVSS 5.3), this vulne
Same weakness CWE-77 – Command Injection
View allShare
External POC / Exploit Code
Leaving vuln.today
EUVD-2026-46426
GHSA-4p62-hqp5-g644