diff --git a/app/config/errors.php b/app/config/errors.php index 74e2de7db2..2b21ff48e2 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -541,9 +541,14 @@ return [ ], Exception::DOMAIN_ALREADY_EXISTS => [ 'name' => Exception::DOMAIN_ALREADY_EXISTS, - 'description' => 'A Domain with the requested ID already exists.', + 'description' => 'The requested domain is currently in use by a project.', 'code' => 409, ], + Exception::DOMAIN_FORBIDDEN => [ + 'name' => Exception::DOMAIN_FORBIDDEN, + 'description' => 'The requested domain cannot be used as a custom domain.', + 'code' => 403, + ], Exception::VARIABLE_NOT_FOUND => [ 'name' => Exception::VARIABLE_NOT_FOUND, 'description' => 'Variable with the requested ID could not be found.', diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 5fef7eab78..c7a85f0489 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -1191,9 +1191,12 @@ App::post('/v1/projects/:projectId/domains') throw new Exception(Exception::PROJECT_NOT_FOUND); } + if ($domain === App::getEnv('_APP_DOMAIN', '') || $domain === App::getEnv('_APP_DOMAIN_TARGET', '')) { + throw new Exception(Exception::DOMAIN_FORBIDDEN); + } + $document = $dbForConsole->findOne('domains', [ - Query::equal('domain', [$domain]), - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('domain', [$domain]) ]); if ($document && !$document->isEmpty()) { @@ -1391,6 +1394,10 @@ App::delete('/v1/projects/:projectId/domains/:domainId') throw new Exception(Exception::DOMAIN_NOT_FOUND); } + if ($domain->getAttribute('domain') === App::getEnv('_APP_DOMAIN', '') || $domain->getAttribute('domain') === App::getEnv('_APP_DOMAIN_TARGET', '')) { + throw new Exception(Exception::DOMAIN_FORBIDDEN); + } + $dbForConsole->deleteDocument('domains', $domain->getId()); $dbForConsole->deleteCachedDocument('projects', $project->getId()); diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 8ee0dca0c6..ecf6e17c1f 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -177,6 +177,7 @@ class Exception extends \Exception /** Domain */ public const DOMAIN_NOT_FOUND = 'domain_not_found'; public const DOMAIN_ALREADY_EXISTS = 'domain_already_exists'; + public const DOMAIN_FORBIDDEN = 'domain_forbidden'; public const DOMAIN_VERIFICATION_FAILED = 'domain_verification_failed'; protected $type = '';