fix: safely resolve MCP environment overrides - #47
Conversation
MCP secrets are often scrubbed and replaced with {env:VAR} placeholders
by the opencode-synced plugin. However, these placeholders were not
being resolved by opencode at runtime, causing authentication failures.
This change implements a recursive environment variable resolution
mechanism in `applyOverridesToRuntimeConfig` to ensure that these
placeholders are correctly replaced with values from `process.env`.
Added tests to verify resolution of nested placeholders and handling
of missing environment variables.
Co-authored-by: iHildy <25069719+iHildy@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the application's configuration system by enabling the dynamic resolution of environment variable placeholders. This change allows sensitive information, such as secrets, to be injected into the configuration at runtime via environment variables, improving security practices and making the application more adaptable across different deployment environments without hardcoding values. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
MCP secrets are often scrubbed and replaced with {env:VAR} placeholders
by the opencode-synced plugin. However, these placeholders were not
being resolved by opencode at runtime, causing authentication failures.
This change implements a recursive environment variable resolution
mechanism in `applyOverridesToRuntimeConfig` to ensure that these
placeholders are correctly replaced with values from `process.env`.
Added tests to verify resolution of nested placeholders and handling
of missing environment variables.
Co-authored-by: iHildy <25069719+iHildy@users.noreply.github.com>
MCP secrets are often scrubbed and replaced with {env:VAR} placeholders
by the opencode-synced plugin. However, these placeholders were not
being resolved by opencode at runtime, causing authentication failures.
This change implements a recursive environment variable resolution
mechanism in `applyOverridesToRuntimeConfig` to ensure that these
placeholders are correctly replaced with values from `process.env`.
Added tests to verify resolution of nested placeholders and handling
of missing environment variables.
Co-authored-by: iHildy <25069719+iHildy@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to resolve environment variable placeholders in the configuration. The implementation adds a recursive resolveEnvPlaceholders function. My review found a critical issue in the regular expression used for placeholder matching which would cause a runtime error. I've also suggested an improvement to make the recursive function robust against circular references. Additionally, I've provided feedback on the new tests to improve their isolation and reliability by using Vitest's environment stubbing features instead of modifying process.env directly.
MCP secrets are often scrubbed and replaced with {env:VAR} placeholders
by the opencode-synced plugin. However, these placeholders were not
being resolved by opencode at runtime, causing authentication failures.
This change implements a recursive environment variable resolution
mechanism in `applyOverridesToRuntimeConfig` to ensure that these
placeholders are correctly replaced with values from `process.env`.
Added tests to verify resolution of nested placeholders and handling
of missing environment variables.
Co-authored-by: iHildy <25069719+iHildy@users.noreply.github.com>
…ers-resolution-17967297301129502178
Summary
{env:VAR}placeholders only inside parsed local overrides before merging them into OpenCode's runtime config__proto__fields before writing repo or override output0600OpenCode already substitutes placeholders found in the raw synced config before parsing. This change intentionally handles the local override file, which the plugin parses and merges later, without reprocessing or cloning the full runtime config.
Verification
bun run check— passedbun test— 123 passed, 0 failed, 269 assertionsbun run test— 123 passed, 0 failed under the repository's Vitest pre-commit runnerbun run build— passed0600, and repo-to-local restored itThe external
--enable-secretsE2E was not executed because the environment policy blocked exporting secret-bearing test payloads to GitHub. The secret path is instead covered through isolated local filesystem, scrub round-trip, permission, and real plugin-hook tests.Closes #44