OPEN-12's option (b) — share the block list and shorten the TTL — was not a deployment decision, it was a rebuild: EdgeStateStore.RefreshTtl was a property initialised to 30 s with no configuration binding anywhere in the tree. The measurement in research/2026-10-01-multi-instance/ showed why that matters: the TTL is not a tuning knob, it is the propagation delay between edges (23.7 s under ~36 req/s, 1.7 s on an idle one), so an operator who runs more than one instance is choosing a staleness bound they cannot set and cannot see. The key is OpenWaf:State:RefreshTtlSeconds, default 30, and the default is unchanged so nothing moves for anyone who does not touch it. A value outside 1-300 aborts startup instead of falling back silently, because a typo in the staleness bound is a security setting failing quietly. /healthz now reports snapshotTtlSeconds, so an operator can read the TTL they actually got. Verified on this commit: 49 unit and 23 integration tests pass (13 new unit cases on the parser; 3 new integration tests that write a ban the way another instance would — straight into the database, no InvalidateAsync — and show a 1 s TTL closing the window inside 5 s while a 300 s TTL keeps serving a source the database has already banned); scripts/smoke.sh 19/19; scripts/compose-smoke.sh 27/27 against the rebuilt image; in a container RefreshTtlSeconds=5 reports snapshotTtlSeconds:5 on /healthz, and =0 aborts the process with the key named in the log. One thing the check taught and the README now says instead of hiding: when startup aborts inside the image, the container stays Up with nothing listening until the HEALTHCHECK goes unhealthy. That is how every startup failure in this image looks, not something this change introduces.
openwaf
An edge that sits in front of an application it knows nothing about, proxies to it, and bans a source because of what the application answered — a run of refusals from one address — while the operator's own block list stays exactly as it was.
Blocking is usually manual: a human notices abuse and adds an IP. That never fires at 3am. openwaf turns the block list from a record of past incidents into a live defence, without inventing a rule language nobody will maintain.
.NET 10, YARP reverse proxy, EF Core, one deployable.
The three pillars, and the one place they meet
There is exactly one middleware that may refuse a request
(EdgeGuardMiddleware). Everything else observes. Precedence is a property of
the design, not a side effect of registration order:
| # | Pillar | Answer | Lifetime |
|---|---|---|---|
| 1 | always-pass prefixes — /admin-api, /admin, /healthz, /readyz, /openapi |
pass | the recovery hatch for an operator who blocked themselves |
| 2 | allowlist (address or CIDR, matched on the raw peer address) | pass | wins over everything, including a geo deny |
| 3 | operator block (source=operator) |
301 to RedirectTo, else a honey-pot list |
never expires |
| 4 | engine ban (source=engine) |
403 + Retry-After + a reason |
expires on its own |
| 5 | geo policy (deny list / allow list) | 451 + a note that says the inference is probabilistic | policy, not data |
A second middleware, ResponseObservationMiddleware, sits inside the guard:
it awaits the upstream, classifies the status the application actually returned,
and feeds a streak counter. Being inside the guard is load-bearing — a refusal
the edge generated itself must never feed the streak that produced the ban.
The streak
N consecutive refusals inside a window of M minutes ⇒ ban for
BanDuration. Consecutive means what it says:
- a
2xx/3xxresets the streak to zero; - a gap longer than
Mrestarts it at one; 4xx(default400-499, inclusive of 400) counts toward a ban;5xx(default500-599) never bans — it raises an alert instead, because a broken deploy would otherwise take the site down twice: once by being broken, once by banning its own honest visitors.
The ban takes effect on the request after the one that matured the streak, because the edge decides from the response it has already served.
The toggle
Automatic banning is a mode, not a replacement:
| mode | observes | records | blocks |
|---|---|---|---|
Off |
yes | yes | no |
Observe |
yes | yes, as candidate_ban alerts |
no |
Enforce |
yes | yes | yes |
Switching it off touches no rows. DELETE /admin-api/blocks?source=engine
clears engine bans and cannot reach an operator's entries — provenance lives on
the row, so "clear the automatic ones" is a filter, not a table operation.
Quickstart
# tests
dotnet test dotnet/OpenWaf.slnx
# end-to-end against a real upstream, with curl assertions
./scripts/smoke.sh
# the whole thing behind a proxy
OPENWAF_ADMIN_TOKEN=change-me docker compose up --build
# the assertions above, against the built image rather than the source tree:
# image HEALTHCHECK, streak ban over a socket, per-source isolation, operator
# block, allowlist precedence, country deny
OPENWAF_ADMIN_TOKEN=change-me ./scripts/compose-smoke.sh
Point one probe at it and watch the ban:
for i in 1 2 3 4; do curl -s -o /dev/null -w '%{http_code}\n' http://localhost:8080/wp-admin; done
# 404 404 404 403
curl -s -H "X-Admin-Token: change-me" 'http://localhost:8080/admin-api/blocks?source=engine'
Configuration
Everything under OpenWaf:Policy (env: OpenWaf__Policy__…), overridable at
runtime through PUT /admin-api/policy, which persists to policy_settings.
| key | default | meaning |
|---|---|---|
Mode |
Observe |
Off / Observe / Enforce |
StreakThreshold |
10 |
N |
StreakWindow |
00:05:00 |
M — the gap that still counts as one streak |
BanDuration |
01:00:00 |
how long a ban stays live |
RefusalRange |
400-499 |
statuses that count toward a ban |
ServerErrorRange |
500-599 |
statuses that raise an alert |
Geo |
Off |
Off / DenyList / AllowList |
TrustProxyHeaders |
false |
may X-Forwarded-For define the source? |
MaxTrackedSources |
10000 |
hard bound on the in-memory streak map |
Ipv4KeyPrefixLength / Ipv6KeyPrefixLength |
32 / 64 |
source-key granularity |
EngineBlockStatus / OperatorBlockStatus |
403 / 301 |
what a block answers |
DefaultRedirectTargets |
iana example | honey-pot targets for operator blocks |
One key is not policy and cannot be changed at runtime, because it decides how long this process may keep enforcing a list that is already out of date:
| key | default | meaning |
|---|---|---|
OpenWaf:State:RefreshTtlSeconds |
30 |
how stale the in-memory block list may get. On a single edge this is invisible; behind a load balancer it is the propagation delay — 23.7 s measured at ~36 req/s in research/2026-10-01-multi-instance/. Anything outside 1–300 aborts startup: the process exits non-zero and the log names the key. In Docker the container stays Up with nothing listening until the image HEALTHCHECK marks it unhealthy — that is what any startup failure in this image looks like, not a special case. /healthz reports the value an operator actually got, as snapshotTtlSeconds. |
Database: Database:Provider = sqlite (default) or postgres,
ConnectionStrings__OpenWaf. GeoIP: GEOIP_MAXMIND_DB_PATH.
Schema
Migrations are the schema of record for PostgreSQL, which is the provider a real deployment runs:
cd dotnet
dotnet ef migrations add <Name> --project OpenWaf.Infrastructure --startup-project OpenWaf.Infrastructure
A migration set is provider-shaped SQL, so it is not applied to the SQLite
default — there the schema is created from the model at startup. OPENWAF_SCHEMA
overrides the choice: migrate, ensurecreated, or none when an operator
manages the schema themselves.
Admin API
Requires X-Admin-Token (or ?token=). No token configured means the admin
API is closed, not open.
GET /admin-api/blocks?source=operator|engine&live=true
POST /admin-api/blocks {"ip","reason","redirectTo"}
DELETE /admin-api/blocks?source=engine[&key=…]
GET /admin-api/allow POST {"match","note","expiresInMinutes"} DELETE /admin-api/allow/{id}
GET /admin-api/policy PUT {"mode":"Enforce","streakThreshold":8,…}
GET /admin-api/observations per-source streaks, durable
GET /admin-api/alerts server_error_streak | candidate_ban
GET /admin-api/countries PUT /admin-api/countries/{code}?allowed=false
GET /admin-api/countries/summary sources and refusals per country, from the aggregates
GET /admin-api/geo which database is loaded and how old it is
GET /admin-api/state snapshot age, tracked sources, counts
Console
GET /admin serves a single page over those endpoints — mode and snapshot age,
live bans with their reasons, the sources being watched, and the countries seen.
It decides nothing: every control on it is one call to the API above. It is on
the always-pass list, so an operator who is themselves blocked can still reach
the page that clears it, and it is never observed, so fumbling it cannot build a
streak. The token is typed into the page and sent as a header; it is never in a
URL, because a token in a query string ends up in proxy logs and browser
history. No external assets — a page that needs a CDN fails at the moment it is
wanted.
What this deliberately costs
Stated, because a defence that hides its failure modes is not a defence.
- One shared IPv4 egress is one source. An office behind one address can accumulate a ban. Mitigations: the streak is consecutive (one honest click resets it), the allowlist outranks every pillar, and the ban explains itself so an operator can undo it in one call.
- IPv6 is grouped to
/64. A subscriber holds a whole/64, so a bot rotating addresses inside one allocation is one source; a per-address v6 rule is unenforceable. A wider prefix over-blocks, which is worse. - Geo is a probabilistic claim about an address, not a fact about a person.
The 451 body says so. The database is pinned by a build argument and ages with
the image, so
/healthzreports its build date andgeoStale. - Streak state is per process. Behind a load balancer, each instance counts its own traffic. Multi-instance deployments need a shared store — recorded as an evolution trigger, not solved by pretending.
- Aggregates, not a request log.
source_observationskeeps counters and the last-seen evidence per source, and ages out afterObservationRetention. Raw IPs are not logged.
Shape
dotnet/
OpenWaf.Domain/ pure decision core: source key, streak, ordered decision
OpenWaf.Infrastructure/ EF Core (sqlite/postgres), snapshot store, writers, MMDB geo
OpenWaf.Edge/ the deployable: guard, observer, admin API, healthcheck mode
OpenWaf.Tests.Unit/ 36 tests over the decision logic
OpenWaf.Tests.Integration/ 19 tests driving the real pipeline against a fake upstream
scripts/smoke.sh 19 assertions against a running edge + a real upstream
scripts/compose-smoke.sh 27 assertions against the built image (compose + nginx)
.github/workflows/ci.yml runs all four gates on every push
docs/ARCHITECTURE.md the design authority and its rulings
Two protections are inherited from the reference deployment rather than rediscovered, and both are load-bearing: at most one durable write per source per 30 s, and a hard LRU bound on the in-memory map, so a scanner farm cannot grow the process or tax the database.