Default the netblock and AS number anomaly thresholds (closes #410)
check / check (push) Successful in 6m7s

The alert-only thresholds per netblock and per AS number now have
defaults that alert on obvious abuse alone: per netblock 1200 and
15000 requests a minute and an hour, 5G and 50G a minute and an hour;
per AS number five times those. The AS number ones default to off
while SWW_WAF_LOOKUP_SOURCE is off. The other scopes stay off. The
README says to tune them to the site's traffic.

Model: opus-5-5
This commit was merged in pull request #484.
This commit is contained in:
clawbot committed 2026-11-20 06:42:25 +01:00
1 parent 8219664ad1
commit 23eaa869dd
8 files changed
+152 -33

No files matched your search

+16
View File
@@ -32,6 +32,22 @@ const (
bytesPerHour = "BYTES_PER_HOUR"
)
// netAndASNThresholdsOff returns the anomaly thresholds per netblock and
// per AS number, the ones on by default, each set to off.
func netAndASNThresholdsOff() map[string]string {
settings := map[string]string{}
for _, scope := range []string{anomalyNet, anomalyASN} {
for _, end := range []string{
requestsPerMinute, requestsPerHour, bytesPerMinute, bytesPerHour,
} {
settings[scope+end] = off
}
}
return settings
}
// The other anomaly settings.
const (
anomalyNetV4Prefix = "SWW_WAF_ANOMALY_NET_V4_PREFIX"
+4 -1
View File
@@ -456,7 +456,9 @@ func (w *wafAndParts) banAbuseIPDBBlacklist(
// at abuseIPDBURL while env sets SWW_WAF_ABUSEIPDB_KEY, and its blacklist is
// fetched from abuseIPDBBlacklistURL.
// SWW_WAF_CORE_RULE_SET_MODE is off unless env sets it, so that only the tests of the
// Core Rule Set have their requests inspected by it.
// Core Rule Set have their requests inspected by it. Likewise the anomaly thresholds
// per netblock and per AS number are off unless env sets them, so that only the tests
// of the anomaly thresholds count requests.
func newWAF(
t *testing.T,
geojsURL string,
@@ -486,6 +488,7 @@ func newWAFWith(
settings[lookupSource] = off
}
maps.Copy(settings, netAndASNThresholdsOff())
maps.Copy(settings, env)
cfg, err := config.WAFFromEnvironment(configtest.Viper(settings))
+1 -1
View File
@@ -405,7 +405,7 @@ func (rq *request) addToHistory() {
// SWW_WAF_RATE_LIMIT_EXEMPT_NETS, and one for a path in
// SWW_WAF_RATE_LIMIT_EXEMPT_PATHS are counted too. It is counted for its
// client's AS number when answerAtTheEnd gives one. With every anomaly
// threshold off, the default, it does nothing.
// threshold off, it does nothing.
func (rq *request) countAnomalies() {
if !anomalyThresholdsSet(rq.h.config) {
return