detached 19cd78f

fix(web): send only the origin as referrer on login pages so the sign-in POST keeps its Origin

commit
19cd78fa8a5a076f5ae76f2ad87f8347e000821a
author
brice · · 2026-10-10 18:35 UTC
parent
8523225
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
2 files · +7 -3
M cmd/ermite/web_session_test.go +3 -1
@@ -127,7 +127,9 @@ func TestWebLoginEndToEnd(t *testing.T) {
127127 p := b.get(path, nil)
128128 assert.Equal(t, 200, p.status)
129129 assert.Equal(t, "no-store", p.hdr.Get("Cache-Control"))
130- assert.Equal(t, "no-referrer", p.hdr.Get("Referrer-Policy"))
130+ // Only the origin leaves the page; no-referrer would make the browser
131+ // send Origin: null on the sign-in POST.
132+ assert.Equal(t, "strict-origin", p.hdr.Get("Referrer-Policy"))
131133 assert.Contains(t, p.body, `method="post"`)
132134 assert.Contains(t, p.body, `action="`+path+`"`)
133135 assert.Nil(t, p.cookie(sessionCookie), "a GET sets no session")
@@ -127,7 +127,9 @@ func TestWebLoginEndToEnd(t *testing.T) {
127 p := b.get(path, nil)127 p := b.get(path, nil)
128 assert.Equal(t, 200, p.status)128 assert.Equal(t, 200, p.status)
129 assert.Equal(t, "no-store", p.hdr.Get("Cache-Control"))129 assert.Equal(t, "no-store", p.hdr.Get("Cache-Control"))
130- assert.Equal(t, "no-referrer", p.hdr.Get("Referrer-Policy"))130+ // Only the origin leaves the page; no-referrer would make the browser
131+ // send Origin: null on the sign-in POST.
132+ assert.Equal(t, "strict-origin", p.hdr.Get("Referrer-Policy"))
131 assert.Contains(t, p.body, `method="post"`)133 assert.Contains(t, p.body, `method="post"`)
132 assert.Contains(t, p.body, `action="`+path+`"`)134 assert.Contains(t, p.body, `action="`+path+`"`)
133 assert.Nil(t, p.cookie(sessionCookie), "a GET sets no session")135 assert.Nil(t, p.cookie(sessionCookie), "a GET sets no session")
M internal/adapters/web/session.go +4 -2
@@ -193,11 +193,13 @@ func validNonce(s string) bool {
193193 const nonceLen = 43
194194
195195 // secretPage writes a page of the login flow: never cached, and its address,
196-// which holds the link, is not sent along when the visitor follows a link.
196+// which holds the link, is never sent along: strict-origin sends only the
197+// origin. no-referrer would also turn the Origin of the sign-in POST into
198+// "null" in browsers, which the POST gate refuses.
197199 func (s *Server) secretPage(w http.ResponseWriter, r *http.Request, status int, c templ.Component) {
198200 h := w.Header()
199201 h.Set("Cache-Control", "no-store")
200- h.Set("Referrer-Policy", "no-referrer")
202+ h.Set("Referrer-Policy", "strict-origin")
201203 s.write(r.Context(), w, r, status, c)
202204 }
203205
@@ -193,11 +193,13 @@ func validNonce(s string) bool {
193 const nonceLen = 43193 const nonceLen = 43
194 194
195 // secretPage writes a page of the login flow: never cached, and its address,195 // secretPage writes a page of the login flow: never cached, and its address,
196-// which holds the link, is not sent along when the visitor follows a link.196+// which holds the link, is never sent along: strict-origin sends only the
197+// origin. no-referrer would also turn the Origin of the sign-in POST into
198+// "null" in browsers, which the POST gate refuses.
197 func (s *Server) secretPage(w http.ResponseWriter, r *http.Request, status int, c templ.Component) {199 func (s *Server) secretPage(w http.ResponseWriter, r *http.Request, status int, c templ.Component) {
198 h := w.Header()200 h := w.Header()
199 h.Set("Cache-Control", "no-store")201 h.Set("Cache-Control", "no-store")
200- h.Set("Referrer-Policy", "no-referrer")202+ h.Set("Referrer-Policy", "strict-origin")
201 s.write(r.Context(), w, r, status, c)203 s.write(r.Context(), w, r, status, c)
202 }204 }
203 205

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 4

Tags 45

↑↓ moveenter openesc close