diff --git a/server/public/model/config.go b/server/public/model/config.go index 4c314681cf3..562d4d04fad 100644 --- a/server/public/model/config.go +++ b/server/public/model/config.go @@ -3539,6 +3539,15 @@ func (s *PluginSettings) Sanitize(pluginManifests []*Manifest) { break } } + + for _, section := range manifest.SettingsSchema.Sections { + for _, definedSetting := range section.Settings { + if definedSetting.Secret && strings.EqualFold(definedSetting.Key, key) { + settings[key] = FakeSetting + break + } + } + } } } } diff --git a/server/public/model/config_test.go b/server/public/model/config_test.go index 9bf79a6e16c..05488297a10 100644 --- a/server/public/model/config_test.go +++ b/server/public/model/config_test.go @@ -1790,6 +1790,91 @@ func TestPluginSettingsSanitize(t *testing.T) { }, }, }, + "secret settings in sections are sanitized": { + manifests: []*Manifest{ + { + Id: pluginID1, + SettingsSchema: &PluginSettingsSchema{ + Settings: []*PluginSetting{ + { + Key: "somesetting", + Type: "text", + Secret: false, + }, + }, + Sections: []*PluginSettingsSection{ + { + Key: "section1", + Settings: []*PluginSetting{ + { + Key: "secrettext", + Type: "text", + Secret: true, + }, + { + Key: "secretnumber", + Type: "number", + Secret: true, + }, + }, + }, + }, + }, + }, + }, + expected: map[string]map[string]any{ + pluginID1: { + "someoldsettings": "some old value", + "somesetting": "some value", + "secrettext": FakeSetting, + "secretnumber": FakeSetting, + }, + }, + }, + "secret settings across multiple sections": { + manifests: []*Manifest{ + { + Id: pluginID1, + SettingsSchema: &PluginSettingsSchema{ + Sections: []*PluginSettingsSection{ + { + Key: "section1", + Settings: []*PluginSetting{ + { + Key: "somesetting", + Type: "text", + Secret: false, + }, + { + Key: "secrettext", + Type: "text", + Secret: true, + }, + }, + }, + { + Key: "section2", + Settings: []*PluginSetting{ + { + Key: "secretnumber", + Type: "number", + Secret: true, + }, + }, + }, + }, + }, + }, + }, + expected: map[string]map[string]any{ + pluginID1: { + "someoldsettings": "some old value", + "somesetting": "some value", + "secrettext": FakeSetting, + "secretnumber": FakeSetting, + }, + }, + }, } { t.Run(name, func(t *testing.T) { c := PluginSettings{}