diff --git a/lib/challenge/interface.go b/lib/challenge/interface.go index 963d6ca1..c7a19449 100644 --- a/lib/challenge/interface.go +++ b/lib/challenge/interface.go @@ -61,7 +61,7 @@ type Impl interface { Setup(mux *http.ServeMux) // Issue a new challenge to the user, called by the Anubis. - Issue(r *http.Request, lg *slog.Logger, in *IssueInput) (templ.Component, error) + Issue(w http.ResponseWriter, r *http.Request, lg *slog.Logger, in *IssueInput) (templ.Component, error) // Validate a challenge, making sure that it passes muster. Validate(r *http.Request, lg *slog.Logger, in *ValidateInput) error diff --git a/lib/challenge/metarefresh/metarefresh.go b/lib/challenge/metarefresh/metarefresh.go index 75ac70fc..9760d50d 100644 --- a/lib/challenge/metarefresh/metarefresh.go +++ b/lib/challenge/metarefresh/metarefresh.go @@ -23,7 +23,7 @@ type Impl struct{} func (i *Impl) Setup(mux *http.ServeMux) {} -func (i *Impl) Issue(r *http.Request, lg *slog.Logger, in *challenge.IssueInput) (templ.Component, error) { +func (i *Impl) Issue(w http.ResponseWriter, r *http.Request, lg *slog.Logger, in *challenge.IssueInput) (templ.Component, error) { u, err := r.URL.Parse(anubis.BasePrefix + "/.within.website/x/cmd/anubis/api/pass-challenge") if err != nil { return nil, fmt.Errorf("can't render page: %w", err) diff --git a/lib/challenge/preact/preact.go b/lib/challenge/preact/preact.go index 0276d7d2..a785f984 100644 --- a/lib/challenge/preact/preact.go +++ b/lib/challenge/preact/preact.go @@ -38,7 +38,7 @@ type impl struct{} func (i *impl) Setup(mux *http.ServeMux) {} -func (i *impl) Issue(r *http.Request, lg *slog.Logger, in *challenge.IssueInput) (templ.Component, error) { +func (i *impl) Issue(w http.ResponseWriter, r *http.Request, lg *slog.Logger, in *challenge.IssueInput) (templ.Component, error) { u, err := r.URL.Parse(anubis.BasePrefix + "/.within.website/x/cmd/anubis/api/pass-challenge") if err != nil { return nil, fmt.Errorf("can't render page: %w", err) diff --git a/lib/challenge/proofofwork/proofofwork.go b/lib/challenge/proofofwork/proofofwork.go index 8cd31277..b9be014e 100644 --- a/lib/challenge/proofofwork/proofofwork.go +++ b/lib/challenge/proofofwork/proofofwork.go @@ -27,7 +27,7 @@ type Impl struct { func (i *Impl) Setup(mux *http.ServeMux) {} -func (i *Impl) Issue(r *http.Request, lg *slog.Logger, in *chall.IssueInput) (templ.Component, error) { +func (i *Impl) Issue(w http.ResponseWriter, r *http.Request, lg *slog.Logger, in *chall.IssueInput) (templ.Component, error) { loc := localization.GetLocalizer(r) return page(loc), nil } diff --git a/lib/challenge/proofofwork/proofofwork_test.go b/lib/challenge/proofofwork/proofofwork_test.go index 4e71bcf7..c0611a53 100644 --- a/lib/challenge/proofofwork/proofofwork_test.go +++ b/lib/challenge/proofofwork/proofofwork_test.go @@ -4,6 +4,7 @@ import ( "errors" "log/slog" "net/http" + "net/http/httptest" "testing" "github.com/TecharoHQ/anubis/lib/challenge" @@ -133,7 +134,7 @@ func TestBasic(t *testing.T) { }, } - if _, err := i.Issue(cs.req, lg, inp); err != nil { + if _, err := i.Issue(httptest.NewRecorder(), cs.req, lg, inp); err != nil { t.Errorf("can't issue challenge: %v", err) } diff --git a/lib/http.go b/lib/http.go index 61107079..5ecb6d12 100644 --- a/lib/http.go +++ b/lib/http.go @@ -29,19 +29,19 @@ var domainMatchRegexp = regexp.MustCompile(`^((xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[ // internal glob matcher. Matching is case-insensitive on hostnames. func matchRedirectDomain(allowed []string, host string) bool { h := strings.ToLower(strings.TrimSpace(host)) - for _, pat := range allowed { - p := strings.ToLower(strings.TrimSpace(pat)) - if strings.Contains(p, glob.GLOB) { - if glob.Glob(p, h) { - return true - } - continue - } - if p == h { - return true - } - } - return false + for _, pat := range allowed { + p := strings.ToLower(strings.TrimSpace(pat)) + if strings.Contains(p, glob.GLOB) { + if glob.Glob(p, h) { + return true + } + continue + } + if p == h { + return true + } + } + return false } type CookieOpts struct { @@ -203,7 +203,7 @@ func (s *Server) RenderIndex(w http.ResponseWriter, r *http.Request, cr policy.C Store: s.store, } - component, err := impl.Issue(r, lg, in) + component, err := impl.Issue(w, r, lg, in) if err != nil { lg.Error("[unexpected] challenge component render failed, please open an issue", "err", err) // This is likely a bug in the template. Should never be triggered as CI tests for this. s.respondWithError(w, r, fmt.Sprintf("%s \"RenderIndex\"", localizer.T("internal_server_error")))