waf: heuristics pass facts through typed fields of decision (closes #442) #477

Merged
clawbot merged 3 commits from issue-442-decision-typed-facts into next 2026-11-19 23:43:01 +01:00
Collaborator

Closes #442.

Heuristics now tell each other what they found through fields of decision. The log line is written from those fields. Nothing reads the log line back to decide, to fill a ban's notes or to raise an alert.

New fields of decision, each with a comment that names what sets it:

  • tags: the request's tags, sorted, each once. addTag adds a tag here and copies the list to the log line.
  • wouldAction: in observe mode, the action enforce mode would have taken. check sets it.
  • brokeLimit: the request broke a limit. banForLimit sets it.
  • method, userAgent: the request as a ban's notes keep it, next to the existing requestURI. startRequest sets them. A ban's notes take the Host from the existing site.

Moved from request to decision: blocklisted, dnsblListed, abuseIPDBHit.

The AS number, AS name and country are now read from lookupAnswer. This covers countries, limitPercentages, allow, a ban's notes and the alerts.

Not obvious from the diff:

  • method and userAgent are needed because byteLimits can ban when the report arrives. At that point waf rebuilds the request from the held decision and has no http.Request to read them from.
  • activeBan keeps the ban's end time in a local variable for its figures. No later heuristic reads it, so it gets no field.
  • Moving the three reputation flags means the copy held for the report carries them too. Nothing reads them after the decision, so behaviour does not change.

Model: opus-5-5

Closes https://git.eeqj.de/sneak/smallwebwaf/issues/442. Heuristics now tell each other what they found through fields of `decision`. The log line is written from those fields. Nothing reads the log line back to decide, to fill a ban's notes or to raise an alert. New fields of `decision`, each with a comment that names what sets it: - `tags`: the request's tags, sorted, each once. `addTag` adds a tag here and copies the list to the log line. - `wouldAction`: in observe mode, the action enforce mode would have taken. `check` sets it. - `brokeLimit`: the request broke a limit. `banForLimit` sets it. - `method`, `userAgent`: the request as a ban's notes keep it, next to the existing `requestURI`. `startRequest` sets them. A ban's notes take the Host from the existing `site`. Moved from `request` to `decision`: `blocklisted`, `dnsblListed`, `abuseIPDBHit`. The AS number, AS name and country are now read from `lookupAnswer`. This covers `countries`, `limitPercentages`, `allow`, a ban's notes and the alerts. Not obvious from the diff: - `method` and `userAgent` are needed because `byteLimits` can ban when the report arrives. At that point waf rebuilds the request from the held `decision` and has no `http.Request` to read them from. - `activeBan` keeps the ban's end time in a local variable for its figures. No later heuristic reads it, so it gets no field. - Moving the three reputation flags means the copy held for the report carries them too. Nothing reads them after the decision, so behaviour does not change. Model: opus-5-5
clawbot added the needs-review label 2026-11-19 23:07:43 +01:00
clawbot added 1 commit 2026-11-19 23:07:43 +01:00
The tags, what observe mode would have done, the broken limit and the
three reputation flags are fields of decision, each naming what sets it.
The log line is written from them and from the lookup answer, and no
heuristic, ban note or alert reads it back. A ban's notes take the
request's method, Host and User-Agent from decision, since the report's
steps have no request to read them from.

Model: opus-5-5
clawbot self-assigned this 2026-11-19 23:07:45 +01:00
clawbot added 2 commits 2026-11-19 23:20:09 +01:00
decision held the visitor's Host twice: as site, set by answerQuestion
for the alerts, and as host, added for a ban's notes. Bans are made only
from questions, where the two are always equal. noted now reads site,
and host is gone.

Model: opus-5-5
The issue's definition of done asks that each fact a heuristic leaves for
a later one is a field of decision whose comment names what sets it. The
comments of skippedLookupWait, counted, the two limit percentages,
attack, blockedByBlockRule and blockedByCoreRuleSet did not.

Model: opus-5-5
Author
Collaborator

Verdict: FAIL
Head: 17bbea919a

  1. internal/waf/request.go, decision: the new field host holds the same value as the existing site. Both are the visitor's Host, and bans are made only from questions, where answerQuestion sets site. Two names for one value leave a reader asking which to use. Acceptable: noted in internal/waf/bans.go reads rq.site, host is removed, and the comment on site says a ban's notes name it too.
  2. internal/waf/request.go, decision: the definition of done in #442 asks that every fact a heuristic leaves for a later one is a field whose comment names what sets it. The comments on skippedLookupWait, counted, rateLimitPercent, bytesLimitPercent, attack, blockedByBlockRule and blockedByCoreRuleSet do not. Acceptable: each names its setter (noteLookup; rateLimits; trapPaths and ruleFiles; ruleFiles; coreRuleSet).

Judgement call: finding 2 reads the definition of done as covering the fields the issue says stay, not only the new ones.

Model: opus-5-5

Verdict: FAIL Head: 17bbea919ab2e57ae478a4a5bfcf99507dedbd92 1. `internal/waf/request.go`, `decision`: the new field `host` holds the same value as the existing `site`. Both are the visitor's Host, and bans are made only from questions, where `answerQuestion` sets `site`. Two names for one value leave a reader asking which to use. Acceptable: `noted` in `internal/waf/bans.go` reads `rq.site`, `host` is removed, and the comment on `site` says a ban's notes name it too. 2. `internal/waf/request.go`, `decision`: the definition of done in https://git.eeqj.de/sneak/smallwebwaf/issues/442 asks that every fact a heuristic leaves for a later one is a field whose comment names what sets it. The comments on `skippedLookupWait`, `counted`, `rateLimitPercent`, `bytesLimitPercent`, `attack`, `blockedByBlockRule` and `blockedByCoreRuleSet` do not. Acceptable: each names its setter (`noteLookup`; `rateLimits`; `trapPaths` and `ruleFiles`; `ruleFiles`; `coreRuleSet`). Judgement call: finding 2 reads the definition of done as covering the fields the issue says stay, not only the new ones. Model: opus-5-5
Author
Collaborator

Verdict: PASS
Head: d3761ac7d0

Heuristics now pass the tags, the observe-mode action, the broken limit and the three reputation flags through typed fields of decision, and no ban note, alert or decision in internal/waf reads the log line back, as #442 asks.

Deviation: I corrected the PR body, which still listed the removed field host and said refusalLimit bans when the report arrives; only byteLimits does.

Model: opus-5-5

Verdict: PASS Head: d3761ac7d00b62371e8a950036477961dad14d62 Heuristics now pass the tags, the observe-mode action, the broken limit and the three reputation flags through typed fields of `decision`, and no ban note, alert or decision in `internal/waf` reads the log line back, as https://git.eeqj.de/sneak/smallwebwaf/issues/442 asks. Deviation: I corrected the PR body, which still listed the removed field `host` and said `refusalLimit` bans when the report arrives; only `byteLimits` does. Model: opus-5-5
clawbot merged commit 17400f68b8 into next 2026-11-19 23:43:01 +01:00
Sign in to join this conversation.