Skip to content

fix: redirect only to the request's own origin while REDIRECT_DOMAINS is empty - #3

Merged
marcos-mendez merged 4 commits into
keel/trixiefrom
fix/redir-same-host
Oct 2, 2026
Merged

marcos-mendez merged 4 commits into
keel/trixiefrom
fix/redir-same-host

Conversation

@marcos-mendez

Copy link
Copy Markdown
Contributor

Closes pass-challenge's open redirect without needing REDIRECT_DOMAINS (review of Keel-Linux/keel-web#3).

Root cause: with REDIRECT_DOMAINS empty, PassChallenge compares the host of redir with itself, because r.URL is redir parsed again. A solved challenge can therefore be sent to any host. Setting REDIRECT_DOMAINS closes this only for the names listed in it. Keel Web cannot list every name ahead of time: a new DNS name, a site from decision 0042, or a cloud public IP behind NAT would each hit redirect_domain_not_allowed.

Change (1.27.0-0+keel3, debian/patches/redir-same-host.patch, DEP-3): a new redirectAllowed function decides:

redir Result
has userinfo refused
relative (no scheme, no host) allowed, as upstream
REDIRECT_DOMAINS set a listed host is allowed, as upstream
REDIRECT_DOMAINS empty allowed only if scheme, host and port equal the request's (X-Forwarded-Proto, or http, plus Host, with default ports filled in)

Tests:

  • TestRedirectAllowed, 18 cases. It covers the same host by name, by a name not in /etc/hosts, by IPv4 and by an IPv6 literal. It refuses another host, //evil, https://a@evil, https://host@evil, another port and another scheme.
  • A new autopkgtest step drives pass-challenge behind nginx with a made-up challenge. The redir check runs first, so the error page shows which way it went. Allowed: same host by an unlisted name, a relative redir, an IPv6 literal. Refused: another host, //evil, userinfo, another IPv6 address.

Test plan

  • build / trixie and autopkgtest / trixie green
  • keel-web#3 depends on anubis (>= 1.27.0-0+keel3) and leaves REDIRECT_DOMAINS empty

… is empty

PassChallenge compared redir's host with itself when REDIRECT_DOMAINS
was empty, so a solved challenge could be sent to any host. A fixed
REDIRECT_DOMAINS cannot list every name a Keel Web site is reached by (a
new DNS name, a 0042 site, a cloud public IP behind NAT).

debian/patches/redir-same-host.patch: with REDIRECT_DOMAINS empty, redir
must be relative or name the request's own scheme, host and port, and
never carries userinfo; with it set, behaviour is unchanged.
TestRedirectAllowed (18 cases) failed to build before the change. The
autopkgtest drives pass-challenge behind nginx: same host by an unlisted
name, relative and IPv6 literal allowed; another host, //evil, userinfo
and another IPv6 address refused.

1.27.0-0+keel3.
marcos-mendez added a commit to Keel-Linux/keel-web that referenced this pull request Oct 2, 2026
…gin check

anubis-redirect-domains built Anubis's allowed list from hostname and ip
addr at each start, never at spec apply, so a new DNS name, a 0042 site
or a public IP behind NAT failed with redirect_domain_not_allowed after
the challenge. anubis 1.27.0-0+keel3 (Keel-Linux/anubis#3) closes the
open redirect itself while REDIRECT_DOMAINS is empty: redir must be
relative or name the request's own scheme, host and port, never with
userinfo. So keel-web drops the generator, its unit, the drop-in and the
postinst, depends on anubis (>= 1.27.0-0+keel3), and drops iproute2.

Measured on the Keel Web container (step7b image, cloud_simple, these
packages): Chromium passes the challenge by unlisted.keel.test (in
neither /etc/hosts nor DNS of the machine, sent as Host), by IPv6 and by
IPv4. With the browser's pass-challenge rewritten to redir
https://evil.example/, //evil.example/ or https://a@evil.example/,
Anubis answers "Redirect domain not allowed" and the browser sends
nothing to evil.example. tests: 100 bats, coverage 100 percent for the
three shell files.
redirectAllowed let through a redir with neither scheme nor host, and Go
parses /\evil.example that way while browsers read /\ as //, so
http.Redirect sent the visitor to evil.example (review of #3).

debian/patches/redir-validate.patch backports upstream's
validateRedirect: no backslash, control byte or leading space, no
opaque URL, no path starting with //, relative only from /, only http
and https; and runs it again on the percent-decoded redir (/%2F/evil,
/%5Cevil). TestPassChallengeRefusesRedirectTricks drives PassChallenge
with 16 such forms (6 of them redirected before the patch) and checks
that a relative and a same-origin redir still pass. The autopkgtest
refuses /\evil, /%2F/evil, /%5Cevil, %09//evil and ' //evil' behind
nginx.
With redir-validate.patch, //evil.example is refused as an invalid
redirect before the host check, so the autopkgtest's refused() expected
the wrong message and failed in CI. A refusal is either "Redirect domain
not allowed" or "Invalid redirect"; allowed() still requires neither.
@marcos-mendez
marcos-mendez merged commit 535cb8f into keel/trixie Oct 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant