geojs: a visitor's wait no longer cuts off the request to GeoJS (closes #404)
check / check (push) Failing after 2m16s
check / check (push) Failing after 2m16s
The GeoJS lookup and its cache move from internal/lookup to internal/geojs, which imports no other package of this repository. waf hands it functions to count requests, report failures and count lookups that went without an answer; waf keeps the log line, the source_failure alert and the metrics. The caller now passes its wait to each lookup. waf passes SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS. A request to GeoJS has its own fixed limit of 10 seconds, and only passing it or an error from GeoJS is a failure. An answer that comes after the caller stopped waiting is kept. internal/lookup keeps the lookup database and returns geojs.Answer. Model: opus-5-5
This commit was merged in pull request #407.
This commit is contained in:
1 parent
a2fcc00ded
commit
caa3079847
21 files changed
+645
-484
No files matched your search
+20
-17
@@ -17,6 +17,7 @@ import (
|
||||
"sneak.berlin/go/smallwebwaf/internal/bans"
|
||||
"sneak.berlin/go/smallwebwaf/internal/config"
|
||||
"sneak.berlin/go/smallwebwaf/internal/coreruleset"
|
||||
"sneak.berlin/go/smallwebwaf/internal/geojs"
|
||||
"sneak.berlin/go/smallwebwaf/internal/lookup"
|
||||
"sneak.berlin/go/smallwebwaf/internal/metrics"
|
||||
"sneak.berlin/go/smallwebwaf/internal/ratelimit"
|
||||
@@ -55,7 +56,7 @@ type Params struct {
|
||||
// ProcessLog receives the process's own messages.
|
||||
ProcessLog *slog.Logger
|
||||
// GeoJSURL is where clients' AS numbers and countries are looked up
|
||||
// while SWW_WAF_LOOKUP_SOURCE is geojs, normally lookup.URL.
|
||||
// while SWW_WAF_LOOKUP_SOURCE is geojs, normally geojs.URL.
|
||||
GeoJSURL string
|
||||
// AbuseIPDBURL is where clients are checked with AbuseIPDB while
|
||||
// SWW_WAF_ABUSEIPDB_KEY is set, normally reputation.AbuseIPDBURL.
|
||||
@@ -93,7 +94,7 @@ type Server struct {
|
||||
|
||||
Ledger *bans.Ledger
|
||||
Limiter *ratelimit.Limiter
|
||||
GeoJS *lookup.GeoJS
|
||||
GeoJS *geojs.GeoJS
|
||||
Anomalies *anomaly.Counters
|
||||
LookupFile *lookup.File
|
||||
Lists *reputation.Lists
|
||||
@@ -164,20 +165,19 @@ func newHandler(params Params) *handler {
|
||||
})
|
||||
}
|
||||
|
||||
h.geojs = lookup.New(lookup.Params{
|
||||
URL: params.GeoJSURL,
|
||||
Timeout: params.Config.ASNAndCountryLookupTimeout,
|
||||
// The country list, the headers, the tag settings that name an asn=
|
||||
// or country= tag and the biased thresholds act on the answer before
|
||||
// the request goes on.
|
||||
Wait: len(params.Config.ExclusivelyAllowedCountries) > 0 ||
|
||||
params.Config.AddLookupHeaders || params.Config.TagsNeedLookup() ||
|
||||
biasedThresholdsSet(params.Config),
|
||||
Answered: h.addLookup,
|
||||
Now: params.Now,
|
||||
ProcessLog: params.ProcessLog,
|
||||
Metrics: m,
|
||||
Alerts: params.Alerts,
|
||||
// The country list, the headers, the tag settings that name an asn= or
|
||||
// country= tag and the biased thresholds act on the answer before the
|
||||
// request goes on.
|
||||
h.waitForGeoJS = len(params.Config.ExclusivelyAllowedCountries) > 0 ||
|
||||
params.Config.AddLookupHeaders || params.Config.TagsNeedLookup() ||
|
||||
biasedThresholdsSet(params.Config)
|
||||
h.geojs = geojs.New(geojs.Params{
|
||||
URL: params.GeoJSURL,
|
||||
Answered: h.addLookup,
|
||||
Now: params.Now,
|
||||
Asked: m.GeoJSRequests.Inc,
|
||||
Failed: h.geojsFailed,
|
||||
WentWithoutAnswer: m.RequestsWithoutGeoJSAnswer.Inc,
|
||||
})
|
||||
m.AddBansAndClients(h.ledger, h.limiter, params.Now)
|
||||
m.AddRules(params.Rules)
|
||||
@@ -268,7 +268,7 @@ type handler struct {
|
||||
metrics *metrics.Metrics
|
||||
limiter *ratelimit.Limiter
|
||||
ledger *bans.Ledger
|
||||
geojs *lookup.GeoJS
|
||||
geojs *geojs.GeoJS
|
||||
anomalies *anomaly.Counters
|
||||
lookupFile *lookup.File
|
||||
lists *reputation.Lists
|
||||
@@ -278,6 +278,9 @@ type handler struct {
|
||||
rules *rules.Files
|
||||
coreRuleSet *coreruleset.CoreRuleSet
|
||||
alerts *alerts.Queue
|
||||
// waitForGeoJS is true when a setting needs each request's answer from
|
||||
// GeoJS before the request goes on.
|
||||
waitForGeoJS bool
|
||||
// awaitingReport holds the decision on each answered question by its id
|
||||
// until its report comes, and nil for a question still being handled.
|
||||
awaitingReport *lru.Cache[string, *decision]
|
||||
|
||||
Reference in new issue
Block a user