Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Keep no-store pages same-origin for Firefox forms

c4e9d9571b41c4d47a6467987fea4f522e6e98d5 · Keenan Nemetz · 8d ago · parent 6c694920

Keep no-store pages same-origin for Firefox forms

Firefox sends Origin: null for a form post from a document with
Referrer-Policy: no-referrer, even when the page and action are same-origin.
sameOriginRequest deliberately refuses the opaque origin, so every form on the
account, sign-in, registration, and invitation pages returned 403 before its
handler ran. Adding an SSH key from Firefox failed even with a correct CSRF
field and a freshly loaded canonical page.

noStore now keeps the referrer same-origin. That still sends no referrer to
another site, while Firefox sends the real Origin and the existing lock accepts
it. The opaque origin remains refused: this fixes the page rather than weakening
the check.

Also name the two CSRF refusal reasons so a stale form or a foreign origin is
not left as a bare bad request.

closes: 01M8AN4K0NWPEQ5CKQ934M5FV5

server/auth_test.go +36−3

@@ -131,7 +131,7 @@ func TestBrowserLoginAndInvitePages(t *testing.T) {
131 131 if got := resp.Header.Get("Cache-Control"); got != "no-store" {
132 132 t.Fatalf("invite page cache header = %q", got)
133 133 }
134 if got := resp.Header.Get("Referrer-Policy"); got != "no-referrer" {
134 if got := resp.Header.Get("Referrer-Policy"); got != "same-origin" {
135 135 t.Fatalf("invite page referrer policy = %q", got)
136 136 }
137 137 // A link in the old shape still works: it is redirected into the fragment.
@@ -819,6 +819,39 @@ func TestAccountAddsAndRemovesItsOwnSSHKey(t *testing.T) {
819 819 }
820 820 }
821 821
822 // A page left open through another sign-in carries the CSRF token of the old
823 // session. The write must not happen, and the refusal must say what to do rather
824 // than leaving the person with "bad request" and no way forward.
825 func TestAStaleAccountFormSaysToReload(t *testing.T) {
826 t.Parallel()
827 f := browserFixture(t)
828 stale, _ := f.browserSession(t, f.ownerID)
829 current, cookie := f.browserSession(t, f.ownerID)
830 pub, _ := keypair(t, filepath.Join(f.cfg.DataDir, "id_stale_form"))
831
832 resp, body := f.browserPost(t, "/-/account/keys", cookie, url.Values{
833 "csrf": {stale.CSRF}, "key": {pub},
834 })
835 if resp.StatusCode != http.StatusForbidden {
836 t.Fatalf("stale token: status=%d body=%s", resp.StatusCode, body)
837 }
838 if !strings.Contains(body, "reload") {
839 t.Fatalf("the refusal does not say how to recover:\n%s", body)
840 }
841 if a, err := f.srv.Identity.Find(f.ownerID); err != nil || len(a.Keys) != 1 {
842 t.Fatalf("the refused write changed the account: %+v, %v", a, err)
843 }
844
845 // Reloading is the repair: the same form with the current session's token
846 // adds the key.
847 resp, body = f.browserPost(t, "/-/account/keys", cookie, url.Values{
848 "csrf": {current.CSRF}, "key": {pub},
849 })
850 if resp.StatusCode != http.StatusSeeOther {
851 t.Fatalf("current token: status=%d body=%s", resp.StatusCode, body)
852 }
853 }
854
822 855 // TestDisplayNameRouteIsGone: an account is only its registered name, so there
823 856 // is no second label to change.
824 857 func TestDisplayNameRouteIsGone(t *testing.T) {
@@ -891,7 +924,7 @@ func TestLoginBeginIsRateLimited(t *testing.T) {
891 924 }
892 925
893 926 // An account page carries the session and the passkeys on it; neither is
894 // something a cache or a referrer should keep.
927 // something a cache or another origin should receive.
895 928 func TestAccountPageIsNotCached(t *testing.T) {
896 929 t.Parallel()
897 930 f := browserFixture(t)
@@ -900,7 +933,7 @@ func TestAccountPageIsNotCached(t *testing.T) {
900 933 if got := resp.Header.Get("Cache-Control"); got != "no-store" {
901 934 t.Fatalf("account page Cache-Control = %q", got)
902 935 }
903 if got := resp.Header.Get("Referrer-Policy"); got != "no-referrer" {
936 if got := resp.Header.Get("Referrer-Policy"); got != "same-origin" {
904 937 t.Fatalf("account page Referrer-Policy = %q", got)
905 938 }
906 939 }