VYPR
Critical severity9.8NVD Advisory· Published Apr 8, 2026· Updated Apr 14, 2026

CVE-2026-31040

CVE-2026-31040

Description

A vulnerability was identified in stata-mcp prior to v1.13.0 where insufficient validation of user-supplied Stata do-file content can lead to command execution.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
stata-mcpPyPI
< 1.13.01.13.0

Affected products

1

Patches

1
52413ce

Merge pull request #21 from 123mutouren321414/fix-stata-shell-escape

1 file changed · +23 0
  • src/stata_mcp/core/stata/stata_do/do.py+23 0 modified
    @@ -65,6 +65,29 @@ def execute_dofile(self,
                 ValueError: Unsupported operating system
                 RuntimeError: Stata execution error
             """
    +        # ===== Initial security guard: validate do-file content =====
    +        def _validate_dofile_content(text: str) -> None:
    +            """
    +            Initial security guard: reject Stata shell-escape directives
    +            like `!cmd` or `shell cmd` to prevent OS command execution.
    +            """
    +            dangerous_tokens = ["\n!", "\nshell "]
    +            for token in dangerous_tokens:
    +                if token in text:
    +                    raise ValueError(
    +                        "Shell-escape commands (!cmd or shell cmd) "
    +                        "are disabled for security reasons."
    +                    )
    +
    +        try:
    +            # Load the do-file content and validate before execution
    +            with open(dofile_path, "r", encoding="utf-8") as f:
    +                dofile_content = f.read()
    +            _validate_dofile_content(dofile_content)
    +        except Exception as e:
    +            return f"There is a security in {dofile_path}, error: {e}"
    +        # ===== End of initial security guard =====
    +                           
             nowtime = get_nowtime()
             log_name = log_file_name or nowtime
             log_file = os.path.join(self.log_file_path, f"{log_name}.log")
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

6

News mentions

0

No linked articles in our index yet.