`Client::Stdio` passes the whole parent environment to the server process

未關閉
#662 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@atesgoral 已經在處理了。

開始於 2026年11月6日。

  • #665 來自 @atesgoral —— 未關閉

評估

難度
4/5
預估耗時
3-5 天
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
ruby
領域
backend, security

研究方向

Read lib/mcp/client/stdio.rb at lines 169–170 and the transport documentation in docs/_client/transports.md; compare the environment behavior with the TypeScript and Python SDKs mentioned in the issue. Reproduce the leak with the provided Ruby script, then add coverage for the intended inheritance behavior. Done when only the documented environment reaches the server and the compatibility behavior is documented.

由索引模型根據 Issue 內容生成。

描述

bug

Client::Stdio#start spawns the server with Open3.popen3(@env || {}, @command, *@args) (stdio.rb:169-170). Process.spawn merges that hash into the inherited environment, so the server gets every variable of the host process (API keys, cloud credentials, tokens), not only the ones in env:.

docs/_client/transports.md describes env: as "A hash of environment variables to set for the server process" and does not say that the rest is inherited. The TypeScript SDK (DEFAULT_INHERITED_ENV_VARS in packages/client/src/stdio.ts) and the Python SDK (get_default_environment() in src/mcp/client/stdio.py) start from a short default list instead.

Repro

Run from the repository root with bundle exec ruby -I lib repro.rb:

require "mcp"

ENV["HOST_ONLY_SECRET"] = "from-host"
transport = MCP::Client::Stdio.new(
  command: "/bin/sh",
  args: ["-c", 'printf "%s\n" "$HOST_ONLY_SECRET"'],
  env: { "SERVER_SETTING" => "1" },
)
transport.start
p transport.instance_variable_get(:@stdout).gets
transport.close

Expected: "\n". Only SERVER_SETTING and a small base environment reach the server.

Actual: "from-host\n"

Suggested fix

Spawn with unsetenv_others: true and a default allow-list (for example HOME, LOGNAME, PATH, SHELL, TERM, USER), merged with env:. Add an option to inherit the full environment for applications that need it, and document the behavior. This changes behavior for applications that rely on inheritance, so it may need a deprecation step or a release note.

主要語言
Ruby
星號
940
分支
143
平均合併
1 天 3 小時
30 天內合併 PR
47

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/ruby-sdk 的其他 Issue

查看 modelcontextprotocol/ruby-sdk 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。