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

Offen
#662 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@atesgoral arbeitet bereits daran.

Seit 06.11.2026.

  • #665 von @atesgoral — offen

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
ruby
Bereich
backend, security

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Ruby
Sterne
940
Forks
143
Ø Merge
1 T. 3 Std.
Gemergte PRs (30 T.)
47

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus modelcontextprotocol/ruby-sdk

Alle Issues in modelcontextprotocol/ruby-sdk

Ähnliche Issues

Weitere Issues zu Ruby

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.