Skip to content

Implement hierarchical .env resolution and sanitize production output - #48

Open
JuanKRuiz wants to merge 3 commits into
gemini-cli-extensions:mainfrom
JuanKRuiz:env-vars-on-windows
Open

Implement hierarchical .env resolution and sanitize production output#48
JuanKRuiz wants to merge 3 commits into
gemini-cli-extensions:mainfrom
JuanKRuiz:env-vars-on-windows

Conversation

@JuanKRuiz

Copy link
Copy Markdown

Description

This Pull Request introduces a significant architectural improvement to handle environment variables securely, addressing the inherent limitations of the MCP sandbox environment within Gemini CLI, alongside a thorough cleanup of legacy telemetry.

🐛 Problem Context

Currently, the Gemini CLI orchestrator isolates MCP server child processes, preventing them from inheriting global OS environment variables (like GEMINI_API_KEY defined via export or system settings). The previous attempt to bypass this isolation forced users to hardcode sensitive API keys directly inside the gemini-extension.json manifest. This severely violates Zero Trust principles and exposes developers to high risks of credential leaks via accidental version control commits (e.g., dotfiles sync).

🚀 Features & Fixes

  • Hierarchical .env Support (Feature): Implemented an aggressive reverse-scan mechanism during the MCP server's bootstrap phase using dotenv. The server now intelligently searches for .env files locally (./.env), within the Gemini CLI concealed config folder (~/.gemini/.env), and finally at the OS user root (~/.env), safely injecting keys into the process.env V8 memory block without compromising the sandbox.
  • Telemetry Sanitization (Fix): Completely removed intrusive hardcoded debug traces (e.g., D:\Gemini\nanobanana\mcp-debug.log) and aggressive console.error logs scattered throughout imageGenerator.ts. This cleans up standard IO output streams, preventing unnecessary disk I/O and standardizing cross-platform deployment.
  • Context Optimization: Introduced .aiignore specifically allowing LLM cognitive analysis over tmp/ while isolating noisy dependencies like node_modules.
  • Security Updates: Updated .gitignore to strictly exclude .env extensions.
  • Documentation: Extensively updated README.md and CHANGELOG.md to guide users on the new secure hierarchical .env setup.

🔗 Related Issues

🧪 Testing Done

  • Verified successful environment variable injection from ~/.gemini/.env and local project paths on Windows.
  • Confirmed the absence of errant mcp-debug.log file creation upon image generation requests.
  • Verified build and TypeScript compilation (npm run build).

🛠️ Checklist

  • I have read the contributing guidelines
  • My code follows the code style of this project (npm run format, npm run lint)
  • I have updated the documentation accordingly
  • I have added/updated the CHANGELOG.md

JuanKRuiz and others added 3 commits February 28, 2026 18:46
…emini-cli-extensions#18)" -m "

- Implement multi-level .env resolution (from project root up to ~/.gemini/.env) to mitigate MCP sandbox isolation.
- Remove hardcoded mcp-debug.log and diagnostic console logging from imageGenerator.ts to sanitize production output.
- Update README.md with comprehensive .env configuration instructions and recommendations.
Fixes gemini-cli-extensions#18"
… telemetry, and diagnostic logs from image generation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Org Account + Vertex Ai API KEY not working API Key Plugin is not working Update incorrect auth documentation for ADC

1 participant