package waf // The heuristic active_ban. It reads SWW_WAF_MODE and SWW_WAF_BAN_RESPONSE; the // bans are the ban ledger's. import ( "context" "time" ) // activeBan refuses a client a ban covers, with SWW_WAF_BAN_RESPONSE: a ban on // a netblock the client is in, in force at now. It notes for the log line when // that ban ends. A request that makes the ban permanent, or in observe mode // would have, raises the alert for it. Its figures are the ban's netblock and // when it ends. type activeBan struct { banMaker banMaker } func (activeBan) name() string { return "active_ban" } func (a activeBan) check( _ context.Context, rq *request, now time.Time, ) *verdict { ledger := a.banMaker.ledger check := ledger.Check if a.banMaker.observe { check = ledger.Find // the ban refuses nothing, and stays as it is } ban, banned, madePermanent := check(rq.client, now) var expires string if banned { expires = banExpires(ban) rq.line.BanExpires = expires } if madePermanent { ban.Expires = time.Time{} // the ban made permanent, which Find leaves as it is a.banMaker.alertBan(rq, ban) } if !banned { return nil } return &verdict{ action: banAction(ban.Permanent()), status: a.banMaker.banResponse, figures: map[string]any{ figureNetblock: ban.Netblock.String(), "ban_expires": expires, }, } }