Fix #116: allow inline styles in CSP (style-src 'self' 'unsafe-inline')
This commit is contained in:
@@ -16,7 +16,7 @@ func TestSecurityHeaders(t *testing.T) {
|
|||||||
h := SecurityHeaders(pages)
|
h := SecurityHeaders(pages)
|
||||||
rec := httptest.NewRecorder()
|
rec := httptest.NewRecorder()
|
||||||
h.ServeHTTP(rec, httptest.NewRequest("GET", "/", nil))
|
h.ServeHTTP(rec, httptest.NewRequest("GET", "/", nil))
|
||||||
wantCSP := "default-src 'self'; script-src 'self' 'unsafe-inline'; frame-ancestors 'none'"
|
wantCSP := "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'"
|
||||||
if got := rec.Header().Get("Content-Security-Policy"); got != wantCSP {
|
if got := rec.Header().Get("Content-Security-Policy"); got != wantCSP {
|
||||||
t.Errorf("CSP = %q, want %q", got, wantCSP)
|
t.Errorf("CSP = %q, want %q", got, wantCSP)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -344,7 +344,7 @@ func SecurityHeaders(next http.Handler) http.Handler {
|
|||||||
// is harmless and arguably desirable.
|
// is harmless and arguably desirable.
|
||||||
h := w.Header()
|
h := w.Header()
|
||||||
h.Set("Content-Security-Policy",
|
h.Set("Content-Security-Policy",
|
||||||
"default-src 'self'; script-src 'self' 'unsafe-inline'; frame-ancestors 'none'")
|
"default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'")
|
||||||
h.Set("Referrer-Policy", "no-referrer")
|
h.Set("Referrer-Policy", "no-referrer")
|
||||||
h.Set("X-Content-Type-Options", "nosniff")
|
h.Set("X-Content-Type-Options", "nosniff")
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
|
|||||||
Reference in New Issue
Block a user