enhancement: Load CSP configuration file if it exists

This commit is contained in:
Florian Schade
2024-09-23 16:12:48 +02:00
parent b3e5d80306
commit 349a25169b
2 changed files with 18 additions and 0 deletions

View File

@@ -1,7 +1,9 @@
package defaults
import (
"os"
"path"
"path/filepath"
"strings"
"time"
@@ -332,6 +334,14 @@ func Sanitize(cfg *config.Config) {
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
// if the CSP config file path is not set, we check if the default file exists and set it if it does
if cfg.CSPConfigFileLocation == "" {
defaultCSPConfigFilePath := filepath.Join(defaults.BaseDataPath(), "proxy", "csp.yaml")
if _, err := os.Stat(defaultCSPConfigFilePath); err == nil {
cfg.CSPConfigFileLocation = defaultCSPConfigFilePath
}
}
}
func mergePolicies(policies []config.Policy, additionalPolicies []config.Policy) []config.Policy {