CVE-2026-47708: MCP-for-Stata Command Injection Vulnerability

CRITICAL
Advisory Identifier: GHSA-4p62-hqp5-g644
CWE-77
Published
Advisory Summary

CVE-2026-47708 is a CRITICAL command injection vulnerability (CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')) affecting MCP-for-Stata libraries in the PyPI ecosystem. The issue involves command injection via log_file_name parameter in stata command wrapper. Remediation is available by upgrading affected packages to version 1.17.3.

CVE-2026-47708 at a Glance

CVE Identifier CVE-2026-47708
GHSA Identifier GHSA-4p62-hqp5-g644
Severity CRITICAL
CVSS v3.1 Base Score N/A
CWE Classification CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')
Affected Product MCP-for-Stata
Package Ecosystem PyPI
Published Date
Last Updated

How to Fix CVE-2026-47708

To remediate this vulnerability, upgrade all affected MCP-for-Stata dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

stata-mcp fixed: 1.17.3
pip install stata-mcp>=1.17.3
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show stata-mcp

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2026-47708, inspect your installed packages using pip:

pip show stata-mcp

Analyze the terminal output to locate any version of MCP-for-Stata in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.17.3), your application is affected.

Note: The pip show stata-mcp command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection'), where the product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component. In MCP-for-Stata, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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

CVE-2026-47708 Affected MCP-for-Stata Versions

1 component(s)
Fixed Versions:
1.17.3
Product / Package Ecosystem Affected Versions Fixed Version
stata-mcp
PyPI
< 1.17.3
1.17.3

References

Frequently Asked Questions

What is CVE-2026-47708?
CVE-2026-47708 is a security vulnerability in MCP-for-Stata involving Command injection via log_file_name parameter in Stata command wrapper under CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection').
Which MCP-for-Stata versions are affected?
Affected versions include releases prior to 1.17.3 across affected packages: stata-mcp.
What version fixes CVE-2026-47708?
Upgrading to 1.17.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is stata-mcp affected?
Yes, stata-mcp is affected in releases prior to 1.17.3. Upgrade your dependency to 1.17.3 or later.
What CWE is associated with CVE-2026-47708?
CVE-2026-47708 is classified under CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection') (The product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component.).
How can I check PyPI dependencies for CVE-2026-47708?
Run the dependency tree command: 'pip show stata-mcp'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-4p62-hqp5-g644",
  "modified" : "2026-06-04T21:00:42Z",
  "published" : "2026-06-04T21:00:42Z",
  "aliases" : [ "CVE-2026-47708" ],
  "summary" : "MCP-for-Stata: Command injection via log_file_name parameter in Stata command wrapper",
  "details" : "### 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",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "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"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "stata-mcp"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.17.3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/SepineTam/stata-mcp/security/advisories/GHSA-4p62-hqp5-g644"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/SepineTam/mcp-for-stata/issues/74"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/SepineTam/mcp-for-stata/commit/e6f945941ae0c7cf5e74a428e0b3dc82b396382f"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/SepineTam/stata-mcp"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-77" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-06-04T21:00:42Z",
    "nvd_published_at" : null
  }
}