`Client::Stdio` passes the whole parent environment to the server process
維護者通常 1 天內回覆
評估
研究方向
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 內容生成。
描述
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 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/ruby-sdk 的其他 Issue
-
Invalid UTF-8 in `MCP-Protocol-Version`, `Mcp-Method` or `Mcp-Name` gives 500 instead of 400可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 78/100
modelcontextprotocol/ruby-sdk#663 ·
維護者通常 1 天內回覆
-
Elicitation results are not checked against `requested_schema`, but the docs say they match it可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 3/5 1-2 天 新手友好度 35/100
modelcontextprotocol/ruby-sdk#661 ·
維護者通常 1 天內回覆
-
HTTP client sends handler exception messages back to the server可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 35/100
modelcontextprotocol/ruby-sdk#660 ·
維護者通常 1 天內回覆
-
`JWTVerifier` answers 500 instead of 401 for a PS256 token when it verifies with an EC key (jwt < 3.3.0)可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 3/5 1-2 天 新手友好度 35/100
modelcontextprotocol/ruby-sdk#659 ·
維護者通常 1 天內回覆
-
`logging/setLevel` from one session changes the log level of other sessions可能已有人在做 @atesgoral 今天認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 35/100
modelcontextprotocol/ruby-sdk#658 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/ruby-sdk 的全部 Issue
相似的 Issue
-
bug javascript
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 88/100
yegor256/netbout.rb#69 ·
-
難度 2/5 1-3 小時 新手友好度 84/100
yegor256/iccq.github.io#161 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
palladius/rails8-app-on-gcp#198 ·
-
bug
難度 1/5 1 小時以內 新手友好度 95/100
WikiEducationFoundation/WikiEduDashboard#7258 ·
維護者通常 1 天內回覆