Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Release Tools Bot <delivery-team+release-tools@gitlab.com>2023-01-10 03:04:05 +0300
committerGitLab Release Tools Bot <delivery-team+release-tools@gitlab.com>2023-01-10 03:04:05 +0300
commitdc7c33f2f421c5f733b11b42b01cc240477c6a70 (patch)
treef62982a8fb48949d62aefe9dc2077666843bd1bd
parentd6282255ed4c14be804f4397872782ff83eb9716 (diff)
parentc105a586d40e1eead5136fbd04ca4c061461e7ea (diff)
Merge remote-tracking branch 'dev/15-5-stable' into 15-5-stable
-rw-r--r--CHANGELOG.md6
-rw-r--r--VERSION2
-rw-r--r--internal/auth/auth.go19
-rw-r--r--internal/auth/auth_test.go15
4 files changed, 37 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 45d54eba..975a19b9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 15.5.7 (2023-01-09)
+
+### Security (1 change)
+
+- [Restrict arbitrary protocol redirection to only https or http URLs](gitlab-org/security/gitlab-pages@f14d39bbaacd76d8be26b6121e732c7327cc0d4d) ([merge request](gitlab-org/security/gitlab-pages!57))
+
## 15.5.6 (2022-12-15)
No changes.
diff --git a/VERSION b/VERSION
index 5542f71b..7a3ee10d 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-15.5.6 \ No newline at end of file
+15.5.7 \ No newline at end of file
diff --git a/internal/auth/auth.go b/internal/auth/auth.go
index 3014936b..06c85eeb 100644
--- a/internal/auth/auth.go
+++ b/internal/auth/auth.go
@@ -39,10 +39,11 @@ const (
authorizeProxyTemplate = "%s?domain=%s&state=%s"
authSessionMaxAge = 60 * 10 // 10 minutes
- failAuthErrMsg = "failed to authenticate request"
- fetchAccessTokenErrMsg = "fetching access token failed"
- queryParameterErrMsg = "failed to parse domain query parameter"
- saveSessionErrMsg = "failed to save the session"
+ failAuthErrMsg = "failed to authenticate request"
+ fetchAccessTokenErrMsg = "fetching access token failed"
+ queryParameterErrMsg = "failed to parse domain query parameter"
+ saveSessionErrMsg = "failed to save the session"
+ domainQueryParameterErrMsg = "domain query parameter only supports http/https protocol"
)
var (
@@ -197,6 +198,7 @@ func (a *Auth) domainAllowed(ctx context.Context, name string, domains source.So
return (domain != nil && err == nil)
}
+// nolint: gocyclo // TODO refactor this function https://gitlab.com/gitlab-org/gitlab-pages/-/issues/813
func (a *Auth) handleProxyingAuth(session *hostSession, w http.ResponseWriter, r *http.Request, domains source.Source) bool {
// handle auth callback e.g. https://gitlab.io/auth?domain=domain&state=state
if shouldProxyAuthToGitlab(r) {
@@ -211,6 +213,15 @@ func (a *Auth) handleProxyingAuth(session *hostSession, w http.ResponseWriter, r
httperrors.Serve500(w)
return true
}
+
+ // domain query param can only contain https or http URLs.
+ if proxyurl.Scheme != "http" && proxyurl.Scheme != "https" {
+ logRequest(r).WithField("domain_query", domain).Warn(domainQueryParameterErrMsg)
+
+ httperrors.Serve401(w)
+ return true
+ }
+
host, _, err := net.SplitHostPort(proxyurl.Host)
if err != nil {
host = proxyurl.Host
diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go
index 4236d695..77e45d8e 100644
--- a/internal/auth/auth_test.go
+++ b/internal/auth/auth_test.go
@@ -171,6 +171,21 @@ func TestTryAuthenticateWithDomainAndState(t *testing.T) {
require.Equal(t, "/public-gitlab.example.com/oauth/authorize?client_id=id&redirect_uri=http://pages.gitlab-example.com/auth&response_type=code&state=state&scope=scope", redirect.String())
}
+func TestTryAuthenticateWithNonHttpDomainAndState(t *testing.T) {
+ auth := createTestAuth(t, "", "")
+
+ result := httptest.NewRecorder()
+
+ r, err := http.NewRequest("Get", "https://example.com/auth?domain=mailto://example.com?body=TESTBODY&state=state", nil)
+ require.NoError(t, err)
+
+ mockCtrl := gomock.NewController(t)
+
+ mockSource := mock.NewMockSource(mockCtrl)
+ require.True(t, auth.TryAuthenticate(result, r, mockSource))
+ require.Equal(t, http.StatusUnauthorized, result.Code)
+}
+
func testTryAuthenticateWithCodeAndState(t *testing.T, https bool) {
t.Helper()