refactor(configuration): ensure all keys are validated (#3208)

This ensures keys that exist in slices are validated.
pull/3081/head
James Elliott 2022-04-16 20:48:07 +10:00 committed by GitHub
parent dc7ca6f03c
commit e56690c2df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 3 deletions

View File

@ -0,0 +1,36 @@
package configuration
import (
"fmt"
"github.com/knadh/koanf"
"github.com/authelia/authelia/v4/internal/utils"
)
func getAllKoanfKeys(ko *koanf.Koanf) (keys []string) {
keys = ko.Keys()
for key, value := range ko.All() {
slc, ok := value.([]interface{})
if !ok {
continue
}
for _, item := range slc {
m, mok := item.(map[string]interface{})
if !mok {
continue
}
for k := range m {
full := fmt.Sprintf("%s[].%s", key, k)
if !utils.IsStringInSlice(full, keys) {
keys = append(keys, full)
}
}
}
}
return keys
}

View File

@ -36,7 +36,7 @@ func LoadAdvanced(val *schema.StructValidator, path string, result interface{},
unmarshal(ko, val, path, result) unmarshal(ko, val, path, result)
return ko.Keys(), nil return getAllKoanfKeys(ko), nil
} }
func unmarshal(ko *koanf.Koanf, val *schema.StructValidator, path string, o interface{}) { func unmarshal(ko *koanf.Koanf, val *schema.StructValidator, path string, o interface{}) {

View File

@ -91,7 +91,7 @@ identity_providers:
clients: clients:
- id: oidc-tester-app - id: oidc-tester-app
secret: foobar secret: foobar
policy: two_factor authorization_policy: two_factor
redirect_uris: redirect_uris:
- https://oidc.example.com:8080/oauth2/callback - https://oidc.example.com:8080/oauth2/callback
# This client is used for testing purpose. As of now, the app must be protected by ACLs # This client is used for testing purpose. As of now, the app must be protected by ACLs

View File

@ -93,7 +93,7 @@ identity_providers:
clients: clients:
- id: oidc-tester-app - id: oidc-tester-app
secret: foobar secret: foobar
policy: two_factor authorization_policy: two_factor
redirect_uris: redirect_uris:
- https://oidc.example.com:8080/oauth2/callback - https://oidc.example.com:8080/oauth2/callback
# This client is used for testing purpose. As of now, the app must be protected by ACLs # This client is used for testing purpose. As of now, the app must be protected by ACLs