From ce425a2c21adaa4f5b21fd6d3f45e404bbe4337c Mon Sep 17 00:00:00 2001 From: compilade Date: Wed, 23 Apr 2025 22:13:11 -0400 Subject: [PATCH] fix(lib): use correct URL for path checker in PassChallenge (#347) Otherwise, `r.URL.Path` was always `/.within.website/x/cmd/anubis/api/pass-challenge` and this didn't match the path checker rules correctly, which caused a failure when the difficulty of these rules was non-default. --- lib/anubis.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/anubis.go b/lib/anubis.go index 7892b15..f6445fb 100644 --- a/lib/anubis.go +++ b/lib/anubis.go @@ -12,6 +12,7 @@ import ( "math" "net" "net/http" + "net/url" "os" "strconv" "strings" @@ -423,6 +424,16 @@ func (s *Server) PassChallenge(w http.ResponseWriter, r *http.Request) { "x-real-ip", r.Header.Get("X-Real-Ip"), ) + redir := r.FormValue("redir") + redirURL, err := url.ParseRequestURI(redir) + if err != nil { + lg.Error("invalid redirect", "err", err) + templ.Handler(web.Base("Oh noes!", web.ErrorPage("invalid redirect", s.opts.WebmasterEmail)), templ.WithStatus(http.StatusInternalServerError)).ServeHTTP(w, r) + return + } + // used by the path checker rule + r.URL = redirURL + cr, rule, err := s.check(r) if err != nil { lg.Error("check failed", "err", err) @@ -459,7 +470,6 @@ func (s *Server) PassChallenge(w http.ResponseWriter, r *http.Request) { timeTaken.Observe(elapsedTime) response := r.FormValue("response") - redir := r.FormValue("redir") challenge := s.challengeFor(r, rule.Challenge.Difficulty)