waf: a heuristic says itself that it refuses whatever the lookup answers #446

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

Start once the issue that gives each heuristic its own settings and parts is closed: #441. This needs heuristics that are built values held in lists.

From the architecture review, "The decision pipeline: the heuristics", under "One condition is written twice, and two more live elsewhere": #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.

Part of what the review found is gone since: each condition is now written once, in its heuristic's file. This issue is what is left of the proposal.

What is there

Adding or changing a heuristic can still mean a change in one of four places outside its file, and the comment in internal/waf/heuristics.go on adding a heuristic names none of them:

  • refusedWhateverTheAnswer (internal/waf/waf.go:152) names the two heuristics that can refuse a request whatever the lookup answers, by their functions refusedByBlocklists and overAWholeRateLimit. startLookUp uses it to skip the wait for GeoJS.
  • waitForGeoJS in newHandler (internal/waf/proxy.go:166) lists which settings need the lookup's answer.
  • checkTags and requestCanGetTag in internal/config/waf.go hold which setting can give a request which tag.
  • findBesideLookup (internal/waf/besidelookup.go:103) does the work of the three heuristics beside the lookup, each by name.

Why it matters

A heuristic that changes when it refuses, needs the lookup, adds a tag or reads the request beside the lookup must also change one of these. Nothing tells its author.

What changes

Two steps, smallest first, as the review gives them:

  • The comment in heuristics.go names the four places.
  • A heuristic that can refuse without the lookup says so itself, through a second small interface it may implement. refusedWhateverTheAnswer then asks the list, and names no heuristic. blocklists and rateLimits implement it, with the two functions they have.

What stays

  • Which requests skip the wait for GeoJS, in enforce mode and in observe mode, where none does.
  • waitForGeoJS, the checks of the tags in config, and findBesideLookup stay as they are. The comment is their only change.

The review is plain about the cost of the second step: one more interface, with two heuristics behind it today. It pays as their number grows.

Done when

  • the comment on adding a heuristic names every place outside a heuristic's file that may change with it;
  • refusedWhateverTheAnswer names no heuristic;
  • behaviour is unchanged: every existing test passes with no assertion changed;
  • make check passes;
  • the PR body lists the new interface's name and its method's. Each says what the thing is to a reader of that one file, the standard of the symbol names audit (#213).

Model: fable-5-2

**Start once the issue that gives each heuristic its own settings and parts is closed: https://git.eeqj.de/sneak/smallwebwaf/issues/441.** This needs heuristics that are built values held in lists. From the architecture review, "The decision pipeline: the heuristics", under "One condition is written twice, and two more live elsewhere": 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. Part of what the review found is gone since: each condition is now written once, in its heuristic's file. This issue is what is left of the proposal. ### What is there Adding or changing a heuristic can still mean a change in one of four places outside its file, and the comment in `internal/waf/heuristics.go` on adding a heuristic names none of them: - `refusedWhateverTheAnswer` (`internal/waf/waf.go:152`) names the two heuristics that can refuse a request whatever the lookup answers, by their functions `refusedByBlocklists` and `overAWholeRateLimit`. `startLookUp` uses it to skip the wait for GeoJS. - `waitForGeoJS` in `newHandler` (`internal/waf/proxy.go:166`) lists which settings need the lookup's answer. - `checkTags` and `requestCanGetTag` in `internal/config/waf.go` hold which setting can give a request which tag. - `findBesideLookup` (`internal/waf/besidelookup.go:103`) does the work of the three heuristics beside the lookup, each by name. ### Why it matters A heuristic that changes when it refuses, needs the lookup, adds a tag or reads the request beside the lookup must also change one of these. Nothing tells its author. ### What changes Two steps, smallest first, as the review gives them: - The comment in `heuristics.go` names the four places. - A heuristic that can refuse without the lookup says so itself, through a second small interface it may implement. `refusedWhateverTheAnswer` then asks the list, and names no heuristic. `blocklists` and `rateLimits` implement it, with the two functions they have. ### What stays - Which requests skip the wait for GeoJS, in enforce mode and in observe mode, where none does. - `waitForGeoJS`, the checks of the tags in `config`, and `findBesideLookup` stay as they are. The comment is their only change. The review is plain about the cost of the second step: one more interface, with two heuristics behind it today. It pays as their number grows. ### Done when - the comment on adding a heuristic names every place outside a heuristic's file that may change with it; - `refusedWhateverTheAnswer` names no heuristic; - behaviour is unchanged: every existing test passes with no assertion changed; - `make check` passes; - the PR body lists the new interface's name and its method's. Each says what the thing is to a reader of that one file, the standard of the symbol names audit (https://git.eeqj.de/sneak/smallwebwaf/issues/213). Model: fable-5-2
clawbot self-assigned this 2026-11-19 17:14:27 +01:00
clawbot added the needs-decision label 2026-11-19 18:23:48 +01:00
Author
Collaborator

Not started: it waits on #441, still open with its PR #462 unmerged; resume once that issue closes.

Model: opus-5-5

Not started: it waits on https://git.eeqj.de/sneak/smallwebwaf/issues/441, still open with its PR https://git.eeqj.de/sneak/smallwebwaf/pulls/462 unmerged; resume once that issue closes. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/smallwebwaf#446