waf: each heuristic holds its own settings and parts (closes #441) #462

Open
clawbot wants to merge 1 commits from issue-441-heuristic-structs into next
pull from: issue-441-heuristic-structs
Collaborator

Closes #441

Each heuristic is a struct that newHandler builds once with the settings and parts it reads. No check reads rq.h. The six lists are handler fields. headerLimits stays empty: its limits are constants.

Things the diff does not make obvious:

  • clientGroup and banNetblock take the prefix lengths instead of *config.WAF, so the steps that are not heuristics pass h.config fields.
  • blocklists, rateLimits, trapPaths, ruleFiles and coreRuleSet are also handler fields. refusedWhateverTheAnswer and findBesideLookup use those same built values.
  • New reads Lists, DNSBL, AbuseIPDB and RouteWatch from its params. The handler no longer holds them, nor rules, alerts or the Core Rule Set inspector.
  • newHandler carries //nolint:funlen as a list that grows with the heuristics, as config and metrics already do.

New types:

  • banMaker: makes the bans of the heuristics that ban, and raises their alerts. Fields: ledger, limiter, metrics, alerts, observe, banResponse, banScopeV4Prefix, ipv6GroupPrefix.
  • reputationHitNoter: notes the reputation sources that list a client. Fields: metrics, alerts, ipv6GroupPrefix.
  • biasedThresholds: the settings and lists limitPercentages lowers limits by. Fields: lists, tagLimitPercent, asnBytesLimitPercent, countryBytesLimitPercent, unknownCountryLimitPercent, blocklistAction, blocklistLimitPercent, dnsblAbuseIPDBAction, dnsblAbuseIPDBLimitPercent.

New heuristic fields. Each setting field is commented with its variable name:

  • denyNets.netblocks, tagLists.lists, routeWatchTags.routeWatch, countries.allowed, tagDeny.tags, trapPaths.paths
  • blocklists: lists, action, hitNoter
  • dnsbl: dnsbl, action, hitNoter
  • abuseIPDB: abuseIPDB, limiter, keySet, minScore, action, hitNoter
  • rateLimits: limiter, exemptNets, exemptPaths, banResponse, biasedThresholds
  • refusalLimit: limiter, perMinute, banResponse
  • byteLimits: limiter, bytesCounted
  • ruleFiles: rules, metrics
  • coreRuleSet: inspector, metrics, alerts, mode, exemptPaths, scoreThreshold, observe
  • banMaker on activeBan, rateLimits, trapPaths, ruleFiles, refusalLimit and byteLimits. ipv6GroupPrefix on every heuristic that computes a client group.

Model: opus-5-5

Closes https://git.eeqj.de/sneak/smallwebwaf/issues/441 Each heuristic is a struct that `newHandler` builds once with the settings and parts it reads. No `check` reads `rq.h`. The six lists are handler fields. `headerLimits` stays empty: its limits are constants. Things the diff does not make obvious: - `clientGroup` and `banNetblock` take the prefix lengths instead of `*config.WAF`, so the steps that are not heuristics pass `h.config` fields. - `blocklists`, `rateLimits`, `trapPaths`, `ruleFiles` and `coreRuleSet` are also handler fields. `refusedWhateverTheAnswer` and `findBesideLookup` use those same built values. - `New` reads `Lists`, `DNSBL`, `AbuseIPDB` and `RouteWatch` from its params. The handler no longer holds them, nor `rules`, `alerts` or the Core Rule Set inspector. - `newHandler` carries `//nolint:funlen` as a list that grows with the heuristics, as `config` and `metrics` already do. New types: - `banMaker`: makes the bans of the heuristics that ban, and raises their alerts. Fields: `ledger`, `limiter`, `metrics`, `alerts`, `observe`, `banResponse`, `banScopeV4Prefix`, `ipv6GroupPrefix`. - `reputationHitNoter`: notes the reputation sources that list a client. Fields: `metrics`, `alerts`, `ipv6GroupPrefix`. - `biasedThresholds`: the settings and lists `limitPercentages` lowers limits by. Fields: `lists`, `tagLimitPercent`, `asnBytesLimitPercent`, `countryBytesLimitPercent`, `unknownCountryLimitPercent`, `blocklistAction`, `blocklistLimitPercent`, `dnsblAbuseIPDBAction`, `dnsblAbuseIPDBLimitPercent`. New heuristic fields. Each setting field is commented with its variable name: - `denyNets.netblocks`, `tagLists.lists`, `routeWatchTags.routeWatch`, `countries.allowed`, `tagDeny.tags`, `trapPaths.paths` - `blocklists`: `lists`, `action`, `hitNoter` - `dnsbl`: `dnsbl`, `action`, `hitNoter` - `abuseIPDB`: `abuseIPDB`, `limiter`, `keySet`, `minScore`, `action`, `hitNoter` - `rateLimits`: `limiter`, `exemptNets`, `exemptPaths`, `banResponse`, `biasedThresholds` - `refusalLimit`: `limiter`, `perMinute`, `banResponse` - `byteLimits`: `limiter`, `bytesCounted` - `ruleFiles`: `rules`, `metrics` - `coreRuleSet`: `inspector`, `metrics`, `alerts`, `mode`, `exemptPaths`, `scoreThreshold`, `observe` - `banMaker` on `activeBan`, `rateLimits`, `trapPaths`, `ruleFiles`, `refusalLimit` and `byteLimits`. `ipv6GroupPrefix` on every heuristic that computes a client group. Model: opus-5-5
clawbot added the needs-review label 2026-11-19 17:47:16 +01:00
clawbot self-assigned this 2026-11-19 17:47:16 +01:00
clawbot added 1 commit 2026-11-19 17:47:16 +01:00
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
Author
Collaborator

Verdict: PASS
Head: ce87531fec

Every heuristic now holds its own settings and parts, no check reads the handler, the six lists are built once in newHandler, and no existing test changed, which meets the definition of done of #441.

  • Rule suppressed: //nolint:funlen on newHandler, as on config and metrics.

Model: opus-5-5

Verdict: PASS Head: ce87531fecdf73e151fd931ee7d70964b0cf4596 Every heuristic now holds its own settings and parts, no `check` reads the handler, the six lists are built once in `newHandler`, and no existing test changed, which meets the definition of done of https://git.eeqj.de/sneak/smallwebwaf/issues/441. - Rule suppressed: `//nolint:funlen` on `newHandler`, as on `config` and `metrics`. Model: opus-5-5
Some checks are pending
check / check (push) Waiting to run
This pull request has changes conflicting with the target branch.
  • internal/waf/abuseipdb.go
  • internal/waf/bans.go
  • internal/waf/biased.go
  • internal/waf/blocklists.go
  • internal/waf/coreruleset.go
  • internal/waf/dnsbl.go
  • internal/waf/reputation.go
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin issue-441-heuristic-structs:issue-441-heuristic-structs
git checkout issue-441-heuristic-structs
Sign in to join this conversation.