Allow Google's sign-in page as a form target
Connect Search Console posts a form that redirects to accounts.google.com, which the Content-Security-Policy's form-action didn't list, so browsers refused it silently. A test now checks every sign-in host is allowed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -128,3 +128,15 @@ func TestSearchConsole(t *testing.T) {
|
|||||||
t.Error("thresholds weren't saved")
|
t.Error("thresholds weren't saved")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A form that leads to a sign-in page is refused by the browser unless the
|
||||||
|
// page's security policy allows that host as a form target.
|
||||||
|
func TestSignInHostsAllowedAsFormTargets(t *testing.T) {
|
||||||
|
_, h := newTestServer(t, nil)
|
||||||
|
csp := do(h, http.MethodGet, "/", nil, nil).Header().Get("Content-Security-Policy")
|
||||||
|
for _, host := range []string{"https://twitter.com", "https://www.linkedin.com", "https://www.reddit.com", "https://accounts.google.com"} {
|
||||||
|
if !strings.Contains(csp, host) {
|
||||||
|
t.Errorf("form-action lacks %s: %s", host, csp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ func (s *Server) guard(next http.Handler) http.Handler {
|
|||||||
h.Set("X-Frame-Options", "DENY")
|
h.Set("X-Frame-Options", "DENY")
|
||||||
h.Set("X-Content-Type-Options", "nosniff")
|
h.Set("X-Content-Type-Options", "nosniff")
|
||||||
h.Set("Referrer-Policy", "same-origin")
|
h.Set("Referrer-Policy", "same-origin")
|
||||||
h.Set("Content-Security-Policy", "default-src 'self'; img-src 'self' data:; style-src 'self'; script-src 'self'; form-action 'self' https://twitter.com https://x.com https://www.linkedin.com https://www.reddit.com https://old.reddit.com; frame-ancestors 'none'")
|
h.Set("Content-Security-Policy", "default-src 'self'; img-src 'self' data:; style-src 'self'; script-src 'self'; form-action 'self' https://twitter.com https://x.com https://www.linkedin.com https://www.reddit.com https://old.reddit.com https://accounts.google.com; frame-ancestors 'none'")
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user