From be27912a6e149d8e54804dbe4044954c431c14b4 Mon Sep 17 00:00:00 2001 From: shimon Date: Wed, 5 Feb 2025 11:35:19 +0200 Subject: [PATCH] _APP_DOMAIN_FUNCTIONS_FALLBACK --- app/controllers/general.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 9088e6bfe9..da326f471d 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -72,11 +72,26 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw } if ($route->isEmpty()) { - if ($host === System::getEnv('_APP_DOMAIN_FUNCTIONS', '')) { + + $appDomainFunctionsFallback = System::getEnv('_APP_DOMAIN_FUNCTIONS_FALLBACK', ''); + $appDomainFunctions = System::getEnv('_APP_DOMAIN_FUNCTIONS' ,''); + + if (!empty($appDomainFunctionsFallback) && \str_ends_with($host, $appDomainFunctionsFallback)) { + $appDomainFunctions = $appDomainFunctionsFallback; + } + + var_dump([ + 'location' => 'router', + '_APP_DOMAIN_FUNCTIONS_FALLBACK' => System::getEnv('_APP_DOMAIN_FUNCTIONS_FALLBACK', ''), + '_APP_DOMAIN_FUNCTIONS' => System::getEnv('_APP_DOMAIN_FUNCTIONS' ,''), + 'appDomainFunctions' => $appDomainFunctions, + ]); + + if ($host === $appDomainFunctions) { throw new AppwriteException(AppwriteException::GENERAL_ACCESS_FORBIDDEN, 'This domain cannot be used for security reasons. Please use any subdomain instead.'); } - if (\str_ends_with($host, System::getEnv('_APP_DOMAIN_FUNCTIONS', ''))) { + if (\str_ends_with($host, $appDomainFunctions)) { throw new AppwriteException(AppwriteException::GENERAL_ACCESS_FORBIDDEN, 'This domain is not connected to any Appwrite resource yet. Please configure custom domain or function domain to allow this request.'); }