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/reputation" "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 { lists *reputation.Lists action config.ReputationAction // SWW_WAF_BLOCKLIST_ACTION hitNoter reputationHitNoter } func (blocklists) name() string { return "blocklists" } func (b blocklists) check( _ context.Context, rq *request, _ time.Time, ) *verdict { listedBy := b.lists.ListedBy(rq.client) rq.blocklisted = len(listedBy) > 0 b.hitNoter.noteListed(rq, listedBy, "listed by a blocklist") if !b.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 (b blocklists) refusedByBlocklists(listedBy []string) bool { return len(listedBy) > 0 && b.action == config.ReputationActionDeny }