Merge pull request #12840 from appwrite/fix-sites-runtimes-allowlist

fix: filter Sites build runtimes by _APP_SITES_RUNTIMES
This commit is contained in:
Chirag Aggarwal authored and GitHub committed 2026-07-13 13:30:42 +05:30
commit b8bc11f969
4 files changed
+47

No files matched your search

@@ -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([
@@ -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);
@@ -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);
@@ -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);
}