diff --git a/docker-compose.yml b/docker-compose.yml index 58b78fcd8e..afc32a518b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1033,7 +1033,7 @@ services: volumes: - appwrite-mariadb:/var/lib/mysql:rw ports: - - "3306:3306" + - "3307:3306" environment: - MYSQL_ROOT_PASSWORD=${_APP_DB_ROOT_PASS} - MYSQL_DATABASE=${_APP_DB_SCHEMA} diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php index f7d9d915ad..64b8c00856 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -71,16 +71,11 @@ class Create extends Action public function action(string $domain, Response $response, Document $project, Certificate $queueForCertificates, Event $queueForEvents, Database $dbForPlatform) { - // 1. Domain format validations - try { - $domain = new Domain($domain); - } catch (\Throwable $e) { - throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage()); - } - // 2. Denied domains check + $domainString = strtolower($domain); + + $deniedDomains = [ - 'localhost', APP_HOSTNAME_INTERNAL ]; @@ -106,15 +101,15 @@ class Create extends Action $deniedDomains[] = $denyListDomain; } - if (\in_array($domain->get(), $deniedDomains)) { + if (\in_array($domainString, $deniedDomains)) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please use a different domain.'); } // TODO: @christyjacob remove once we migrate the rules in 1.7.x - $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique(); + $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domainString) : ID::unique(); $status = 'created'; - if (\str_ends_with($domain->get(), $functionsDomain) || \str_ends_with($domain->get(), $sitesDomain)) { + if (\str_ends_with($domainString, $functionsDomain) || \str_ends_with($domainString, $sitesDomain)) { $status = 'verified'; } if ($status === 'created') { @@ -135,15 +130,15 @@ class Create extends Action } $validator = new AnyOf($validators, AnyOf::TYPE_STRING); - if ($validator->isValid($domain->get())) { + if ($validator->isValid($domainString)) { $status = 'verifying'; } } $owner = ''; if ( - ($functionsDomain != '' && \str_ends_with($domain->get(), $functionsDomain)) || - ($sitesDomain != '' && \str_ends_with($domain->get(), $sitesDomain)) + ($functionsDomain != '' && \str_ends_with($domainString, $functionsDomain)) || + ($sitesDomain != '' && \str_ends_with($domainString, $sitesDomain)) ) { $owner = 'Appwrite'; } @@ -152,12 +147,12 @@ class Create extends Action '$id' => $ruleId, 'projectId' => $project->getId(), 'projectInternalId' => $project->getSequence(), - 'domain' => $domain->get(), + 'domain' => $domainString, 'status' => $status, 'type' => 'api', 'trigger' => 'manual', 'certificateId' => '', - 'search' => implode(' ', [$ruleId, $domain->get()]), + 'search' => implode(' ', [$ruleId, $domainString]), 'owner' => $owner, 'region' => $project->getAttribute('region') ]); diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php index b66e6875bb..74c69dfe85 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php @@ -76,16 +76,10 @@ class Create extends Action public function action(string $domain, string $functionId, string $branch, Response $response, Document $project, Certificate $queueForCertificates, Event $queueForEvents, Database $dbForPlatform, Database $dbForProject) { - // 1. Domain format validations - try { - $domain = new Domain($domain); - } catch (\Throwable $e) { - throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage()); - } - // 2. Denied domains check + $domainString = strtolower($domain); + $deniedDomains = [ - 'localhost', APP_HOSTNAME_INTERNAL ]; @@ -111,7 +105,7 @@ class Create extends Action $deniedDomains[] = $denyListDomain; } - if (\in_array($domain->get(), $deniedDomains)) { + if (\in_array($domainString, $deniedDomains)) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please use a different domain.'); } @@ -123,10 +117,10 @@ class Create extends Action $deployment = $dbForProject->getDocument('deployments', $function->getAttribute('deploymentId', '')); // TODO: @christyjacob remove once we migrate the rules in 1.7.x - $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique(); + $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domainString) : ID::unique(); $status = 'created'; - if (\str_ends_with($domain->get(), $functionsDomain) || \str_ends_with($domain->get(), $sitesDomain)) { + if (\str_ends_with($domainString, $functionsDomain) || \str_ends_with($domainString, $sitesDomain)) { $status = 'verified'; } if ($status === 'created') { @@ -147,15 +141,15 @@ class Create extends Action } $validator = new AnyOf($validators, AnyOf::TYPE_STRING); - if ($validator->isValid($domain->get())) { + if ($validator->isValid($domainString)) { $status = 'verifying'; } } $owner = ''; if ( - ($functionsDomain != '' && \str_ends_with($domain->get(), $functionsDomain)) || - ($sitesDomain != '' && \str_ends_with($domain->get(), $sitesDomain)) + ($functionsDomain != '' && \str_ends_with($domainString, $functionsDomain)) || + ($sitesDomain != '' && \str_ends_with($domainString, $sitesDomain)) ) { $owner = 'Appwrite'; } @@ -164,7 +158,7 @@ class Create extends Action '$id' => $ruleId, 'projectId' => $project->getId(), 'projectInternalId' => $project->getSequence(), - 'domain' => $domain->get(), + 'domain' => $domainString, 'status' => $status, 'type' => 'deployment', 'trigger' => 'manual', @@ -175,7 +169,7 @@ class Create extends Action 'deploymentResourceInternalId' => $function->getSequence(), 'deploymentVcsProviderBranch' => $branch, 'certificateId' => '', - 'search' => implode(' ', [$ruleId, $domain->get(), $branch]), + 'search' => implode(' ', [$ruleId, $domainString, $branch]), 'owner' => $owner, 'region' => $project->getAttribute('region') ]); diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php index 74ce0f62b9..af4ff3d2fd 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php @@ -79,16 +79,11 @@ class Create extends Action public function action(string $domain, string $url, int $statusCode, string $resourceId, string $resourceType, Response $response, Document $project, Certificate $queueForCertificates, Event $queueForEvents, Database $dbForPlatform, Database $dbForProject) { - // 1. Domain format validations - try { - $domain = new Domain($domain); - } catch (\Throwable $e) { - throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage()); - } + // Domain is already validated by AppwriteDomain validator + $domainString = strtolower($domain); + - // 2. Denied domains check $deniedDomains = [ - 'localhost', APP_HOSTNAME_INTERNAL ]; @@ -114,7 +109,7 @@ class Create extends Action $deniedDomains[] = $denyListDomain; } - if (\in_array($domain->get(), $deniedDomains)) { + if (\in_array($domainString, $deniedDomains)) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please use a different domain.'); } @@ -128,10 +123,10 @@ class Create extends Action } // TODO: @christyjacob remove once we migrate the rules in 1.7.x - $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique(); + $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domainString) : ID::unique(); $status = 'created'; - if (\str_ends_with($domain->get(), $functionsDomain) || \str_ends_with($domain->get(), $sitesDomain)) { + if (\str_ends_with($domainString, $functionsDomain) || \str_ends_with($domainString, $sitesDomain)) { $status = 'verified'; } if ($status === 'created') { @@ -152,15 +147,15 @@ class Create extends Action } $validator = new AnyOf($validators, AnyOf::TYPE_STRING); - if ($validator->isValid($domain->get())) { + if ($validator->isValid($domainString)) { $status = 'verifying'; } } $owner = ''; if ( - ($functionsDomain != '' && \str_ends_with($domain->get(), $functionsDomain)) || - ($sitesDomain != '' && \str_ends_with($domain->get(), $sitesDomain)) + ($functionsDomain != '' && \str_ends_with($domainString, $functionsDomain)) || + ($sitesDomain != '' && \str_ends_with($domainString, $sitesDomain)) ) { $owner = 'Appwrite'; } @@ -169,7 +164,7 @@ class Create extends Action '$id' => $ruleId, 'projectId' => $project->getId(), 'projectInternalId' => $project->getSequence(), - 'domain' => $domain->get(), + 'domain' => $domainString, 'status' => $status, 'type' => 'redirect', 'trigger' => 'manual', @@ -179,7 +174,7 @@ class Create extends Action 'deploymentResourceId' => $resource->getId(), 'deploymentResourceInternalId' => $resource->getSequence(), 'certificateId' => '', - 'search' => implode(' ', [$ruleId, $domain->get()]), + 'search' => implode(' ', [$ruleId, $domainString]), 'owner' => $owner, 'region' => $project->getAttribute('region') ]); diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php index dd7582d034..3e39fd4030 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php @@ -76,16 +76,11 @@ class Create extends Action public function action(string $domain, string $siteId, string $branch, Response $response, Document $project, Certificate $queueForCertificates, Event $queueForEvents, Database $dbForPlatform, Database $dbForProject) { - // 1. Domain format validations - try { - $domain = new Domain($domain); - } catch (\Throwable $e) { - throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage()); - } - // 2. Denied domains check + $domainString = strtolower($domain); + + $deniedDomains = [ - 'localhost', APP_HOSTNAME_INTERNAL ]; @@ -111,7 +106,7 @@ class Create extends Action $deniedDomains[] = $denyListDomain; } - if (\in_array($domain->get(), $deniedDomains)) { + if (\in_array($domainString, $deniedDomains)) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please use a different domain.'); } @@ -123,10 +118,10 @@ class Create extends Action $deployment = $dbForProject->getDocument('deployments', $site->getAttribute('deploymentId', '')); // TODO: @christyjacob remove once we migrate the rules in 1.7.x - $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domain->get()) : ID::unique(); + $ruleId = System::getEnv('_APP_RULES_FORMAT') === 'md5' ? md5($domainString) : ID::unique(); $status = 'created'; - if (\str_ends_with($domain->get(), $functionsDomain) || \str_ends_with($domain->get(), $sitesDomain)) { + if (\str_ends_with($domainString, $functionsDomain) || \str_ends_with($domainString, $sitesDomain)) { $status = 'verified'; } if ($status === 'created') { @@ -147,15 +142,15 @@ class Create extends Action } $validator = new AnyOf($validators, AnyOf::TYPE_STRING); - if ($validator->isValid($domain->get())) { + if ($validator->isValid($domainString)) { $status = 'verifying'; } } $owner = ''; if ( - ($functionsDomain != '' && \str_ends_with($domain->get(), $functionsDomain)) || - ($sitesDomain != '' && \str_ends_with($domain->get(), $sitesDomain)) + ($functionsDomain != '' && \str_ends_with($domainString, $functionsDomain)) || + ($sitesDomain != '' && \str_ends_with($domainString, $sitesDomain)) ) { $owner = 'Appwrite'; } @@ -164,7 +159,7 @@ class Create extends Action '$id' => $ruleId, 'projectId' => $project->getId(), 'projectInternalId' => $project->getSequence(), - 'domain' => $domain->get(), + 'domain' => $domainString, 'status' => $status, 'type' => 'deployment', 'trigger' => 'manual', @@ -175,7 +170,7 @@ class Create extends Action 'deploymentResourceInternalId' => $site->getSequence(), 'deploymentVcsProviderBranch' => $branch, 'certificateId' => '', - 'search' => implode(' ', [$ruleId, $domain->get(), $branch]), + 'search' => implode(' ', [$ruleId, $domainString, $branch]), 'owner' => $owner, 'region' => $project->getAttribute('region') ]);