check / check (push) Waiting to run
BytesCounted, LookupSource, BlocklistAction, DNSBLAbuseIPDBAction and CoreRuleSetMode become named string types declared in config, with constants for their values. Every comparison in waf and sww uses the constants, and the private duplicates fileSource and deny go. The two action settings share ReputationAction. The values and the strings written to logs, metrics and alerts are unchanged. Model: opus-5-5
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package waf
|
|
|
|
// The heuristic blocklists. It reads SWW_WAF_BLOCKLIST_ACTION, and the blocklists
|
|
// through the reputation lists.
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"sneak.berlin/go/smallwebwaf/internal/config"
|
|
"sneak.berlin/go/smallwebwaf/internal/requestlog"
|
|
)
|
|
|
|
// blocklists notes the blocklists that list the client, as noteListed does,
|
|
// and refuses the request when SWW_WAF_BLOCKLIST_ACTION is deny. Being limit, it
|
|
// lowers the client's limits instead (see limitPercentages), and being log, it
|
|
// does nothing more. Its figure is the blocklists that list the client.
|
|
type blocklists struct{}
|
|
|
|
func (blocklists) name() string { return "blocklists" }
|
|
|
|
func (blocklists) check(
|
|
_ context.Context,
|
|
rq *request,
|
|
_ time.Time,
|
|
) *verdict {
|
|
listedBy := rq.h.lists.ListedBy(rq.client)
|
|
rq.blocklisted = len(listedBy) > 0
|
|
rq.noteListed(listedBy, "listed by a blocklist")
|
|
|
|
if !rq.refusedByBlocklists(listedBy) {
|
|
return nil
|
|
}
|
|
|
|
return &verdict{
|
|
action: requestlog.ActionClientDenied,
|
|
figures: map[string]any{"lists": listedBy},
|
|
}
|
|
}
|
|
|
|
// refusedByBlocklists reports whether the heuristic blocklists refuses a
|
|
// client, given listedBy, the blocklists that list it: it does when one lists
|
|
// it and SWW_WAF_BLOCKLIST_ACTION is deny.
|
|
func (rq *request) refusedByBlocklists(listedBy []string) bool {
|
|
return len(listedBy) > 0 && rq.h.config.BlocklistAction ==
|
|
config.ReputationActionDeny
|
|
}
|