check / check (push) Failing after 1m42s
Each heuristic that refuses a request sets the status on its verdict. check copies it into the refusal, or in observe mode notes it, and no longer works the status out from the action. refusalLimit takes the status from that verdict instead of from a switch over the action. Model: opus-5-5
39 lines
858 B
Go
39 lines
858 B
Go
package waf
|
|
|
|
// The heuristic deny_nets. It reads SWW_WAF_DENY_NETS and SWW_WAF_BAN_RESPONSE.
|
|
|
|
import (
|
|
"context"
|
|
"net/netip"
|
|
"time"
|
|
|
|
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
|
)
|
|
|
|
// denyNets refuses a client in SWW_WAF_DENY_NETS, with SWW_WAF_BAN_RESPONSE.
|
|
// Its figure is the netblock of the setting the client is in.
|
|
type denyNets struct {
|
|
netblocks []netip.Prefix // SWW_WAF_DENY_NETS
|
|
banResponse int // SWW_WAF_BAN_RESPONSE
|
|
}
|
|
|
|
func (denyNets) name() string { return "deny_nets" }
|
|
|
|
func (d denyNets) check(
|
|
_ context.Context,
|
|
rq *request,
|
|
_ time.Time,
|
|
) *verdict {
|
|
for _, netblock := range d.netblocks {
|
|
if netblock.Contains(rq.client) {
|
|
return &verdict{
|
|
action: requestlog.ActionClientDenied,
|
|
status: d.banResponse,
|
|
figures: map[string]any{figureNetblock: netblock.String()},
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|