Merge pull request #7934 from appwrite/fix-custom-domain
Prevent functions domain to be used as custom domain
This commit is contained in:
commit
b2c57e2d8b
|
@ -49,6 +49,12 @@ App::post('/v1/proxy/rules')
|
||||||
if ($domain === $mainDomain) {
|
if ($domain === $mainDomain) {
|
||||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'You cannot assign your main domain to specific resource. Please use subdomain or a different domain.');
|
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'You cannot assign your main domain to specific resource. Please use subdomain or a different domain.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', '');
|
||||||
|
if (str_ends_with($domain, $functionsDomain)) {
|
||||||
|
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'You cannot assign your functions domain or it\'s subdomain to specific resource. Please use different domain.');
|
||||||
|
}
|
||||||
|
|
||||||
if ($domain === 'localhost' || $domain === APP_HOSTNAME_INTERNAL) {
|
if ($domain === 'localhost' || $domain === APP_HOSTNAME_INTERNAL) {
|
||||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please pick another one.');
|
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please pick another one.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,43 @@
|
||||||
|
|
||||||
namespace Tests\E2E\Services\Projects;
|
namespace Tests\E2E\Services\Projects;
|
||||||
|
|
||||||
|
use Tests\E2E\Client;
|
||||||
use Tests\E2E\Scopes\ProjectCustom;
|
use Tests\E2E\Scopes\ProjectCustom;
|
||||||
use Tests\E2E\Scopes\Scope;
|
use Tests\E2E\Scopes\Scope;
|
||||||
use Tests\E2E\Scopes\SideServer;
|
use Tests\E2E\Scopes\SideServer;
|
||||||
|
use Utopia\System\System;
|
||||||
|
|
||||||
class ProjectsCustomServerTest extends Scope
|
class ProjectsCustomServerTest extends Scope
|
||||||
{
|
{
|
||||||
use ProjectCustom;
|
use ProjectCustom;
|
||||||
use SideServer;
|
use SideServer;
|
||||||
|
|
||||||
public function testMock()
|
// Domains
|
||||||
|
|
||||||
|
public function testCreateProjectRule()
|
||||||
{
|
{
|
||||||
$this->assertEquals(true, true);
|
$headers = array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
'x-appwrite-mode' => 'admin',
|
||||||
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->client->call(Client::METHOD_POST, '/proxy/rules', $headers, [
|
||||||
|
'resourceType' => 'api',
|
||||||
|
'domain' => 'api.appwrite.test',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $response['headers']['status-code']);
|
||||||
|
|
||||||
|
// prevent functions domain
|
||||||
|
$functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', '');
|
||||||
|
|
||||||
|
$response = $this->client->call(Client::METHOD_POST, '/proxy/rules', $headers, [
|
||||||
|
'resourceType' => 'api',
|
||||||
|
'domain' => $functionsDomain,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(400, $response['headers']['status-code']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue