Sign in

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

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0:2222/vole.git

A free and open-source forge that lives in your Git repo.

Harden the browser sign-in surface

edf9db6e07e5fd676049abcd41e78790b0953652 · Keenan Nemetz · 12d ago · parent 62b59a76

Harden the browser sign-in surface

The passkey ceremonies were the one place an anonymous client could make
the instance work, and they answered more than they had to. Sign-in told a
stranger whether an account existed, nothing bounded how often a client
could ask, an invite token sat in the request path where every access log
would keep it, and a session lookup hashed whatever cookie it was handed.

Sign-in no longer answers the question. An unknown account, a retired one
and an account with no passkey all get an ordinary assertion request
naming one credential that will not be found, which is a shape WebAuthn
cannot distinguish from a real account. Only finishing the ceremony fails,
generically.

The ceremonies are rate-limited per address (20 begins a minute, 60
finishes) and per account name (10 begins), and registration per address
(5), with 429 and Retry-After past the budget. The in-flight ceremony map
is capped at 4096 entries, swept on every put, five-minute TTL, so a
client that never finishes one cannot grow it. The key is the configured
trusted-proxy header when there is one, the connection otherwise.

Enrollment tokens moved into the URL fragment: /invite#<token> is never
sent to the server, so it reaches no log of ours and no proxy access log,
and no referrer carries it. Links in the old /invite/<token> shape are
redirected into the fragment, and the paths this instance does log are
redacted. The page itself renders before the token is known, so the
account name appears only after the ceremony.

CSRF checks no longer parse the request body. JSON endpoints require the
X-Vole-CSRF header; form endpoints parse a body that readForm has already
bounded with MaxBytesReader, and then compare the field or the header.
Logout bounds its body before parsing and answers a client with no
session the same way it answers a successful sign-out.

Sign-in, registration, enrollment, the account page and the admin invite
page are no-store, no-cache and no-referrer. HSTS now follows the
transport rather than the passkey feature: a request over TLS, or an
https public_url, is an HTTPS instance whether or not browser sign-in is
configured.

Sessions refuse a cookie that is not the shape this store issues (base64url,
at most 64 characters) before hashing or querying it, and the stored
User-Agent is cut to 256 bytes.

A passkey whose signature counter does not advance is refused at sign-in
and recorded as auth.clone-warning. The policy is documented; the trade is
that an authenticator with a broken counter needs an admin to remove its
passkey.

Tests: the limiter's window and per-key budgets, 429 with Retry-After on a
real begin, the decoy's shape and its silence about account state, the
ceremony cap and its sweep, the JSON endpoints refusing a form CSRF field,
HSTS across TLS/proxy/http, no-store on the auth pages, the invite token
redacted from a logged server error, the legacy invite redirect, logout
refusing an oversized body, the account page's headers, session token
shape and User-Agent truncation.

server/web/web.go +17−2

@@ -15,6 +15,7 @@ package web
15 15 import (
16 16 "html/template"
17 17 "net/http"
18 "strings"
18 19 "sync"
19 20 "time"
20 21
@@ -66,6 +67,9 @@ type Web struct {
66 67
67 68 // statusCache holds the last filesystem walk shown on the status page.
68 69 statusCache statusCache
70
71 // limits bounds the authentication ceremonies; see ratelimit.go.
72 limits authLimits
69 73 }
70 74
71 75 func New(repos *repo.Store, ix *index.Store, ident *identity.Store, rs *runs.Store, cfg *config.Config) (*Web, error) {
@@ -75,7 +79,7 @@ func New(repos *repo.Store, ix *index.Store, ident *identity.Store, rs *runs.Sto
75 79 }
76 80 w := &Web{Repos: repos, Index: ix, Ident: ident, Runs: rs, Cfg: cfg,
77 81 Auth: auth, Ceremonies: newCeremonyStore(), Started: time.Now().UTC(),
78 sem: make(chan struct{}, archiveConc)}
82 sem: make(chan struct{}, archiveConc), limits: newAuthLimits()}
79 83 // The templates are parsed after the Web exists because two of the functions
80 84 // they call (who, nav) read the roster through the Web: metadata files carry
81 85 // account names, and a page should show the account name for either.
@@ -123,11 +127,22 @@ func (w *Web) notFound(rw http.ResponseWriter, r *http.Request) {
123 127 // NotFoundPage is the catch-all route. It uses the same view as every other 404.
124 128 func (w *Web) NotFoundPage(rw http.ResponseWriter, r *http.Request) { w.notFound(rw, r) }
125 129
130 // loggablePath is a request path with any secret in it removed. An enrollment
131 // link used to carry its token as a path segment, and a log is read by far more
132 // people than a link is sent to; a client following an old link must not be able
133 // to put that secret in the log by making the page fail.
134 func loggablePath(p string) string {
135 if strings.HasPrefix(p, "/invite/") {
136 return "/invite/[redacted]"
137 }
138 return p
139 }
140
126 141 // serverError is the styled 500. The detail goes to the log rather than the
127 142 // page: a store path or a stack trace is not something a browser should learn.
128 143 func (w *Web) serverError(rw http.ResponseWriter, r *http.Request, detail string) {
129 144 if detail != "" && w.Logger != nil {
130 w.Logger("server error %s %s: %s", r.Method, r.URL.Path, detail)
145 w.Logger("server error %s %s: %s", r.Method, loggablePath(r.URL.Path), detail)
131 146 }
132 147 w.render(rw, "servererror", struct {
133 148 Page