Merge pull request #13514 from appwrite/feat-capacitor-origin

feat: support capacitor:// as an allowed origin
This commit is contained in:
Matej Bačo authored and GitHub committed 2026-09-07 18:52:52 +02:00
commit e80162f335
4 files changed
+24

No files matched your search

+2
View File
@@ -26,6 +26,7 @@ class Platform
public const SCHEME_WINDOWS = 'appwrite-windows';
public const SCHEME_LINUX = 'appwrite-linux';
public const SCHEME_TAURI = 'tauri';
public const SCHEME_CAPACITOR = 'capacitor';
public const string LOOPBACK_HOSTNAME = 'localhost';
@@ -70,6 +71,7 @@ class Platform
self::SCHEME_SAFARI_EXTENSION => 'Web (Safari Extension)',
self::SCHEME_EDGE_EXTENSION => 'Web (Edge Extension)',
self::SCHEME_TAURI => 'Web (Tauri)',
self::SCHEME_CAPACITOR => 'Web (Capacitor)',
];
/**
@@ -70,6 +70,7 @@ class Origin extends Validator
Platform::SCHEME_SAFARI_EXTENSION,
Platform::SCHEME_EDGE_EXTENSION,
Platform::SCHEME_TAURI,
Platform::SCHEME_CAPACITOR,
];
if (in_array($this->scheme, $webPlatforms, true)) {
$validator = new Hostname($this->allowedHostnames);
+16
View File
@@ -115,6 +115,22 @@ final class CorsTest extends TestCase
$this->assertSame('https://example.com', $result[Cors::HEADER_ALLOW_ORIGIN]);
}
public function testNonHttpSchemeOriginIsMatchedByHost(): void
{
$cors = new Cors(
allowedHosts: ['app.example.com'],
allowedMethods: ['POST'],
allowedHeaders: ['X-Test'],
exposedHeaders: [],
allowCredentials: true
);
/* Webview origins such as Capacitor's carry a custom scheme, see Platform::SCHEME_CAPACITOR */
$result = $cors->headers('capacitor://app.example.com');
$this->assertSame('capacitor://app.example.com', $result[Cors::HEADER_ALLOW_ORIGIN]);
}
public function testOriginIsLowercasedForMatching(): void
{
$cors = new Cors(
@@ -79,6 +79,11 @@ final class OriginTest extends TestCase
$this->assertEquals(false, $validator->isValid('tauri://example.com'));
$this->assertSame('Invalid Origin. Register your new client (example.com) as a new Web (Tauri) platform on your project console dashboard', $validator->getDescription());
$this->assertEquals(true, $validator->isValid('capacitor://localhost'));
$this->assertEquals(true, $validator->isValid('capacitor://appwrite.io'));
$this->assertEquals(false, $validator->isValid('capacitor://example.com'));
$this->assertSame('Invalid Origin. Register your new client (example.com) as a new Web (Capacitor) platform on your project console dashboard', $validator->getDescription());
$this->assertEquals(false, $validator->isValid('random-scheme://localhost'));
$this->assertSame('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-<PROJECT_ID>`', $validator->getDescription());
}