waf: a verdict carries the status the visitor gets #443

Open
opened 2026-11-19 17:14:27 +01:00 by clawbot · 1 comment
Collaborator

Start once the issue that gives heuristics typed facts on decision is closed: #442. The review orders this as the third of three steps inside the heuristics.

From the architecture review, "The decision pipeline: the heuristics", under "A verdict does not say what the visitor gets": #283 (comment). Approved for building: #283 (comment). The code was read at 809d266 on next, where discriminator is now waf. Line numbers are that commit's.

What is there

  • verdict (internal/waf/heuristics.go:25) is {action string; figures map[string]any}. The action is a word for the log line.
  • check (internal/waf/request.go:186) works out the status afterwards, by a switch over that word:
    • 403 for a block rule or the Core Rule Set;
    • 503 for checks that ran out of time;
    • 414 for a request line too long;
    • 431 for headers too large;
    • SWW_WAF_BAN_RESPONSE for the rest.
  • refusalLimit (internal/waf/refusallimit.go:51) repeats part of that switch, over what would have been done in observe mode.
  • In the afterAnswer and onReport lists the action is never read: refusalLimit and byteLimits return &verdict{figures: …}.

Why it matters

A new heuristic that answers with a status of its own edits the switch in check, outside its file. The status is decided by a string comparison far from the code that knows it.

What changes

  • verdict carries the status, set by the heuristic that gives it.
  • check then only applies observe mode.
  • refusalLimit takes the status from the verdict that refused the request, or in observe mode would have.

After:

type verdict struct {
	action  string
	status  int // what the visitor is answered with; 0 closes the connection
	figures map[string]any
}

What stays

  • The status and the action of every refusal, in enforce mode and as observe mode logs it.
  • A status of 0 still closes the visitor's connection without an answer, as SWW_WAF_BAN_RESPONSE set to close asks.

Done when

  • no switch or comparison over an action word decides a status;
  • behaviour is unchanged: every existing test passes with no assertion changed;
  • make check passes;
  • the PR body lists every new field name.

Model: fable-5-2

**Start once the issue that gives heuristics typed facts on `decision` is closed: https://git.eeqj.de/sneak/smallwebwaf/issues/442.** The review orders this as the third of three steps inside the heuristics. From the architecture review, "The decision pipeline: the heuristics", under "A verdict does not say what the visitor gets": https://git.eeqj.de/sneak/smallwebwaf/issues/283#issuecomment-173833. Approved for building: https://git.eeqj.de/sneak/smallwebwaf/issues/283#issuecomment-183550. The code was read at `809d266` on `next`, where `discriminator` is now `waf`. Line numbers are that commit's. ### What is there - `verdict` (`internal/waf/heuristics.go:25`) is `{action string; figures map[string]any}`. The action is a word for the log line. - `check` (`internal/waf/request.go:186`) works out the status afterwards, by a `switch` over that word: - 403 for a block rule or the Core Rule Set; - 503 for checks that ran out of time; - 414 for a request line too long; - 431 for headers too large; - `SWW_WAF_BAN_RESPONSE` for the rest. - `refusalLimit` (`internal/waf/refusallimit.go:51`) repeats part of that `switch`, over what would have been done in observe mode. - In the `afterAnswer` and `onReport` lists the action is never read: `refusalLimit` and `byteLimits` return `&verdict{figures: …}`. ### Why it matters A new heuristic that answers with a status of its own edits the `switch` in `check`, outside its file. The status is decided by a string comparison far from the code that knows it. ### What changes - `verdict` carries the status, set by the heuristic that gives it. - `check` then only applies observe mode. - `refusalLimit` takes the status from the verdict that refused the request, or in observe mode would have. After: ```go type verdict struct { action string status int // what the visitor is answered with; 0 closes the connection figures map[string]any } ``` ### What stays - The status and the action of every refusal, in enforce mode and as observe mode logs it. - A status of 0 still closes the visitor's connection without an answer, as `SWW_WAF_BAN_RESPONSE` set to close asks. ### Done when - no `switch` or comparison over an action word decides a status; - behaviour is unchanged: every existing test passes with no assertion changed; - `make check` passes; - the PR body lists every new field name. Model: fable-5-2
clawbot self-assigned this 2026-11-19 17:14:27 +01:00
Author
Collaborator

Not started: this issue waits until the issue that gives heuristics typed facts on decision is closed (#442), which is still open with no PR.

Model: opus-5-5

Not started: this issue waits until the issue that gives heuristics typed facts on `decision` is closed (https://git.eeqj.de/sneak/smallwebwaf/issues/442), which is still open with no PR. Model: opus-5-5
clawbot added the needs-decision label 2026-11-19 18:23:51 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/smallwebwaf#443