From d613237fb447fefc6a2520da6cce593681210cff Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 18 Jul 2025 22:08:43 +0530 Subject: [PATCH 1/3] chore: improve invalid scheme error in origin check --- src/Appwrite/Network/Validator/Origin.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Appwrite/Network/Validator/Origin.php b/src/Appwrite/Network/Validator/Origin.php index fc58651723..bdf56f0f9b 100644 --- a/src/Appwrite/Network/Validator/Origin.php +++ b/src/Appwrite/Network/Validator/Origin.php @@ -75,6 +75,10 @@ class Origin extends Validator return 'Invalid Origin.'; } + if (!isset($platform)) { + return 'Invalid Scheme. The scheme used ( ' . $this->scheme . ' ) 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'; } From c55f039f13baef7c504e87d380f6a7430b26c6fb Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 18 Jul 2025 22:23:33 +0530 Subject: [PATCH 2/3] chore: add unit test --- src/Appwrite/Network/Validator/Origin.php | 8 +++++--- tests/unit/Network/Validators/OriginTest.php | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Network/Validator/Origin.php b/src/Appwrite/Network/Validator/Origin.php index bdf56f0f9b..fff12fa045 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,15 +70,15 @@ 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 (!isset($platform)) { - return 'Invalid Scheme. The scheme used ( ' . $this->scheme . ' ) is not supported. If you are using a custom scheme, please change it to `appwrite-callback-`'; + 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 ' diff --git a/tests/unit/Network/Validators/OriginTest.php b/tests/unit/Network/Validators/OriginTest.php index 516108bc32..1a150bada9 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()); } } From 7fecfc73ca5adf493778bc4657b954bb2f619c48 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Sat, 19 Jul 2025 10:39:39 +0530 Subject: [PATCH 3/3] fix: formatting --- src/Appwrite/Network/Validator/Origin.php | 2 +- tests/unit/Network/Validators/OriginTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Network/Validator/Origin.php b/src/Appwrite/Network/Validator/Origin.php index fff12fa045..7843a17f1c 100644 --- a/src/Appwrite/Network/Validator/Origin.php +++ b/src/Appwrite/Network/Validator/Origin.php @@ -78,7 +78,7 @@ class Origin extends Validator } 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 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 ' diff --git a/tests/unit/Network/Validators/OriginTest.php b/tests/unit/Network/Validators/OriginTest.php index 1a150bada9..d312f8c5a5 100644 --- a/tests/unit/Network/Validators/OriginTest.php +++ b/tests/unit/Network/Validators/OriginTest.php @@ -108,6 +108,6 @@ class OriginTest extends TestCase $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()); + $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()); } }