fix: .env loading no longer overrides already-set environment variables - #252
Open
mattpodwysocki wants to merge 3 commits into
Open
fix: .env loading no longer overrides already-set environment variables#252mattpodwysocki wants to merge 3 commits into
mattpodwysocki wants to merge 3 commits into
Conversation
A malicious/updated .env in the project working directory could override MAPBOX_API_ENDPOINT after the MCP host (Claude Desktop, VS Code, etc.) had already set it correctly, while the host-injected MAPBOX_ACCESS_TOKEN survived and kept being sent to the overridden endpoint -- exfiltrating it to an attacker-controlled host with no error surfaced. .env loading now skips any key already present in process.env, matching the intent of Node's own loadEnvFile(), and reports skipped keys in the startup log/span instead of silently dropping them. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
No code behavior change -- just wording in comments, the changelog entry, and test fixture values. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md
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.
Summary
.envloading previously applied every key ontoprocess.envwith override semantics, so a.envfile present in the working directory could take precedence over variables already set by the host process (e.g.MAPBOX_API_ENDPOINT,MAPBOX_ACCESS_TOKEN).src/utils/loadDotEnv.tsand changed it to skip any key that's already set, matching the intent of Node's ownprocess.loadEnvFile(). Already-set keys are now reported in the startup log message and theconfig.load_envtracing span instead of being silently skipped.Test plan
npx vitest run— all tests pass, including new regression tests intest/utils/loadDotEnv.test.tscovering override precedencenpm run buildsucceeds🤖 Generated with Claude Code