check / check (push) Waiting to run
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
37 lines
724 B
Go
37 lines
724 B
Go
package waf
|
|
|
|
// The heuristic deny_nets. It reads SWW_WAF_DENY_NETS.
|
|
|
|
import (
|
|
"context"
|
|
"net/netip"
|
|
"time"
|
|
|
|
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
|
)
|
|
|
|
// denyNets refuses a client in SWW_WAF_DENY_NETS. Its figure is the netblock of
|
|
// the setting the client is in.
|
|
type denyNets struct {
|
|
netblocks []netip.Prefix // SWW_WAF_DENY_NETS
|
|
}
|
|
|
|
func (denyNets) name() string { return "deny_nets" }
|
|
|
|
func (d denyNets) check(
|
|
_ context.Context,
|
|
rq *request,
|
|
_ time.Time,
|
|
) *verdict {
|
|
for _, netblock := range d.netblocks {
|
|
if netblock.Contains(rq.client) {
|
|
return &verdict{
|
|
action: requestlog.ActionClientDenied,
|
|
figures: map[string]any{figureNetblock: netblock.String()},
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|