mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-03 21:00:24 +00:00
fix(httplib): prevent leaking localhost:3000 in public links (#39217)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"gitea.dev/modules/cache"
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/httpcache"
|
||||
"gitea.dev/modules/httplib"
|
||||
"gitea.dev/modules/log"
|
||||
"gitea.dev/modules/paginator"
|
||||
"gitea.dev/modules/reqctx"
|
||||
@@ -257,8 +258,8 @@ func APIContexter() func(http.Handler) http.Handler {
|
||||
Repo: &Repository{},
|
||||
Org: &APIOrganization{},
|
||||
}
|
||||
|
||||
ctx.SetContextValue(apiContextKey, ctx)
|
||||
httplib.MarkRequestSupportPublicURL(ctx)
|
||||
|
||||
// FIXME: GLOBAL-PARSE-FORM: see more details in another FIXME comment
|
||||
if ctx.Req.Method == http.MethodPost && strings.Contains(ctx.Req.Header.Get("Content-Type"), "multipart/form-data") {
|
||||
|
||||
@@ -218,10 +218,9 @@ func NewBaseContext(resp http.ResponseWriter, req *http.Request) *Base {
|
||||
Locale: middleware.Locale(resp, req),
|
||||
Data: reqCtx.GetData(),
|
||||
}
|
||||
b.Req = b.Req.WithContext(b)
|
||||
b.Req = httplib.RequestWithContext(b.Req, reqCtx)
|
||||
reqCtx.SetContextValue(BaseContextKey, b)
|
||||
reqCtx.SetContextValue(translation.ContextKey, b.Locale)
|
||||
reqCtx.SetContextValue(httplib.RequestContextKey, b.Req)
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/cache"
|
||||
"gitea.dev/modules/httpcache"
|
||||
"gitea.dev/modules/httplib"
|
||||
"gitea.dev/modules/reqctx"
|
||||
"gitea.dev/modules/session"
|
||||
"gitea.dev/modules/setting"
|
||||
@@ -119,6 +120,7 @@ func NewWebContext(base *Base, render Render, session session.Store) *Context {
|
||||
ctx.TemplateContext = NewTemplateContextForWeb(ctx, ctx.Base.Req, ctx.Base.Locale)
|
||||
ctx.Flash = &middleware.Flash{DataStore: ctx, Values: url.Values{}}
|
||||
ctx.SetContextValue(WebContextKey, ctx)
|
||||
httplib.MarkRequestSupportPublicURL(ctx)
|
||||
return ctx
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user