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