check / check (push) Failing after 1m53s
Each discriminator check is now a type in its own file behind one small interface, listed in `heuristics.go`. Adding a heuristic is one file and one line. Behaviour does not change. Refusal and ban log lines gain `heuristic` and `heuristic_figures`. A ban after the answer, by `refusal_limit` or `byte_limits`, logs `after_answer_heuristic` and its figures, so one line can name both. Deviation: four lists, not the planned three, so `refusal_limit` still bans at the decision. Rule suppressed: `//nolint:lll` on one struct tag. Model: opus-5-5
30 lines
659 B
Go
30 lines
659 B
Go
package discriminator
|
|
|
|
// The heuristic deny_nets. It reads SWW_DENY_NETS.
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
|
)
|
|
|
|
// denyNets refuses a client in SWW_DENY_NETS. Its figure is the netblock of
|
|
// the setting the client is in.
|
|
type denyNets struct{}
|
|
|
|
func (denyNets) name() string { return "deny_nets" }
|
|
|
|
func (denyNets) check(_ context.Context, rq *request, _ time.Time) *verdict {
|
|
for _, netblock := range rq.h.config.DenyNets {
|
|
if netblock.Contains(rq.client) {
|
|
return &verdict{
|
|
action: requestlog.ActionDenied,
|
|
figures: map[string]any{figureNetblock: netblock.String()},
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|