From 2e7ff3fedd4c3fb89dad8bddceb8e10846c2cef6 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 28 Jul 2025 22:03:43 +0300 Subject: [PATCH] all: fix trailing slash in subrouters --- bridgev2/matrix/provisioning.go | 6 ++++-- federation/keyserver.go | 3 ++- mediaproxy/mediaproxy.go | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bridgev2/matrix/provisioning.go b/bridgev2/matrix/provisioning.go index 7f4b8a2e..6b594deb 100644 --- a/bridgev2/matrix/provisioning.go +++ b/bridgev2/matrix/provisioning.go @@ -142,15 +142,17 @@ func (prov *ProvisioningAPI) Init() { debugRouter.HandleFunc("GET /pprof/symbol", pprof.Symbol) debugRouter.HandleFunc("GET /pprof/trace", pprof.Trace) debugRouter.HandleFunc("/pprof/", pprof.Index) - prov.br.AS.Router.Handle("/debug", exhttp.ApplyMiddleware( + prov.br.AS.Router.Handle("/debug/", exhttp.ApplyMiddleware( debugRouter, + exhttp.StripPrefix("/debug"), hlog.NewHandler(prov.br.Log.With().Str("component", "debug api").Logger()), prov.DebugAuthMiddleware, )) } - prov.br.AS.Router.Handle("/_matrix/provision", exhttp.ApplyMiddleware( + prov.br.AS.Router.Handle("/_matrix/provision/", exhttp.ApplyMiddleware( prov.Router, + exhttp.StripPrefix("/_matrix/provision"), hlog.NewHandler(prov.log), hlog.RequestIDHandler("request_id", "Request-Id"), exhttp.CORSMiddleware, diff --git a/federation/keyserver.go b/federation/keyserver.go index 37998786..35ec59fd 100644 --- a/federation/keyserver.go +++ b/federation/keyserver.go @@ -62,8 +62,9 @@ func (ks *KeyServer) Register(r *http.ServeMux) { NotFound: exerrors.Must(json.Marshal(mautrix.MUnrecognized.WithMessage("Unrecognized endpoint"))), MethodNotAllowed: exerrors.Must(json.Marshal(mautrix.MUnrecognized.WithMessage("Invalid method for endpoint"))), } - r.Handle("/_matrix/key", exhttp.ApplyMiddleware( + r.Handle("/_matrix/key/", exhttp.ApplyMiddleware( keyRouter, + exhttp.StripPrefix("/_matrix/key"), exhttp.HandleErrors(errorBodies), )) } diff --git a/mediaproxy/mediaproxy.go b/mediaproxy/mediaproxy.go index 6fbcdbad..a5f07afa 100644 --- a/mediaproxy/mediaproxy.go +++ b/mediaproxy/mediaproxy.go @@ -208,12 +208,14 @@ func (mp *MediaProxy) RegisterRoutes(router *http.ServeMux) { NotFound: exerrors.Must(json.Marshal(mautrix.MUnrecognized.WithMessage("Unrecognized endpoint"))), MethodNotAllowed: exerrors.Must(json.Marshal(mautrix.MUnrecognized.WithMessage("Invalid method for endpoint"))), } - router.Handle("/_matrix/federation", exhttp.ApplyMiddleware( + router.Handle("/_matrix/federation/", exhttp.ApplyMiddleware( mp.FederationRouter, + exhttp.StripPrefix("/_matrix/federation"), exhttp.HandleErrors(errorBodies), )) - router.Handle("/_matrix/client/v1/media", exhttp.ApplyMiddleware( + router.Handle("/_matrix/client/v1/media/", exhttp.ApplyMiddleware( mp.ClientMediaRouter, + exhttp.StripPrefix("/_matrix/client/v1/media"), exhttp.CORSMiddleware, exhttp.HandleErrors(errorBodies), ))