fix(ui): preserve env var references when saving config through web UI#1377
Open
LorranHippolyte wants to merge 1 commit into
Open
fix(ui): preserve env var references when saving config through web UI#1377LorranHippolyte wants to merge 1 commit into
LorranHippolyte wants to merge 1 commit into
Conversation
GET /api/config was returning the interpolated config (with actual API
key values resolved from env vars). When the UI saved it back via
POST /api/config, the literal key values were written to disk, silently
destroying all ${VAR_NAME} placeholders.
Add readRawConfigFile() that reads and parses config.json without
calling interpolateEnvVars(), and use it exclusively in GET /api/config.
The runtime path (initConfig → readConfigFile) is unchanged.
Fixes musistudio#1373
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Problem
Closes #1373
When users configure
api_keyfields with environment variable references (e.g.${ZAI_API_KEY}), opening the web UI and saving the config silently overwrites those references with the literal resolved values — permanently exposing API keys inconfig.json.Root cause:
GET /api/configcalledreadConfigFile(), which runsinterpolateEnvVars()before returning. The UI received the interpolated config (real key values), andPOST /api/configwrote those literal values back to disk.Fix
Added
readRawConfigFile()inpackages/server/src/utils/index.ts— reads and parsesconfig.jsonvia JSON5 without callinginterpolateEnvVars(). TheGET /api/configendpoint now uses this function instead ofreadConfigFile().The existing
readConfigFile()→initConfig()runtime path is completely unchanged, so server startup behaviour is unaffected.Changes
packages/server/src/utils/index.ts— addreadRawConfigFile()(exported)packages/server/src/server.ts—GET /api/configusesreadRawConfigFile()Testing
api_key: "${MY_KEY}"inconfig.jsonccr startand openccr uiconfig.jsonstill contains${MY_KEY}(not the resolved value)