Count sign-in attempts per address and client, guard the sign-in form with a token, ration both forms per address

A wrong password from anywhere counted against the address, so ten locked
its owner out. Attempts are now counted per address and client, with a
looser bound per address alone. The sign-in form carries a token matched
by a cookie (login CSRF). POST /login and /signup are rationed per client
address, a hash waits at most ten seconds for a turn, and server init
writes signup_open: false.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-04 10:26:29 +02:00
1 parent f1b49d0251
commit 44cd58005a
11 files changed
+312 -22

No files matched your search

+14
View File
@@ -54,6 +54,12 @@ func (b *browser) get(path string) (int, string) {
func (b *browser) post(path string, form url.Values) (int, string, string) {
b.t.Helper()
// The sign-in form carries a token its page set, as a browser's would.
if path == "/login" && form.Get("csrf") == "" {
_, page := b.get("/login")
form = cloneValues(form)
form.Set("csrf", csrf(b.t, page))
}
req, _ := http.NewRequestWithContext(context.Background(), http.MethodPost,
b.base+path, strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
@@ -613,3 +619,11 @@ func TestChatSendNeedsItsToken(t *testing.T) {
}
}
}
func cloneValues(v url.Values) url.Values {
out := url.Values{}
for k, vs := range v {
out[k] = append([]string{}, vs...)
}
return out
}