Skip to content

fix(settings): strip env-supplied ApiKeys from the request before persisting#9438

Merged
mudler merged 1 commit intomudler:masterfrom
SAY-5:fix/settings-api-keys-duplicate-9071
Apr 20, 2026
Merged

fix(settings): strip env-supplied ApiKeys from the request before persisting#9438
mudler merged 1 commit intomudler:masterfrom
SAY-5:fix/settings-api-keys-duplicate-9071

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented Apr 20, 2026

Fixes #9071.

GET /api/settings returns settings.ApiKeys as the merged env+runtime list via ApplicationConfig.ToRuntimeSettings(). The WebUI displays that list and round-trips it back on POST /api/settings unchanged.

UpdateSettingsEndpoint was then doing:

appConfig.ApiKeys = append(envKeys, runtimeKeys...)

where runtimeKeys already contained envKeys (because the UI got them from the merged GET). Every save therefore duplicated the env keys on top of the previous merge, and also wrote the duplicates to runtime_settings.json so the duplication survived restarts and compounded with each save. That is the user-visible behaviour in the recording on #9071: the Web UI shows the keys twice / three times after consecutive saves.

Before we marshal the settings to disk or call ApplyRuntimeSettings, drop any incoming key that already appears in startupConfig.ApiKeys. The file on disk now stores only the genuinely runtime-added keys; the subsequent append(envKeys, runtimeKeys...) produces one copy of each env key, as intended. Behaviour is unchanged for users who never had env keys set.

…sisting

GET /api/settings returns settings.ApiKeys as the merged env+runtime list
via ApplicationConfig.ToRuntimeSettings(). The WebUI displays that list and
round-trips it back on POST /api/settings unchanged.

UpdateSettingsEndpoint was then doing:

    appConfig.ApiKeys = append(envKeys, runtimeKeys...)

where runtimeKeys already contained envKeys (because the UI got them from
the merged GET). Every save therefore duplicated the env keys on top of
the previous merge, and also wrote the duplicates to runtime_settings.json
so the duplication survived restarts and compounded with each save. This
is the user-visible behaviour in mudler#9071: the Web UI shows the keys
twice / three times after consecutive saves.

Before we marshal the settings to disk or call ApplyRuntimeSettings, drop
any incoming key that already appears in startupConfig.ApiKeys. The file
on disk now stores only the genuinely runtime-added keys; the subsequent
append(envKeys, runtimeKeys...) produces one copy of each env key, as
intended. Behaviour is unchanged for users who never had env keys set.

Fixes mudler#9071
@mudler mudler merged commit 6480715 into mudler:master Apr 20, 2026
1 check failed
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.

Saving settings duplicates API keys

2 participants