From 3060788ca3dd8bc5ff1810b14dc387bf4676610d Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Thu, 19 Nov 2026 08:48:43 +0000 Subject: [PATCH] reputation: name a client on AbuseIPDB's blacklist BlacklistEntry The type was named Listed, in a package whose DNSBL verdicts carry a field Listed and whose blocklists list clients too, so the name alone did not say which list it was on. Model: opus-5-5 --- internal/reputation/abuseipdb.go | 18 ++++++++++-------- internal/reputation/blacklist_test.go | 13 ++++++++----- internal/waf/abuseipdbblacklist.go | 2 +- internal/waf/abuseipdbblacklist_test.go | 4 ++-- internal/waf/export_test.go | 2 +- internal/waf/proxy.go | 3 ++- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/internal/reputation/abuseipdb.go b/internal/reputation/abuseipdb.go index 429b3a5..4e16f11 100644 --- a/internal/reputation/abuseipdb.go +++ b/internal/reputation/abuseipdb.go @@ -59,9 +59,9 @@ type ChecksSpent struct { Spent int } -// Listed is a client on AbuseIPDB's blacklist: its address and its abuse -// confidence score. -type Listed struct { +// BlacklistEntry is a client on AbuseIPDB's blacklist: its address and its +// abuse confidence score. +type BlacklistEntry struct { Addr netip.Addr Score int64 } @@ -90,7 +90,7 @@ type AbuseIPDBParams struct { BlacklistURL string Threshold int64 BlacklistRefresh time.Duration - Blacklisted func([]Listed) + Blacklisted func([]BlacklistEntry) // Now tells the time, normally time.Now in UTC. Now func() time.Time // ProcessLog receives each check or fetch of the blacklist that fails, @@ -404,7 +404,9 @@ func (a *AbuseIPDB) ask( // Threshold or more, sending the key in the header Key. An answer other // than 200, one longer than maxListBytes or without the list, an entry // whose address does not read, and none within fetchTimeout, fail. -func (a *AbuseIPDB) fetchBlacklist(ctx context.Context) ([]Listed, error) { +func (a *AbuseIPDB) fetchBlacklist( + ctx context.Context, +) ([]BlacklistEntry, error) { ctx, cancel := context.WithTimeout(ctx, fetchTimeout) defer cancel() @@ -447,7 +449,7 @@ func (a *AbuseIPDB) fetchBlacklist(ctx context.Context) ([]Listed, error) { } // parseBlacklist reads body, AbuseIPDB's answer with its blacklist. -func parseBlacklist(body []byte) ([]Listed, error) { +func parseBlacklist(body []byte) ([]BlacklistEntry, error) { var answer struct { Data *[]struct { IPAddress string `json:"ipAddress"` @@ -464,7 +466,7 @@ func parseBlacklist(body []byte) ([]Listed, error) { return nil, errNoBlacklist } - listed := make([]Listed, 0, len(*answer.Data)) + listed := make([]BlacklistEntry, 0, len(*answer.Data)) for i, entry := range *answer.Data { addr, err := netip.ParseAddr(entry.IPAddress) @@ -478,7 +480,7 @@ func parseBlacklist(body []byte) ([]Listed, error) { ) } - listed = append(listed, Listed{ + listed = append(listed, BlacklistEntry{ Addr: addr.Unmap(), Score: entry.AbuseConfidenceScore, }) } diff --git a/internal/reputation/blacklist_test.go b/internal/reputation/blacklist_test.go index d79b371..894135b 100644 --- a/internal/reputation/blacklist_test.go +++ b/internal/reputation/blacklist_test.go @@ -33,7 +33,7 @@ func TestBlacklistIsFetchedAtOnceAndEveryRefresh(t *testing.T) { `{"ipAddress":"2001:db8::9","abuseConfidenceScore":90}]}`} got := runBlacklist(t, abuseIPDB, key, newQueue()) - want := []reputation.Listed{ + want := []reputation.BlacklistEntry{ {Addr: netip.MustParseAddr("203.0.113.9"), Score: 100}, {Addr: netip.MustParseAddr("198.51.100.7"), Score: 95}, {Addr: netip.MustParseAddr("2001:db8::9"), Score: 90}, @@ -123,7 +123,7 @@ func TestFailedBlacklistFetchIsAlertedAndTriedAgainAtTheNextRefresh( abuseIPDB.answer(`{"data":[]}`) time.Sleep(time.Hour) synctest.Wait() - got.want(t, []reputation.Listed{}) + got.want(t, []reputation.BlacklistEntry{}) }) }) } @@ -190,11 +190,14 @@ func (s *blacklistStandIn) answer(body string) { // blacklisted holds the clients on each blacklist given to Blacklisted. type blacklisted struct { mu sync.Mutex - fetched [][]reputation.Listed + fetched [][]reputation.BlacklistEntry } // want checks the clients on each blacklist given so far. -func (b *blacklisted) want(t *testing.T, want ...[]reputation.Listed) { +func (b *blacklisted) want( + t *testing.T, + want ...[]reputation.BlacklistEntry, +) { t.Helper() b.mu.Lock() @@ -222,7 +225,7 @@ func runBlacklist( p.Threshold = 90 p.BlacklistRefresh = time.Hour p.Alerts = queue - p.Blacklisted = func(listed []reputation.Listed) { + p.Blacklisted = func(listed []reputation.BlacklistEntry) { got.mu.Lock() defer got.mu.Unlock() diff --git a/internal/waf/abuseipdbblacklist.go b/internal/waf/abuseipdbblacklist.go index 0993047..a1085e7 100644 --- a/internal/waf/abuseipdbblacklist.go +++ b/internal/waf/abuseipdbblacklist.go @@ -14,7 +14,7 @@ import ( // 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.Listed) { +func (h *handler) banAbuseIPDBBlacklist(listed []reputation.BlacklistEntry) { scores := make(map[netip.Prefix]int64, len(listed)) for _, client := range listed { diff --git a/internal/waf/abuseipdbblacklist_test.go b/internal/waf/abuseipdbblacklist_test.go index 33b78ab..3756699 100644 --- a/internal/waf/abuseipdbblacklist_test.go +++ b/internal/waf/abuseipdbblacklist_test.go @@ -54,7 +54,7 @@ func TestClientsOnTheAbuseIPDBBlacklistAreBannedForTheBanDays(t *testing.T) { }) // Two clients in one netblock make one ban, with the higher score. - server.BanAbuseIPDBBlacklist([]reputation.Listed{ + server.BanAbuseIPDBBlacklist([]reputation.BlacklistEntry{ {Addr: netip.MustParseAddr(client), Score: 95}, {Addr: netip.MustParseAddr(otherClient), Score: 100}, {Addr: netip.MustParseAddr("2001:db8:5::1"), Score: 90}, @@ -88,7 +88,7 @@ func TestAbuseIPDBBlacklistMakesNoBanInObserveMode(t *testing.T) { map[string]string{mode: "observe"}, ) - server.BanAbuseIPDBBlacklist([]reputation.Listed{ + server.BanAbuseIPDBBlacklist([]reputation.BlacklistEntry{ {Addr: netip.MustParseAddr(client), Score: 100}, }) diff --git a/internal/waf/export_test.go b/internal/waf/export_test.go index e8d641c..21de795 100644 --- a/internal/waf/export_test.go +++ b/internal/waf/export_test.go @@ -18,7 +18,7 @@ func (s *Server) SetBesideLookupTimeLimit(limit time.Duration) { // BanAbuseIPDBBlacklist does on s what a fetch of AbuseIPDB's blacklist with // the clients on listed does. -func (s *Server) BanAbuseIPDBBlacklist(listed []reputation.Listed) { +func (s *Server) BanAbuseIPDBBlacklist(listed []reputation.BlacklistEntry) { h := s.Handler.(*handler) //nolint:forcetypeassert // New makes it one h.banAbuseIPDBBlacklist(listed) } diff --git a/internal/waf/proxy.go b/internal/waf/proxy.go index 7a0c029..e6db51a 100644 --- a/internal/waf/proxy.go +++ b/internal/waf/proxy.go @@ -206,7 +206,8 @@ func newHandler(params Params) *handler { // 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.Listed), + params Params, m *metrics.Metrics, + blacklisted func([]reputation.BlacklistEntry), ) (*reputation.Lists, *reputation.DNSBL, *reputation.AbuseIPDB) { cfg := params.Config lists := reputation.New(reputation.Params{