waf: each heuristic holds its own settings and parts (closes #441)
check / check (push) Failing after 2m18s

Every heuristic is a struct built once in newHandler with the settings
and collaborators it reads; no check reads the handler. The six lists
are handler fields built there. Code several heuristics share takes what
it needs as arguments or lives on a struct they hold: banMaker for bans
and their alerts, reputationHitNoter for reputation hits,
biasedThresholds for limit percentages. The handler keeps blocklists,
rateLimits, trapPaths, ruleFiles and coreRuleSet as fields too, since
refusedWhateverTheAnswer and findBesideLookup use them.

Model: opus-5-5
This commit is contained in:
sneak authored and clawbot committed 2026-11-19 19:41:05 +00:00
1 parent 433d5cc0a9
commit a46770ed58
27 files changed
+647 -334

No files matched your search

+11 -9
View File
@@ -123,10 +123,10 @@ func New(params Params) *Server {
GeoJS: h.geojs,
Anomalies: h.anomalies,
LookupFile: h.lookupFile,
Lists: h.lists,
DNSBL: h.dnsbl,
AbuseIPDB: h.abuseIPDB,
RouteWatch: h.routeWatch,
Lists: params.Lists,
DNSBL: params.DNSBL,
AbuseIPDB: params.AbuseIPDB,
RouteWatch: params.RouteWatch,
Metrics: h.metrics,
}
}
@@ -154,8 +154,10 @@ func (rq *request) refusedWhateverTheAnswer(now time.Time) bool {
return false
}
return rq.refusedByBlocklists(rq.h.lists.ListedBy(rq.client)) ||
rq.overAWholeRateLimit(now)
listedBy := rq.h.blocklists.lists.ListedBy(rq.client)
return rq.h.blocklists.refusedByBlocklists(listedBy) ||
rq.h.rateLimits.overAWholeRateLimit(rq, now)
}
// answerQuestion runs the checks on the visitor's request a question
@@ -194,7 +196,7 @@ func (h *handler) answerQuestion(w http.ResponseWriter, r *http.Request) {
if refused == nil && !underOwnPrefix {
rq.allow()
// In observe mode, what enforce mode would have refused counts here.
rq.runBanningHeuristics(r.Context(), afterAnswer())
rq.runBanningHeuristics(r.Context(), rq.h.afterAnswer)
return
}
@@ -213,7 +215,7 @@ func (h *handler) answerQuestion(w http.ResponseWriter, r *http.Request) {
)
}
rq.banAndCount(r.Context(), afterAnswer())
rq.banAndCount(r.Context(), rq.h.afterAnswer)
}
// readQuestion returns the visitor's address and the body a question carries,
@@ -486,7 +488,7 @@ func (h *handler) finishWith(
if rq.allowed {
rq.line.DurationUpstreamTotalMS = &report.DurationUpstreamTotalMS
rq.banAndCount(ctx, onReport())
rq.banAndCount(ctx, rq.h.onReport)
rq.h.metrics.RequestReported(
&rq.line,