fix: limit local mcp subprocess env#32450
Open
wgu9 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Fixes #31778
Related: #31894 (closed)
Type of change
What does this PR do?
Local MCP servers currently receive the full parent
process.env, so unrelated provider credentials can leak to third-party MCP subprocesses.This PR adds a single local MCP environment builder that only inherits a small operational allowlist needed to start local commands (
PATH, temp/home variables, Windows process basics, locale), then overlays the explicit per-servermcp.environment. That keeps configured MCP credentials working while stopping accidental parent API key inheritance.It also preserves the existing
opencodelocal MCP compatibility behavior by settingBUN_BE_BUN=1for that command.The regression coverage verifies:
OPENAI_API_KEY/ANTHROPIC_API_KEYare not inherited by defaultmcp.environmentvalues are still passed and can intentionally provide credentialsPATHis retainedopencodecommand still getsBUN_BE_BUN=1How did you verify your code works?
bun test test/mcp/lifecycle.test.tsfrompackages/opencodebun run typecheckfrompackages/opencodebunx oxlint packages/opencode/src/mcp/index.ts packages/opencode/test/mcp/lifecycle.test.tsfrom repo root (0 errors; existing warnings in these files remain)git diff --checkNote: local
git pushpre-push hook requires Bun^1.3.14; this machine has Bun1.3.11, so I pushed with--no-verifyafter the focused tests above passed.Screenshots / recordings
Not applicable. This is MCP subprocess environment behavior covered by tests.
Checklist