check / check (push) Successful in 5m7s
The command is now `sww waf`, and the package is `internal/waf`. Types, functions, files, tests, comments, docs, the Dockerfile, the runit script, `script/`, compose examples, the log field `waf_line` and the `X-From-Waf` test header follow. No behaviour changes, and no setting changes name: rproxy already finds the waf through `SWRP_WAF_BACKEND`. Done with one `sed -i` (Discriminator and DISCRIMINATOR to WAF, discriminator to waf) over the files `git grep -i discriminator` listed, as sneak allowed for this rename, then `git mv` for the package and files. Model: opus-5-5
30 lines
655 B
Go
30 lines
655 B
Go
package waf
|
|
|
|
// 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.ActionClientDenied,
|
|
figures: map[string]any{figureNetblock: netblock.String()},
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|