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/web/auth.go +22−4

@@ -402,12 +402,16 @@ func (w *Web) servesHTTPS(r *http.Request) bool {
402 402 }
403 403
404 404 // noStore marks a page that must not be kept anywhere: an enrollment link, a
405 // sign-in form, an account page. The referrer is dropped as well, because the
405 // sign-in form, an account page. The referrer is kept same-origin, because the
406 406 // page's URL may itself be a secret a click would carry to somebody else.
407 //
408 // It must not be no-referrer: Firefox sends Origin: null for a form post from a
409 // no-referrer page, and sameOriginRequest refuses an opaque origin. same-origin
410 // still sends nothing to another site, which is all the URL secrecy needs.
407 411 func (w *Web) noStore(rw http.ResponseWriter) {
408 412 rw.Header().Set("Cache-Control", "no-store")
409 413 rw.Header().Set("Pragma", "no-cache")
410 rw.Header().Set("Referrer-Policy", "no-referrer")
414 rw.Header().Set("Referrer-Policy", "same-origin")
411 415 }
412 416
413 417 func (w *Web) enabled() bool { return w.Auth != nil && w.Auth.Enabled() }
@@ -550,14 +554,28 @@ func (w *Web) checkCSRF(r *http.Request) bool {
550 554 // csrfOK is the form endpoints' check: the header, or the csrf field of a body
551 555 // that readForm has already bounded and parsed.
552 556 func (w *Web) csrfOK(r *http.Request) bool {
557 return w.csrfProblem(r) == ""
558 }
559
560 // csrfProblem names why a form post was refused, so the person reading the error
561 // can tell a misconfigured origin from a page left open through another sign-in.
562 // Both answers are safe to say: neither reveals a token, and an attacker already
563 // knows where its own request came from. The token is the secret.
564 func (w *Web) csrfProblem(r *http.Request) string {
553 565 if !w.sameOriginRequest(r) {
554 return false
566 return "this request came from another origin; open the instance at its configured address and try again"
555 567 }
556 568 got := r.Header.Get("X-Vole-CSRF")
557 569 if got == "" {
558 570 got = r.PostFormValue("csrf")
559 571 }
560 return w.csrfToken(r, got)
572 if !w.csrfToken(r, got) {
573 // The token is derived from the session, so a page filled before a new
574 // sign-in carries one this session cannot verify. Reloading the page is
575 // the only safe repair: the write did not happen.
576 return "this page was opened in an earlier session; reload it and try again"
577 }
578 return ""
561 579 }
562 580
563 581 // sameOriginRequest is the second lock on the same door as the CSRF token: when the