Skip to content

Commit

Permalink
Allow to disable CSP from config file (can be useful with docker)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Jun 29, 2018
1 parent a7e2380 commit 72f36d3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
11 changes: 2 additions & 9 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

var flagAllowRoot bool
var flagAppdirs []string
var flagDisableCSP bool
var flagDevMode bool

// serveCmd represents the serve command
Expand Down Expand Up @@ -59,13 +58,6 @@ example), you can use the --appdir flag like this:
config.BuildMode = config.ModeDev
}

if flagDisableCSP {
if !config.IsDevRelease() {
return errors.New("Using --disable-csp is allowed only for development")
}
config.GetConfig().CSPDisabled = true
}

var apps map[string]string
if len(flagAppdirs) > 0 {
apps = make(map[string]string)
Expand Down Expand Up @@ -218,7 +210,8 @@ func init() {
flags.BoolVar(&flagAllowRoot, "allow-root", false, "Allow to start as root (disabled by default)")
flags.StringSliceVar(&flagAppdirs, "appdir", nil, "Mount a directory as the 'app' application")

flags.BoolVar(&flagDisableCSP, "disable-csp", false, "Disable the Content Security Policy (only available for development)")
flags.Bool("disable-csp", false, "Disable the Content Security Policy (only available for development)")
checkNoErr(viper.BindPFlag("disable_csp", flags.Lookup("disable-csp")))

flags.String("csp-whitelist", "", "Whitelisted domains for the default allowed origins of the Content Secury Policy")
checkNoErr(viper.BindPFlag("csp_whitelist", flags.Lookup("csp-whitelist")))
Expand Down
3 changes: 3 additions & 0 deletions cozy.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ csp_whitelist:
# style: https://whitelisted.domain.com/
# font: https://whitelisted.domain.com/

# It can useful to disable the CSP policy to debug and test things in local
# disable_csp: true

log:
# logger level (debug, info, warning, panic, fatal) - flags: --log-level
level: info
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,10 @@ func UseViper(v *viper.Viper) error {
CSPWhitelist: v.GetStringMapString("csp_whitelist"),
}

if IsDevRelease() && v.GetBool("disable_csp") {
config.CSPDisabled = true
}

return logger.Init(config.Logger)
}

Expand Down

0 comments on commit 72f36d3

Please sign in to comment.