diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php index b1f0a5bc1f..e49ace4486 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php @@ -11,6 +11,7 @@ use Utopia\Config\Config; use Utopia\Database\Document; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; +use Utopia\System\System; class XList extends Base { @@ -52,11 +53,30 @@ class XList extends Base public function action(Response $response) { $frameworks = Config::getParam('frameworks'); + $allowList = \array_filter(\array_map('trim', \explode(',', System::getEnv('_APP_SITES_RUNTIMES', '')))); foreach ($frameworks as $key => $framework) { if (!empty($framework['adapters'])) { $frameworks[$key]['adapters'] = \array_values($framework['adapters']); } + + if (!empty($allowList) && !empty($framework['runtimes'])) { + $frameworks[$key]['runtimes'] = \array_values(\array_filter( + $framework['runtimes'], + fn ($runtime) => \in_array($runtime, $allowList, true) + )); + + // Drop frameworks that have no enabled build runtimes left. + if (empty($frameworks[$key]['runtimes'])) { + unset($frameworks[$key]); + continue; + } + + // Keep the default buildRuntime aligned with the filtered allowlist. + if (!\in_array($frameworks[$key]['buildRuntime'] ?? '', $frameworks[$key]['runtimes'], true)) { + $frameworks[$key]['buildRuntime'] = $frameworks[$key]['runtimes'][0]; + } + } } $response->dynamic(new Document([ diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php index 3c51c57420..9472a82174 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php @@ -144,6 +144,12 @@ class Create extends Base } } + $allowList = \array_filter(\array_map('trim', \explode(',', System::getEnv('_APP_SITES_RUNTIMES', '')))); + + if (!empty($allowList) && !\in_array($buildRuntime, $allowList, true)) { + throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Runtime "' . $buildRuntime . '" is not supported'); + } + $siteId = ($siteId == 'unique()') ? ID::unique() : $siteId; $installation = $dbForPlatform->getDocument('installations', $installationId); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 532c92a428..b97f30ff58 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -158,6 +158,12 @@ class Update extends Base } } + $allowList = \array_filter(\array_map('trim', \explode(',', System::getEnv('_APP_SITES_RUNTIMES', '')))); + + if (!empty($allowList) && !empty($buildRuntime) && !\in_array($buildRuntime, $allowList, true)) { + throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Runtime "' . $buildRuntime . '" is not supported'); + } + // TODO: If only branch changes, re-deploy $site = $dbForProject->getDocument('sites', $siteId); diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 0440d7afb7..88e50ec7b4 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -135,6 +135,21 @@ final class SitesCustomServerTest extends Scope $this->assertEquals(201, $variable2['headers']['status-code']); $this->assertEquals(201, $variable3['headers']['status-code']); + /** + * Test for FAILURE + * Reject buildRuntime values outside _APP_SITES_RUNTIMES (static-1,node-22 in test env). + */ + $site = $this->createSite([ + 'buildRuntime' => 'node-24', + 'framework' => 'other', + 'name' => 'Unsupported Runtime Site', + 'siteId' => ID::unique(), + ]); + + $this->assertEquals(400, $site['headers']['status-code']); + $this->assertEquals('general_argument_invalid', $site['body']['type']); + $this->assertStringContainsString('Runtime "node-24" is not supported', (string) $site['body']['message']); + $this->cleanupSite($siteId); }