From 227cd24936e9fce3bccc54d2274fc8562158bd5a Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Mon, 21 Feb 2022 16:04:59 +0100 Subject: [PATCH] Ensure logo & favicon form assets are used as default values --- system/rest/settings.go | 2 +- system/types/app_settings.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/system/rest/settings.go b/system/rest/settings.go index 61d25a375..c55c92538 100644 --- a/system/rest/settings.go +++ b/system/rest/settings.go @@ -99,5 +99,5 @@ func (ctrl *Settings) Set(ctx context.Context, r *request.SettingsSet) (interfac // // This is available to all authenticated users func (ctrl *Settings) Current(ctx context.Context, r *request.SettingsCurrent) (interface{}, error) { - return service.CurrentSettings, nil + return service.CurrentSettings.WithDefaults(), nil } diff --git a/system/types/app_settings.go b/system/types/app_settings.go index d26241a5d..5e3c5fbfc 100644 --- a/system/types/app_settings.go +++ b/system/types/app_settings.go @@ -290,6 +290,19 @@ type ( } ) +// WithDefaults sets defaults on copy (!!) of settings +// to avoid any unintended corruption or leaks +func (cs AppSettings) WithDefaults() *AppSettings { + if len(strings.TrimSpace(cs.UI.IconLogo)) == 0 { + cs.UI.IconLogo = "/assets/favicon32x32.png" + } + if len(strings.TrimSpace(cs.UI.MainLogo)) == 0 { + cs.UI.MainLogo = "/assets/logo.png" + } + + return &cs +} + func (set *ExternalAuthProvider) ValidConfiguration() bool { if !set.Enabled || set.Handle == "" || set.Key == "" || set.Secret == "" { return false