diff --git a/src/Appwrite/Network/Validator/AppwriteDomain.php b/src/Appwrite/Network/Validator/AppwriteDomain.php index 1fd4cbc70d..ebb9aad697 100644 --- a/src/Appwrite/Network/Validator/AppwriteDomain.php +++ b/src/Appwrite/Network/Validator/AppwriteDomain.php @@ -3,7 +3,7 @@ namespace Appwrite\Network\Validator; use Utopia\System\System; -use Utopia\Validator; +use Utopia\Validator\Domain as ValidatorDomain; /** * AppwriteDomain @@ -14,7 +14,7 @@ use Utopia\Validator; * * @package Appwrite\Network\Validator */ -class AppwriteDomain extends Validator +class AppwriteDomain extends ValidatorDomain { protected string $suffix; @@ -46,8 +46,18 @@ class AppwriteDomain extends Validator */ public function isValid($value): bool { - // Basic validation - if (!is_string($value) || empty($value) || preg_match('/\s/', $value)) { + // Basic validation - check type and spaces first + if (!is_string($value) || empty($value)) { + return false; + } + + // Check for spaces (before and after trimming) + if (preg_match('/\s/', $value)) { + return false; + } + + // First check if it's a valid domain using parent validator + if (!parent::isValid($value)) { return false; } @@ -88,28 +98,4 @@ class AppwriteDomain extends Validator return true; } - - /** - * Is array - * - * Function will return false as this validator validates strings. - * - * @return bool - */ - public function isArray(): bool - { - return false; - } - - /** - * Get Type - * - * Returns validator type. - * - * @return string - */ - public function getType(): string - { - return self::TYPE_STRING; - } } 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 7f55db6d72..39c6bd2d4b 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -19,9 +19,7 @@ use Utopia\Domains\Domain; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\System\System; -use Utopia\Validator\AllOf; use Utopia\Validator\AnyOf; -use Utopia\Validator\Domain as ValidatorDomain; use Utopia\Validator\IP; class Create extends Action @@ -62,7 +60,7 @@ class Create extends Action ->label('abuse-limit', 10) ->label('abuse-key', 'userId:{userId}, url:{url}') ->label('abuse-time', 60) - ->param('domain', null, new AllOf([new ValidatorDomain(), new AppwriteDomain()]), 'Domain name.') + ->param('domain', null, new AppwriteDomain(), 'Domain name.') ->inject('response') ->inject('project') ->inject('queueForCertificates') 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 aa85deaa2f..2c91dcf41b 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php @@ -21,7 +21,6 @@ use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\System\System; use Utopia\Validator\AnyOf; -use Utopia\Validator\Domain as ValidatorDomain; use Utopia\Validator\IP; use Utopia\Validator\Text; @@ -63,7 +62,7 @@ class Create extends Action ->label('abuse-limit', 10) ->label('abuse-key', 'userId:{userId}, url:{url}') ->label('abuse-time', 60) - ->param('domain', null, new AllOf([new ValidatorDomain(), new AppwriteDomain()]), 'Domain name.') + ->param('domain', null, new AppwriteDomain(), 'Domain name.') ->param('functionId', '', new UID(), 'ID of function to be executed.') ->param('branch', '', new Text(255, 0), 'Name of VCS branch to deploy changes automatically', true) ->inject('response') 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 ed2b4bb619..0a32e2dde6 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php @@ -20,9 +20,7 @@ use Utopia\Domains\Domain; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\System\System; -use Utopia\Validator\AllOf; use Utopia\Validator\AnyOf; -use Utopia\Validator\Domain as ValidatorDomain; use Utopia\Validator\IP; use Utopia\Validator\URL; use Utopia\Validator\WhiteList; @@ -65,7 +63,7 @@ class Create extends Action ->label('abuse-limit', 10) ->label('abuse-key', 'userId:{userId}, url:{url}') ->label('abuse-time', 60) - ->param('domain', null, new AllOf([new ValidatorDomain(), new AppwriteDomain()]), 'Domain name.') + ->param('domain', null, new AppwriteDomain(), 'Domain name.') ->param('url', null, new URL(), 'Target URL of redirection') ->param('statusCode', null, new WhiteList([301, 302, 307, 308]), 'Status code of redirection') ->param('resourceId', '', new UID(), 'ID of parent resource.') 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 7b86ac6b5d..58fa79ffcd 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php @@ -21,7 +21,6 @@ use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\System\System; use Utopia\Validator\AnyOf; -use Utopia\Validator\Domain as ValidatorDomain; use Utopia\Validator\IP; use Utopia\Validator\Text; @@ -63,7 +62,7 @@ class Create extends Action ->label('abuse-limit', 10) ->label('abuse-key', 'userId:{userId}, url:{url}') ->label('abuse-time', 60) - ->param('domain', null, new AllOf([new ValidatorDomain(), new AppwriteDomain()]), 'Domain name.') + ->param('domain', null, new AppwriteDomain(), 'Domain name.') ->param('siteId', '', new UID(), 'ID of site to be executed.') ->param('branch', '', new Text(255, 0), 'Name of VCS branch to deploy changes automatically', true) ->inject('response')