diff --git a/src/Appwrite/Network/Validator/Origin.php b/src/Appwrite/Network/Validator/Origin.php index fc58651723..7843a17f1c 100644 --- a/src/Appwrite/Network/Validator/Origin.php +++ b/src/Appwrite/Network/Validator/Origin.php @@ -12,6 +12,7 @@ class Origin extends Validator protected array $schemes = []; protected ?string $scheme = null; protected ?string $host = null; + protected string $origin = ''; /** * Constructor @@ -32,6 +33,7 @@ class Origin extends Validator */ public function isValid($origin): bool { + $this->origin = $origin; $this->scheme = null; $this->host = null; @@ -68,13 +70,17 @@ class Origin extends Validator */ public function getDescription(): string { - $platform = $this->scheme ? Platform::getNameByScheme($this->scheme) : null; + $platform = $this->scheme ? Platform::getNameByScheme($this->scheme) : ''; $host = $this->host ? '(' . $this->host . ')' : ''; if (empty($this->host) && empty($this->scheme)) { return 'Invalid Origin.'; } + if (empty($platform)) { + return 'Invalid Scheme. The scheme used (' . $this->scheme . ') in the Origin (' . $this->origin . ') is not supported. If you are using a custom scheme, please change it to `appwrite-callback-`'; + } + return 'Invalid Origin. Register your new client ' . $host . ' as a new ' . $platform . ' platform on your project console dashboard'; } diff --git a/tests/unit/Network/Validators/OriginTest.php b/tests/unit/Network/Validators/OriginTest.php index 516108bc32..d312f8c5a5 100644 --- a/tests/unit/Network/Validators/OriginTest.php +++ b/tests/unit/Network/Validators/OriginTest.php @@ -106,5 +106,8 @@ class OriginTest extends TestCase $this->assertEquals(false, $validator->isValid('ms-browser-extension://com.company.appname')); $this->assertEquals('Invalid Origin. Register your new client (com.company.appname) as a new Web (Edge Extension) platform on your project console dashboard', $validator->getDescription()); + + $this->assertEquals(false, $validator->isValid('random-scheme://localhost')); + $this->assertEquals('Invalid Scheme. The scheme used (random-scheme) in the Origin (random-scheme://localhost) is not supported. If you are using a custom scheme, please change it to `appwrite-callback-`', $validator->getDescription()); } }