mirror of
https://github.com/cole-maxwell1/todo-hetzner.git
synced 2026-10-27 10:52:49 -05:00
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:
@@ -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)
|
||||
|
||||
@@ -56,6 +56,9 @@ func TestListRendersEscapedTodos(t *testing.T) {
|
||||
if strings.Contains(recorder.Body.String(), "<script>") || !strings.Contains(recorder.Body.String(), "<script>") {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user