From 429cc20eb7935b3e3f9ee945a130c3b72c63b50d Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sun, 10 Sep 2017 08:28:12 +0000 Subject: [PATCH] cmd/syncthing: Add some common security releated HTTP headers (fixes #4360) GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4361 --- cmd/syncthing/gui.go | 25 +++++++++++++++++++++++-- cmd/syncthing/gui_statics.go | 12 ++++++------ lib/config/guiconfiguration.go | 21 +++++++++++---------- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index b15881bf..57134d45 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -332,7 +332,7 @@ func (s *apiService) Serve() { } // Add the CORS handling - handler = corsMiddleware(handler) + handler = corsMiddleware(handler, guiCfg.InsecureAllowFrameLoading) if addressIsLocalhost(guiCfg.Address()) && !guiCfg.InsecureSkipHostCheck { // Verify source host @@ -459,7 +459,7 @@ func debugMiddleware(h http.Handler) http.Handler { }) } -func corsMiddleware(next http.Handler) http.Handler { +func corsMiddleware(next http.Handler, allowFrameLoading bool) http.Handler { // Handle CORS headers and CORS OPTIONS request. // CORS OPTIONS request are typically sent by browser during AJAX preflight // when the browser initiate a POST request. @@ -486,6 +486,27 @@ func corsMiddleware(next http.Handler) http.Handler { return } + // Other security related headers that should be present. + // https://www.owasp.org/index.php/Security_Headers + + if !allowFrameLoading { + // We don't want to be rendered in an