Skip to main content
Menu
Advisories

Surfacing daemon and generated registrations run python -m with the project directory on sys.path

GHSA-2P94-5932-5F3PPublished Updated GitHub

Description

The surfacing daemon is started as python -m memtomem_stm daemon run --detached with the hook process's working directory inherited. Under -m, Python puts the working directory at sys.path[0], ahead of the standard library and site-packages, so a module in the project directory is imported instead of the installed one. Opening an untrusted checkout in a host that has the mms hook PostToolUse hook installed can therefore run code from that checkout as the user.

The 0.7.3 fix for GHSA-hqh4-75hx-xq46 hardened executable lookup (PATH); it does not change sys.path.

Details

  • src/memtomem_stm/daemon/spawn.py:33 builds [sys.executable, "-m", "memtomem_stm", "daemon", "run", "--detached"] and calls subprocess.Popen with no cwd=, no -P / -I, and no PYTHONSAFEPATH.
  • It is reached from src/memtomem_stm/cli/hook_cmd.py:686-690 when no warm daemon answers. hook.use_daemon and hook.auto_spawn both default to True.
  • The console-script entry points (mms, memtomem-stm, memtomem-stm-proxy) are not affected: their sys.path[0] is the script directory.

Same launch shape, confirmed by reading the source but not run end to end:

  • src/memtomem_stm/cli/proxy.py:978 (_registration_command) registers <python> -m memtomem_stm with MCP hosts, which usually start servers in the project directory.
  • src/memtomem_stm/cli/proxy.py:6549 configures the bundled demo upstream as <python> -m memtomem_stm.demo_server.

Reproduction (0.7.7 source at 38a605af, macOS, Python 3.13.2)

  1. In an empty directory create memtomem_stm/__init__.py (empty) and memtomem_stm/__main__.py that writes a marker file.
  2. With a fresh HOME (so no daemon is running) and default configuration, run from that directory: mms hook --host claude with a PostToolUse payload for Read on stdin.
  3. The marker file appears; the shadow __main__ received ['daemon', 'run', '--detached'].

A directory holding only click.py is enough as well: python -m memtomem_stm --help from there imports it. So is a types.py, in an environment that has not already loaded types at startup (a plain python -m venv).

Controls, all negative: the same command from an empty directory; the mms console script from the shadow directories; python -P -m memtomem_stm from the shadow directories.

Impact

Arbitrary code execution as the user, in a detached process, on the first eligible tool call (Read, Grep, Glob, Bash by default) made in an untrusted project directory while no daemon for the current configuration is alive. A project that merely has a top-level module whose name collides with something the daemon imports also breaks daemon startup there.

Fix

Every interpreter STM starts or registers is launched with -P (safe_module_argv() in src/memtomem_stm/utils/exec_env.py), so Python no longer puts the working directory first on its import path. A PYTHONPATH entry that names the working directory still applies; that is the user's own environment.

An in-process guard (removing the working directory from sys.path at the top of the entry modules) was tried and dropped: Python imports from the working directory before any STM code runs (runpy needs types, among others), so in a plain venv a project types.py still ran.

Remediation after upgrading

Existing registrations are kept on upgrade and still start without -P. STM cannot protect such a launch from inside, so each one has to be refreshed, passing the same --config <path> if the registration uses a non-default config:

  • project .mcp.json: from that project, mms register --client json --replace-registration (mms register prints this command when it keeps such an entry);
  • Claude Code user scope: mms register --client claude --replace-registration;
  • Codex: mms register --client codex --replace-registration;
  • a host config edited or copied by hand: insert "-P" before "-m" in the entry's args;
  • the demo upstream: set upstream_servers.demo.args in stm_proxy.json to ["-P", "-m", "memtomem_stm.demo_server"].

Verification status

Verified locally on macOS (Python 3.12, 3.13, 3.14). Windows is unverified until the post-merge CI matrix runs; -P is an interpreter flag with no platform-specific behaviour.

Affected versions

References

GitHub · memtomem/memtomem-stm