From 5d7abd15ee1db09beb568e936824d06677a028f6 Mon Sep 17 00:00:00 2001 From: navigator Date: Fri, 2 Oct 2026 03:15:51 +0000 Subject: [PATCH 1/3] fix: serve the challenge to clients that do not accept gzip Upstream's RenderIndex refused one challenged request in 64, at random, with HTTP 500 when the client did not list gzip in Accept-Encoding. A missing Accept-Encoding accepts any coding (RFC 9110, 12.5.3), and real clients send none (curl by default, some accessibility and archiving tools, proxies that strip it), so Keel Web answered them 500 at random instead of the proof of work (Keel-Linux/keel-web#2). Upstream's #1958, after 1.27.0, only changes the status to the policy's DENY and keeps the sampling. debian/patches/challenge-without-gzip.patch drops the sampled refusal and adds TestNonGzipClientGetsChallenge (4096 requests each without Accept-Encoding, with identity and with br, all challenged; it failed at request 67 before the patch). TestChallengeFor_ErrNotFound, skipped as flaky because of the refusal, runs again. The autopkgtest sends 512 requests without Accept-Encoding through nginx and expects the challenge page with 200 every time. 1.27.0-0+keel2. --- debian/changelog | 15 ++++ debian/patches/challenge-without-gzip.patch | 98 +++++++++++++++++++++ debian/patches/series | 1 + debian/rules | 5 +- debian/tests/behind-nginx | 16 +++- 5 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 debian/patches/challenge-without-gzip.patch create mode 100644 debian/patches/series diff --git a/debian/changelog b/debian/changelog index fa4204fe..e3b6212c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,18 @@ +anubis (1.27.0-0+keel2) trixie; urgency=medium + + * Serve the challenge to clients that do not accept gzip + (debian/patches/challenge-without-gzip.patch). Upstream refused one + such request in 64 at random with HTTP 500, and Keel Web answered 500 + to those clients (Keel-Linux/keel-web#2). A missing Accept-Encoding + accepts any coding; the proof of work is the defence. The patch adds + a test of 4096 requests without gzip, all challenged. + * debian/rules: TestChallengeFor_ErrNotFound, skipped as flaky because + of that refusal, runs again. + * autopkgtest: 512 requests without Accept-Encoding through nginx all + get the challenge page with HTTP 200. + + -- Marcos Méndez Fri, 02 Oct 2026 04:00:00 +0000 + anubis (1.27.0-0+keel1) trixie; urgency=medium * Keel Linux build for trixie, based on the Debian Go team's diff --git a/debian/patches/challenge-without-gzip.patch b/debian/patches/challenge-without-gzip.patch new file mode 100644 index 00000000..6f6fb2bc --- /dev/null +++ b/debian/patches/challenge-without-gzip.patch @@ -0,0 +1,98 @@ +Description: Serve the challenge to clients that do not accept gzip + RenderIndex refused one challenged request in 64, at random, when the + client did not list gzip in Accept-Encoding, with HTTP 500 and the page + "client_error_browser". A client without Accept-Encoding accepts any + coding (RFC 9110, section 12.5.3), and real clients send none: curl by + default, some accessibility and archiving tools, proxies that strip the + header. They got a server error at random while the proof of work, the + actual defence, was never reached. Keel Web saw it on its own test + client (Keel-Linux/keel-web#2). + . + Upstream changed the answer to the policy's DENY status in #1958 (after + 1.27.0) and kept the sampling, which their commit leaves to "its own + discussion"; this patch drops the sampled refusal, so such a client gets + the challenge every time, and adds a test that 4096 requests without + gzip, with identity and with br are all challenged. The test + TestChallengeFor_ErrNotFound, skipped as flaky by debian/rules because of + this refusal, runs again. +Author: Marcos Mendez +Bug: https://github.com/Keel-Linux/keel-web/issues/2 +Bug-Upstream: https://github.com/TecharoHQ/anubis/issues/1009 +Forwarded: not-needed +Last-Update: 2026-10-02 +--- +--- a/lib/anubis_test.go ++++ b/lib/anubis_test.go +@@ -845,6 +845,38 @@ func TestStripBasePrefixFromRequest(t *testing.T) { + } + } + ++// TestNonGzipClientGetsChallenge makes sure that a client which does not ++// advertise gzip in Accept-Encoding is handed the challenge like any other, ++// every time, instead of an error page for one request in 64 at random. ++func TestNonGzipClientGetsChallenge(t *testing.T) { ++ pol := loadPolicies(t, "testdata/aggressive_403.yaml", 0) ++ ++ srv := spawnAnubis(t, Options{ ++ Next: http.NewServeMux(), ++ Policy: pol, ++ }) ++ ++ const requests = 4096 ++ ++ for _, encoding := range []string{"", "identity", "br"} { ++ for i := 0; i < requests; i++ { ++ req := httptest.NewRequest("GET", "http://example.com/", nil) ++ req.Header.Set("X-Real-IP", "127.0.0.1") ++ req.Header.Set("User-Agent", "CHALLENGE") ++ if encoding != "" { ++ req.Header.Set("Accept-Encoding", encoding) ++ } ++ ++ w := httptest.NewRecorder() ++ srv.maybeReverseProxyOrPage(w, req) ++ ++ if w.Code != pol.StatusCodes.Challenge { ++ t.Fatalf("Accept-Encoding %q, request %d: got status %d, wanted %d (challenge)", encoding, i, w.Code, pol.StatusCodes.Challenge) ++ } ++ } ++ } ++} ++ + // TestChallengeFor_ErrNotFound makes sure that users with invalid challenge IDs + // in the test cookie don't get rejected by the database lookup failing. + func TestChallengeFor_ErrNotFound(t *testing.T) { +--- a/lib/http.go ++++ b/lib/http.go +@@ -8,7 +8,6 @@ import ( + "encoding/hex" + "errors" + "fmt" +- "math/rand" + "net/http" + "net/url" + "regexp" +@@ -167,10 +166,6 @@ func (t UnixRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { + return t.Transport.RoundTrip(req) + } + +-func randomChance(n int) bool { +- return rand.Intn(n) == 0 +-} +- + // XXX(Xe): generated by ChatGPT + func rot13(s string) string { + rotated := make([]rune, len(s)) +@@ -228,12 +223,6 @@ func (s *Server) RenderIndex(w http.ResponseWriter, r *http.Request, cr policy.C + + lg, r := s.getRequestLogger(r) + +- if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") && randomChance(64) { +- lg.ErrorContext(r.Context(), "client was given a challenge but does not in fact support gzip compression") +- s.respondWithError(w, r, localizer.T("client_error_browser"), "") +- return +- } +- + { + asn, asnDesc := asnFromContext(r.Context()) + challengesIssued.WithLabelValues("embedded", asn, asnDesc).Add(1) diff --git a/debian/patches/series b/debian/patches/series new file mode 100644 index 00000000..0f967b6a --- /dev/null +++ b/debian/patches/series @@ -0,0 +1 @@ +challenge-without-gzip.patch diff --git a/debian/rules b/debian/rules index 9e89fabe..61dac5bb 100755 --- a/debian/rules +++ b/debian/rules @@ -26,9 +26,6 @@ GENERATED := web/static/js web/static/locales \ # Packages whose tests need the network, a browser or a container runtime. TEST_SKIP := /internal/test$$|/cmd/containerbuild$$|/internal/dnsbl$$ -# Flaky by design: RenderIndex refuses a client without gzip support at -# random (1 in 64), and this test sends no Accept-Encoding. -TEST_SKIP_FLAKY := ^TestChallengeFor_ErrNotFound$$ %: dh $@ @@ -50,7 +47,7 @@ override_dh_auto_build: override_dh_auto_test: ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) - go test -count=1 -skip '$(TEST_SKIP_FLAKY)' $$(go list ./... | grep -Ev '$(TEST_SKIP)') + go test -count=1 $$(go list ./... | grep -Ev '$(TEST_SKIP)') endif override_dh_auto_install: diff --git a/debian/tests/behind-nginx b/debian/tests/behind-nginx index 0f4d7611..a8a3c9e0 100755 --- a/debian/tests/behind-nginx +++ b/debian/tests/behind-nginx @@ -85,12 +85,24 @@ echo "$listeners" | grep -qv '^127\.0\.0\.1:' && fail "anubis listens beyond the pass "anubis listens on the loopback only" get() { # get NAME UA [CLIENT_IP]: body to $WORK/NAME, prints the status - # --compressed: Anubis refuses, at random, a challenged client that - # does not accept gzip, as no browser does. curl -sS --compressed -o "$WORK/$1" -w '%{http_code}' -A "$2" \ ${3:+-H "X-Test-Client: $3"} "$FRONT/some/page" } +# A client that does not accept gzip gets the challenge every time. +# Upstream refused one such request in 64 at random with HTTP 500 +# (Keel-Linux/keel-web#2); 512 of them all passing that way had a chance +# of 1 in 3000. +i=0 +while [ "$i" -lt 512 ]; do + code=$(curl -sS -o "$WORK/no-gzip" -w '%{http_code}' -A "$BROWSER" \ + -H "X-Test-Client: 203.0.113.11" "$FRONT/some/page") + [ "$code" = 200 ] && grep -q 'id="anubis_challenge"' "$WORK/no-gzip" \ + || fail "request $i without Accept-Encoding: HTTP $code, not the challenge" + i=$((i + 1)) +done +pass "512 requests without Accept-Encoding: the challenge page, HTTP 200, every time" + code=$(get browser "$BROWSER" 203.0.113.10) grep -q 'id="anubis_challenge"' "$WORK/browser" \ || fail "a browser was not challenged (HTTP $code)" From b2954be3714be0e75b1037a63d0b54cc1ab4ff56 Mon Sep 17 00:00:00 2001 From: navigator Date: Fri, 2 Oct 2026 04:31:06 +0000 Subject: [PATCH 2/3] docs: the patch's DEP-3 header gives upstream's history and why Keel drops the sampling Forwarded: no instead of not-needed. The header names upstream #501, which brought the sampled refusal, and #1958, which only changed its status and left the sampling to a discussion of its own, and says why Keel drops it: a DENY page is still an error for a legitimate client, any scraper sends gzip for free, and the proof of work is the real defence. --- debian/patches/challenge-without-gzip.patch | 23 +++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/debian/patches/challenge-without-gzip.patch b/debian/patches/challenge-without-gzip.patch index 6f6fb2bc..540dbadf 100644 --- a/debian/patches/challenge-without-gzip.patch +++ b/debian/patches/challenge-without-gzip.patch @@ -8,17 +8,28 @@ Description: Serve the challenge to clients that do not accept gzip actual defence, was never reached. Keel Web saw it on its own test client (Keel-Linux/keel-web#2). . - Upstream changed the answer to the policy's DENY status in #1958 (after - 1.27.0) and kept the sampling, which their commit leaves to "its own - discussion"; this patch drops the sampled refusal, so such a client gets - the challenge every time, and adds a test that 4096 requests without - gzip, with identity and with br are all challenged. The test + Upstream history: the sampled refusal came with #501 ("ensure that + clients store cookies", https://github.com/TecharoHQ/anubis/pull/501); + #1958 (https://github.com/TecharoHQ/anubis/pull/1958, merged after + 1.27.0) changed its answer from 500 to the policy's DENY status and + logged it at INFO, and left the sampling itself open: its commit says + "whether the rejection should be sampled needs its own discussion". + Keel drops it rather than take #1958: a refusal at DENY status is still + an error page instead of the challenge for a legitimate client, and the + heuristic stops no scraper that sends "Accept-Encoding: gzip", which + costs nothing. The proof of work is the real defence, and every client + without gzip still has to solve it. Not forwarded yet: it belongs in the + sampling discussion that #1958 leaves open, where Keel will raise it. + . + This patch drops the sampled refusal, so such a client gets the + challenge every time, and adds a test that 4096 requests without gzip, + with identity and with br are all challenged. The test TestChallengeFor_ErrNotFound, skipped as flaky by debian/rules because of this refusal, runs again. Author: Marcos Mendez Bug: https://github.com/Keel-Linux/keel-web/issues/2 Bug-Upstream: https://github.com/TecharoHQ/anubis/issues/1009 -Forwarded: not-needed +Forwarded: no Last-Update: 2026-10-02 --- --- a/lib/anubis_test.go From 4df5fd40ae020aadc82c6490c3cfa1aba74f8480 Mon Sep 17 00:00:00 2001 From: navigator Date: Fri, 2 Oct 2026 04:38:53 +0000 Subject: [PATCH 3/3] fix: accept IPv6 literals in REDIRECT_DOMAINS Keel Web closes pass-challenge's open redirect by setting REDIRECT_DOMAINS to the machine's names and addresses (Anubis compares the host of redir with itself when it is unset). The host of an IPv6 URL is [2001:db8::1], but main refused that entry at start: url.Parse reads it as a path whose first segment has a colon. Measured on the Keel Web container: anubis@keel exited with "cannot parse redirect-domain". debian/patches/redirect-domains-ipv6.patch accepts an entry that parses as the host of a URL, or as a URL as before, and adds TestParseRedirectDomains (it failed to build before the change). --- debian/changelog | 4 + debian/patches/redirect-domains-ipv6.patch | 92 ++++++++++++++++++++++ debian/patches/series | 1 + 3 files changed, 97 insertions(+) create mode 100644 debian/patches/redirect-domains-ipv6.patch diff --git a/debian/changelog b/debian/changelog index e3b6212c..c881f9f4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,10 @@ anubis (1.27.0-0+keel2) trixie; urgency=medium to those clients (Keel-Linux/keel-web#2). A missing Accept-Encoding accepts any coding; the proof of work is the defence. The patch adds a test of 4096 requests without gzip, all challenged. + * Accept IPv6 literals ([2001:db8::1]) in REDIRECT_DOMAINS + (debian/patches/redirect-domains-ipv6.patch): Keel Web sets it to the + machine's names and addresses to close pass-challenge's open + redirect, and Anubis refused to start on an IPv6 entry. * debian/rules: TestChallengeFor_ErrNotFound, skipped as flaky because of that refusal, runs again. * autopkgtest: 512 requests without Accept-Encoding through nginx all diff --git a/debian/patches/redirect-domains-ipv6.patch b/debian/patches/redirect-domains-ipv6.patch new file mode 100644 index 00000000..d4355961 --- /dev/null +++ b/debian/patches/redirect-domains-ipv6.patch @@ -0,0 +1,92 @@ +Description: Accept IPv6 literals in REDIRECT_DOMAINS + Without REDIRECT_DOMAINS, pass-challenge redirects a solved challenge to + any host: it compares the host of redir with itself (lib/anubis.go, + PassChallenge), an open redirect. Keel Web sets REDIRECT_DOMAINS to the + machine's names and addresses, as its default site answers by IP too; + the host of an IPv6 URL is bracketed, [2001:db8::1], and that is what + Anubis compares, but main refused such an entry at start, as url.Parse + reads it as a path whose first segment has a colon ("cannot parse + redirect-domain"). An entry is now accepted when it parses as the host + of a URL (url.Parse("//" + entry)), or as a URL as before, so nothing + accepted before is refused. TestParseRedirectDomains covers names, + addresses, an IPv6 literal, a glob and a refused entry. +Author: Marcos Mendez +Forwarded: no +Last-Update: 2026-10-02 +--- +--- a/cmd/anubis/main.go ++++ b/cmd/anubis/main.go +@@ -119,6 +119,25 @@ func doHealthCheck() error { + return nil + } + ++// parseRedirectDomains splits REDIRECT_DOMAINS on commas and checks each ++// entry. An entry is a host as it appears in a URL, so an IPv6 literal is ++// bracketed, [2001:db8::1]; url.Parse alone refuses that ("first path ++// segment in URL cannot contain colon"), so an entry is accepted when it ++// parses as the host of a URL, or, as before, as a URL. ++func parseRedirectDomains(s string) ([]string, error) { ++ var domains []string ++ for domain := range strings.SplitSeq(s, ",") { ++ domain = strings.TrimSpace(domain) ++ if _, err := url.Parse("//" + domain); err != nil { ++ if _, err := url.Parse(domain); err != nil { ++ return nil, fmt.Errorf("cannot parse redirect-domain %q: %w", domain, err) ++ } ++ } ++ domains = append(domains, domain) ++ } ++ return domains, nil ++} ++ + func parseSameSite(s string) http.SameSite { + switch strings.ToLower(s) { + case "none": +@@ -400,13 +419,9 @@ func run(ctx context.Context) { + + var redirectDomainsList []string + if *redirectDomains != "" { +- domains := strings.SplitSeq(*redirectDomains, ",") +- for domain := range domains { +- _, err = url.Parse(domain) +- if err != nil { +- log.Fatalf("cannot parse redirect-domain %q: %s", domain, err.Error()) +- } +- redirectDomainsList = append(redirectDomainsList, strings.TrimSpace(domain)) ++ redirectDomainsList, err = parseRedirectDomains(*redirectDomains) ++ if err != nil { ++ log.Fatal(err) + } + } else { + lg.WarnContext(ctx, "REDIRECT_DOMAINS is not set, Anubis will redirect to any domain, see https://anubis.techaro.lol/docs/admin/configuration/redirect-domains") +--- a/cmd/anubis/main_test.go ++++ b/cmd/anubis/main_test.go +@@ -4,9 +4,28 @@ import ( + "net/http" + "net/http/httptest" + "net/url" ++ "slices" + "testing" + ) + ++// TestParseRedirectDomains makes sure that REDIRECT_DOMAINS takes an IPv6 ++// literal the way it appears as the host of a URL, [2001:db8::1], next to ++// names and globs, and still refuses what no host can be. ++func TestParseRedirectDomains(t *testing.T) { ++ got, err := parseRedirectDomains("web, web.example.org,10.0.3.158,[fd42:b2:0:1::6554],*.example.org") ++ if err != nil { ++ t.Fatalf("unexpected error: %v", err) ++ } ++ want := []string{"web", "web.example.org", "10.0.3.158", "[fd42:b2:0:1::6554]", "*.example.org"} ++ if !slices.Equal(got, want) { ++ t.Fatalf("got %q, want %q", got, want) ++ } ++ ++ if _, err := parseRedirectDomains("web,%zz"); err == nil { ++ t.Fatal("an unparseable domain was accepted") ++ } ++} ++ + func TestMakeReverseProxy(t *testing.T) { + type received struct { + host string diff --git a/debian/patches/series b/debian/patches/series index 0f967b6a..a12f9c1d 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1 +1,2 @@ challenge-without-gzip.patch +redirect-domains-ipv6.patch