diff --git a/docs/self-host.md b/docs/self-host.md
index 55f3788..7d37a2e 100644
--- a/docs/self-host.md
+++ b/docs/self-host.md
@@ -26,8 +26,10 @@ requires ≥ 1.27.1).
Guarantees: passwords are bcrypt; git tokens are stored only as SHA-256
digests; the data dir is 0700 and the SQLite file 0600; all SQL is
parameterized; every page sets `X-Frame-Options: DENY`,
-`X-Content-Type-Options: nosniff`, `Referrer-Policy: no-referrer`, and a
-restrictive `Permissions-Policy`; `/raw` and release downloads additionally
+`X-Content-Type-Options: nosniff`, `Referrer-Policy: same-origin` (not
+`no-referrer` — that policy makes browsers send a literal `Origin: null` on
+same-origin form POSTs, which would break the Origin-based CSRF check), and
+a restrictive `Permissions-Policy`; `/raw` and release downloads additionally
set `Content-Security-Policy: default-src 'none'` and force
`text/plain`/`octet-stream` with `Content-Disposition: attachment`.
diff --git a/internal/web/web.go b/internal/web/web.go
index a8afbbc..22ccd6b 100644
--- a/internal/web/web.go
+++ b/internal/web/web.go
@@ -180,9 +180,14 @@ func (s *Server) Handler() http.Handler {
// Site-wide hardening: pages are never meaningfully frameable, every
// response carries an explicit type, repo URLs never leak in a
// Referer, and no powerful browser features are exposed.
+ // same-origin (not no-referrer): no-referrer makes browsers send a
+ // literal "Origin: null" on same-origin form POSTs (spec behaviour),
+ // which breaks the sameOrigin CSRF check on every login/settings
+ // form. same-origin still withholds the referrer on cross-origin
+ // navigations.
w.Header().Set("X-Frame-Options", "DENY")
w.Header().Set("X-Content-Type-Options", "nosniff")
- w.Header().Set("Referrer-Policy", "no-referrer")
+ w.Header().Set("Referrer-Policy", "same-origin")
w.Header().Set("Permissions-Policy", "geolocation=(), microphone=(), camera=()")
if r.URL.Path == "/static/chroma.css" {
w.Header().Set("Content-Type", "text/css; charset=utf-8")
diff --git a/internal/web/web_test.go b/internal/web/web_test.go
index 54da615..03d73c2 100644
--- a/internal/web/web_test.go
+++ b/internal/web/web_test.go
@@ -280,8 +280,8 @@ func TestSecurityHeaders(t *testing.T) {
if got := resp.Header.Get("X-Content-Type-Options"); got != "nosniff" {
t.Errorf("X-Content-Type-Options = %q, want nosniff", got)
}
- if got := resp.Header.Get("Referrer-Policy"); got != "no-referrer" {
- t.Errorf("Referrer-Policy = %q, want no-referrer", got)
+ if got := resp.Header.Get("Referrer-Policy"); got != "same-origin" {
+ t.Errorf("Referrer-Policy = %q, want same-origin", got)
}
if got := resp.Header.Get("Permissions-Policy"); got == "" {
t.Error("Permissions-Policy header missing")
web: use Referrer-Policy same-origin, not no-referrer
no-referrer makes browsers send a literal "Origin: null" on same-origin form POSTs (WHATWG HTML/Fetch behaviour, confirmed in Chromium and Firefox), so the sameOrigin CSRF check rejected every login/settings form with "cross-origin request rejected". same-origin still withholds the referrer on cross-origin navigations. Rejecting "null" is kept.
2fe5bbcd90cd2133b5bc58ba52ecfa5e663290bb
cjosie <administrator@josie-c.com> · 2026-10-16T18:35 ·
browse files at this commit
parents:
dbd235a