waf: each heuristic holds its own settings and parts (closes #441)
check / check (push) Failing after 2m18s
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:
1 parent
433d5cc0a9
commit
a46770ed58
27 files changed
+647
-334
No files matched your search
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"sneak.berlin/go/smallwebwaf/internal/bans"
|
||||
"sneak.berlin/go/smallwebwaf/internal/config"
|
||||
"sneak.berlin/go/smallwebwaf/internal/metrics"
|
||||
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
||||
"sneak.berlin/go/smallwebwaf/internal/rules"
|
||||
)
|
||||
@@ -22,11 +23,15 @@ import (
|
||||
// mode raises the alert for the ban
|
||||
// it would have made. Either rule's match is noted as an offence, for the
|
||||
// client's history. Its figures are the rule's id and action.
|
||||
type ruleFiles struct{}
|
||||
type ruleFiles struct {
|
||||
rules *rules.Files
|
||||
metrics *metrics.Metrics
|
||||
banMaker banMaker
|
||||
}
|
||||
|
||||
func (ruleFiles) name() string { return "rule_files" }
|
||||
|
||||
func (ruleFiles) check(
|
||||
func (r ruleFiles) check(
|
||||
_ context.Context,
|
||||
rq *request,
|
||||
now time.Time,
|
||||
@@ -35,7 +40,7 @@ func (ruleFiles) check(
|
||||
|
||||
for _, rule := range matched {
|
||||
rq.line.RuleIDs = append(rq.line.RuleIDs, rule.ID)
|
||||
rq.h.metrics.RuleMatched(rule.ID, rule.Action)
|
||||
r.metrics.RuleMatched(rule.ID, rule.Action)
|
||||
}
|
||||
|
||||
if len(matched) == 0 {
|
||||
@@ -60,7 +65,8 @@ func (ruleFiles) check(
|
||||
rq.attack = true
|
||||
|
||||
return &verdict{
|
||||
action: rq.banForAttack(
|
||||
action: r.banMaker.banForAttack(
|
||||
rq,
|
||||
now,
|
||||
bans.Notes{RuleID: last.ID, Target: last.Target},
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user