fix(httplib): prevent leaking localhost:3000 in public links (#39217)

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Elisei Roca
2026-09-02 19:32:33 +00:00
committed by GitHub
co-authored by wxiaoguang
parent 52fcd2d2a0
commit bcd913a4e2
9 changed files with 76 additions and 44 deletions
+9 -4
View File
@@ -130,13 +130,18 @@ func ArtifactsRoutes(prefix string) *web.Router {
return m
}
func newArtifactContext(resp http.ResponseWriter, req *http.Request) *ArtifactContext {
base := context.NewBaseContext(resp, req)
ctx := &ArtifactContext{Base: base}
ctx.SetContextValue(artifactContextKey, ctx)
httplib.MarkRequestSupportPublicURL(ctx)
return ctx
}
func ArtifactContexter() func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
base := context.NewBaseContext(resp, req)
ctx := &ArtifactContext{Base: base}
ctx.SetContextValue(artifactContextKey, ctx)
ctx := newArtifactContext(resp, req)
// action task call server api with Bearer ACTIONS_RUNTIME_TOKEN
// we should verify the ACTIONS_RUNTIME_TOKEN
+1 -4
View File
@@ -114,7 +114,6 @@ import (
"gitea.dev/modules/util"
"gitea.dev/modules/web"
"gitea.dev/services/actions"
"gitea.dev/services/context"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/reflect/protoreflect"
@@ -132,9 +131,7 @@ type artifactV4Routes struct {
func ArtifactV4Contexter() func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
base := context.NewBaseContext(resp, req)
ctx := &ArtifactContext{Base: base}
ctx.SetContextValue(artifactContextKey, ctx)
ctx := newArtifactContext(resp, req)
next.ServeHTTP(ctx.Resp, ctx.Req)
})
}