From d4c2db39bf239d071c6ac96815efa8fd8b03ad94 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 8 May 2024 21:34:43 +0800 Subject: Refactor AppURL usage (#30885) (#30891) Backport #30885 Fix #30883 Fix #29591 Co-authored-by: KN4CK3R --- routers/common/middleware.go | 3 +++ routers/common/redirect.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'routers/common') diff --git a/routers/common/middleware.go b/routers/common/middleware.go index c7c75fb099..8b661993bb 100644 --- a/routers/common/middleware.go +++ b/routers/common/middleware.go @@ -4,11 +4,13 @@ package common import ( + go_context "context" "fmt" "net/http" "strings" "code.gitea.io/gitea/modules/cache" + "code.gitea.io/gitea/modules/httplib" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/web/middleware" @@ -34,6 +36,7 @@ func ProtocolMiddlewares() (handlers []any) { } }() req = req.WithContext(middleware.WithContextData(req.Context())) + req = req.WithContext(go_context.WithValue(req.Context(), httplib.RequestContextKey, req)) next.ServeHTTP(resp, req) }) }) diff --git a/routers/common/redirect.go b/routers/common/redirect.go index 34044e814b..d64f74ec82 100644 --- a/routers/common/redirect.go +++ b/routers/common/redirect.go @@ -17,7 +17,7 @@ func FetchRedirectDelegate(resp http.ResponseWriter, req *http.Request) { // The typical page is "issue comment" page. The backend responds "/owner/repo/issues/1#comment-2", // then frontend needs this delegate to redirect to the new location with hash correctly. redirect := req.PostFormValue("redirect") - if !httplib.IsCurrentGiteaSiteURL(redirect) { + if !httplib.IsCurrentGiteaSiteURL(req.Context(), redirect) { resp.WriteHeader(http.StatusBadRequest) return } -- cgit v1.2.3