Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3305014847 | ||
|
|
5b5a12e57c | ||
|
|
3222c55009 | ||
|
|
580fa8f26a | ||
|
|
a320407ea5 | ||
|
|
aa19f8b854 | ||
|
|
f2fd9cd734 |
No files matched your search
@@ -416,8 +416,8 @@ full, and the limits that are fixed rather than settings.
|
|||||||
Each example is a complete `compose.yaml`. `smallwebwaf` is the tag
|
Each example is a complete `compose.yaml`. `smallwebwaf` is the tag
|
||||||
`make docker` gives the image; on another host, use the name you pushed it
|
`make docker` gives the image; on another host, use the name you pushed it
|
||||||
under, by digest. Docker Compose puts the services on a private network of its
|
under, by digest. Docker Compose puts the services on a private network of its
|
||||||
own, where each reaches the others by service name. Each example publishes
|
own, where each reaches the others by service name. Each example but "On the
|
||||||
`rproxy`'s port on the host, for trying it out.
|
open internet" publishes `rproxy`'s port on the host, for trying it out.
|
||||||
|
|
||||||
### Smallest setup
|
### Smallest setup
|
||||||
|
|
||||||
@@ -449,6 +449,142 @@ volumes:
|
|||||||
waf-state:
|
waf-state:
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### On the open internet
|
||||||
|
|
||||||
|
One gitea at `git.example.com`, with traefik in front of `rproxy`. traefik gets
|
||||||
|
the certificate from Let's Encrypt and is the only service with published ports.
|
||||||
|
`waf` sets what most sites set. More `waf` settings follow, commented out, each
|
||||||
|
with what it does and when to set it.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
traefik:
|
||||||
|
# traefik v3.7.19, 2026-11-13
|
||||||
|
image: traefik@sha256:a6c0194dda77bcb804824580f36fa7edc56e315b1acfe933366c8b52844a78a4
|
||||||
|
restart: unless-stopped
|
||||||
|
command:
|
||||||
|
- --providers.docker=true
|
||||||
|
- --providers.docker.exposedByDefault=false
|
||||||
|
- --entryPoints.web.address=:80
|
||||||
|
- --entryPoints.websecure.address=:443
|
||||||
|
# Redirect plain HTTP to HTTPS.
|
||||||
|
- --entryPoints.web.http.redirections.entryPoint.to=websecure
|
||||||
|
- --entryPoints.web.http.redirections.entryPoint.scheme=https
|
||||||
|
# A Let's Encrypt certificate for each site, by the TLS-ALPN
|
||||||
|
# challenge on port 443.
|
||||||
|
- --entryPoints.websecure.http.tls.certResolver=le
|
||||||
|
- --certificatesResolvers.le.acme.email=hostmaster@example.com
|
||||||
|
- --certificatesResolvers.le.acme.storage=/letsencrypt/acme.json
|
||||||
|
- --certificatesResolvers.le.acme.tlsChallenge=true
|
||||||
|
# Give a request 10 minutes to arrive, rather than 1, for the
|
||||||
|
# large git pushes the rproxy lines below accept.
|
||||||
|
# - --entryPoints.websecure.transport.respondingTimeouts.readTimeout=600s
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
|
- "443:443"
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
|
- acme:/letsencrypt
|
||||||
|
|
||||||
|
app:
|
||||||
|
# Your app: here a gitea, which listens on port 3000.
|
||||||
|
image: registry.example/app@sha256:0000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
rproxy:
|
||||||
|
image: smallwebwaf
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
SWW_RPROXY_WAF_BACKEND: http://waf:8080
|
||||||
|
SWW_RPROXY_UPSTREAM_URL: http://app:3000
|
||||||
|
# Accept git pushes up to 1 GiB, rather than 100 MiB, sent in
|
||||||
|
# up to 10 minutes, rather than 1, with traefik's readTimeout
|
||||||
|
# line above.
|
||||||
|
# SWW_RPROXY_MAX_REQUEST_SIZE: 1G
|
||||||
|
# SWW_RPROXY_MAX_REQUEST_TIME_MS: "600000"
|
||||||
|
labels:
|
||||||
|
- traefik.enable=true
|
||||||
|
- traefik.http.routers.git.rule=Host(`git.example.com`)
|
||||||
|
- traefik.http.routers.git.entryPoints=websecure
|
||||||
|
- traefik.http.services.git.loadBalancer.server.port=8080
|
||||||
|
|
||||||
|
waf:
|
||||||
|
image: smallwebwaf
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
SWW_COMMAND: waf
|
||||||
|
# The name in every log line, alert and metric. The default,
|
||||||
|
# the container's host name, is a random id under Compose.
|
||||||
|
SWW_WAF_INSTANCE_NAME: host1/waf
|
||||||
|
# The app each hostname serves. Only that app's fixes to the
|
||||||
|
# Core Rule Set apply there.
|
||||||
|
SWW_WAF_APPS: git.example.com:gitea
|
||||||
|
# Monitoring skips every check.
|
||||||
|
SWW_WAF_ALLOW_NETS: 192.0.2.10
|
||||||
|
# The office and the CI runner, which would exceed the rate
|
||||||
|
# limits, are never rate limited.
|
||||||
|
SWW_WAF_RATE_LIMIT_EXEMPT_NETS: 203.0.113.0/24,198.51.100.7
|
||||||
|
# WordPress paths, which only scanners ask a gitea for. One
|
||||||
|
# request for one bans the client.
|
||||||
|
SWW_WAF_TRAP_PATHS: /wp-login.php,/xmlrpc.php
|
||||||
|
# Spamhaus's list of netblocks hijacked or leased by
|
||||||
|
# criminals. Their clients are refused.
|
||||||
|
SWW_WAF_BLOCKLIST_URLS: https://www.spamhaus.org/drop/drop.txt
|
||||||
|
# The token for the ban endpoints, to lift a ban without
|
||||||
|
# editing bans.json.
|
||||||
|
SWW_WAF_ADMIN_TOKEN_FILE: /etc/sww/tokens/admin
|
||||||
|
# Alerts, such as one for each ban, to an ntfy topic.
|
||||||
|
SWW_WAF_ALERT_NTFY_URL: https://ntfy.example.com/smallwebwaf
|
||||||
|
|
||||||
|
# Refuse nothing and ban no one, for the first days. Each log
|
||||||
|
# line says what enforce mode would have done.
|
||||||
|
# SWW_WAF_MODE: observe
|
||||||
|
# The access token for an ntfy topic that is not public.
|
||||||
|
# SWW_WAF_ALERT_NTFY_TOKEN_FILE: /etc/sww/tokens/ntfy
|
||||||
|
# The token for /_sww/metrics, for Prometheus. Unset, the
|
||||||
|
# metrics are off.
|
||||||
|
# SWW_WAF_METRICS_TOKEN_FILE: /etc/sww/tokens/metrics
|
||||||
|
# 600 requests an hour rather than 1500, to ban slower
|
||||||
|
# scrapers. A fast human reader can reach it too.
|
||||||
|
# SWW_WAF_RATE_LIMIT_PER_HOUR: "600"
|
||||||
|
# A quarter of every limit for clients in two hosting
|
||||||
|
# networks, where scrapers run rather than people.
|
||||||
|
# SWW_WAF_TAG_LIMIT_PERCENT: asn=14061:25,asn=16276:25
|
||||||
|
# For a site only for people in a few countries. Clients
|
||||||
|
# elsewhere are refused, and so are any the lookup cannot place.
|
||||||
|
# SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES: de,at,ch
|
||||||
|
# Close a refused request's connection rather than answer
|
||||||
|
# 403. traefik then answers 502, so a scraper cannot tell a
|
||||||
|
# ban from a broken site.
|
||||||
|
# SWW_WAF_BAN_RESPONSE: close
|
||||||
|
# A copy of every log line to a syslog server.
|
||||||
|
# SWW_WAF_LOG_REMOTE_URL: syslog+tls://logs.example.com:6514
|
||||||
|
volumes:
|
||||||
|
- waf-state:/var/lib/sww
|
||||||
|
- /srv/sww/tokens:/etc/sww/tokens:ro
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
acme:
|
||||||
|
waf-state:
|
||||||
|
```
|
||||||
|
|
||||||
|
Change these before the first start:
|
||||||
|
|
||||||
|
- `git.example.com`, in the router rule and in `SWW_WAF_APPS`;
|
||||||
|
- the email address for Let's Encrypt;
|
||||||
|
- the ntfy topic's URL;
|
||||||
|
- the app's image and port;
|
||||||
|
- the netblocks, which are documentation addresses.
|
||||||
|
|
||||||
|
Make the admin token file first, as for any token file:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
mkdir -p /srv/sww/tokens
|
||||||
|
openssl rand -hex 32 > /srv/sww/tokens/admin
|
||||||
|
chown 65532:65532 /srv/sww/tokens/admin
|
||||||
|
chmod 0400 /srv/sww/tokens/admin
|
||||||
|
```
|
||||||
|
|
||||||
### Custom per-address limits
|
### Custom per-address limits
|
||||||
|
|
||||||
For a site with no API:
|
For a site with no API:
|
||||||
|
|||||||
@@ -71,59 +71,6 @@ func TestServerHasTheFixedLimits(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// getOfSize is a GET whose request line and headers, the blank line that ends
|
|
||||||
// them included, are size bytes long.
|
|
||||||
func getOfSize(size int) string {
|
|
||||||
const start, end = "GET / HTTP/1.1\r\nHost: site.example\r\nX-Pad: ", "\r\n\r\n"
|
|
||||||
|
|
||||||
return start + strings.Repeat("x", size-len(start)-len(end)) + end
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestARequestLineAndHeadersOf32KiBReachTheApp(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
standIn := startWAF(t, allow)
|
|
||||||
app := startApp(t, greet)
|
|
||||||
addr, _ := startRProxy(t, standIn.URL, app.URL, nil)
|
|
||||||
|
|
||||||
conn := dial(t, addr)
|
|
||||||
send(t, conn, getOfSize(32<<10))
|
|
||||||
|
|
||||||
if status := readStatus(t, conn); status != http.StatusOK {
|
|
||||||
t.Errorf("status %d, want the app's 200", status)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestARequestLineAndHeadersOver32KiBAreRefusedAndTheConnectionClosed(
|
|
||||||
t *testing.T,
|
|
||||||
) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
standIn := startWAF(t, allow)
|
|
||||||
app := startApp(t, func(http.ResponseWriter, *http.Request) {
|
|
||||||
t.Error("the app was asked")
|
|
||||||
})
|
|
||||||
addr, _ := startRProxy(t, standIn.URL, app.URL, nil)
|
|
||||||
|
|
||||||
conn := dial(t, addr)
|
|
||||||
send(t, conn, getOfSize(32<<10+1))
|
|
||||||
|
|
||||||
// io.ReadAll returns without an error only once rproxy has closed the
|
|
||||||
// connection.
|
|
||||||
text, err := io.ReadAll(conn)
|
|
||||||
if err != nil || !strings.HasPrefix(string(text), "HTTP/1.1 431 ") {
|
|
||||||
t.Errorf(
|
|
||||||
"read %q (%v), want 431 and the connection closed",
|
|
||||||
text,
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(standIn.questions) != 0 {
|
|
||||||
t.Error("waf was asked")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestABodyAnnouncedOverItsLimitIsRefusedOnceWAFAllowsIt(t *testing.T) {
|
func TestABodyAnnouncedOverItsLimitIsRefusedOnceWAFAllowsIt(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -324,8 +324,7 @@ func greet(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// startRProxy starts rproxy with waf at backend and the app at appURL, and
|
// startRProxy starts rproxy with waf at backend and the app at appURL, and
|
||||||
// the settings in env on top of the defaults. It returns where rproxy listens
|
// the settings in env on top of the defaults. It returns where rproxy listens
|
||||||
// and what it writes. SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS is a minute unless env
|
// and what it writes.
|
||||||
// sets it, so that a busy host cannot make rproxy drop a question or a report.
|
|
||||||
func startRProxy(
|
func startRProxy(
|
||||||
t *testing.T, backend, appURL string, env map[string]string,
|
t *testing.T, backend, appURL string, env map[string]string,
|
||||||
) (string, *output) {
|
) (string, *output) {
|
||||||
@@ -358,7 +357,6 @@ func startServerLogging(
|
|||||||
|
|
||||||
settings := map[string]string{
|
settings := map[string]string{
|
||||||
"SWW_RPROXY_WAF_BACKEND": backend, "SWW_RPROXY_UPSTREAM_URL": appURL,
|
"SWW_RPROXY_WAF_BACKEND": backend, "SWW_RPROXY_UPSTREAM_URL": appURL,
|
||||||
wafBackendTimeout: "60000",
|
|
||||||
}
|
}
|
||||||
maps.Copy(settings, env)
|
maps.Copy(settings, env)
|
||||||
|
|
||||||
|
|||||||
@@ -51,9 +51,7 @@ func runRProxy(ctx context.Context, env map[string]string, out *output) int {
|
|||||||
|
|
||||||
// startRProxy runs rproxy with waf at backend and the app at appURL, and
|
// startRProxy runs rproxy with waf at backend and the app at appURL, and
|
||||||
// returns its URL and what it writes. It believes X-Forwarded-For from the
|
// returns its URL and what it writes. It believes X-Forwarded-For from the
|
||||||
// tests. It waits a minute for waf's answer, so that a slow answer on a busy
|
// tests. It stops as the test ends, and that it stopped in order is checked.
|
||||||
// host is not taken for no answer. It stops as the test ends, and that it
|
|
||||||
// stopped in order is checked.
|
|
||||||
func startRProxy(t *testing.T, backend, appURL string) (string, *output) {
|
func startRProxy(t *testing.T, backend, appURL string) (string, *output) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
@@ -67,7 +65,6 @@ func startRProxy(t *testing.T, backend, appURL string) (string, *output) {
|
|||||||
"SWW_RPROXY_UPSTREAM_URL": appURL,
|
"SWW_RPROXY_UPSTREAM_URL": appURL,
|
||||||
"SWW_RPROXY_TRUSTED_PROXIES": localhost + "/32",
|
"SWW_RPROXY_TRUSTED_PROXIES": localhost + "/32",
|
||||||
wafBackend: backend,
|
wafBackend: backend,
|
||||||
wafBackendTimeout: "60000",
|
|
||||||
}, out)
|
}, out)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -552,9 +549,7 @@ func TestAStatusWAFDoesNotTakeIsReportedAs599(t *testing.T) {
|
|||||||
// startRProxyProcess runs `sww rproxy` in a process of its own, with the
|
// startRProxyProcess runs `sww rproxy` in a process of its own, with the
|
||||||
// settings in env, each as NAME=value. It returns where rproxy listens and a
|
// settings in env, each as NAME=value. It returns where rproxy listens and a
|
||||||
// function that sends rproxy SIGTERM and fails the test unless it exits with
|
// function that sends rproxy SIGTERM and fails the test unless it exits with
|
||||||
// status 0 within waitLimit. It waits a minute for waf's answers unless env
|
// status 0 within waitLimit.
|
||||||
// sets SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS, so that a busy host cannot make it
|
|
||||||
// drop a question.
|
|
||||||
func startRProxyProcess(t *testing.T, env ...string) (string, func()) {
|
func startRProxyProcess(t *testing.T, env ...string) (string, func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
@@ -570,8 +565,7 @@ func startRProxyProcess(t *testing.T, env ...string) (string, func()) {
|
|||||||
|
|
||||||
cmd.Env = append(os.Environ(),
|
cmd.Env = append(os.Environ(),
|
||||||
commandForMain+"=rproxy",
|
commandForMain+"=rproxy",
|
||||||
"SWW_RPROXY_LISTEN_ADDR="+localhost+":0",
|
"SWW_RPROXY_LISTEN_ADDR="+localhost+":0")
|
||||||
wafBackendTimeout+"=60000")
|
|
||||||
cmd.Env = append(cmd.Env, env...)
|
cmd.Env = append(cmd.Env, env...)
|
||||||
|
|
||||||
exited := startProcess(t, cmd)
|
exited := startProcess(t, cmd)
|
||||||
|
|||||||
+4
-10
@@ -67,9 +67,6 @@ type Params struct {
|
|||||||
Viper *viper.Viper
|
Viper *viper.Viper
|
||||||
// Stdout receives the request log and the process's own messages.
|
// Stdout receives the request log and the process's own messages.
|
||||||
Stdout io.Writer
|
Stdout io.Writer
|
||||||
// BesideLookupTimeLimit is the waf.Params.BesideLookupTimeLimit RunWAF
|
|
||||||
// gives waf. Main leaves it zero, waf's own limit; tests lengthen it.
|
|
||||||
BesideLookupTimeLimit time.Duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main runs the command os.Args names, and returns the process's exit status.
|
// Main runs the command os.Args names, and returns the process's exit status.
|
||||||
@@ -149,7 +146,7 @@ func RunWAF(ctx context.Context, params Params) int {
|
|||||||
|
|
||||||
return runWAFWithSettings(
|
return runWAFWithSettings(
|
||||||
ctx,
|
ctx,
|
||||||
params,
|
params.Version,
|
||||||
cfg,
|
cfg,
|
||||||
stdout,
|
stdout,
|
||||||
remote,
|
remote,
|
||||||
@@ -162,7 +159,7 @@ func RunWAF(ctx context.Context, params Params) int {
|
|||||||
// SWW_WAF_LOG_REMOTE_URL is set.
|
// SWW_WAF_LOG_REMOTE_URL is set.
|
||||||
func runWAFWithSettings(
|
func runWAFWithSettings(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
params Params,
|
version string,
|
||||||
cfg *config.WAF,
|
cfg *config.WAF,
|
||||||
stdout io.Writer,
|
stdout io.Writer,
|
||||||
remote *remotelog.Sender,
|
remote *remotelog.Sender,
|
||||||
@@ -196,7 +193,6 @@ func runWAFWithSettings(
|
|||||||
ruleFiles,
|
ruleFiles,
|
||||||
alertQueue,
|
alertQueue,
|
||||||
crs,
|
crs,
|
||||||
params.BesideLookupTimeLimit,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cannotStart(processLog, "cannot use the lookup database", err)
|
return cannotStart(processLog, "cannot use the lookup database", err)
|
||||||
@@ -225,7 +221,7 @@ func runWAFWithSettings(
|
|||||||
}
|
}
|
||||||
|
|
||||||
processLog.Info("starting",
|
processLog.Info("starting",
|
||||||
"version", params.Version,
|
"version", version,
|
||||||
"address", listener.Addr().String(),
|
"address", listener.Addr().String(),
|
||||||
"settings", cfg)
|
"settings", cfg)
|
||||||
|
|
||||||
@@ -253,7 +249,7 @@ func cannotStart(processLog *slog.Logger, message string, err error) int {
|
|||||||
func newServer(
|
func newServer(
|
||||||
cfg *config.WAF, stdout io.Writer, processLog *slog.Logger,
|
cfg *config.WAF, stdout io.Writer, processLog *slog.Logger,
|
||||||
now func() time.Time, ruleFiles *rules.Files, alertQueue *alerts.Queue,
|
now func() time.Time, ruleFiles *rules.Files, alertQueue *alerts.Queue,
|
||||||
crs *coreruleset.CoreRuleSet, besideLookupTimeLimit time.Duration,
|
crs *coreruleset.CoreRuleSet,
|
||||||
) (*waf.Server, error) {
|
) (*waf.Server, error) {
|
||||||
var lookupFile *lookup.File
|
var lookupFile *lookup.File
|
||||||
|
|
||||||
@@ -282,8 +278,6 @@ func newServer(
|
|||||||
Now: now,
|
Now: now,
|
||||||
Rules: ruleFiles,
|
Rules: ruleFiles,
|
||||||
Alerts: alertQueue,
|
Alerts: alertQueue,
|
||||||
|
|
||||||
BesideLookupTimeLimit: besideLookupTimeLimit,
|
|
||||||
})
|
})
|
||||||
server.Metrics.AddAlerts(alertQueue)
|
server.Metrics.AddAlerts(alertQueue)
|
||||||
|
|
||||||
|
|||||||
@@ -173,9 +173,6 @@ func run(ctx context.Context, env map[string]string, out *output) int {
|
|||||||
Version: testVersion,
|
Version: testVersion,
|
||||||
Viper: v,
|
Viper: v,
|
||||||
Stdout: out,
|
Stdout: out,
|
||||||
// The race detector and a busy host can slow the Core Rule Set's
|
|
||||||
// inspections past waf's own limit.
|
|
||||||
BesideLookupTimeLimit: time.Hour,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,8 +90,6 @@ func TestMainRunsWAF(t *testing.T) {
|
|||||||
cmd := exec.CommandContext(t.Context(), binary)
|
cmd := exec.CommandContext(t.Context(), binary)
|
||||||
cmd.Stdout = out
|
cmd.Stdout = out
|
||||||
|
|
||||||
// The Core Rule Set is off. Main keeps waf's own limit for its checks,
|
|
||||||
// and on a busy host the Core Rule Set's inspection can pass it.
|
|
||||||
cmd.Env = append(os.Environ(),
|
cmd.Env = append(os.Environ(),
|
||||||
"TZ="+zone,
|
"TZ="+zone,
|
||||||
commandForMain+"="+wafCommand,
|
commandForMain+"="+wafCommand,
|
||||||
@@ -99,8 +97,7 @@ func TestMainRunsWAF(t *testing.T) {
|
|||||||
stateDir+"="+dir,
|
stateDir+"="+dir,
|
||||||
cacheDir+"="+dir,
|
cacheDir+"="+dir,
|
||||||
ruleFilesDir+"="+t.TempDir(),
|
ruleFilesDir+"="+t.TempDir(),
|
||||||
lookupSource+"=off",
|
lookupSource+"=off")
|
||||||
"SWW_WAF_CORE_RULE_SET_MODE=off")
|
|
||||||
|
|
||||||
exited := startProcess(t, cmd)
|
exited := startProcess(t, cmd)
|
||||||
|
|
||||||
|
|||||||
@@ -73,10 +73,10 @@ func newWAFHoldingTheCoreRuleSet(
|
|||||||
|
|
||||||
server, out, queue := newWAFWith(t, func(params waf.Params) *waf.Server {
|
server, out, queue := newWAFWith(t, func(params waf.Params) *waf.Server {
|
||||||
params.CoreRuleSet = crs
|
params.CoreRuleSet = crs
|
||||||
params.BesideLookupTimeLimit = waf.BesideLookupTimeLimit
|
|
||||||
|
|
||||||
return waf.New(params)
|
return waf.New(params)
|
||||||
}, silentGeoJSURL, time.Now, settings)
|
}, silentGeoJSURL, time.Now, settings)
|
||||||
|
server.SetBesideLookupTimeLimit(waf.BesideLookupTimeLimit)
|
||||||
|
|
||||||
return server, out, queue
|
return server, out, queue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,13 @@
|
|||||||
package waf
|
package waf
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
// BesideLookupTimeLimit is besideLookupTimeLimit.
|
// BesideLookupTimeLimit is besideLookupTimeLimit.
|
||||||
const BesideLookupTimeLimit = besideLookupTimeLimit
|
const BesideLookupTimeLimit = besideLookupTimeLimit
|
||||||
|
|
||||||
|
// SetBesideLookupTimeLimit gives the heuristics of besideLookup limit on s in
|
||||||
|
// place of besideLookupTimeLimit.
|
||||||
|
func (s *Server) SetBesideLookupTimeLimit(limit time.Duration) {
|
||||||
|
h := s.Handler.(*handler) //nolint:forcetypeassert // New makes it one
|
||||||
|
h.besideLookupLimit = limit
|
||||||
|
}
|
||||||
+2
-12
@@ -4,7 +4,6 @@
|
|||||||
package waf
|
package waf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cmp"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@@ -84,11 +83,6 @@ type Params struct {
|
|||||||
// failing, a query to a DNSBL zone or a check with AbuseIPDB failing,
|
// failing, a query to a DNSBL zone or a check with AbuseIPDB failing,
|
||||||
// or the day's AbuseIPDB checks used up.
|
// or the day's AbuseIPDB checks used up.
|
||||||
Alerts *alerts.Queue
|
Alerts *alerts.Queue
|
||||||
// BesideLookupTimeLimit is how long the heuristics of besideLookup have
|
|
||||||
// for a request. Zero means besideLookupTimeLimit. Tests that run the
|
|
||||||
// Core Rule Set lengthen it, since the race detector and a busy host can
|
|
||||||
// slow an inspection past besideLookupTimeLimit.
|
|
||||||
BesideLookupTimeLimit time.Duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CoreRuleSetInspector inspects a request with the Core Rule Set, as
|
// CoreRuleSetInspector inspects a request with the Core Rule Set, as
|
||||||
@@ -174,10 +168,7 @@ func newHandler(params Params) *handler {
|
|||||||
coreRuleSet: params.CoreRuleSet,
|
coreRuleSet: params.CoreRuleSet,
|
||||||
alerts: params.Alerts,
|
alerts: params.Alerts,
|
||||||
|
|
||||||
besideLookupLimit: cmp.Or(
|
besideLookupLimit: besideLookupTimeLimit,
|
||||||
params.BesideLookupTimeLimit,
|
|
||||||
besideLookupTimeLimit,
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
if params.Config.RouteWatchURL != "" {
|
if params.Config.RouteWatchURL != "" {
|
||||||
h.routeWatch = routewatch.New(routewatch.Params{
|
h.routeWatch = routewatch.New(routewatch.Params{
|
||||||
@@ -301,8 +292,7 @@ type handler struct {
|
|||||||
// waitForGeoJS is true when a setting needs each request's answer from
|
// waitForGeoJS is true when a setting needs each request's answer from
|
||||||
// GeoJS before the request goes on.
|
// GeoJS before the request goes on.
|
||||||
waitForGeoJS bool
|
waitForGeoJS bool
|
||||||
// besideLookupLimit is how long the heuristics of besideLookup have for a
|
// besideLookupLimit is besideLookupTimeLimit. Only tests change it.
|
||||||
// request, as Params.BesideLookupTimeLimit says.
|
|
||||||
besideLookupLimit time.Duration
|
besideLookupLimit time.Duration
|
||||||
// awaitingReport holds the decision on each answered question by its id
|
// awaitingReport holds the decision on each answered question by its id
|
||||||
// until its report comes, and nil for a question still being handled.
|
// until its report comes, and nil for a question still being handled.
|
||||||
|
|||||||
@@ -510,11 +510,13 @@ func newWAFWith(
|
|||||||
Now: now,
|
Now: now,
|
||||||
Rules: ruleFiles,
|
Rules: ruleFiles,
|
||||||
Alerts: alertQueue,
|
Alerts: alertQueue,
|
||||||
// The tests of the limit set it back, and hold the Core Rule Set
|
|
||||||
// with a stand-in.
|
|
||||||
BesideLookupTimeLimit: time.Hour,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// The race detector and a busy host can slow the Core Rule Set's
|
||||||
|
// inspections past the time limit. The tests of the limit set it back, and
|
||||||
|
// hold the Core Rule Set with a stand-in.
|
||||||
|
server.SetBesideLookupTimeLimit(time.Hour)
|
||||||
|
|
||||||
return server, out, alertQueue
|
return server, out, alertQueue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user