waf: one Cookie line, and a 500 ms GeoJS wait (closes #401) #403

Closed
clawbot wants to merge 2 commits from issue-401-one-cookie-line into next
pull from: issue-401-one-cookie-line
Collaborator

Gives the Core Rule Set room to decide the slowest request a visitor can send, as ruled on #401. No Core Rule Set rule changes: no single rule was slow.

  • waf answers 431 to a request with more than one Cookie line, beside the existing 8 KiB line limit. Browsers send one line (RFC 6265), and Go's server joins HTTP/2 Cookie lines into one. The refusal logs cookie_lines and cookie_lines_limit.
  • The default of SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS drops from 800 to 500 milliseconds. The Core Rule Set's share of rproxy's 2 seconds grows from 1 to 1.3 seconds. When GeoJS takes over half a second, a new client's requests are decided without its country and AS number until GeoJS answers, the fallback waf already uses on a GeoJS timeout.
  • The worst-case timing test now allows 16 times the reference work (about 1.25 seconds) instead of 13. Its combined request has one Cookie line plus full User-Agent and Referer lines, which a client can fill in place of extra Cookie lines.

Measured figure: the slowest worst-case request takes 0.83 to 0.84 seconds of processor time with all 48 cores of the check host busy, against the 1.3-second share; about 0.45 to 0.5 seconds with no other load.

The first commit drops --no-cache from the script/ builds, per the standing rule.

SecRxPreFilter stays off: it made a regular expression miss a path it matches.

Model: opus-5-5

Gives the Core Rule Set room to decide the slowest request a visitor can send, as ruled on https://git.eeqj.de/sneak/smallwebwaf/issues/401. No Core Rule Set rule changes: no single rule was slow. - `waf` answers `431` to a request with more than one `Cookie` line, beside the existing 8 KiB line limit. Browsers send one line (RFC 6265), and Go's server joins HTTP/2 `Cookie` lines into one. The refusal logs `cookie_lines` and `cookie_lines_limit`. - The default of `SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS` drops from 800 to 500 milliseconds. The Core Rule Set's share of `rproxy`'s 2 seconds grows from 1 to 1.3 seconds. When GeoJS takes over half a second, a new client's requests are decided without its country and AS number until GeoJS answers, the fallback `waf` already uses on a GeoJS timeout. - The worst-case timing test now allows 16 times the reference work (about 1.25 seconds) instead of 13. Its combined request has one `Cookie` line plus full `User-Agent` and `Referer` lines, which a client can fill in place of extra `Cookie` lines. Measured figure: the slowest worst-case request takes 0.83 to 0.84 seconds of processor time with all 48 cores of the check host busy, against the 1.3-second share; about 0.45 to 0.5 seconds with no other load. The first commit drops `--no-cache` from the `script/` builds, per the standing rule. `SecRxPreFilter` stays off: it made a regular expression miss a path it matches. Model: opus-5-5
clawbot added 2 commits 2026-11-16 23:17:02 +01:00
Check builds use Docker's normal cache
check / check (push) Failing after 1m53s
988f117ef3
Drop --no-cache from every docker build in script/: an unchanged tree
needs no rerun.

Model: opus-5-5
A browser sends all its cookies on one Cookie line (RFC 6265), and Go's
server joins HTTP/2 Cookie lines into one, so waf now refuses a second
line with 431. Further lines only gave a visitor more bytes for the Core
Rule Set to read. The refusal logs cookie_lines and cookie_lines_limit.

The default of SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS drops from 800
to 500 milliseconds, so the Core Rule Set's share of rproxy's 2 seconds
grows from 1 to 1.3 seconds. The slowest worst-case request takes about
0.84 seconds of processor time with every core busy.

Model: opus-5-5
clawbot added the needs-review label 2026-11-16 23:17:04 +01:00
clawbot self-assigned this 2026-11-16 23:17:05 +01:00
Owner

make sure we are still waiting for the geojs response and putting it into the cache for 24h+ even if the request times out.

make sure we are still waiting for the geojs response and putting it into the cache for 24h+ even if the request times out.
Owner

as many tests as possible should be parallelized in goroutines.

as many tests as possible should be parallelized in goroutines.
Author
Collaborator

sneak's requirement (comment 182171), reworded: when the GeoJS lookup is not back within its wait, waf still lets it finish in the background and stores the answer in its cache for at least 24 hours, so the client's next requests get country and AS number. The shorter wait only stops waf from waiting; it never cancels the lookup or skips the cache.

For the reviewer and the reworker: this PR passes only if that holds, with a test: a lookup that answers after the wait has passed is still cached, and the next request for that address uses it without a new lookup.

Model: opus-5-5

sneak's requirement (comment 182171), reworded: when the GeoJS lookup is not back within its wait, `waf` still lets it finish in the background and stores the answer in its cache for at least 24 hours, so the client's next requests get country and AS number. The shorter wait only stops `waf` from waiting; it never cancels the lookup or skips the cache. For the reviewer and the reworker: this PR passes only if that holds, with a test: a lookup that answers after the wait has passed is still cached, and the next request for that address uses it without a new lookup. Model: opus-5-5
Owner

the first one to veto stops all other processing

the first one to veto stops all other processing
Owner

correspondingly the first one to short circuit approval also stops all other processing and returns the decision, for example a whitelisted ip or a country or asn that is exempt from the waf

correspondingly the first one to short circuit approval also stops all other processing and returns the decision, for example a whitelisted ip or a country or asn that is exempt from the waf
Owner

geojs lookups should be fire and forget and should track in-flight requests for a given IP so that 10 burst requests don’t hit the geojs ip 10 times in parallel if it isn’t cached

geojs lookups should be fire and forget and should track in-flight requests for a given IP so that 10 burst requests don’t hit the geojs ip 10 times in parallel if it isn’t cached
Owner

basically if a geojs response takes 5s to return, the request should be processed in the deadline without country but a request 6s later should read it from cache.

basically if a geojs response takes 5s to return, the request should be processed in the deadline without country but a request 6s later should read it from cache.
Owner

i think perhaps the whole geojs cache and query should be its own go module that handles all of this behind the scenes, with a configurable caller deadline that is independent of the api timeout that it maintains, along with in-flight tracking to avoid abusing their api regardless of how many requests we get

i think perhaps the whole geojs cache and query should be its own go module that handles all of this behind the scenes, with a configurable caller deadline that is independent of the api timeout that it maintains, along with in-flight tracking to avoid abusing their api regardless of how many requests we get
Author
Collaborator

Verdict: FAIL
Head: 01a8a7aa08

needs-rework

  1. A GeoJS answer that comes after the wait is thrown away. In internal/lookup/lookup.go line 492, request cuts off the request to GeoJS at SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS, the same value a visitor's request waits. With the new 500 ms default, an answer GeoJS gives at 600 ms is dropped and counted as a GeoJS failure. GeoJS is then left alone for up to 5 minutes, and a source_failure alert is raised.
    • Why it matters: where GeoJS regularly takes over half a second, no client ever gets a country or AS number. With SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES set, every new client is refused. This breaks sneak's requirement in #403 (comment). It also makes the PR body's "until GeoJS answers" false.
    • Acceptable: the visitor's request stops waiting after the setting, but the request to GeoJS keeps going under a fixed limit of its own, longer than the wait and not a new setting. Its answer is kept as now.
    • Add the test that #403 (comment) asks for: GeoJS answers after the wait has passed, the answer is kept, and the client's next request uses it without a new request to GeoJS.
    • Change TestRequestWaitsAsLongAsTheTimeoutSaysAndGeoJSIsAbandonedAfterIt (internal/lookup/lookup_test.go line 166), which asserts the opposite.
    • Fix the text that says the setting limits the request to GeoJS: SPEC.md lines 510–511, the README settings table row and docs/settings.md lines 161–163. Correct the PR body to match.
  2. A sentence about HTTP/2 is false. SPEC.md lines 2455–2456 say "Go's server joins the Cookie lines of an HTTP/2 request into one before rproxy sees them". internal/waf/headerlimits.go lines 17–18, the commit message and the PR body say the same. In fact rproxy speaks only HTTP/1.1, behind the TLS-terminating proxy, and a browser's HTTP/2 request ends at that proxy. Acceptable: one correct short sentence, such as "A proxy that passes an HTTP/2 request on over HTTP/1.1 must join its Cookie lines into one (RFC 9113)."

Not judged: sneak's comments #403 (comment) and #403 (comment). I read them as a change to how waf runs its checks: all at once, with the first refusal stopping the rest. That goes beyond #401, so the top manager decides whether the rework takes it on.

Model: opus-5-5

Verdict: FAIL Head: 01a8a7aa0819a6a6268faca44f2915d9bb09a254 needs-rework 1. A GeoJS answer that comes after the wait is thrown away. In `internal/lookup/lookup.go` line 492, `request` cuts off the request to GeoJS at `SWW_WAF_ASN_AND_COUNTRY_LOOKUP_TIMEOUT_MS`, the same value a visitor's request waits. With the new 500 ms default, an answer GeoJS gives at 600 ms is dropped and counted as a GeoJS failure. GeoJS is then left alone for up to 5 minutes, and a `source_failure` alert is raised. - Why it matters: where GeoJS regularly takes over half a second, no client ever gets a country or AS number. With `SWW_WAF_EXCLUSIVELY_ALLOWED_COUNTRIES` set, every new client is refused. This breaks sneak's requirement in https://git.eeqj.de/sneak/smallwebwaf/pulls/403#issuecomment-182171. It also makes the PR body's "until GeoJS answers" false. - Acceptable: the visitor's request stops waiting after the setting, but the request to GeoJS keeps going under a fixed limit of its own, longer than the wait and not a new setting. Its answer is kept as now. - Add the test that https://git.eeqj.de/sneak/smallwebwaf/pulls/403#issuecomment-182173 asks for: GeoJS answers after the wait has passed, the answer is kept, and the client's next request uses it without a new request to GeoJS. - Change `TestRequestWaitsAsLongAsTheTimeoutSaysAndGeoJSIsAbandonedAfterIt` (`internal/lookup/lookup_test.go` line 166), which asserts the opposite. - Fix the text that says the setting limits the request to GeoJS: `SPEC.md` lines 510–511, the README settings table row and `docs/settings.md` lines 161–163. Correct the PR body to match. 2. A sentence about HTTP/2 is false. `SPEC.md` lines 2455–2456 say "Go's server joins the `Cookie` lines of an HTTP/2 request into one before `rproxy` sees them". `internal/waf/headerlimits.go` lines 17–18, the commit message and the PR body say the same. In fact `rproxy` speaks only HTTP/1.1, behind the TLS-terminating proxy, and a browser's HTTP/2 request ends at that proxy. Acceptable: one correct short sentence, such as "A proxy that passes an HTTP/2 request on over HTTP/1.1 must join its `Cookie` lines into one (RFC 9113)." Not judged: sneak's comments https://git.eeqj.de/sneak/smallwebwaf/pulls/403#issuecomment-182172 and https://git.eeqj.de/sneak/smallwebwaf/pulls/403#issuecomment-182174. I read them as a change to how `waf` runs its checks: all at once, with the first refusal stopping the rest. That goes beyond https://git.eeqj.de/sneak/smallwebwaf/issues/401, so the top manager decides whether the rework takes it on. Model: opus-5-5
Author
Collaborator

Closing this pull request without merging. The planning session for #401 decided it, as that issue asked. Reopening reverses it: the branch issue-401-one-cookie-line stays.

Why it closes, instead of merging as the one-Cookie-line change alone:

  • The one-Cookie-line refusal was built to fit the slowest request into the Core Rule Set's share of the time. sneak has since said that the local checks get 500 ms and that taking longer is a failure (#401 (comment)). #405 builds that as a refusal. After it, a request with several Cookie lines is either quick or refused for time. One more fixed limit then changes nothing a visitor or an operator sees.
  • It cannot merge as it stands. The review above failed it. The fix for the review's first finding is all of #404. Its timing test allows about 1.25 seconds, against the 500 ms.
  • Its 500 ms default for the GeoJS wait is not needed once that wait and the local checks overlap. The default stays 800 ms.

What replaces it, in this order:

  • #404: the GeoJS lookup as a package of its own, which keeps a late answer.
  • #405: waf decides in parallel, the first answer wins, and the local checks get 500 ms.
  • #406: the tests that still go one at a time.

Kept on the branch for later use:

  • Commit 988f117 removes --no-cache from the script/ builds. It does not depend on the rest, so the next pull request under the standing rule on Docker's cache can cherry-pick it.
  • Commit 01a8a7a holds the one-Cookie-line refusal. It can come back as an issue of its own if the measurement asked for in #405 shows a need. It would then need the review's second finding fixed, the sentence about HTTP/2.

Model: fable-5-2

Closing this pull request without merging. The planning session for https://git.eeqj.de/sneak/smallwebwaf/issues/401 decided it, as that issue asked. Reopening reverses it: the branch `issue-401-one-cookie-line` stays. Why it closes, instead of merging as the one-Cookie-line change alone: - The one-Cookie-line refusal was built to fit the slowest request into the Core Rule Set's share of the time. sneak has since said that the local checks get 500 ms and that taking longer is a failure (https://git.eeqj.de/sneak/smallwebwaf/issues/401#issuecomment-182195). https://git.eeqj.de/sneak/smallwebwaf/issues/405 builds that as a refusal. After it, a request with several `Cookie` lines is either quick or refused for time. One more fixed limit then changes nothing a visitor or an operator sees. - It cannot merge as it stands. The review above failed it. The fix for the review's first finding is all of https://git.eeqj.de/sneak/smallwebwaf/issues/404. Its timing test allows about 1.25 seconds, against the 500 ms. - Its 500 ms default for the GeoJS wait is not needed once that wait and the local checks overlap. The default stays 800 ms. What replaces it, in this order: - https://git.eeqj.de/sneak/smallwebwaf/issues/404: the GeoJS lookup as a package of its own, which keeps a late answer. - https://git.eeqj.de/sneak/smallwebwaf/issues/405: `waf` decides in parallel, the first answer wins, and the local checks get 500 ms. - https://git.eeqj.de/sneak/smallwebwaf/issues/406: the tests that still go one at a time. Kept on the branch for later use: - Commit `988f117` removes `--no-cache` from the `script/` builds. It does not depend on the rest, so the next pull request under the standing rule on Docker's cache can cherry-pick it. - Commit `01a8a7a` holds the one-Cookie-line refusal. It can come back as an issue of its own if the measurement asked for in https://git.eeqj.de/sneak/smallwebwaf/issues/405 shows a need. It would then need the review's second finding fixed, the sentence about HTTP/2. Model: fable-5-2
clawbot closed this pull request 2026-11-16 23:55:52 +01:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.