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
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"sneak.berlin/go/smallwebwaf/internal/config"
|
||||
"sneak.berlin/go/smallwebwaf/internal/reputation"
|
||||
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
||||
)
|
||||
|
||||
@@ -15,20 +16,24 @@ import (
|
||||
// and refuses the request when SWW_WAF_BLOCKLIST_ACTION is deny. Being limit, it
|
||||
// lowers the client's limits instead (see limitPercentages), and being log, it
|
||||
// does nothing more. Its figure is the blocklists that list the client.
|
||||
type blocklists struct{}
|
||||
type blocklists struct {
|
||||
lists *reputation.Lists
|
||||
action config.ReputationAction // SWW_WAF_BLOCKLIST_ACTION
|
||||
hitNoter reputationHitNoter
|
||||
}
|
||||
|
||||
func (blocklists) name() string { return "blocklists" }
|
||||
|
||||
func (blocklists) check(
|
||||
func (b blocklists) check(
|
||||
_ context.Context,
|
||||
rq *request,
|
||||
_ time.Time,
|
||||
) *verdict {
|
||||
listedBy := rq.h.lists.ListedBy(rq.client)
|
||||
listedBy := b.lists.ListedBy(rq.client)
|
||||
rq.blocklisted = len(listedBy) > 0
|
||||
rq.noteListed(listedBy, "listed by a blocklist")
|
||||
b.hitNoter.noteListed(rq, listedBy, "listed by a blocklist")
|
||||
|
||||
if !rq.refusedByBlocklists(listedBy) {
|
||||
if !b.refusedByBlocklists(listedBy) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -41,7 +46,6 @@ func (blocklists) check(
|
||||
// refusedByBlocklists reports whether the heuristic blocklists refuses a
|
||||
// client, given listedBy, the blocklists that list it: it does when one lists
|
||||
// it and SWW_WAF_BLOCKLIST_ACTION is deny.
|
||||
func (rq *request) refusedByBlocklists(listedBy []string) bool {
|
||||
return len(listedBy) > 0 && rq.h.config.BlocklistAction ==
|
||||
config.ReputationActionDeny
|
||||
func (b blocklists) refusedByBlocklists(listedBy []string) bool {
|
||||
return len(listedBy) > 0 && b.action == config.ReputationActionDeny
|
||||
}
|
||||
Reference in new issue
Block a user