feat(security): #278 update csp directives
This commit was merged in pull request #279.
This commit is contained in:
@@ -4,10 +4,25 @@ import "net/http"
|
|||||||
|
|
||||||
func ContentSecurityPolicy(next http.Handler) http.Handler {
|
func ContentSecurityPolicy(next http.Handler) http.Handler {
|
||||||
|
|
||||||
|
values := map[string]string{
|
||||||
|
"default-src": "'none'",
|
||||||
|
"script-src": "'self' https://umami.me-fit.eu",
|
||||||
|
"connect-src": "'self' https://umami.me-fit.eu",
|
||||||
|
"img-src": "'self'",
|
||||||
|
"style-src": "'self'",
|
||||||
|
"form-action": "'self'",
|
||||||
|
"frame-ancestors": "'none'",
|
||||||
|
}
|
||||||
|
|
||||||
|
var headerValue string
|
||||||
|
for key, value := range values {
|
||||||
|
headerValue += key + " " + value + "; "
|
||||||
|
}
|
||||||
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
// While this value can be overridden, it can't be moved to after the next.ServeHTTP call,
|
// While this value can be overridden, it can't be moved to after the next.ServeHTTP call,
|
||||||
// because if the response writer get's closed, the headers can't be set anymore
|
// because if the response writer get's closed, the headers can't be set anymore
|
||||||
w.Header().Set("Content-Security-Policy", "default-src 'self' https://umami.me-fit.eu; frame-ancestors 'none'")
|
w.Header().Set("Content-Security-Policy", headerValue)
|
||||||
|
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user