Skip to content

Commit ac4319b

Browse files
committed
fix
1 parent 55d5a74 commit ac4319b

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

Diff for: .github/workflows/pull-db-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ jobs:
201201
runs-on: ubuntu-latest
202202
services:
203203
mssql:
204-
image: mcr.microsoft.com/mssql/server:2017-latest
204+
image: mcr.microsoft.com/mssql/server:2022-latest
205205
env:
206206
ACCEPT_EULA: Y
207207
MSSQL_PID: Standard

Diff for: modules/httplib/url.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ func getRequestScheme(req *http.Request) string {
5252
return ""
5353
}
5454

55-
func getForwardedHost(req *http.Request) string {
56-
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host
57-
return req.Header.Get("X-Forwarded-Host")
58-
}
59-
6055
// GuessCurrentAppURL tries to guess the current full app URL (with sub-path) by http headers. It always has a '/' suffix, exactly the same as setting.AppURL
6156
func GuessCurrentAppURL(ctx context.Context) string {
6257
return GuessCurrentHostURL(ctx) + setting.AppSubURL + "/"
@@ -81,11 +76,9 @@ func GuessCurrentHostURL(ctx context.Context) string {
8176
if reqScheme == "" {
8277
return strings.TrimSuffix(setting.AppURL, setting.AppSubURL+"/")
8378
}
84-
reqHost := getForwardedHost(req)
85-
if reqHost == "" {
86-
reqHost = req.Host
87-
}
88-
return reqScheme + "://" + reqHost
79+
// X-Forwarded-Host has many problems: non-standard, not well-defined (X-Forwarded-Port or not), conflicts with Host header.
80+
// So do not use X-Forwarded-Host, just use Host header directly.
81+
return reqScheme + "://" + req.Host
8982
}
9083

9184
// MakeAbsoluteURL tries to make a link to an absolute URL:

Diff for: modules/httplib/url_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestMakeAbsoluteURL(t *testing.T) {
7070
"X-Forwarded-Proto": {"https"},
7171
},
7272
})
73-
assert.Equal(t, "https://forwarded-host/foo", MakeAbsoluteURL(ctx, "/foo"))
73+
assert.Equal(t, "https://user-host/foo", MakeAbsoluteURL(ctx, "/foo"))
7474
}
7575

7676
func TestIsCurrentGiteaSiteURL(t *testing.T) {
@@ -119,5 +119,6 @@ func TestIsCurrentGiteaSiteURL(t *testing.T) {
119119
},
120120
})
121121
assert.True(t, IsCurrentGiteaSiteURL(ctx, "http://localhost:3000"))
122-
assert.True(t, IsCurrentGiteaSiteURL(ctx, "https://forwarded-host"))
122+
assert.True(t, IsCurrentGiteaSiteURL(ctx, "https://user-host"))
123+
assert.False(t, IsCurrentGiteaSiteURL(ctx, "https://forwarded-host"))
123124
}

0 commit comments

Comments
 (0)