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 21:32:33 +02:00
committed by GitHub
parent 52fcd2d2a0
commit bcd913a4e2
9 changed files with 76 additions and 44 deletions

View File

@@ -4,12 +4,12 @@
package url
import (
"context"
"net/http"
"net/url"
"testing"
"gitea.dev/modules/httplib"
"gitea.dev/modules/reqctx"
"gitea.dev/modules/setting"
"gitea.dev/modules/test"
@@ -175,11 +175,13 @@ func TestParseRepositoryURL(t *testing.T) {
defer test.MockVariableValue(&setting.AppURL, "https://localhost:3000")()
defer test.MockVariableValue(&setting.SSH.Domain, "try.gitea.io")()
ctx := reqctx.NewRequestContextForTest(t)
ctxURL, _ := url.Parse("https://gitea")
ctxReq := &http.Request{URL: ctxURL, Header: http.Header{}}
ctxReq.Host = ctxURL.Host
ctxReq.Header.Add("X-Forwarded-Proto", ctxURL.Scheme)
ctx := context.WithValue(t.Context(), httplib.RequestContextKey, ctxReq)
httplib.RequestWithContext(ctxReq, ctx)
httplib.MarkRequestSupportPublicURL(ctx)
cases := []struct {
input string
ownerName, repoName, remaining string