don't report csp violations by default
Ted Unangst tedu@tedunangst.com
Fri, 04 Aug 2023 13:06:24 -0400
1 files changed,
8 insertions(+),
1 deletions(-)
jump to
M
web.go
→
web.go
@@ -2560,6 +2560,9 @@ }
} func fiveoh(w http.ResponseWriter, r *http.Request) { + if !develMode { + return + } fd, err := os.OpenFile("violations.json", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { elog.Printf("error opening violations! %s", err)@@ -2606,7 +2609,11 @@ }
func addcspheaders(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Security-Policy", "default-src 'none'; script-src 'self'; connect-src 'self'; style-src 'self'; img-src 'self'; media-src 'self'; report-uri /csp-violation") + policy := "default-src 'none'; script-src 'self'; connect-src 'self'; style-src 'self'; img-src 'self'; media-src 'self'" + if develMode { + policy += "; report-uri /csp-violation" + } + w.Header().Set("Content-Security-Policy", policy) next.ServeHTTP(w, r) }) }