Browse Source

feat(ui): add stdlib cross-origin protection middleware

Wrap the UI handler chain with http.CrossOriginProtection as the
outermost layer so cross-origin unsafe-method requests are rejected
via Sec-Fetch-Site/Origin checks before session lookup or token CSRF
validation runs. Stacks with the existing per-session token CSRF for
defense in depth; API handlers are unaffected.
Frédéric Guillot 3 days ago
parent
commit
deef74e75b
1 changed files with 2 additions and 2 deletions
  1. 2 2
      internal/ui/ui.go

+ 2 - 2
internal/ui/ui.go

@@ -181,6 +181,6 @@ func Serve(store *storage.Storage, pool *worker.Pool) http.Handler {
 		w.Write([]byte("User-agent: *\nDisallow: /"))
 	})
 
-	// Apply middleware chain: web session -> CSRF validation -> handlers.
-	return webSessionMiddleware.handle(csrfMiddleware.handle(mux))
+	// Apply middleware chain: cross-origin protection -> web session -> CSRF validation -> handlers.
+	return http.NewCrossOriginProtection().Handler(webSessionMiddleware.handle(csrfMiddleware.handle(mux)))
 }