From 68cd867bf76a0bfe6c07c13acb25ac231de4998f Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sun, 12 May 2024 12:56:47 +0200 Subject: build: optimise and fix handing of csp headers in dev mode --- internal/server/mux.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'internal/server') diff --git a/internal/server/mux.go b/internal/server/mux.go index ee7daed..95b7e14 100644 --- a/internal/server/mux.go +++ b/internal/server/mux.go @@ -11,7 +11,6 @@ import ( "net/url" "os" "path" - "slices" "strconv" "time" @@ -69,8 +68,10 @@ type ResultData[T options.NixOption] struct { } func applyDevModeOverrides(config *cfg.Config) { - config.CSP.ScriptSrc = slices.Insert(config.CSP.ScriptSrc, 0, "'unsafe-inline'") - config.CSP.ConnectSrc = slices.Insert(config.CSP.ConnectSrc, 0, "'self'") + if len(config.CSP.ScriptSrc) == 0 { + config.CSP.ScriptSrc = config.CSP.DefaultSrc + } + config.CSP.ScriptSrc = append(config.CSP.ScriptSrc, "'unsafe-inline'") } func NewMux(runtimeConfig *Config) (*http.ServeMux, error) { -- cgit 1.4.1