refactor(configuration): ensure all keys are validated (#3208)
This ensures keys that exist in slices are validated.pull/3081/head
parent
dc7ca6f03c
commit
e56690c2df
|
@ -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
|
||||||
|
}
|
|
@ -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{}) {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue