Skip to main content

stata-mcp CVE-2026-47708

| EUVDEUVD-2026-46426 CRITICAL
Command Injection (CWE-77)
2026-06-04 https://github.com/SepineTam/stata-mcp GHSA-4p62-hqp5-g644 PYSEC-2026-544
9.3
CVSS 4.0 · Vendor: https://github.com/SepineTam/stata-mcp
Share

Severity by source

Vendor (https://github.com/SepineTam/stata-mcp) PRIMARY
9.3 CRITICAL
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
vuln.today AI
9.8 CRITICAL

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.

3.1 AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
4.0 AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N

Primary rating from Vendor (https://github.com/SepineTam/stata-mcp).

CVSS VectorVendor: https://github.com/SepineTam/stata-mcp

Attack Vector
Network
Attack Complexity
Low
Privileges Required
None
User Interaction
None
Scope
X

Lifecycle Timeline

5
Analysis Updated
Jul 21, 2026 - 21:28 vuln.today
v2 (cvss_changed)
Re-analysis Queued
Jul 21, 2026 - 21:22 vuln.today
cvss_changed
CVSS changed
Jul 21, 2026 - 21:22 NVD
9.3 (CRITICAL)
Source Code Evidence Fetched
Jun 04, 2026 - 21:15 vuln.today
Analysis Generated
Jun 04, 2026 - 21:15 vuln.today

DescriptionCVE.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:

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 the intended log directory.

Proof of Concept

When calling stata_do via MCP tool with:

json
{
  "dofile_path": "test.do",
  "log_file_name": "'; shell echo pwned > /tmp/pwned.txt; '"
}

The generated Stata commands become:

stata
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 shell command 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

  1. Apply strict allowlist validation to log_name (only alphanumeric, underscore, dot, hyphen; max 128 chars)
  2. Resolve and verify the constructed log path remains within the intended log directory
  3. Consider generating safe internal filenames (e.g., UUIDs) instead of accepting user-defined log names for command construction
  4. Apply similar sanitization to dofile_path before 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.

More in Python

View all
CVE-2025-24016 CRITICAL POC
9.9 Feb 10

Wazuh SIEM platform versions 4.4.0 through 4.9.0 contain an unsafe deserialization vulnerability in the DistributedAPI t

CVE-2025-27520 CRITICAL POC
9.8 Apr 04

BentoML version 1.4.2 and earlier contains an unauthenticated remote code execution vulnerability through insecure deser

CVE-2025-2945 CRITICAL POC
9.9 Apr 03

pgAdmin 4 contains critical remote code execution vulnerabilities in the Query Tool download and Cloud Deployment endpoi

CVE-2013-5093 MEDIUM POC
6.8 Sep 27

The renderLocalView function in render/views.py in graphite-web in Graphite 0.9.5 through 0.9.10 uses the pickle Python

CVE-2025-32375 CRITICAL POC
9.8 Apr 09

BentoML is a Python library for building online serving systems optimized for AI apps and model inference. Rated critica

CVE-2014-0224 HIGH POC
7.4 Jun 05

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

CVE-2024-21644 HIGH POC
7.5 Jan 08

pyLoad download manager version prior to 0.5.0b3.dev77 exposes the Flask SECRET_KEY through an unauthenticated endpoint.

CVE-2026-33017 CRITICAL POC
9.3 Mar 17

Langflow (a visual LLM pipeline builder) contains a critical unauthenticated code execution vulnerability (CVE-2026-3301

CVE-2017-9462 HIGH POC
8.8 Jun 06

In Mercurial before 4.1.3, "hg serve --stdio" allows remote authenticated users to launch the Python debugger, and conse

CVE-2026-49869 CRITICAL POC
10.0 Jun 26

Unauthenticated remote code execution affects Kestra OSS (the open-source event-driven orchestration platform) prior to

CVE-2026-39987 CRITICAL POC
9.3 Apr 08

Unauthenticated remote code execution in Marimo ≤0.20.4 allows attackers to execute arbitrary system commands via the `/

CVE-2024-21645 MEDIUM POC
5.3 Jan 08

pyLoad is the free and open-source Download Manager written in pure Python. Rated medium severity (CVSS 5.3), this vulne

Share

CVE-2026-47708 vulnerability details – vuln.today

This site uses cookies essential for authentication and security. No tracking or analytics cookies are used. Privacy Policy