Skip to content

fix(ui): preserve env var references when saving config through web UI#1377

Open
LorranHippolyte wants to merge 1 commit into
musistudio:mainfrom
LorranHippolyte:fix/ui-config-env-var-overwrite
Open

fix(ui): preserve env var references when saving config through web UI#1377
LorranHippolyte wants to merge 1 commit into
musistudio:mainfrom
LorranHippolyte:fix/ui-config-env-var-overwrite

Conversation

@LorranHippolyte
Copy link
Copy Markdown

Problem

Closes #1373

When users configure api_key fields 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 in config.json.

Root cause: GET /api/config called readConfigFile(), which runs interpolateEnvVars() before returning. The UI received the interpolated config (real key values), and POST /api/config wrote those literal values back to disk.

Fix

Added readRawConfigFile() in packages/server/src/utils/index.ts — reads and parses config.json via JSON5 without calling interpolateEnvVars(). The GET /api/config endpoint now uses this function instead of readConfigFile().

The existing readConfigFile()initConfig() runtime path is completely unchanged, so server startup behaviour is unaffected.

Changes

  • packages/server/src/utils/index.ts — add readRawConfigFile() (exported)
  • packages/server/src/server.tsGET /api/config uses readRawConfigFile()

Testing

  1. Set api_key: "${MY_KEY}" in config.json
  2. Start ccr start and open ccr ui
  3. Make any change in the UI and save
  4. Verify config.json still contains ${MY_KEY} (not the resolved value)

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>
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.

UI Save Config overwrites env var references with literal API keys

1 participant