Merge branch '1.8.x' into allow-custom-sender

This commit is contained in:
Darshan 2025-12-12 17:29:45 +05:30
commit 1cc6c9c0f1
2 changed files with 22 additions and 1 deletions

View file

@ -198,8 +198,14 @@ App::setResource('allowedHostnames', function (array $platform, Document $projec
$allowed[] = $request->getHostname();
}
/* Allow the request origin if a dev key or rule is found */
$originHostname = parse_url($request->getOrigin(), PHP_URL_HOST);
/* Add request hostname for preflight requests */
if ($request->getMethod() === 'OPTIONS') {
$allowed[] = $originHostname;
}
/* Allow the request origin if a dev key or rule is found */
if ((!$rule->isEmpty() || !$devKey->isEmpty()) && !empty($originHostname)) {
$allowed[] = $originHostname;
}

View file

@ -184,7 +184,22 @@ class HTTPTest extends Scope
'origin' => 'http://google.com',
]);
$this->assertNull($response['headers']['access-control-allow-origin'] ?? null);
}
public function testPreflight()
{
$endpoint = '/v1/projects'; // Can be any non-404 route
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_OPTIONS, $endpoint, [
'origin' => 'http://random.com',
'access-control-request-headers' => 'X-Appwrite-Project',
'access-control-request-method' => 'GET'
]);
$this->assertEquals('http://random.com', $response['headers']['access-control-allow-origin']);
}
public function testConsoleRedirect()