Bound every slog line against client-chosen text (closes #176)
All checks were successful
check / check (push) Successful in 2m55s

This commit was merged in pull request #180.
This commit is contained in:
2026-08-18 06:03:10 +02:00
parent f6ec78e2c8
commit 563e834cf2
15 changed files with 1782 additions and 171 deletions

View File

@@ -7,6 +7,8 @@ import (
"net/http"
"sync"
"time"
"sneak.berlin/go/webhooker/internal/logfield"
)
const (
@@ -372,8 +374,17 @@ func (m *Middleware) RecordLoginFailure(
) bool {
throttled := m.guard().fail(m.clientKey(r), username)
if throttled {
// Truncated even though chi pins this route's path to
// the 12-byte constant "/pages/login": RecordLoginFailure
// is exported and takes any *http.Request, so a caller on
// a route with a URL parameter would otherwise widen this
// line. logbound_test.go pins the cap by making exactly
// that call, since no request through the mux can.
m.log.Warn(
"login failure limit exceeded", "path", r.URL.Path,
"login failure limit exceeded",
"path", logfield.Truncate(
r.URL.Path, logfield.MaxBytes,
),
)
}