waf: the header limits are the first check (closes #311)
check / check (push) Waiting to run

A request over 50 cookies or 100 header fields is now refused by the first
check after SWW_ALLOW_NETS. It causes no lookup, no query to RouteWatch, a DNS
blocklist or AbuseIPDB, no rule file match and no Core Rule Set. The rate
limits no longer count it, and a banned or denied client gets 431 for it. It
makes no ban, makes no ban permanent and is not counted in a ban's notes. In
observe mode no lookup is made for it. Requests within the limits go through
the same checks in the same order.

Model: opus-5-5
This commit is contained in:
sneak committed 2026-11-11 02:14:23 +00:00
1 parent f7e3190654
commit 174b6edca7
6 files changed
+155 -79

No files matched your search

+28 -19
View File
@@ -145,10 +145,12 @@ field gives that name. `refusal_limit` and `byte_limits` give theirs in
- An IPv6 client is its group: the netblock of `SWW_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 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
3. The header limits (`header_limits`; see "Answering in time"). They come first
after `SWW_ALLOW_NETS`, since they only 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_ROUTEWATCH_URL` is set. A client in
`SWW_ALLOW_NETS` gets no tag.
`SWW_ALLOW_NETS` skips the header limits and gets no tag.
4. The static lists. A client in `SWW_ALLOW_NETS` skips steps 5 to 15, the byte
limits and the error burst. A client in `SWW_DENY_NETS` is refused
(`deny_nets`); a client in both lists is let through.
@@ -181,10 +183,9 @@ field gives that name. `refusal_limit` and `byte_limits` give theirs in
refused and bans the client.
13. The rule files (`rule_files`; see "Rule files"). Matching stops at the first
rule that refuses.
14. The header limits (`header_limits`; see "Answering in time"), and then the
Core Rule Set (`core_rule_set`; see "Attack detection"). A Core Rule Set
match is refused with `403` while `SWW_WAF_MODE` is `block`, and only logged
and alerted while it is `detect`.
14. The Core Rule Set (`core_rule_set`; see "Attack detection"). A match is
refused with `403` while `SWW_WAF_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
@@ -237,11 +238,16 @@ apply.
## Bans
Until a ban ends, every request from its netblock is refused with
`SWW_BAN_RESPONSE`. The netblock is the client: its IPv4 address, widened to
`SWW_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_BAN_RESPONSE`, unless it is over the header limits. The netblock is the
client: its IPv4 address, widened to `SWW_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.
A request over the header limits is refused with `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:
@@ -2020,7 +2026,6 @@ waits on these, which run in the background:
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 `SWW_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
@@ -2032,8 +2037,8 @@ number and country stay unknown until GeoJS has answered. So while
`SWW_UNKNOWN_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;
@@ -2052,13 +2057,17 @@ either one:
Real clients never reach these limits. The answer is `deny` with `431`, and the
log line's action is `request_header_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.
no offence.
The header limits are the first check after `SWW_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_DENY_NETS` also gets `431` for such a request.
The limits apply on every path and in every `SWW_WAF_MODE`. A client in
`SWW_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.
such a request is answered `allow` with `would_action`, and no other check runs
on it.
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