Files
smallwebwaf/internal/waf/abuseipdbblacklist.go
T
clawbot dfffeb73ec
check / check (push) Failing after 8m52s
waf: ban the clients on AbuseIPDB's blacklist (closes #411)
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
2026-11-19 10:03:42 +00:00

40 lines
1.1 KiB
Go

package waf
// The bans for AbuseIPDB's blacklist. They read SWW_WAF_ABUSEIPDB_BAN_DAYS and
// SWW_WAF_MODE; the blacklist is fetched by the reputation package.
import (
"net/netip"
"sneak.berlin/go/smallwebwaf/internal/reputation"
)
// banAbuseIPDBBlacklist bans the netblock of each client on AbuseIPDB's
// blacklist, listed, for SWW_WAF_ABUSEIPDB_BAN_DAYS, as the ledger's
// BanForAbuseIPDB describes, and logs how many clients were listed and how
// many bans were made. Clients in one netblock make one ban, with the
// highest of their scores. In observe mode it makes no ban.
func (h *handler) banAbuseIPDBBlacklist(listed []reputation.BlacklistEntry) {
scores := make(map[netip.Prefix]int64, len(listed))
for _, client := range listed {
netblock := h.netblock(client.Addr)
scores[netblock] = max(scores[netblock], client.Score)
}
made := 0
if !h.config.Observe {
now := h.now()
made = h.ledger.BanForAbuseIPDB(
now, now.Add(h.config.AbuseIPDBBanDuration), scores,
)
}
h.processLog.Info(
"fetched AbuseIPDB's blacklist",
"clients", len(listed),
"bans_made", made,
)
}