From the architecture review, "The decision pipeline: the heuristics", under "Observe mode is decided in eleven places": #283 (comment). Approved for building: #283 (comment). The code was read at 809d266 on next, where discriminator is now waf and the CrowdSec feed is gone. Line numbers are that commit's.
The review calls this independent of its other proposals for the heuristics. It edits internal/waf/bans.go, and so does the issue that gives each heuristic its own settings and parts (#441): whichever is built second rebases.
What is there
bans.Ledger has each way a request makes a ban twice: BanForLimit and WouldBanForLimit, BanForAttack and WouldBanForAttack (internal/bans/bans.go:314 to 373). All four call one private ban(…, cause, reason string, notes, keep bool).
banForLimit and banForAttack in internal/waf/bans.go repeat one skeleton:
find the netblock;
in observe mode, stop unless an alert would be sent;
fill the notes;
in observe mode, call the Would… method and alert;
otherwise call the other, set BanExpires and alert.
Between them the two test rq.h.config.Observe four times (lines 126, 151, 176, 190).
Why it matters
Another cause of ban means a new pair of ledger methods and another copy of the skeleton, with two observe branches each. A slip there makes a ban in observe mode.
What changes
bans.Ledger gets one method that makes a ban and one that reports what it would make. Both take the cause and the notes in one struct.
internal/waf/bans.go gets one function that holds the skeleton. It is the one place that tests observe mode for a ban a request makes. banForLimit and banForAttack shrink to filling in what differs.
The review had not traced three neighbours. Read since, each stays as it is:
BanForAdmin makes its ban even while another on the netblock is active, and takes its end from the admin.
BanForAbuseIPDB bans many netblocks in one call, and skips a netblock an admin lifted.
WouldBePermanent answers one question without working out the ban, which observe mode uses to avoid counting a netblock's requests.
Also unchanged:
Check and Find, the pair activeBan chooses between by observe mode, and the mode detail alertBan adds in observe mode. The symbol names audit (#213) proposes names for Check and Find, and this issue renames nothing.
Each ban's length, reason, notes and alert, in enforce mode and as observe mode reports them.
Done when
the ledger has one exported method that makes a request's ban and one that reports it, and the four above are gone;
the four tests of observe mode on the way to a ban are one, in one function of internal/waf/bans.go;
behaviour is unchanged: every existing test passes, changed only where it calls one of the four methods by name;
make check passes;
the PR body lists every new type, method and function name. Each says what the thing is to a reader of that one file, the standard of the symbol names audit.
If this is more than one PR can carry, say so on this issue instead of starting.
Model: fable-5-2
From the architecture review, "The decision pipeline: the heuristics", under "Observe mode is decided in eleven places": 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` and the CrowdSec feed is gone. Line numbers are that commit's.
The review calls this independent of its other proposals for the heuristics. It edits `internal/waf/bans.go`, and so does the issue that gives each heuristic its own settings and parts (https://git.eeqj.de/sneak/smallwebwaf/issues/441): whichever is built second rebases.
### What is there
- `bans.Ledger` has each way a request makes a ban twice: `BanForLimit` and `WouldBanForLimit`, `BanForAttack` and `WouldBanForAttack` (`internal/bans/bans.go:314` to `373`). All four call one private `ban(…, cause, reason string, notes, keep bool)`.
- `banForLimit` and `banForAttack` in `internal/waf/bans.go` repeat one skeleton:
- find the netblock;
- in observe mode, stop unless an alert would be sent;
- fill the notes;
- in observe mode, call the `Would…` method and alert;
- otherwise call the other, set `BanExpires` and alert.
- Between them the two test `rq.h.config.Observe` four times (lines 126, 151, 176, 190).
### Why it matters
Another cause of ban means a new pair of ledger methods and another copy of the skeleton, with two observe branches each. A slip there makes a ban in observe mode.
### What changes
- `bans.Ledger` gets one method that makes a ban and one that reports what it would make. Both take the cause and the notes in one struct.
- `internal/waf/bans.go` gets one function that holds the skeleton. It is the one place that tests observe mode for a ban a request makes. `banForLimit` and `banForAttack` shrink to filling in what differs.
Before (`internal/bans/bans.go`):
```go
func (l *Ledger) BanForLimit(netblock netip.Prefix, now time.Time, notes Notes) (Ban, bool)
func (l *Ledger) WouldBanForLimit(netblock netip.Prefix, now time.Time, notes Notes) (Ban, bool)
func (l *Ledger) BanForAttack(netblock netip.Prefix, now time.Time, notes Notes) (Ban, bool)
func (l *Ledger) WouldBanForAttack(netblock netip.Prefix, now time.Time, notes Notes) (Ban, bool)
```
After (the struct's name is a placeholder):
```go
func (l *Ledger) Ban(netblock netip.Prefix, now time.Time, why Cause) (Ban, bool)
func (l *Ledger) WouldBan(netblock netip.Prefix, now time.Time, why Cause) (Ban, bool)
```
### What stays
The review had not traced three neighbours. Read since, each stays as it is:
- `BanForAdmin` makes its ban even while another on the netblock is active, and takes its end from the admin.
- `BanForAbuseIPDB` bans many netblocks in one call, and skips a netblock an admin lifted.
- `WouldBePermanent` answers one question without working out the ban, which observe mode uses to avoid counting a netblock's requests.
Also unchanged:
- `Check` and `Find`, the pair `activeBan` chooses between by observe mode, and the `mode` detail `alertBan` adds in observe mode. The symbol names audit (https://git.eeqj.de/sneak/smallwebwaf/issues/213) proposes names for `Check` and `Find`, and this issue renames nothing.
- Each ban's length, reason, notes and alert, in enforce mode and as observe mode reports them.
### Done when
- the ledger has one exported method that makes a request's ban and one that reports it, and the four above are gone;
- the four tests of observe mode on the way to a ban are one, in one function of `internal/waf/bans.go`;
- behaviour is unchanged: every existing test passes, changed only where it calls one of the four methods by name;
- `make check` passes;
- the PR body lists every new type, method and function name. Each says what the thing is to a reader of that one file, the standard of the symbol names audit.
If this is more than one PR can carry, say so on this issue instead of starting.
Model: fable-5-2
clawbot
self-assigned this 2026-11-19 17:14:27 +01:00
bans.Ledger has Ban and WouldBan, which take a bans.Grounds (cause and notes); the four old methods are gone.
banClient in internal/waf/bans.go holds the shared skeleton and the one observe-mode test; banForLimit and banForAttack fill in what differs.
Judgement call: Ban and WouldBan panic for a cause other than CauseLimit or CauseAttack.
Model: opus-5-5
Built in https://git.eeqj.de/sneak/smallwebwaf/pulls/469, branch `issue-444-one-ban-method`.
- `bans.Ledger` has `Ban` and `WouldBan`, which take a `bans.Grounds` (cause and notes); the four old methods are gone.
- `banClient` in `internal/waf/bans.go` holds the shared skeleton and the one observe-mode test; `banForLimit` and `banForAttack` fill in what differs.
- Judgement call: `Ban` and `WouldBan` panic for a cause other than `CauseLimit` or `CauseAttack`.
Model: opus-5-5
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
From the architecture review, "The decision pipeline: the heuristics", under "Observe mode is decided in eleven places": #283 (comment). Approved for building: #283 (comment). The code was read at
809d266onnext, wherediscriminatoris nowwafand the CrowdSec feed is gone. Line numbers are that commit's.The review calls this independent of its other proposals for the heuristics. It edits
internal/waf/bans.go, and so does the issue that gives each heuristic its own settings and parts (#441): whichever is built second rebases.What is there
bans.Ledgerhas each way a request makes a ban twice:BanForLimitandWouldBanForLimit,BanForAttackandWouldBanForAttack(internal/bans/bans.go:314to373). All four call one privateban(…, cause, reason string, notes, keep bool).banForLimitandbanForAttackininternal/waf/bans.gorepeat one skeleton:Would…method and alert;BanExpiresand alert.rq.h.config.Observefour times (lines 126, 151, 176, 190).Why it matters
Another cause of ban means a new pair of ledger methods and another copy of the skeleton, with two observe branches each. A slip there makes a ban in observe mode.
What changes
bans.Ledgergets one method that makes a ban and one that reports what it would make. Both take the cause and the notes in one struct.internal/waf/bans.gogets one function that holds the skeleton. It is the one place that tests observe mode for a ban a request makes.banForLimitandbanForAttackshrink to filling in what differs.Before (
internal/bans/bans.go):After (the struct's name is a placeholder):
What stays
The review had not traced three neighbours. Read since, each stays as it is:
BanForAdminmakes its ban even while another on the netblock is active, and takes its end from the admin.BanForAbuseIPDBbans many netblocks in one call, and skips a netblock an admin lifted.WouldBePermanentanswers one question without working out the ban, which observe mode uses to avoid counting a netblock's requests.Also unchanged:
CheckandFind, the pairactiveBanchooses between by observe mode, and themodedetailalertBanadds in observe mode. The symbol names audit (#213) proposes names forCheckandFind, and this issue renames nothing.Done when
internal/waf/bans.go;make checkpasses;If this is more than one PR can carry, say so on this issue instead of starting.
Model: fable-5-2
Built in #469, branch
issue-444-one-ban-method.bans.LedgerhasBanandWouldBan, which take abans.Grounds(cause and notes); the four old methods are gone.banClientininternal/waf/bans.goholds the shared skeleton and the one observe-mode test;banForLimitandbanForAttackfill in what differs.BanandWouldBanpanic for a cause other thanCauseLimitorCauseAttack.Model: opus-5-5