From bc9afc003196c40c8c119a180ac250b9d3e538b0 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 1 Sep 2026 11:23:35 +0530 Subject: [PATCH 1/3] feat: make the GitLab endpoint configurable Both GitLab surfaces hardcoded https://gitlab.com, so a self-hosted GitLab could not be used for either repository integration or console sign-in. _APP_VCS_GITLAB_ENDPOINT covers repository integration: the vcs registry entry Vcs\Factory hands to setEndpoint() and to the OAuth2 builder, plus the authorize and callback handlers that build their own client. _APP_CONSOLE_GITLAB_ENDPOINT covers console sign-in. Auth\OAuth2\Gitlab reads its endpoint out of a JSON-encoded secret, so gitlabSecret now carries {"clientSecret","endpoint"} rather than the raw secret string. That also fixes console sign-in outright, which threw "Invalid secret" on the undecodable plain string. The value stays empty when unconfigured so account.php keeps reporting the provider as disabled. Both default to https://gitlab.com. --- .env | 2 ++ app/config/console.php | 8 +++++++- app/config/variables.php | 18 ++++++++++++++++++ app/config/vcs.php | 5 +++-- docker-compose.yml | 4 ++++ src/Appwrite/Auth/OAuth2/Gitlab.php | 5 +++-- .../Modules/VCS/Http/Gitlab/Authorize/Get.php | 2 +- .../Modules/VCS/Http/Gitlab/Callback/Get.php | 2 +- 8 files changed, 39 insertions(+), 7 deletions(-) diff --git a/.env b/.env index 3ff3672e3d..7fe753006f 100644 --- a/.env +++ b/.env @@ -41,6 +41,7 @@ _APP_CONSOLE_GITHUB_APP_ID= _APP_CONSOLE_GITHUB_SECRET= _APP_CONSOLE_GITLAB_APP_ID= _APP_CONSOLE_GITLAB_SECRET= +_APP_CONSOLE_GITLAB_ENDPOINT=https://gitlab.com _APP_CONSOLE_BITBUCKET_APP_ID= _APP_CONSOLE_BITBUCKET_SECRET= _APP_CONSOLE_GOOGLE_APP_ID= @@ -181,6 +182,7 @@ _APP_VCS_GITEA_BROWSER_ENDPOINT=http://localhost:9515 _APP_VCS_GITEA_CLIENT_ID= _APP_VCS_GITEA_CLIENT_SECRET= _APP_VCS_GITEA_WEBHOOK_SECRET=gitea-webhook-secret +_APP_VCS_GITLAB_ENDPOINT=https://gitlab.com _APP_VCS_GITLAB_CLIENT_ID= _APP_VCS_GITLAB_CLIENT_SECRET= _APP_VCS_GITLAB_WEBHOOK_SECRET= diff --git a/app/config/console.php b/app/config/console.php index bc4c6f0b49..0d99ad71b5 100644 --- a/app/config/console.php +++ b/app/config/console.php @@ -59,7 +59,13 @@ $console = [ 'githubSecret' => System::getEnv('_APP_CONSOLE_GITHUB_SECRET', ''), 'githubAppid' => System::getEnv('_APP_CONSOLE_GITHUB_APP_ID', ''), 'gitlabEnabled' => true, - 'gitlabSecret' => System::getEnv('_APP_CONSOLE_GITLAB_SECRET', ''), + // Auth\OAuth2\Gitlab reads its endpoint out of a JSON-encoded secret, so + // _APP_CONSOLE_GITLAB_ENDPOINT travels with the credential. Stays empty when + // unconfigured so account.php keeps reporting the provider as disabled. + 'gitlabSecret' => empty(System::getEnv('_APP_CONSOLE_GITLAB_SECRET', '')) ? '' : \json_encode([ + 'clientSecret' => System::getEnv('_APP_CONSOLE_GITLAB_SECRET', ''), + 'endpoint' => System::getEnv('_APP_CONSOLE_GITLAB_ENDPOINT', 'https://gitlab.com'), + ]), 'gitlabAppid' => System::getEnv('_APP_CONSOLE_GITLAB_APP_ID', ''), 'bitbucketEnabled' => true, 'bitbucketSecret' => System::getEnv('_APP_CONSOLE_BITBUCKET_SECRET', ''), diff --git a/app/config/variables.php b/app/config/variables.php index e21b086f92..2580d0046c 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -295,6 +295,15 @@ return [ 'question' => '', 'filter' => '' ], + [ + 'name' => '_APP_CONSOLE_GITLAB_ENDPOINT', + 'description' => 'URL of the GitLab instance used for signing in to the Appwrite console, for self-hosted GitLab. This is separate from _APP_VCS_GITLAB_ENDPOINT, which powers repository integration rather than console sign-in.', + 'introduction' => '2.0.0', + 'default' => 'https://gitlab.com', + 'required' => false, + 'question' => '', + 'filter' => '' + ], [ 'name' => '_APP_CONSOLE_BITBUCKET_APP_ID', 'description' => 'Bitbucket OAuth consumer key used for signing in to the Appwrite console. You can find it in your Bitbucket workspace settings under OAuth consumers. This is separate from _APP_VCS_BITBUCKET_CLIENT_ID, which powers repository integration rather than console sign-in.', @@ -1572,6 +1581,15 @@ return [ 'question' => '', 'filter' => '' ], + [ + 'name' => '_APP_VCS_GITLAB_ENDPOINT', + 'description' => 'URL of your self-hosted GitLab instance, reachable from the Appwrite server and the browser.', + 'introduction' => '2.0.0', + 'default' => 'https://gitlab.com', + 'required' => false, + 'question' => '', + 'filter' => '' + ], [ 'name' => '_APP_VCS_GITLAB_CLIENT_ID', 'description' => 'GitLab OAuth2 application client ID. You can generate one in your GitLab instance under Settings > Applications.', diff --git a/app/config/vcs.php b/app/config/vcs.php index f21d54c803..c1c5f21deb 100644 --- a/app/config/vcs.php +++ b/app/config/vcs.php @@ -8,6 +8,7 @@ use Appwrite\Auth\OAuth2\Bitbucket as OAuth2Bitbucket; use Appwrite\Auth\OAuth2\Gitea as OAuth2Gitea; use Appwrite\Auth\OAuth2\Github as OAuth2Github; use Appwrite\Auth\OAuth2\Gitlab as OAuth2Gitlab; +use Utopia\System\System; use Utopia\VCS\Adapter\Git\Bitbucket; use Utopia\VCS\Adapter\Git\Gitea; use Utopia\VCS\Adapter\Git\GitHub; @@ -55,8 +56,8 @@ return [ 'clientSecret' => $clientSecret, 'endpoint' => $endpoint, ]), ''), - // Only official gitlab.com is supported -- fixed, not configurable. - 'endpoint' => 'https://gitlab.com', + // Defaults to gitlab.com; self-hosted installs point _APP_VCS_GITLAB_ENDPOINT at their own instance. + 'endpoint' => System::getEnv('_APP_VCS_GITLAB_ENDPOINT', 'https://gitlab.com'), 'variables' => [ 'clientId' => ['required' => true, 'envVariable' => '_APP_VCS_GITLAB_CLIENT_ID'], 'clientSecret' => ['required' => true, 'envVariable' => '_APP_VCS_GITLAB_CLIENT_SECRET'], diff --git a/docker-compose.yml b/docker-compose.yml index c709dc73e5..99a32c9628 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -103,6 +103,7 @@ services: - _APP_CONSOLE_GITHUB_SECRET - _APP_CONSOLE_GITLAB_APP_ID - _APP_CONSOLE_GITLAB_SECRET + - _APP_CONSOLE_GITLAB_ENDPOINT - _APP_CONSOLE_BITBUCKET_APP_ID - _APP_CONSOLE_BITBUCKET_SECRET - _APP_CONSOLE_GOOGLE_APP_ID @@ -229,6 +230,7 @@ services: - _APP_VCS_GITEA_CLIENT_ID - _APP_VCS_GITEA_CLIENT_SECRET - _APP_VCS_GITEA_WEBHOOK_SECRET + - _APP_VCS_GITLAB_ENDPOINT - _APP_VCS_GITLAB_CLIENT_ID - _APP_VCS_GITLAB_CLIENT_SECRET - _APP_VCS_GITLAB_WEBHOOK_SECRET @@ -482,6 +484,7 @@ services: - _APP_VCS_GITEA_CLIENT_ID - _APP_VCS_GITEA_CLIENT_SECRET - _APP_VCS_GITEA_WEBHOOK_SECRET + - _APP_VCS_GITLAB_ENDPOINT - _APP_VCS_GITLAB_CLIENT_ID - _APP_VCS_GITLAB_CLIENT_SECRET - _APP_VCS_GITLAB_WEBHOOK_SECRET @@ -824,6 +827,7 @@ services: - _APP_VCS_GITEA_CLIENT_ID - _APP_VCS_GITEA_CLIENT_SECRET - _APP_VCS_GITEA_WEBHOOK_SECRET + - _APP_VCS_GITLAB_ENDPOINT - _APP_VCS_GITLAB_CLIENT_ID - _APP_VCS_GITLAB_CLIENT_SECRET - _APP_VCS_GITLAB_WEBHOOK_SECRET diff --git a/src/Appwrite/Auth/OAuth2/Gitlab.php b/src/Appwrite/Auth/OAuth2/Gitlab.php index db72385a12..938926cf37 100644 --- a/src/Appwrite/Auth/OAuth2/Gitlab.php +++ b/src/Appwrite/Auth/OAuth2/Gitlab.php @@ -11,8 +11,9 @@ use Appwrite\Auth\OAuth2; * Shared with the "Sign in with GitLab" account-login OAuth2 provider, which * stores its secret as JSON ({"clientSecret": "...", "endpoint": "..."}) to * support self-hosted GitLab per-project. The VCS flow (see app/config/vcs.php) - * only supports official gitlab.com, but still encodes to that same JSON - * shape so getAppSecret()/getEndpoint() stay correct for both consumers. + * and the console project (see app/config/console.php) encode to that same JSON + * shape, taking their endpoint from _APP_VCS_GITLAB_ENDPOINT and + * _APP_CONSOLE_GITLAB_ENDPOINT respectively. */ class Gitlab extends OAuth2 { diff --git a/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Authorize/Get.php b/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Authorize/Get.php index 34e8dd71b0..0eca4c9906 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Authorize/Get.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Authorize/Get.php @@ -31,7 +31,7 @@ class Get extends Base System::getEnv('_APP_VCS_GITLAB_CLIENT_ID', ''), \json_encode([ 'clientSecret' => System::getEnv('_APP_VCS_GITLAB_CLIENT_SECRET', ''), - 'endpoint' => 'https://gitlab.com', + 'endpoint' => System::getEnv('_APP_VCS_GITLAB_ENDPOINT', 'https://gitlab.com'), ]), $callback, $state, diff --git a/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Callback/Get.php b/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Callback/Get.php index 6d86b25fa1..e48f488f5d 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Callback/Get.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/Gitlab/Callback/Get.php @@ -30,7 +30,7 @@ class Get extends Base System::getEnv('_APP_VCS_GITLAB_CLIENT_ID', ''), \json_encode([ 'clientSecret' => System::getEnv('_APP_VCS_GITLAB_CLIENT_SECRET', ''), - 'endpoint' => 'https://gitlab.com', + 'endpoint' => System::getEnv('_APP_VCS_GITLAB_ENDPOINT', 'https://gitlab.com'), ]), $callback ); From 1bae8729749550de890c03970311bac1075dae8a Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 1 Sep 2026 12:07:52 +0530 Subject: [PATCH 2/3] fix(oauth2): stop GitLab rejecting a plain-string secret getAppSecret() decoded appSecret with JSON_THROW_ON_ERROR and turned any failure into "Invalid secret", so a secret that is not a JSON object took down every call that needed it. The legacy PATCH /v1/projects/:projectId/oauth2 writes the secret verbatim for any provider in the oAuthProviders config, gitlab included, so projects configured through it fail sign-in outright. A numeric secret decoded fine and then tripped the array return type instead. Fall back to treating the raw string as the client secret, matching Google, which grew the same fallback for the same reason. Also rtrim the endpoint, as Gitea's setEndpoint() does, so a configured endpoint with a trailing slash no longer builds //oauth/authorize. --- src/Appwrite/Auth/OAuth2/Gitlab.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2/Gitlab.php b/src/Appwrite/Auth/OAuth2/Gitlab.php index 938926cf37..fd2464b4ff 100644 --- a/src/Appwrite/Auth/OAuth2/Gitlab.php +++ b/src/Appwrite/Auth/OAuth2/Gitlab.php @@ -231,7 +231,8 @@ class Gitlab extends OAuth2 } /** - * Decode the JSON stored in appSecret + * Decode the JSON stored in appSecret. + * Falls back to treating the raw string as the client secret for backwards compatibility. * * @return array */ @@ -240,8 +241,13 @@ class Gitlab extends OAuth2 try { $secret = \json_decode($this->appSecret, true, 512, JSON_THROW_ON_ERROR); } catch (\Throwable $th) { - throw new \Exception('Invalid secret'); + return ['clientSecret' => $this->appSecret]; } + + if (!\is_array($secret)) { + return ['clientSecret' => $this->appSecret]; + } + return $secret; } @@ -256,6 +262,6 @@ class Gitlab extends OAuth2 $defaultEndpoint = 'https://gitlab.com'; $secret = $this->getAppSecret(); $endpoint = $secret['endpoint'] ?? $defaultEndpoint; - return empty($endpoint) ? $defaultEndpoint : $endpoint; + return empty($endpoint) ? $defaultEndpoint : \rtrim($endpoint, '/'); } } From a38e90dcf4266a5a5c6e342e52c2dd00ba2d79e8 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Wed, 2 Sep 2026 13:50:44 +0530 Subject: [PATCH 3/3] chore: ship the GitLab endpoint variables empty System::getEnv is getenv($name) ?: $default, so a set-but-empty variable falls through to the https://gitlab.com default the config already carries. Shipping the value blank keeps the sample env and a generated install free of a URL that only self-hosted GitLab needs to change, matching the Gitea endpoint entry. The effective default moves into the descriptions. --- .env | 4 ++-- app/config/variables.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.env b/.env index 7fe753006f..6fcb35a315 100644 --- a/.env +++ b/.env @@ -41,7 +41,7 @@ _APP_CONSOLE_GITHUB_APP_ID= _APP_CONSOLE_GITHUB_SECRET= _APP_CONSOLE_GITLAB_APP_ID= _APP_CONSOLE_GITLAB_SECRET= -_APP_CONSOLE_GITLAB_ENDPOINT=https://gitlab.com +_APP_CONSOLE_GITLAB_ENDPOINT= _APP_CONSOLE_BITBUCKET_APP_ID= _APP_CONSOLE_BITBUCKET_SECRET= _APP_CONSOLE_GOOGLE_APP_ID= @@ -182,7 +182,7 @@ _APP_VCS_GITEA_BROWSER_ENDPOINT=http://localhost:9515 _APP_VCS_GITEA_CLIENT_ID= _APP_VCS_GITEA_CLIENT_SECRET= _APP_VCS_GITEA_WEBHOOK_SECRET=gitea-webhook-secret -_APP_VCS_GITLAB_ENDPOINT=https://gitlab.com +_APP_VCS_GITLAB_ENDPOINT= _APP_VCS_GITLAB_CLIENT_ID= _APP_VCS_GITLAB_CLIENT_SECRET= _APP_VCS_GITLAB_WEBHOOK_SECRET= diff --git a/app/config/variables.php b/app/config/variables.php index 2580d0046c..4b69212e75 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -297,9 +297,9 @@ return [ ], [ 'name' => '_APP_CONSOLE_GITLAB_ENDPOINT', - 'description' => 'URL of the GitLab instance used for signing in to the Appwrite console, for self-hosted GitLab. This is separate from _APP_VCS_GITLAB_ENDPOINT, which powers repository integration rather than console sign-in.', + 'description' => 'URL of the GitLab instance used for signing in to the Appwrite console, for self-hosted GitLab. Defaults to https://gitlab.com when unset. This is separate from _APP_VCS_GITLAB_ENDPOINT, which powers repository integration rather than console sign-in.', 'introduction' => '2.0.0', - 'default' => 'https://gitlab.com', + 'default' => '', 'required' => false, 'question' => '', 'filter' => '' @@ -1583,9 +1583,9 @@ return [ ], [ 'name' => '_APP_VCS_GITLAB_ENDPOINT', - 'description' => 'URL of your self-hosted GitLab instance, reachable from the Appwrite server and the browser.', + 'description' => 'URL of your self-hosted GitLab instance, reachable from the Appwrite server and the browser. Defaults to https://gitlab.com when unset.', 'introduction' => '2.0.0', - 'default' => 'https://gitlab.com', + 'default' => '', 'required' => false, 'question' => '', 'filter' => ''