waf: run the trap paths, rule files and Core Rule Set during the GeoJS wait (closes #405)
check / check (push) Failing after 1m51s

While the lookup waits for GeoJS, the trap paths, the rule files and the
Core Rule Set run at the same time as the checks after the lookup. The
first side to refuse answers the request; what the other side finds leaves
no trace. Those three checks have 500 ms together: past it, the request is
refused with 503 as checks_timed_out, with no ban and no offence.

Tests hold GeoJS and the Core Rule Set with stand-ins under synctest. The
test helper lifts the 500 ms limit for tests that run the real Core Rule
Set, which the race detector slows past it.

Model: opus-5-5
This commit was merged in pull request #408.
This commit is contained in:
clawbot committed 2026-11-17 06:11:52 +01:00
1 parent caa3079847
commit 8c9f20d346
19 files changed
+902 -84

No files matched your search

+53 -13
View File
@@ -173,7 +173,8 @@ field gives that name. `refusal_limit` and `byte_limits` give theirs in
`country=` tag.
Otherwise the request goes on at once. A request that ends before the answer
comes is logged without it.
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").
7. The country list (`countries`; see "Country list").
8. The reputation sources (see "Reputation"), in this order:
@@ -2379,8 +2380,9 @@ runs no check, writes no request log line and counts nothing in the metrics.
### The answer
`waf` runs steps 3 to 16 of "What happens to a request", in that order. Every
answer but the last below carries `X-Sww-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-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
@@ -2392,6 +2394,8 @@ answer but the last below carries `X-Sww-Disposition`.
- `SWW_WAF_BAN_RESPONSE`, for a refusal;
- `403`, for a `block` rule or the Core Rule Set;
- `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
@@ -2412,9 +2416,15 @@ The Core Rule Set inspects the body a question carries only while
`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. The longest a question waits on an outside source is
`SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS`, by default 800 milliseconds, well
within that time.
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 6 says so, and for at most
@@ -2446,10 +2456,38 @@ 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 `SWW_WAF_DNSBL_ABUSEIPDB_ACTION` is
`deny`;
- a trap path;
- a rule file;
- the Core Rule Set.
`deny`.
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
@@ -2499,9 +2537,11 @@ body can add up to more than the body. From 1 KiB of JSON, Coraza makes at most
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. So `waf` answers it within the default 2 seconds, even
after the default 800 milliseconds of waiting for GeoJS. Enough such requests at
once can still overload `waf` past `SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS`.
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