Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(mcp): stop stdio transport from force-enabling shell tools (GHSA-6wjh)

Haozhe Wu106edbdb41db
diff --git a/README.md b/README.md
index 8a76fa7c2..7c502bbc7 100644
--- a/README.md
+++ b/README.md
@@ -927,7 +927,7 @@ Interactive docs: `http://localhost:8899/docs`
For localhost development, `vibe-trading serve` keeps the browser workflow simple. For any non-local client, sensitive API endpoints require `API_AUTH_KEY`; use `Authorization: Bearer <key>` for JSON/upload requests. Browser EventSource streams are handled by the Web UI after you enter the same key once in Settings.
-Shell-capable tools are available to local CLI and trusted localhost workflows, but are not exposed to remote API sessions unless you explicitly set `VIBE_TRADING_ENABLE_SHELL_TOOLS=1`. Document and journal readers are limited to upload/import roots by default; place files under `agent/uploads`, `agent/runs`, `./uploads`, `./data`, `~/.vibe-trading/uploads`, or `~/.vibe-trading/imports`, or add a dedicated directory through `VIBE_TRADING_ALLOWED_FILE_ROOTS`.
+Shell-capable tools (`bash` / `background_run`) are enabled only for the interactive local CLI. Every other surface — the HTTP/SSE API and the MCP server on **all** transports (stdio included) — keeps them off unless you explicitly opt in with `VIBE_TRADING_ENABLE_SHELL_TOOLS=1` (or pass `--enable-shell-tools` to `vibe-trading-mcp`). Transport type never implicitly grants shell access. Document and journal readers are limited to upload/import roots by default; place files under `agent/uploads`, `agent/runs`, `./uploads`, `./data`, `~/.vibe-trading/uploads`, or `~/.vibe-trading/imports`, or add a dedicated directory through `VIBE_TRADING_ALLOWED_FILE_ROOTS`.
Generated backtest code runs as a local Python subprocess and can make network requests through the configured market-data loaders. Its environment is intentionally narrow: the runner keeps OS/Python basics, proxy/certificate settings, `VIBE_TRADING_ALLOWED_RUN_ROOTS`, and read-only market-data keys such as `TUSHARE_TOKEN`, `FMP_API_KEY`, `FRED_API_KEY`, and `VIBE_TRADING_IWENCAI_KEY`. It does not pass LLM provider keys, API auth tokens, shell-tool switches, broker trading secrets, or live/advisory toggles to generated strategy code by default.
diff --git a/README_ar.md b/README_ar.md
index 0adf59036..56dc63d69 100644
--- a/README_ar.md
+++ b/README_ar.md
@@ -869,7 +869,7 @@ vibe-trading serve --port 8899
للتطوير على localhost، يبقي `vibe-trading serve` سير المتصفح بسيطاً. لأي عميل غير محلي، تتطلب نقاط API الحساسة `API_AUTH_KEY`؛ استخدم `Authorization: Bearer <key>` لطلبات JSON/الرفع. تتعامل Web UI مع تدفقات Browser EventSource بعد إدخال المفتاح نفسه مرة واحدة في Settings.
-تتوفر الأدوات القادرة على shell للـ CLI المحلي وتدفقات localhost الموثوقة، لكنها لا تُعرض لجلسات API البعيدة ما لم تضبط صراحة `VIBE_TRADING_ENABLE_SHELL_TOOLS=1`. قارئات المستندات والسجلات محدودة افتراضياً بجذور الرفع/الاستيراد؛ ضع الملفات تحت `agent/uploads` أو `agent/runs` أو `./uploads` أو `./data` أو `~/.vibe-trading/uploads` أو `~/.vibe-trading/imports`، أو أضف دليلاً مخصصاً عبر `VIBE_TRADING_ALLOWED_FILE_ROOTS`.
+الأدوات القادرة على shell (`bash` / `background_run`) مفعّلة فقط لواجهة CLI المحلية التفاعلية. أما بقية الأسطح — واجهة HTTP/SSE و MCP server على **جميع** وسائط النقل (بما في ذلك stdio) — فتبقى معطّلة ما لم تفعّلها صراحة عبر `VIBE_TRADING_ENABLE_SHELL_TOOLS=1` (أو تمرير `--enable-shell-tools` إلى `vibe-trading-mcp`). نوع وسيط النقل لا يمنح صلاحية shell ضمنيًا أبدًا. قارئات المستندات والسجلات محدودة افتراضياً بجذور الرفع/الاستيراد؛ ضع الملفات تحت `agent/uploads` أو `agent/runs` أو `./uploads` أو `./data` أو `~/.vibe-trading/uploads` أو `~/.vibe-trading/imports`، أو أضف دليلاً مخصصاً عبر `VIBE_TRADING_ALLOWED_FILE_ROOTS`.
### إعدادات Web UI
diff --git a/README_ja.md b/README_ja.md
index 711cfb4f3..7afbf1605 100644
--- a/README_ja.md
+++ b/README_ja.md
@@ -866,7 +866,7 @@ Interactive docs: `http://localhost:8899/docs`
localhost 開発では、`vibe-trading serve` は browser workflow を簡単に保ちます。非ローカル client では、sensitive API endpoints に `API_AUTH_KEY` が必要です。JSON/upload requests には `Authorization: Bearer <key>` を使ってください。Browser EventSource streams は、Settings で同じ key を一度入力した後、Web UI が処理します。
-Shell-capable tools は local CLI と trusted localhost workflows で利用できますが、`VIBE_TRADING_ENABLE_SHELL_TOOLS=1` を明示的に設定しない限り remote API sessions には公開されません。Document と journal readers は既定で upload/import roots に制限されます。ファイルは `agent/uploads`、`agent/runs`、`./uploads`、`./data`、`~/.vibe-trading/uploads`、`~/.vibe-trading/imports` の下に置くか、`VIBE_TRADING_ALLOWED_FILE_ROOTS` で専用 directory を追加してください。
+Shell-capable tools(`bash` / `background_run`)はインタラクティブな local CLI でのみ有効です。それ以外のすべての面 — HTTP/SSE API と MCP server の**すべての** transport(stdio を含む)— は、`VIBE_TRADING_ENABLE_SHELL_TOOLS=1` を明示的に設定する(または `vibe-trading-mcp` に `--enable-shell-tools` を渡す)まで無効のままです。transport の種類が暗黙に shell アクセスを許可することはありません。Document と journal readers は既定で upload/import roots に制限されます。ファイルは `agent/uploads`、`agent/runs`、`./uploads`、`./data`、`~/.vibe-trading/uploads`、`~/.vibe-trading/imports` の下に置くか、`VIBE_TRADING_ALLOWED_FILE_ROOTS` で専用 directory を追加してください。
### Web UI Settings
diff --git a/README_ko.md b/README_ko.md
index 027f99388..5c7ac4b33 100644
--- a/README_ko.md
+++ b/README_ko.md
@@ -869,7 +869,7 @@ Interactive docs: `http://localhost:8899/docs`
localhost 개발에서 `vibe-trading serve`는 browser workflow를 단순하게 유지합니다. non-local client에서는 민감한 API endpoint에 `API_AUTH_KEY`가 필요합니다. JSON/upload request에는 `Authorization: Bearer <key>`를 사용하세요. Browser EventSource stream은 Web UI Settings에 같은 key를 한 번 입력하면 Web UI가 처리합니다.
-Shell-capable tools는 local CLI와 trusted localhost workflow에서 사용할 수 있지만, `VIBE_TRADING_ENABLE_SHELL_TOOLS=1`을 명시적으로 설정하지 않는 한 remote API session에는 노출되지 않습니다. Document와 journal reader는 기본적으로 upload/import roots로 제한됩니다. 파일은 `agent/uploads`, `agent/runs`, `./uploads`, `./data`, `~/.vibe-trading/uploads`, `~/.vibe-trading/imports` 아래에 두거나, `VIBE_TRADING_ALLOWED_FILE_ROOTS`로 전용 directory를 추가하세요.
+Shell-capable tools(`bash` / `background_run`)는 대화형 local CLI에서만 활성화됩니다. 그 외 모든 표면 — HTTP/SSE API와 MCP server의 **모든** transport(stdio 포함) — 는 `VIBE_TRADING_ENABLE_SHELL_TOOLS=1`을 명시적으로 설정하지 않는 한(또는 `vibe-trading-mcp`에 `--enable-shell-tools`를 전달하지 않는 한) 비활성 상태로 유지됩니다. transport 종류가 암묵적으로 shell 접근을 부여하는 일은 없습니다. Document와 journal reader는 기본적으로 upload/import roots로 제한됩니다. 파일은 `agent/uploads`, `agent/runs`, `./uploads`, `./data`, `~/.vibe-trading/uploads`, `~/.vibe-trading/imports` 아래에 두거나, `VIBE_TRADING_ALLOWED_FILE_ROOTS`로 전용 directory를 추가하세요.
### Web UI Settings
diff --git a/README_zh.md b/README_zh.md
index a5775cf69..5b26f55d0 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -894,7 +894,7 @@ vibe-trading serve --port 8899
对于 localhost 开发,`vibe-trading serve` 会保持浏览器工作流简单。对任何非本地客户端,敏感 API endpoints 都要求 `API_AUTH_KEY`;JSON/upload 请求请使用 `Authorization: Bearer <key>`。浏览器 EventSource streams 会在你于 Settings 中输入同一个 key 后由 Web UI 处理。
-Shell-capable tools 可用于本地 CLI 与可信 localhost 工作流,但不会暴露给远程 API sessions,除非你显式设置 `VIBE_TRADING_ENABLE_SHELL_TOOLS=1`。文档和日志读取器默认限制在 upload/import roots 内;请将文件放在 `agent/uploads`、`agent/runs`、`./uploads`、`./data`、`~/.vibe-trading/uploads` 或 `~/.vibe-trading/imports` 下,或通过 `VIBE_TRADING_ALLOWED_FILE_ROOTS` 添加专用目录。
+Shell-capable tools(`bash` / `background_run`)仅对交互式本地 CLI 启用。其他所有入口 —— HTTP/SSE API 以及 MCP server 的**所有** transport(含 stdio)—— 默认关闭,除非你显式设置 `VIBE_TRADING_ENABLE_SHELL_TOOLS=1`(或给 `vibe-trading-mcp` 传 `--enable-shell-tools`)。transport 类型永远不会隐式授予 shell 访问权限。文档和日志读取器默认限制在 upload/import roots 内;请将文件放在 `agent/uploads`、`agent/runs`、`./uploads`、`./data`、`~/.vibe-trading/uploads` 或 `~/.vibe-trading/imports` 下,或通过 `VIBE_TRADING_ALLOWED_FILE_ROOTS` 添加专用目录。
### Web UI Settings
diff --git a/agent/mcp_server.py b/agent/mcp_server.py
index 6fd63361a..a659a27b1 100644
--- a/agent/mcp_server.py
+++ b/agent/mcp_server.py
@@ -81,16 +81,42 @@ logger = logging.getLogger(__name__)
_skills_loader = None
_registry = None
_goal_store = None
-_include_shell_tools = True
+# Fail-closed default: the bash / background_run shell tools are a remote
+# code-execution surface once the MCP server is reachable by any client (stdio,
+# SSE, or Streamable HTTP), so they stay OFF unless an operator explicitly opts
+# in. main() may flip this on via --enable-shell-tools or the
+# VIBE_TRADING_ENABLE_SHELL_TOOLS env var. Keeping the module-level default off
+# means an ASGI/import deployment that never calls main() also stays safe.
+_include_shell_tools = False
def _env_shell_tools_enabled() -> bool:
- """Return whether shell tools were explicitly enabled for network MCP."""
+ """Return whether shell tools were explicitly enabled via the environment."""
from src.config.accessor import get_env_config
return get_env_config().api.vibe_trading_enable_shell_tools
+def _resolve_include_shell_tools(cli_opt_in: bool) -> bool:
+ """Resolve whether the MCP server should register shell tools.
+
+ Shell tools (``bash`` / ``background_run``) run arbitrary OS commands and are
+ an RCE surface regardless of transport. They are therefore disabled for every
+ transport unless the operator explicitly opts in. Transport type never
+ implicitly grants shell access: previously ``stdio`` force-enabled these tools
+ with no opt-out (GHSA-6wjh-cc6v-xfrx), which also widened the reachable
+ surface of the ``bash`` OS-command-injection issue (GHSA-m768-22r9-h4x7).
+
+ Args:
+ cli_opt_in: Whether ``--enable-shell-tools`` was passed on the command line.
+
+ Returns:
+ True only when the operator opted in via the flag or the
+ ``VIBE_TRADING_ENABLE_SHELL_TOOLS`` environment variable.
+ """
+ return bool(cli_opt_in) or _env_shell_tools_enabled()
+
+
def _get_skills_loader():
global _skills_loader
if _skills_loader is None:
@@ -1916,8 +1942,15 @@ def main():
parser.add_argument(
"--port", type=int, default=8900, help="SSE/HTTP port (default: 8900)"
)
+ parser.add_argument(
+ "--enable-shell-tools",
+ action="store_true",
+ help="Register the bash / background_run shell tools (arbitrary OS "
+ "command execution — RCE surface). OFF by default for every transport; "
+ "equivalent to setting VIBE_TRADING_ENABLE_SHELL_TOOLS=1.",
+ )
args = parser.parse_args()
- _include_shell_tools = True if args.transport == "stdio" else _env_shell_tools_enabled()
+ _include_shell_tools = _resolve_include_shell_tools(args.enable_shell_tools)
_registry = None
_get_registry() # pre-warm: avoids deadlock when first tools/call lazy-inits inside FastMCP worker thread
diff --git a/agent/tests/test_mcp_regression.py b/agent/tests/test_mcp_regression.py
index 3e3454a46..94c90818f 100644
--- a/agent/tests/test_mcp_regression.py
+++ b/agent/tests/test_mcp_regression.py
@@ -182,6 +182,60 @@ def test_mcp_server_exposes_well_known_tool_names() -> None:
)
+# ---------------------------------------------------------------------------
+# Shell-tool opt-in policy (GHSA-6wjh-cc6v-xfrx / GHSA-m768-22r9-h4x7)
+#
+# The bash / background_run tools run arbitrary OS commands. The MCP server must
+# NOT register them unless the operator explicitly opts in — for EVERY transport.
+# stdio previously force-enabled them with no opt-out; that is the regression
+# these tests guard against.
+# ---------------------------------------------------------------------------
+
+
+def test_mcp_server_module_default_shell_tools_off() -> None:
+ """The module-level default must be fail-closed (no shell tools)."""
+ mod = _import_mcp_server()
+
+ assert mod._include_shell_tools is False
+
+
+def test_mcp_resolve_shell_tools_off_without_opt_in(monkeypatch: pytest.MonkeyPatch) -> None:
+ """No CLI flag + no env var => shell tools stay off, regardless of transport."""
+ mod = _import_mcp_server()
+ monkeypatch.setattr(mod, "_env_shell_tools_enabled", lambda: False)
+
+ assert mod._resolve_include_shell_tools(False) is False
+
+
+def test_mcp_resolve_shell_tools_cli_opt_in(monkeypatch: pytest.MonkeyPatch) -> None:
+ """The --enable-shell-tools flag turns shell tools on even with env unset."""
+ mod = _import_mcp_server()
+ monkeypatch.setattr(mod, "_env_shell_tools_enabled", lambda: False)
+
+ assert mod._resolve_include_shell_tools(True) is True
+
+
+def test_mcp_resolve_shell_tools_env_opt_in(monkeypatch: pytest.MonkeyPatch) -> None:
+ """VIBE_TRADING_ENABLE_SHELL_TOOLS=1 turns shell tools on without the flag."""
+ mod = _import_mcp_server()
+ monkeypatch.setattr(mod, "_env_shell_tools_enabled", lambda: True)
+
+ assert mod._resolve_include_shell_tools(False) is True
+
+
+def test_mcp_registry_omits_shell_tools_under_default_policy(monkeypatch: pytest.MonkeyPatch) -> None:
+ """A registry built with the server's fail-closed default omits bash tools."""
+ from src.tools import build_registry
+
+ monkeypatch.delenv("VIBE_TRADING_ENABLE_SHELL_TOOLS", raising=False)
+ mod = _import_mcp_server()
+
+ registry = build_registry(include_shell_tools=mod._include_shell_tools)
+
+ assert "bash" not in registry.tool_names
+ assert "background_run" not in registry.tool_names
+
+
class _RecordingRegistry:
"""Tiny registry stub that records MCP wrapper payloads."""