check / check (push) Failing after 1m42s
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
49 lines
1.3 KiB
Go
49 lines
1.3 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 (
|
|
"log/slog"
|
|
"net/netip"
|
|
"time"
|
|
|
|
"sneak.berlin/go/smallwebwaf/internal/bans"
|
|
"sneak.berlin/go/smallwebwaf/internal/config"
|
|
"sneak.berlin/go/smallwebwaf/internal/reputation"
|
|
)
|
|
|
|
// BanAbuseIPDBBlacklist bans in ledger the netblock of each client on
|
|
// AbuseIPDB's blacklist, listed, for SWW_WAF_ABUSEIPDB_BAN_DAYS from now, as
|
|
// the ledger's BanForAbuseIPDB describes. It logs to processLog 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 BanAbuseIPDBBlacklist(
|
|
cfg *config.WAF, ledger *bans.Ledger, processLog *slog.Logger,
|
|
now time.Time, listed []reputation.BlacklistEntry,
|
|
) {
|
|
scores := make(map[netip.Prefix]int64, len(listed))
|
|
|
|
for _, client := range listed {
|
|
netblock := banNetblock(
|
|
cfg.BanScopeV4Prefix, cfg.IPv6GroupPrefix, client.Addr,
|
|
)
|
|
scores[netblock] = max(scores[netblock], client.Score)
|
|
}
|
|
|
|
made := 0
|
|
|
|
if !cfg.Observe {
|
|
made = ledger.BanForAbuseIPDB(
|
|
now, now.Add(cfg.AbuseIPDBBanDuration), scores,
|
|
)
|
|
}
|
|
|
|
processLog.Info(
|
|
"fetched AbuseIPDB's blacklist",
|
|
"clients", len(listed),
|
|
"bans_made", made,
|
|
)
|
|
}
|