fix(handler): preserve origin on form submissions

Use the same-origin referrer policy to prevent Chrome from sending a null Origin header on POST requests.
This commit is contained in:
cole-maxwell1
2026-08-07 15:30:49 -05:00
parent b8f655ac58
commit 94d18ff8e2
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -131,7 +131,7 @@ func (h *Handler) serverError(w http.ResponseWriter, r *http.Request, err error)
func (h *Handler) security(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Security-Policy", "default-src 'self'; style-src 'self'; form-action 'self'; frame-ancestors 'none'; base-uri 'self'")
w.Header().Set("Referrer-Policy", "no-referrer")
w.Header().Set("Referrer-Policy", "same-origin")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("X-Frame-Options", "DENY")
next.ServeHTTP(w, r)
+3
View File
@@ -56,6 +56,9 @@ func TestListRendersEscapedTodos(t *testing.T) {
if strings.Contains(recorder.Body.String(), "<script>") || !strings.Contains(recorder.Body.String(), "&lt;script&gt;") {
t.Fatalf("title was not escaped: %s", recorder.Body.String())
}
if got := recorder.Header().Get("Referrer-Policy"); got != "same-origin" {
t.Fatalf("Referrer-Policy = %q, want %q", got, "same-origin")
}
}
func TestCreateValidatesAndTrimsTitle(t *testing.T) {