mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-12 11:13:21 +02:00
Add some validation on values provided to USER_DISABLED_FEATURES and EXTERNAL_USER_DISABLED_FEATURES (#36688)
This commit is contained in:
parent
8051056075
commit
7012c969b6
@ -5,6 +5,7 @@ package setting
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"code.gitea.io/gitea/modules/container"
|
"code.gitea.io/gitea/modules/container"
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Admin settings
|
// Admin settings
|
||||||
@ -15,12 +16,33 @@ var Admin struct {
|
|||||||
ExternalUserDisableFeatures container.Set[string]
|
ExternalUserDisableFeatures container.Set[string]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var validUserFeatures = container.SetOf(
|
||||||
|
UserFeatureDeletion,
|
||||||
|
UserFeatureManageSSHKeys,
|
||||||
|
UserFeatureManageGPGKeys,
|
||||||
|
UserFeatureManageMFA,
|
||||||
|
UserFeatureManageCredentials,
|
||||||
|
UserFeatureChangeUsername,
|
||||||
|
UserFeatureChangeFullName,
|
||||||
|
)
|
||||||
|
|
||||||
func loadAdminFrom(rootCfg ConfigProvider) {
|
func loadAdminFrom(rootCfg ConfigProvider) {
|
||||||
sec := rootCfg.Section("admin")
|
sec := rootCfg.Section("admin")
|
||||||
Admin.DisableRegularOrgCreation = sec.Key("DISABLE_REGULAR_ORG_CREATION").MustBool(false)
|
Admin.DisableRegularOrgCreation = sec.Key("DISABLE_REGULAR_ORG_CREATION").MustBool(false)
|
||||||
Admin.DefaultEmailNotification = sec.Key("DEFAULT_EMAIL_NOTIFICATIONS").MustString("enabled")
|
Admin.DefaultEmailNotification = sec.Key("DEFAULT_EMAIL_NOTIFICATIONS").MustString("enabled")
|
||||||
Admin.UserDisabledFeatures = container.SetOf(sec.Key("USER_DISABLED_FEATURES").Strings(",")...)
|
Admin.UserDisabledFeatures = container.SetOf(sec.Key("USER_DISABLED_FEATURES").Strings(",")...)
|
||||||
Admin.ExternalUserDisableFeatures = container.SetOf(sec.Key("EXTERNAL_USER_DISABLE_FEATURES").Strings(",")...).Union(Admin.UserDisabledFeatures)
|
Admin.ExternalUserDisableFeatures = container.SetOf(sec.Key("EXTERNAL_USER_DISABLE_FEATURES").Strings(",")...).Union(Admin.UserDisabledFeatures)
|
||||||
|
|
||||||
|
for feature := range Admin.UserDisabledFeatures {
|
||||||
|
if !validUserFeatures.Contains(feature) {
|
||||||
|
log.Warn("USER_DISABLED_FEATURES contains unknown feature %q", feature)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for feature := range Admin.ExternalUserDisableFeatures {
|
||||||
|
if !validUserFeatures.Contains(feature) && !Admin.UserDisabledFeatures.Contains(feature) {
|
||||||
|
log.Warn("EXTERNAL_USER_DISABLE_FEATURES contains unknown feature %q", feature)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user