waf: run the trap paths, rule files and Core Rule Set during the GeoJS wait (closes #405)
check / check (push) Failing after 1m56s
check / check (push) Failing after 1m56s
While the lookup waits for GeoJS, the trap paths, the rule files and the Core Rule Set run at the same time as the checks after the lookup. The first side to refuse answers the request; what the other side finds leaves no trace. Those three checks have 500 ms together: past it, the request is refused with 503 as checks_timed_out, with no ban and no offence. Tests hold GeoJS and the Core Rule Set with stand-ins under synctest. The test helper lifts the 500 ms limit for tests that run the real Core Rule Set, which the race detector slows past it. Model: opus-5-5
This commit is contained in:
1 parent
caa3079847
commit
098bbe8878
19 files changed
+900
-83
No files matched your search
+43
-9
@@ -81,6 +81,9 @@ type request struct {
|
||||
checked time.Time
|
||||
// refused is what the request was refused with, nil if it was not.
|
||||
refused *refusal
|
||||
// findings is what the heuristics of besideLookup found of the request,
|
||||
// once waf has taken it, and nil before.
|
||||
findings *besideLookupFindings
|
||||
// requestBytes is how many bytes of the request's body have been read.
|
||||
requestBytes int64
|
||||
}
|
||||
@@ -177,9 +180,9 @@ func requestHeaders(r *http.Request, names []string) map[string]string {
|
||||
// check is the one place where a request can be refused. It returns nil to let
|
||||
// the request through. The heuristics of checkClient decide: a request they
|
||||
// refuse is answered with SWW_WAF_BAN_RESPONSE, 403 for a block rule or the Core
|
||||
// Rule Set, or 414 or 431 for the header limits. In observe mode nothing is refused,
|
||||
// and the log line names what enforce mode would have done. ctx is the
|
||||
// request's own context.
|
||||
// Rule Set, 503 for heuristics that ran out of time, or 414 or 431 for the
|
||||
// header limits. In observe mode nothing is refused, and the log line names
|
||||
// what enforce mode would have done. ctx is the request's own context.
|
||||
func (rq *request) check(ctx context.Context) *refusal {
|
||||
v := rq.checkClient(ctx)
|
||||
if v == nil {
|
||||
@@ -196,6 +199,11 @@ func (rq *request) check(ctx context.Context) *refusal {
|
||||
case action == requestlog.ActionBlockedByBlockRule ||
|
||||
action == requestlog.ActionBlockedByCoreRuleSet:
|
||||
return &refusal{status: http.StatusForbidden, action: action}
|
||||
case action == requestlog.ActionChecksTimedOut:
|
||||
return &refusal{
|
||||
status: http.StatusServiceUnavailable,
|
||||
action: action,
|
||||
}
|
||||
case action == requestlog.ActionRequestLineTooLong:
|
||||
return &refusal{status: http.StatusRequestURITooLong, action: action}
|
||||
case action == requestlog.ActionRequestHeaderTooLarge:
|
||||
@@ -208,11 +216,16 @@ func (rq *request) check(ctx context.Context) *refusal {
|
||||
}
|
||||
}
|
||||
|
||||
// checkClient runs the heuristics of beforeLookup on the request, then looks
|
||||
// up the client's AS number and country, then runs those of afterLookup. It
|
||||
// returns the first verdict, or nil when none gives one. A client in
|
||||
// SWW_WAF_ALLOW_NETS skips them all, and is not looked up. ctx is the request's
|
||||
// own context.
|
||||
// checkClient runs the heuristics on the request, and returns the first
|
||||
// verdict, or nil when none gives one. A client in SWW_WAF_ALLOW_NETS skips them
|
||||
// all, and is not looked up. ctx is the request's own context.
|
||||
//
|
||||
// The heuristics of beforeLookup run first. Then the client's AS number and
|
||||
// country are looked up, and afterLookup runs once the lookup has its result.
|
||||
// While the lookup waits for GeoJS, besideLookup runs too, as runBesideLookup
|
||||
// says. A lookup that needs no wait is done, and afterLookup with it, before
|
||||
// besideLookup starts, so that besideLookup does no work for a request
|
||||
// afterLookup refuses.
|
||||
func (rq *request) checkClient(ctx context.Context) *verdict {
|
||||
if isInside(rq.client, rq.h.config.AllowNets) {
|
||||
return nil
|
||||
@@ -225,7 +238,28 @@ func (rq *request) checkClient(ctx context.Context) *verdict {
|
||||
return v
|
||||
}
|
||||
|
||||
rq.lookUp(ctx, now)
|
||||
lookedUp := rq.startLookUp(ctx, now)
|
||||
|
||||
select {
|
||||
case result := <-lookedUp:
|
||||
v := rq.afterLookUp(ctx, result)
|
||||
if v != nil {
|
||||
return v
|
||||
}
|
||||
|
||||
return rq.runBesideLookup(ctx, nil)
|
||||
default:
|
||||
return rq.runBesideLookup(ctx, lookedUp)
|
||||
}
|
||||
}
|
||||
|
||||
// afterLookUp notes result, the lookup's, and runs the heuristics of
|
||||
// afterLookup. It returns the first verdict, or nil when none gives one. ctx is
|
||||
// the request's own context.
|
||||
func (rq *request) afterLookUp(
|
||||
ctx context.Context, result lookupResult,
|
||||
) *verdict {
|
||||
rq.noteLookup(result)
|
||||
|
||||
// The lookup can wait for GeoJS, so the checks after it read the time
|
||||
// again: a request counted at the time it arrived could be counted
|
||||
|
||||
Reference in new issue
Block a user