From 55968280bafa272d89192706cabdd88020e69fb9 Mon Sep 17 00:00:00 2001
From: Will McCutchen <will@mccutch.org>
Date: Fri, 13 Oct 2017 18:53:09 -0700
Subject: [PATCH] Add Content-Security-Policy header to index page

---
 httpbin/handlers.go      | 1 +
 httpbin/handlers_test.go | 1 +
 2 files changed, 2 insertions(+)

diff --git a/httpbin/handlers.go b/httpbin/handlers.go
index 3896c28..9a4349d 100644
--- a/httpbin/handlers.go
+++ b/httpbin/handlers.go
@@ -34,6 +34,7 @@ func (h *HTTPBin) Index(w http.ResponseWriter, r *http.Request) {
 		http.Error(w, "Not Found", http.StatusNotFound)
 		return
 	}
+	w.Header().Set("Content-Security-Policy", "default-src 'self'; style-src 'unsafe-inline'")
 	writeHTML(w, assets.MustAsset("index.html"), http.StatusOK)
 }
 
diff --git a/httpbin/handlers_test.go b/httpbin/handlers_test.go
index c341343..9a94a02 100644
--- a/httpbin/handlers_test.go
+++ b/httpbin/handlers_test.go
@@ -64,6 +64,7 @@ func TestIndex(t *testing.T) {
 	handler.ServeHTTP(w, r)
 
 	assertContentType(t, w, htmlContentType)
+	assertHeader(t, w, "Content-Security-Policy", "default-src 'self'; style-src 'unsafe-inline'")
 	assertBodyContains(t, w, "go-httpbin")
 }
 
-- 
GitLab