Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d3f212b0d |
No files matched your search
@@ -43,6 +43,15 @@ func (b blocklists) check(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// refusesWhateverTheLookupAnswers reports whether blocklists refuses rq, as
|
||||||
|
// refusedByBlocklists says. The lookup's answer plays no part in it.
|
||||||
|
func (b blocklists) refusesWhateverTheLookupAnswers(
|
||||||
|
rq *request,
|
||||||
|
_ time.Time,
|
||||||
|
) bool {
|
||||||
|
return b.refusedByBlocklists(b.lists.ListedBy(rq.client))
|
||||||
|
}
|
||||||
|
|
||||||
// refusedByBlocklists reports whether the heuristic blocklists refuses a
|
// refusedByBlocklists reports whether the heuristic blocklists refuses a
|
||||||
// client, given listedBy, the blocklists that list it: it does when one lists
|
// client, given listedBy, the blocklists that list it: it does when one lists
|
||||||
// it and SWW_WAF_BLOCKLIST_ACTION is deny.
|
// it and SWW_WAF_BLOCKLIST_ACTION is deny.
|
||||||
|
|||||||
@@ -9,6 +9,16 @@ import (
|
|||||||
// and holds the settings and parts it reads. Add one line for it to one of the
|
// and holds the settings and parts it reads. Add one line for it to one of the
|
||||||
// lists that newHandler builds, which hands it those settings and parts. Its
|
// lists that newHandler builds, which hands it those settings and parts. Its
|
||||||
// settings go in config.WAF, and the comment at the top of its file names them.
|
// settings go in config.WAF, and the comment at the top of its file names them.
|
||||||
|
// A heuristic of afterLookup that can refuse a request whatever the lookup
|
||||||
|
// answers also implements refusesWithoutLookup.
|
||||||
|
//
|
||||||
|
// Three places outside its file may change with it:
|
||||||
|
// - waitForGeoJS in newHandler lists the settings that need the lookup's
|
||||||
|
// answer;
|
||||||
|
// - requestCanGetTag in internal/config/waf.go holds which setting can give a
|
||||||
|
// request which tag;
|
||||||
|
// - findBesideLookup does the work of each heuristic of besideLookup, by
|
||||||
|
// name.
|
||||||
|
|
||||||
// heuristic is one of the checks that decide what waf does with a
|
// heuristic is one of the checks that decide what waf does with a
|
||||||
// request.
|
// request.
|
||||||
@@ -20,6 +30,15 @@ type heuristic interface {
|
|||||||
check(ctx context.Context, rq *request, now time.Time) *verdict
|
check(ctx context.Context, rq *request, now time.Time) *verdict
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// refusesWithoutLookup is a heuristic of afterLookup that can tell, before the
|
||||||
|
// lookup answers, that it will refuse a request whatever the answer.
|
||||||
|
type refusesWithoutLookup interface {
|
||||||
|
// refusesWhateverTheLookupAnswers reports whether the heuristic will refuse
|
||||||
|
// rq at now, whatever the lookup answers about its client. It changes
|
||||||
|
// nothing.
|
||||||
|
refusesWhateverTheLookupAnswers(rq *request, now time.Time) bool
|
||||||
|
}
|
||||||
|
|
||||||
// verdict is a heuristic refusing a request, or banning its client: the action
|
// verdict is a heuristic refusing a request, or banning its client: the action
|
||||||
// the log line names, one of requestlog's Action constants, and the figures the
|
// the log line names, one of requestlog's Action constants, and the figures the
|
||||||
// heuristic acted on, by name, such as the count and the limit.
|
// heuristic acted on, by name, such as the count and the limit.
|
||||||
|
|||||||
+25
-31
@@ -177,30 +177,6 @@ func newHandler(params Params) *handler {
|
|||||||
ipv6GroupPrefix: cfg.IPv6GroupPrefix,
|
ipv6GroupPrefix: cfg.IPv6GroupPrefix,
|
||||||
}
|
}
|
||||||
|
|
||||||
h.blocklists = blocklists{
|
|
||||||
lists: params.Lists,
|
|
||||||
action: cfg.BlocklistAction,
|
|
||||||
hitNoter: hitNoter,
|
|
||||||
}
|
|
||||||
h.rateLimits = rateLimits{
|
|
||||||
limiter: params.Limiter,
|
|
||||||
exemptNets: cfg.RateLimitExemptNets,
|
|
||||||
exemptPaths: cfg.RateLimitExemptPaths,
|
|
||||||
banResponse: cfg.BanResponse,
|
|
||||||
ipv6GroupPrefix: cfg.IPv6GroupPrefix,
|
|
||||||
biasedThresholds: biasedThresholds{
|
|
||||||
lists: params.Lists,
|
|
||||||
tagLimitPercent: cfg.TagLimitPercent,
|
|
||||||
asnBytesLimitPercent: cfg.ASNBytesLimitPercent,
|
|
||||||
countryBytesLimitPercent: cfg.CountryBytesLimitPercent,
|
|
||||||
unknownCountryLimitPercent: cfg.UnknownCountryLimitPercent,
|
|
||||||
blocklistAction: cfg.BlocklistAction,
|
|
||||||
blocklistLimitPercent: cfg.BlocklistLimitPercent,
|
|
||||||
dnsblAbuseIPDBAction: cfg.DNSBLAbuseIPDBAction,
|
|
||||||
dnsblAbuseIPDBLimitPercent: cfg.DNSBLAbuseIPDBLimitPercent,
|
|
||||||
},
|
|
||||||
banMaker: sharedBanMaker,
|
|
||||||
}
|
|
||||||
h.trapPaths = trapPaths{paths: cfg.TrapPaths, banMaker: sharedBanMaker}
|
h.trapPaths = trapPaths{paths: cfg.TrapPaths, banMaker: sharedBanMaker}
|
||||||
h.ruleFiles = ruleFiles{
|
h.ruleFiles = ruleFiles{
|
||||||
rules: params.Rules,
|
rules: params.Rules,
|
||||||
@@ -230,7 +206,11 @@ func newHandler(params Params) *handler {
|
|||||||
}
|
}
|
||||||
h.afterLookup = []heuristic{
|
h.afterLookup = []heuristic{
|
||||||
countries{allowed: cfg.ExclusivelyAllowedCountries},
|
countries{allowed: cfg.ExclusivelyAllowedCountries},
|
||||||
h.blocklists,
|
blocklists{
|
||||||
|
lists: params.Lists,
|
||||||
|
action: cfg.BlocklistAction,
|
||||||
|
hitNoter: hitNoter,
|
||||||
|
},
|
||||||
dnsbl{
|
dnsbl{
|
||||||
dnsbl: params.DNSBL,
|
dnsbl: params.DNSBL,
|
||||||
action: cfg.DNSBLAbuseIPDBAction,
|
action: cfg.DNSBLAbuseIPDBAction,
|
||||||
@@ -246,7 +226,25 @@ func newHandler(params Params) *handler {
|
|||||||
hitNoter: hitNoter,
|
hitNoter: hitNoter,
|
||||||
},
|
},
|
||||||
tagDeny{tags: cfg.TagDeny},
|
tagDeny{tags: cfg.TagDeny},
|
||||||
h.rateLimits,
|
rateLimits{
|
||||||
|
limiter: params.Limiter,
|
||||||
|
exemptNets: cfg.RateLimitExemptNets,
|
||||||
|
exemptPaths: cfg.RateLimitExemptPaths,
|
||||||
|
banResponse: cfg.BanResponse,
|
||||||
|
ipv6GroupPrefix: cfg.IPv6GroupPrefix,
|
||||||
|
biasedThresholds: biasedThresholds{
|
||||||
|
lists: params.Lists,
|
||||||
|
tagLimitPercent: cfg.TagLimitPercent,
|
||||||
|
asnBytesLimitPercent: cfg.ASNBytesLimitPercent,
|
||||||
|
countryBytesLimitPercent: cfg.CountryBytesLimitPercent,
|
||||||
|
unknownCountryLimitPercent: cfg.UnknownCountryLimitPercent,
|
||||||
|
blocklistAction: cfg.BlocklistAction,
|
||||||
|
blocklistLimitPercent: cfg.BlocklistLimitPercent,
|
||||||
|
dnsblAbuseIPDBAction: cfg.DNSBLAbuseIPDBAction,
|
||||||
|
dnsblAbuseIPDBLimitPercent: cfg.DNSBLAbuseIPDBLimitPercent,
|
||||||
|
},
|
||||||
|
banMaker: sharedBanMaker,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
h.besideLookup = []heuristic{h.trapPaths, h.ruleFiles, h.coreRuleSet}
|
h.besideLookup = []heuristic{h.trapPaths, h.ruleFiles, h.coreRuleSet}
|
||||||
h.afterBesideLookup = []heuristic{tagDeny{tags: cfg.TagDeny}}
|
h.afterBesideLookup = []heuristic{tagDeny{tags: cfg.TagDeny}}
|
||||||
@@ -323,11 +321,7 @@ type handler struct {
|
|||||||
// afterAnswer, they only ban.
|
// afterAnswer, they only ban.
|
||||||
onReport []heuristic
|
onReport []heuristic
|
||||||
|
|
||||||
// The heuristics of the lists that other steps of a request use too:
|
// The heuristics of besideLookup, whose work findBesideLookup does.
|
||||||
// refusedWhateverTheAnswer asks blocklists and rateLimits, and
|
|
||||||
// findBesideLookup does the work of trapPaths, ruleFiles and coreRuleSet.
|
|
||||||
blocklists blocklists
|
|
||||||
rateLimits rateLimits
|
|
||||||
trapPaths trapPaths
|
trapPaths trapPaths
|
||||||
ruleFiles ruleFiles
|
ruleFiles ruleFiles
|
||||||
coreRuleSet coreRuleSet
|
coreRuleSet coreRuleSet
|
||||||
|
|||||||
@@ -67,11 +67,14 @@ func (r rateLimits) check(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// overAWholeRateLimit reports whether the heuristic rate_limits will refuse rq
|
// refusesWhateverTheLookupAnswers reports whether the heuristic rate_limits
|
||||||
// at now, whatever its client's limit percentages: the rate limits count it,
|
// will refuse rq at now, whatever its client's limit percentages, which the
|
||||||
// and one more request from its client takes it over a whole rate limit. It
|
// lookup's answer can lower: the rate limits count it, and one more request
|
||||||
// counts nothing.
|
// from its client takes it over a whole rate limit. It counts nothing.
|
||||||
func (r rateLimits) overAWholeRateLimit(rq *request, now time.Time) bool {
|
func (r rateLimits) refusesWhateverTheLookupAnswers(
|
||||||
|
rq *request,
|
||||||
|
now time.Time,
|
||||||
|
) bool {
|
||||||
return r.countedByRateLimits(rq) &&
|
return r.countedByRateLimits(rq) &&
|
||||||
r.limiter.OverARateLimit(
|
r.limiter.OverARateLimit(
|
||||||
clientGroup(r.ipv6GroupPrefix, rq.client),
|
clientGroup(r.ipv6GroupPrefix, rq.client),
|
||||||
|
|||||||
+10
-6
@@ -72,18 +72,22 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// refusedWhateverTheAnswer reports whether the request is one that does not wait
|
// refusedWhateverTheAnswer reports whether the request is one that does not wait
|
||||||
// for GeoJS, since the checks will refuse it at now whatever GeoJS answers about
|
// for GeoJS, since the checks will refuse it at now whatever GeoJS answers about
|
||||||
// its client: the heuristic blocklists or rate_limits will refuse it, as a
|
// its client: a heuristic of afterLookup that implements refusesWithoutLookup
|
||||||
// function in that heuristic's file says. In observe mode, which refuses
|
// says it will refuse it. In observe mode, which refuses nothing, none is.
|
||||||
// nothing, none is. rproxy lets a request through when waf answers too late.
|
// rproxy lets a request through when waf answers too late.
|
||||||
func (rq *request) refusedWhateverTheAnswer(now time.Time) bool {
|
func (rq *request) refusedWhateverTheAnswer(now time.Time) bool {
|
||||||
if rq.h.config.Observe {
|
if rq.h.config.Observe {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
listedBy := rq.h.blocklists.lists.ListedBy(rq.client)
|
for _, each := range rq.h.afterLookup {
|
||||||
|
knows, ok := each.(refusesWithoutLookup)
|
||||||
|
if ok && knows.refusesWhateverTheLookupAnswers(rq, now) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return rq.h.blocklists.refusedByBlocklists(listedBy) ||
|
return false
|
||||||
rq.h.rateLimits.overAWholeRateLimit(rq, now)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// answerQuestion runs the checks on the visitor's request a question
|
// answerQuestion runs the checks on the visitor's request a question
|
||||||
|
|||||||
Reference in new issue
Block a user