waf: ban the clients on AbuseIPDB's blacklist (closes #411)
check / check (push) Failing after 8m52s

While SWW_WAF_ABUSEIPDB_KEY is set, waf fetches AbuseIPDB's blacklist at
the start and every SWW_WAF_ABUSEIPDB_BLACKLIST_REFRESH_INTERVAL_MINS
(60), cut at SWW_WAF_ABUSEIPDB_THRESHOLD (90, from 25 to 100). Each
listed client's netblock gets a ban of SWW_WAF_ABUSEIPDB_BAN_DAYS (30)
with the new cause abuseipdb. The blacklist itself is not kept.

These bans do not count toward SWW_WAF_MAX_BANS, so a 10,000-address
blacklist cannot push out the bans for limits and attacks. An ended
abuseipdb ban is forgotten at each fetch and each read of bans.json. A
netblock with an active ban is left alone, and so is one whose abuseipdb
ban an admin lifted, until that ban would have ended. Observe mode makes
no ban.

Model: opus-5-5
This commit is contained in:
clawbot committed 2026-11-19 10:03:42 +00:00
1 parent 9f42460f70
commit dfffeb73ec
22 files changed
+1304 -205

No files matched your search

+14 -6
View File
@@ -63,6 +63,10 @@ type Params struct {
// AbuseIPDBURL is where clients are checked with AbuseIPDB while
// SWW_WAF_ABUSEIPDB_KEY is set, normally reputation.AbuseIPDBURL.
AbuseIPDBURL string
// AbuseIPDBBlacklistURL is where AbuseIPDB's blacklist is fetched from
// while SWW_WAF_ABUSEIPDB_KEY is set, normally
// reputation.AbuseIPDBBlacklistURL.
AbuseIPDBBlacklistURL string
// LookupFile is the lookup database they are looked up in while
// SWW_WAF_LOOKUP_SOURCE is file, and nil otherwise.
LookupFile *lookup.File
@@ -126,7 +130,6 @@ func newHandler(params Params) *handler {
params.Config.MetricsBusiestCountriesAndASNs,
params.Config.InstanceName,
)
lists, dnsbl, abuseIPDB := newReputation(params, m)
awaitingReport, err := lru.New[string, *decision](maxAwaitingReport)
if err != nil {
@@ -167,9 +170,6 @@ func newHandler(params Params) *handler {
Alerts: params.Alerts,
}),
lookupFile: params.LookupFile,
lists: lists,
dnsbl: dnsbl,
abuseIPDB: abuseIPDB,
rules: params.Rules,
coreRuleSet: params.CoreRuleSet,
alerts: params.Alerts,
@@ -179,6 +179,10 @@ func newHandler(params Params) *handler {
besideLookupTimeLimit,
),
}
h.lists, h.dnsbl, h.abuseIPDB = newReputation(
params, m, h.banAbuseIPDBBlacklist,
)
if params.Config.RouteWatchURL != "" {
h.routeWatch = routewatch.New(routewatch.Params{
URL: params.Config.RouteWatchURL, Now: params.Now, ProcessLog: params.ProcessLog,
@@ -208,9 +212,11 @@ func newHandler(params Params) *handler {
// newReputation returns the lists fetched from URLs, the DNSBL zones'
// verdicts and AbuseIPDB's scores, as the settings in params name them,
// with none fetched, asked for or checked yet, and adds their metrics to
// m, AbuseIPDB's while SWW_WAF_ABUSEIPDB_KEY is set.
// m, AbuseIPDB's while SWW_WAF_ABUSEIPDB_KEY is set. blacklisted receives
// the clients on each AbuseIPDB blacklist fetched.
func newReputation(
params Params, m *metrics.Metrics,
blacklisted func([]reputation.BlacklistEntry),
) (*reputation.Lists, *reputation.DNSBL, *reputation.AbuseIPDB) {
cfg := params.Config
lists := reputation.New(reputation.Params{
@@ -231,7 +237,9 @@ func newReputation(
abuseIPDB := reputation.NewAbuseIPDB(reputation.AbuseIPDBParams{
URL: params.AbuseIPDBURL, Key: cfg.AbuseIPDBKey, MinScore: cfg.AbuseIPDBMinScore,
DailyBudget: cfg.AbuseIPDBDailyBudget, CacheTTL: cfg.IPReputationCacheTTL,
Timeout: cfg.DNSBLAbuseIPDBTimeout, Now: params.Now, ProcessLog: params.ProcessLog,
Timeout: cfg.DNSBLAbuseIPDBTimeout, BlacklistURL: params.AbuseIPDBBlacklistURL,
Threshold: cfg.AbuseIPDBThreshold, BlacklistRefresh: cfg.AbuseIPDBBlacklistRefresh,
Blacklisted: blacklisted, Now: params.Now, ProcessLog: params.ProcessLog,
Alerts: params.Alerts,
})