From 55e76fe537378d5a504ae4bdb705aed10d76dc7a Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Wed, 12 Aug 2026 23:55:37 +0530 Subject: [PATCH 01/13] test(sites): assert start commands never leave the server The commands that boot a framework are an internal contract between Appwrite and the runtime image. Nothing in the frameworks or templates response models declares them, so they are already stripped, but that guarantee lives only in the absence of a rule and would break the moment someone adds one. Walk both payloads and fail on a startCommand key, on any configured start command, and on any string reaching for a runtime helper script. Also pin that a site created without a start command keeps an empty one rather than being seeded with the framework default. --- app/config/frameworks.php | 6 +- tests/e2e/Services/Sites/SitesBase.php | 58 ++++++++++++++ .../Services/Sites/SitesCustomClientTest.php | 21 +++++ .../Services/Sites/SitesCustomServerTest.php | 40 ++++++++++ tests/unit/Deployment/DetectionTest.php | 45 +++++++++++ tests/unit/Deployment/FrameworksTest.php | 79 +++++++++++++++++++ 6 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 tests/unit/Deployment/FrameworksTest.php diff --git a/app/config/frameworks.php b/app/config/frameworks.php index 342657017f..d7cd958ece 100644 --- a/app/config/frameworks.php +++ b/app/config/frameworks.php @@ -240,11 +240,15 @@ return [ 'bundleCommand' => 'bash /usr/local/server/helpers/tanstack-start/bundle.sh', 'envCommand' => 'source /usr/local/server/helpers/tanstack-start/env.sh', 'adapters' => [ + // TanStack Start >= 1.133 builds vite-native, emitting the server + // entry as dist/server/server.js next to dist/client. Builds that + // opt into the nitro plugin emit .output instead, which the runtime + // still detects, but they have to override the directory here. 'ssr' => [ 'key' => 'ssr', 'buildCommand' => 'npm run build', 'installCommand' => 'npm install', - 'outputDirectory' => './.output', + 'outputDirectory' => './dist', 'startCommand' => 'bash helpers/tanstack-start/server.sh', ], 'static' => [ diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index 00cc0a6cc6..c48814332d 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -6,6 +6,7 @@ use Appwrite\Tests\Async; use Appwrite\Tests\Async\Exceptions\Critical; use CURLFile; use Tests\E2E\Client; +use Utopia\Config\Config; use Utopia\Console; use Utopia\Database\Helpers\ID; use Utopia\Database\Query; @@ -18,6 +19,9 @@ trait SitesBase protected string $stdout = ''; protected string $stderr = ''; + /** @var list|null */ + protected ?array $internalStartCommands = null; + protected function setupSite(mixed $params): string { $site = $this->client->call(Client::METHOD_POST, '/sites', array_merge([ @@ -496,4 +500,58 @@ trait SitesBase return $specification['slug']; } + + /** + * The commands that boot a framework are an internal contract between Appwrite and the + * runtime image, and they change without notice. Leaking one lets a client copy it into + * their own site, so it must not reach a response body at all - not as a value a console + * could render, and not as a default a console could offer as a placeholder. + * + * @return list + */ + protected function getInternalStartCommands(): array + { + if ($this->internalStartCommands !== null) { + return $this->internalStartCommands; + } + + $commands = []; + + foreach (Config::getParam('frameworks', []) as $framework) { + foreach ($framework['adapters'] ?? [] as $adapter) { + if (!empty($adapter['startCommand'])) { + $commands[] = $adapter['startCommand']; + } + } + } + + $this->assertNotEmpty($commands, 'Expected at least one framework to define a start command.'); + + $this->internalStartCommands = \array_values(\array_unique($commands)); + + return $this->internalStartCommands; + } + + protected function assertStartCommandNotExposed(mixed $payload, string $path = 'body'): void + { + if (\is_string($payload)) { + foreach ($this->getInternalStartCommands() as $command) { + $this->assertNotSame($command, $payload, 'Internal start command exposed at ' . $path); + } + + // Every internal command shells out to a helper script shipped in the runtime image. + $this->assertStringNotContainsString('helpers/', $payload, 'Internal helper script exposed at ' . $path); + + return; + } + + if (!\is_array($payload)) { + return; + } + + foreach ($payload as $key => $value) { + $this->assertNotSame('startCommand', $key, 'Start command exposed at ' . $path . '.' . $key); + $this->assertStartCommandNotExposed($value, $path . '.' . $key); + } + } } diff --git a/tests/e2e/Services/Sites/SitesCustomClientTest.php b/tests/e2e/Services/Sites/SitesCustomClientTest.php index b87faec691..97f5df1e0e 100644 --- a/tests/e2e/Services/Sites/SitesCustomClientTest.php +++ b/tests/e2e/Services/Sites/SitesCustomClientTest.php @@ -117,6 +117,27 @@ final class SitesCustomClientTest extends Scope $this->assertEquals(400, $templates['headers']['status-code']); } + public function testListTemplatesHidesStartCommand() + { + $templates = $this->client->call(Client::METHOD_GET, '/sites/templates', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'limit' => 5000, + ]); + + $this->assertEquals(200, $templates['headers']['status-code']); + $this->assertGreaterThan(0, $templates['body']['total']); + + $this->assertStartCommandNotExposed($templates['body']); + + $template = $this->getTemplate('starter-for-nextjs'); + + $this->assertEquals(200, $template['headers']['status-code']); + + $this->assertStartCommandNotExposed($template['body']); + } + public function testGetTemplate() { /** diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 59d252af87..02a2562627 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2262,6 +2262,46 @@ final class SitesCustomServerTest extends Scope $this->assertArrayHasKey('outputDirectory', $framework['adapters'][0]); } + public function testGetFrameworksHidesStartCommand(): void + { + $frameworks = $this->client->call(Client::METHOD_GET, '/sites/frameworks', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ])); + + $this->assertEquals(200, $frameworks['headers']['status-code']); + $this->assertGreaterThan(0, $frameworks['body']['total']); + + $this->assertStartCommandNotExposed($frameworks['body']); + } + + public function testCreateSiteHidesStartCommand(): void + { + $siteId = $this->setupSite([ + 'siteId' => ID::unique(), + 'name' => 'SSR site without a start command', + 'framework' => 'nextjs', + 'adapter' => 'ssr', + 'buildRuntime' => 'node-22', + 'outputDirectory' => './.next', + 'buildCommand' => 'npm run build', + 'installCommand' => 'npm install', + ]); + + $site = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(200, $site['headers']['status-code']); + + // An omitted start command stays empty; the runtime resolves its own default at boot. + $this->assertSame('', $site['body']['startCommand']); + + $this->cleanupSite($siteId); + } + public function testSiteStatic(): void { $siteId = $this->setupSite([ diff --git a/tests/unit/Deployment/DetectionTest.php b/tests/unit/Deployment/DetectionTest.php index 42ec656830..984fae98a9 100644 --- a/tests/unit/Deployment/DetectionTest.php +++ b/tests/unit/Deployment/DetectionTest.php @@ -24,4 +24,49 @@ final class DetectionTest extends TestCase $this->assertSame('ssr', $detection->getName()); $this->assertNull($detection->getFallbackFile()); } + + /** + * TanStack Start >= 1.133 builds vite-native, emitting the server entry as + * dist/server/server.js alongside dist/client. + */ + public function testRenderingFindsTanStackStartSSR(): void + { + $detection = Detection::rendering('tanstack-start', [ + './client/assets/main-BBU0Zbc3.js', + './server/server.js', + ]); + + $this->assertSame('ssr', $detection->getName()); + $this->assertNull($detection->getFallbackFile()); + } + + /** + * Opting into the nitro plugin keeps the older layout, where the server + * entry is .output/server/index.mjs. + */ + public function testRenderingFindsTanStackStartNitroSSR(): void + { + $detection = Detection::rendering('tanstack-start', [ + './public/favicon.ico', + './server/index.mjs', + ]); + + $this->assertSame('ssr', $detection->getName()); + $this->assertNull($detection->getFallbackFile()); + } + + /** + * A prerendered build ships only the client bundle, so no server entry is + * present to match on. + */ + public function testRenderingFindsTanStackStartStatic(): void + { + $detection = Detection::rendering('tanstack-start', [ + './index.html', + './assets/main-BBU0Zbc3.js', + ]); + + $this->assertSame('static', $detection->getName()); + $this->assertSame('index.html', $detection->getFallbackFile()); + } } diff --git a/tests/unit/Deployment/FrameworksTest.php b/tests/unit/Deployment/FrameworksTest.php new file mode 100644 index 0000000000..3d3a2d34ec --- /dev/null +++ b/tests/unit/Deployment/FrameworksTest.php @@ -0,0 +1,79 @@ + + */ + private array $frameworks; + + protected function setUp(): void + { + parent::setUp(); + + // Read the file rather than Config, which other suites overwrite. + $this->frameworks = require __DIR__ . '/../../../app/config/frameworks.php'; + } + + /** + * TanStack Start >= 1.133 builds vite-native: dist/server/server.js next to + * dist/client. Only builds that opt into the nitro plugin still emit + * .output, and those override the directory on the site. + */ + public function testTanStackStartAdaptersShareViteOutput(): void + { + $adapters = $this->frameworks['tanstack-start']['adapters']; + + $this->assertSame('./dist', $adapters['ssr']['outputDirectory']); + $this->assertSame('./dist/client', $adapters['static']['outputDirectory']); + } + + /** + * nuxt generate writes .output/public, and leaves dist as a symlink to it. + */ + public function testNuxtStaticOutputIsInsideDotOutput(): void + { + $adapters = $this->frameworks['nuxt']['adapters']; + + $this->assertSame('./.output', $adapters['ssr']['outputDirectory']); + $this->assertSame('./.output/public', $adapters['static']['outputDirectory']); + } + + /** + * Next.js is the one framework whose static export genuinely leaves the ssr + * build root, so it is excluded rather than special-cased below. + */ + public function testStaticOutputStaysInsideSsrOutput(): void + { + foreach ($this->frameworks as $key => $framework) { + if ($key === 'nextjs') { + continue; + } + + $ssr = $framework['adapters']['ssr']['outputDirectory'] ?? null; + $static = $framework['adapters']['static']['outputDirectory'] ?? null; + + if ($ssr === null || $static === null) { + continue; + } + + $this->assertStringStartsWith( + \rtrim($ssr, '/') . '/', + \rtrim($static, '/') . '/', + "Framework '{$key}' serves static files from outside its ssr build output." + ); + } + } +} From cb64087d95e1d273b9a773ffb2224ef833e64b86 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 00:06:44 +0530 Subject: [PATCH 02/13] Revert unrelated framework output directory work The previous commit swept in an in-flight change to the TanStack Start output directory along with the unit tests written against it. That work belongs to a separate change, and the snapshot caught it mid-edit: FrameworksTest asserts a Nuxt static output directory that the committed config does not carry, so the unit suite fails. Restore app/config/frameworks.php and DetectionTest.php to their state on main and drop FrameworksTest, leaving this branch with only the Sites e2e tests it is meant to carry. --- app/config/frameworks.php | 6 +- tests/unit/Deployment/DetectionTest.php | 45 -------------- tests/unit/Deployment/FrameworksTest.php | 79 ------------------------ 3 files changed, 1 insertion(+), 129 deletions(-) delete mode 100644 tests/unit/Deployment/FrameworksTest.php diff --git a/app/config/frameworks.php b/app/config/frameworks.php index d7cd958ece..342657017f 100644 --- a/app/config/frameworks.php +++ b/app/config/frameworks.php @@ -240,15 +240,11 @@ return [ 'bundleCommand' => 'bash /usr/local/server/helpers/tanstack-start/bundle.sh', 'envCommand' => 'source /usr/local/server/helpers/tanstack-start/env.sh', 'adapters' => [ - // TanStack Start >= 1.133 builds vite-native, emitting the server - // entry as dist/server/server.js next to dist/client. Builds that - // opt into the nitro plugin emit .output instead, which the runtime - // still detects, but they have to override the directory here. 'ssr' => [ 'key' => 'ssr', 'buildCommand' => 'npm run build', 'installCommand' => 'npm install', - 'outputDirectory' => './dist', + 'outputDirectory' => './.output', 'startCommand' => 'bash helpers/tanstack-start/server.sh', ], 'static' => [ diff --git a/tests/unit/Deployment/DetectionTest.php b/tests/unit/Deployment/DetectionTest.php index 984fae98a9..42ec656830 100644 --- a/tests/unit/Deployment/DetectionTest.php +++ b/tests/unit/Deployment/DetectionTest.php @@ -24,49 +24,4 @@ final class DetectionTest extends TestCase $this->assertSame('ssr', $detection->getName()); $this->assertNull($detection->getFallbackFile()); } - - /** - * TanStack Start >= 1.133 builds vite-native, emitting the server entry as - * dist/server/server.js alongside dist/client. - */ - public function testRenderingFindsTanStackStartSSR(): void - { - $detection = Detection::rendering('tanstack-start', [ - './client/assets/main-BBU0Zbc3.js', - './server/server.js', - ]); - - $this->assertSame('ssr', $detection->getName()); - $this->assertNull($detection->getFallbackFile()); - } - - /** - * Opting into the nitro plugin keeps the older layout, where the server - * entry is .output/server/index.mjs. - */ - public function testRenderingFindsTanStackStartNitroSSR(): void - { - $detection = Detection::rendering('tanstack-start', [ - './public/favicon.ico', - './server/index.mjs', - ]); - - $this->assertSame('ssr', $detection->getName()); - $this->assertNull($detection->getFallbackFile()); - } - - /** - * A prerendered build ships only the client bundle, so no server entry is - * present to match on. - */ - public function testRenderingFindsTanStackStartStatic(): void - { - $detection = Detection::rendering('tanstack-start', [ - './index.html', - './assets/main-BBU0Zbc3.js', - ]); - - $this->assertSame('static', $detection->getName()); - $this->assertSame('index.html', $detection->getFallbackFile()); - } } diff --git a/tests/unit/Deployment/FrameworksTest.php b/tests/unit/Deployment/FrameworksTest.php deleted file mode 100644 index 3d3a2d34ec..0000000000 --- a/tests/unit/Deployment/FrameworksTest.php +++ /dev/null @@ -1,79 +0,0 @@ - - */ - private array $frameworks; - - protected function setUp(): void - { - parent::setUp(); - - // Read the file rather than Config, which other suites overwrite. - $this->frameworks = require __DIR__ . '/../../../app/config/frameworks.php'; - } - - /** - * TanStack Start >= 1.133 builds vite-native: dist/server/server.js next to - * dist/client. Only builds that opt into the nitro plugin still emit - * .output, and those override the directory on the site. - */ - public function testTanStackStartAdaptersShareViteOutput(): void - { - $adapters = $this->frameworks['tanstack-start']['adapters']; - - $this->assertSame('./dist', $adapters['ssr']['outputDirectory']); - $this->assertSame('./dist/client', $adapters['static']['outputDirectory']); - } - - /** - * nuxt generate writes .output/public, and leaves dist as a symlink to it. - */ - public function testNuxtStaticOutputIsInsideDotOutput(): void - { - $adapters = $this->frameworks['nuxt']['adapters']; - - $this->assertSame('./.output', $adapters['ssr']['outputDirectory']); - $this->assertSame('./.output/public', $adapters['static']['outputDirectory']); - } - - /** - * Next.js is the one framework whose static export genuinely leaves the ssr - * build root, so it is excluded rather than special-cased below. - */ - public function testStaticOutputStaysInsideSsrOutput(): void - { - foreach ($this->frameworks as $key => $framework) { - if ($key === 'nextjs') { - continue; - } - - $ssr = $framework['adapters']['ssr']['outputDirectory'] ?? null; - $static = $framework['adapters']['static']['outputDirectory'] ?? null; - - if ($ssr === null || $static === null) { - continue; - } - - $this->assertStringStartsWith( - \rtrim($ssr, '/') . '/', - \rtrim($static, '/') . '/', - "Framework '{$key}' serves static files from outside its ssr build output." - ); - } - } -} From d6a58529d7a4308e58cbca46b5f3e4cd39377903 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 00:11:45 +0530 Subject: [PATCH 03/13] Simplify the start command assertion SitesBase carries thirty-nine helpers with no docblocks and a single inline comment, so a getter that also asserts, a memoised trait property and a recursion threading a path string for its failure messages all sat well outside the file. Encode the payload once and assert against the string. The key check gets stronger as a result - it catches startCommand at any depth without walking - and JSON_UNESCAPED_SLASHES keeps the helper paths intact, which the default encoding would have hidden behind escaped slashes. --- tests/e2e/Services/Sites/SitesBase.php | 53 ++++---------------------- 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index c48814332d..f56536f76c 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -19,9 +19,6 @@ trait SitesBase protected string $stdout = ''; protected string $stderr = ''; - /** @var list|null */ - protected ?array $internalStartCommands = null; - protected function setupSite(mixed $params): string { $site = $this->client->call(Client::METHOD_POST, '/sites', array_merge([ @@ -501,57 +498,21 @@ trait SitesBase return $specification['slug']; } - /** - * The commands that boot a framework are an internal contract between Appwrite and the - * runtime image, and they change without notice. Leaking one lets a client copy it into - * their own site, so it must not reach a response body at all - not as a value a console - * could render, and not as a default a console could offer as a placeholder. - * - * @return list - */ - protected function getInternalStartCommands(): array + protected function assertStartCommandNotExposed(array $payload): void { - if ($this->internalStartCommands !== null) { - return $this->internalStartCommands; - } + $body = \json_encode($payload, JSON_UNESCAPED_SLASHES); - $commands = []; + $this->assertStringNotContainsString('startCommand', $body); + + // Every framework start command shells out to a helper script shipped in the runtime image. + $this->assertStringNotContainsString('helpers/', $body); foreach (Config::getParam('frameworks', []) as $framework) { foreach ($framework['adapters'] ?? [] as $adapter) { if (!empty($adapter['startCommand'])) { - $commands[] = $adapter['startCommand']; + $this->assertStringNotContainsString($adapter['startCommand'], $body); } } } - - $this->assertNotEmpty($commands, 'Expected at least one framework to define a start command.'); - - $this->internalStartCommands = \array_values(\array_unique($commands)); - - return $this->internalStartCommands; - } - - protected function assertStartCommandNotExposed(mixed $payload, string $path = 'body'): void - { - if (\is_string($payload)) { - foreach ($this->getInternalStartCommands() as $command) { - $this->assertNotSame($command, $payload, 'Internal start command exposed at ' . $path); - } - - // Every internal command shells out to a helper script shipped in the runtime image. - $this->assertStringNotContainsString('helpers/', $payload, 'Internal helper script exposed at ' . $path); - - return; - } - - if (!\is_array($payload)) { - return; - } - - foreach ($payload as $key => $value) { - $this->assertNotSame('startCommand', $key, 'Start command exposed at ' . $path . '.' . $key); - $this->assertStartCommandNotExposed($value, $path . '.' . $key); - } } } From abaf46790ecf27eaa10da74d8ea9debd6a5d2ed6 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 00:15:15 +0530 Subject: [PATCH 04/13] Drop the redundant start command loop All twenty-three start commands in app/config/frameworks.php shell out to a helper script, so every value the loop asserted against was already caught by the helpers/ check two lines above it. Reading the config back only restated what that check covers, and it was the one thing pulling Config into the trait. --- tests/e2e/Services/Sites/SitesBase.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index f56536f76c..a01b08f414 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -6,7 +6,6 @@ use Appwrite\Tests\Async; use Appwrite\Tests\Async\Exceptions\Critical; use CURLFile; use Tests\E2E\Client; -use Utopia\Config\Config; use Utopia\Console; use Utopia\Database\Helpers\ID; use Utopia\Database\Query; @@ -506,13 +505,5 @@ trait SitesBase // Every framework start command shells out to a helper script shipped in the runtime image. $this->assertStringNotContainsString('helpers/', $body); - - foreach (Config::getParam('frameworks', []) as $framework) { - foreach ($framework['adapters'] ?? [] as $adapter) { - if (!empty($adapter['startCommand'])) { - $this->assertStringNotContainsString($adapter['startCommand'], $body); - } - } - } } } From 93a36f2ba37df23efe94cd11ffdee30279ea7b35 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 00:18:17 +0530 Subject: [PATCH 05/13] Inline the start command assertion One assertion behind a named helper only moved the reader somewhere else to find it. Assert on the encoded body at each call site instead, and drop the helpers/ check with it - that one guarded against a start command leaking under some other key name, which is a wider claim than these tests set out to make. SitesBase keeps the shape it had before this branch. --- tests/e2e/Services/Sites/SitesBase.php | 10 ---------- tests/e2e/Services/Sites/SitesCustomClientTest.php | 4 ++-- tests/e2e/Services/Sites/SitesCustomServerTest.php | 2 +- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index a01b08f414..00cc0a6cc6 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -496,14 +496,4 @@ trait SitesBase return $specification['slug']; } - - protected function assertStartCommandNotExposed(array $payload): void - { - $body = \json_encode($payload, JSON_UNESCAPED_SLASHES); - - $this->assertStringNotContainsString('startCommand', $body); - - // Every framework start command shells out to a helper script shipped in the runtime image. - $this->assertStringNotContainsString('helpers/', $body); - } } diff --git a/tests/e2e/Services/Sites/SitesCustomClientTest.php b/tests/e2e/Services/Sites/SitesCustomClientTest.php index 97f5df1e0e..1e9abcb411 100644 --- a/tests/e2e/Services/Sites/SitesCustomClientTest.php +++ b/tests/e2e/Services/Sites/SitesCustomClientTest.php @@ -129,13 +129,13 @@ final class SitesCustomClientTest extends Scope $this->assertEquals(200, $templates['headers']['status-code']); $this->assertGreaterThan(0, $templates['body']['total']); - $this->assertStartCommandNotExposed($templates['body']); + $this->assertStringNotContainsString('startCommand', (string) json_encode($templates['body'])); $template = $this->getTemplate('starter-for-nextjs'); $this->assertEquals(200, $template['headers']['status-code']); - $this->assertStartCommandNotExposed($template['body']); + $this->assertStringNotContainsString('startCommand', (string) json_encode($template['body'])); } public function testGetTemplate() diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 02a2562627..b748a0af94 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2272,7 +2272,7 @@ final class SitesCustomServerTest extends Scope $this->assertEquals(200, $frameworks['headers']['status-code']); $this->assertGreaterThan(0, $frameworks['body']['total']); - $this->assertStartCommandNotExposed($frameworks['body']); + $this->assertStringNotContainsString('startCommand', (string) json_encode($frameworks['body'])); } public function testCreateSiteHidesStartCommand(): void From a09d7553fbfecd2ad1c32d6d40a3f85d95c4f589 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 00:38:33 +0530 Subject: [PATCH 06/13] fix(sites): stop listFrameworks leaking runtime commands Response models filter nested Documents, not plain arrays. listFrameworks handed Config's raw rows straight to the response, so every key on them went out with it: each adapter's startCommand, plus the framework-level bundleCommand, envCommand and screenshotSleep. The console read that leaked start command and wrote it into sites as if the user had typed it. Wrap the rows in Documents so the declared models decide what ships. --- .../Platform/Modules/Sites/Http/Frameworks/XList.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php index e49ace4486..c0098dca3a 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php @@ -79,9 +79,19 @@ class XList extends Base } } + // Response models only filter nested Documents. Handing over the raw config arrays + // ships every key they carry, including the start, bundle and env commands that + // belong to the runtime image. + $frameworks = \array_map(fn (array $framework) => new Document(\array_replace($framework, [ + 'adapters' => \array_map( + fn (array $adapter) => new Document($adapter), + $framework['adapters'] ?? [] + ), + ])), \array_values($frameworks)); + $response->dynamic(new Document([ 'total' => count($frameworks), - 'frameworks' => \array_values($frameworks) + 'frameworks' => $frameworks ]), Response::MODEL_FRAMEWORK_LIST); } } From 617ce5eb5f5fb4529b5ad95606a9ce004f9b1add Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 00:40:18 +0530 Subject: [PATCH 07/13] Trim the comment on the frameworks response to one line --- src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php index c0098dca3a..52ddc1d53e 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php @@ -79,9 +79,7 @@ class XList extends Base } } - // Response models only filter nested Documents. Handing over the raw config arrays - // ships every key they carry, including the start, bundle and env commands that - // belong to the runtime image. + // Response models only filter nested Documents; plain arrays ship every key they carry. $frameworks = \array_map(fn (array $framework) => new Document(\array_replace($framework, [ 'adapters' => \array_map( fn (array $adapter) => new Document($adapter), From 19dff5c9748a0300aa43be5878f13d876d87ce0b Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 13:17:18 +0530 Subject: [PATCH 08/13] Filter model-typed rules handed raw arrays output() recursed into a rule's items only when they were already Documents, so an endpoint passing config rows straight through shipped every key on them. listFrameworks did exactly that and leaked each adapter's startCommand along with the framework-level bundleCommand, envCommand and screenshotSleep. Coerce arrays to Documents where the rule names a model, which lets the declared rules govern the output wherever the payload came from, and drop the wrapping listFrameworks needed to work around it. A union type is always a list of models, never scalars, so the array check is enough to tell a nested model from a rule like runtimes. --- .../Modules/Sites/Http/Frameworks/XList.php | 10 +-------- src/Appwrite/Utopia/Response.php | 9 ++++++++ tests/unit/Utopia/ResponseTest.php | 21 +++++++++++++++++++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php index 52ddc1d53e..e49ace4486 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php @@ -79,17 +79,9 @@ class XList extends Base } } - // Response models only filter nested Documents; plain arrays ship every key they carry. - $frameworks = \array_map(fn (array $framework) => new Document(\array_replace($framework, [ - 'adapters' => \array_map( - fn (array $adapter) => new Document($adapter), - $framework['adapters'] ?? [] - ), - ])), \array_values($frameworks)); - $response->dynamic(new Document([ 'total' => count($frameworks), - 'frameworks' => $frameworks + 'frameworks' => \array_values($frameworks) ]), Response::MODEL_FRAMEWORK_LIST); } } diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index aa261a320b..2ee1d508a6 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -562,6 +562,11 @@ class Response extends SwooleResponse } foreach ($data[$key] as $index => $item) { + // A model-typed rule handed a raw array would otherwise ship every key it carries. + if (\is_array($item) && (\is_array($rule['type']) || self::hasModel($rule['type']))) { + $item = new Document($item); + } + if ($item instanceof Document) { $ruleType = null; @@ -597,6 +602,10 @@ class Response extends SwooleResponse } } } else { + if (\is_array($data[$key]) && (\is_array($rule['type']) || self::hasModel($rule['type']))) { + $data[$key] = new Document($data[$key]); + } + if ($data[$key] instanceof Document) { $data[$key] = $this->output($data[$key], $rule['type']); } diff --git a/tests/unit/Utopia/ResponseTest.php b/tests/unit/Utopia/ResponseTest.php index e00809ce26..2d83240b44 100644 --- a/tests/unit/Utopia/ResponseTest.php +++ b/tests/unit/Utopia/ResponseTest.php @@ -188,6 +188,27 @@ final class ResponseTest extends TestCase $this->assertArrayNotHasKey('hidden', $single); } + public function testResponseModelListsOfArrays(): void + { + $output = $this->response->output(new Document([ + 'singles' => [ + [ + 'string' => 'lorem ipsum', + 'integer' => 123, + 'boolean' => true, + 'hidden' => 'secret' + ] + ], + ]), 'lists'); + + $this->assertCount(1, $output['singles']); + + $single = $output['singles'][0]; + $this->assertArrayHasKey('string', $single); + $this->assertArrayHasKey('required', $single); + $this->assertArrayNotHasKey('hidden', $single); + } + public function testResponseModelNested(): void { $output = $this->response->output(new Document([ From c52584df175f9e8ea025a6d0fb9c7644efadf3e8 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 13:39:37 +0530 Subject: [PATCH 09/13] Coerce only single model rules, never unions Coercing a union-typed value into a Document reached a branch that had never run: the single-value path hands rule['type'] to output(), which takes a string, so a user's hashOptions returned a 500 instead of its algo. Only the array branch resolves a model per item. Restrict the coercion to array rules naming one model, and leave the single-value path as it was. --- src/Appwrite/Utopia/Response.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 2ee1d508a6..c5ef65ceda 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -563,7 +563,8 @@ class Response extends SwooleResponse foreach ($data[$key] as $index => $item) { // A model-typed rule handed a raw array would otherwise ship every key it carries. - if (\is_array($item) && (\is_array($rule['type']) || self::hasModel($rule['type']))) { + // Union types are left alone: their branch resolves a model per item. + if (\is_array($item) && !\is_array($rule['type']) && self::hasModel($rule['type'])) { $item = new Document($item); } @@ -602,10 +603,6 @@ class Response extends SwooleResponse } } } else { - if (\is_array($data[$key]) && (\is_array($rule['type']) || self::hasModel($rule['type']))) { - $data[$key] = new Document($data[$key]); - } - if ($data[$key] instanceof Document) { $data[$key] = $this->output($data[$key], $rule['type']); } From f426cf4f6e4bae26657fa51d88a9bfe33fbe0b6c Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 14:01:10 +0530 Subject: [PATCH 10/13] Fix the leak in the endpoint rather than in Response Coercing arrays inside output() is new behaviour in code every service and cloud inherits, and it already cost a regression: union-typed rules reached a branch that cannot resolve them and returned 500s on account reads. Endpoints building their own Documents is the shape already used by listMockNumbers, listNamespaces and listOAuth2Providers. Restore that shape in listFrameworks and leave Response untouched. Making the model authoritative everywhere is worth doing, but as its own change with a response-shape test per endpoint it alters. --- .../Modules/Sites/Http/Frameworks/XList.php | 10 ++++++++- src/Appwrite/Utopia/Response.php | 6 ------ tests/unit/Utopia/ResponseTest.php | 21 ------------------- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php index e49ace4486..52ddc1d53e 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php @@ -79,9 +79,17 @@ class XList extends Base } } + // Response models only filter nested Documents; plain arrays ship every key they carry. + $frameworks = \array_map(fn (array $framework) => new Document(\array_replace($framework, [ + 'adapters' => \array_map( + fn (array $adapter) => new Document($adapter), + $framework['adapters'] ?? [] + ), + ])), \array_values($frameworks)); + $response->dynamic(new Document([ 'total' => count($frameworks), - 'frameworks' => \array_values($frameworks) + 'frameworks' => $frameworks ]), Response::MODEL_FRAMEWORK_LIST); } } diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index c5ef65ceda..aa261a320b 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -562,12 +562,6 @@ class Response extends SwooleResponse } foreach ($data[$key] as $index => $item) { - // A model-typed rule handed a raw array would otherwise ship every key it carries. - // Union types are left alone: their branch resolves a model per item. - if (\is_array($item) && !\is_array($rule['type']) && self::hasModel($rule['type'])) { - $item = new Document($item); - } - if ($item instanceof Document) { $ruleType = null; diff --git a/tests/unit/Utopia/ResponseTest.php b/tests/unit/Utopia/ResponseTest.php index 2d83240b44..e00809ce26 100644 --- a/tests/unit/Utopia/ResponseTest.php +++ b/tests/unit/Utopia/ResponseTest.php @@ -188,27 +188,6 @@ final class ResponseTest extends TestCase $this->assertArrayNotHasKey('hidden', $single); } - public function testResponseModelListsOfArrays(): void - { - $output = $this->response->output(new Document([ - 'singles' => [ - [ - 'string' => 'lorem ipsum', - 'integer' => 123, - 'boolean' => true, - 'hidden' => 'secret' - ] - ], - ]), 'lists'); - - $this->assertCount(1, $output['singles']); - - $single = $output['singles'][0]; - $this->assertArrayHasKey('string', $single); - $this->assertArrayHasKey('required', $single); - $this->assertArrayNotHasKey('hidden', $single); - } - public function testResponseModelNested(): void { $output = $this->response->output(new Document([ From 3f05ac1736de680b525357e4a4ee5e66c4fe755a Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 15:05:53 +0530 Subject: [PATCH 11/13] Stop the template lists shipping their ranking score Both template lists hand raw config rows to dynamic(), so score - internal ranking used only to sort the list - went out with them. The single-template endpoints already build a Document and were unaffected. Site templates also gain demoUrl, which the model declares and the config omits, so it now reports its default rather than being absent. --- .../Platform/Modules/Functions/Http/Templates/XList.php | 5 ++++- src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php | 5 ++++- tests/e2e/Services/Sites/SitesCustomClientTest.php | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php index f334351fef..3b1f24c1d2 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php @@ -81,7 +81,10 @@ class XList extends Base }); $total = $includeTotal ? \count($templates) : 0; - $templates = \array_slice($templates, $offset, $limit); + $templates = \array_map( + fn (array $template) => new Document($template), + \array_slice($templates, $offset, $limit) + ); $response->dynamic(new Document([ 'templates' => $templates, 'total' => $total, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php index 722cf986f8..56f7eb0fee 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php @@ -84,7 +84,10 @@ class XList extends Base }); $total = \count($templates); - $templates = \array_slice($templates, $offset, $limit); + $templates = \array_map( + fn (array $template) => new Document($template), + \array_slice($templates, $offset, $limit) + ); $response->dynamic(new Document([ 'templates' => $templates, 'total' => $total, diff --git a/tests/e2e/Services/Sites/SitesCustomClientTest.php b/tests/e2e/Services/Sites/SitesCustomClientTest.php index 1e9abcb411..c498ea024e 100644 --- a/tests/e2e/Services/Sites/SitesCustomClientTest.php +++ b/tests/e2e/Services/Sites/SitesCustomClientTest.php @@ -117,7 +117,7 @@ final class SitesCustomClientTest extends Scope $this->assertEquals(400, $templates['headers']['status-code']); } - public function testListTemplatesHidesStartCommand() + public function testListTemplatesHidesInternalFields() { $templates = $this->client->call(Client::METHOD_GET, '/sites/templates', array_merge([ 'content-type' => 'application/json', @@ -130,6 +130,7 @@ final class SitesCustomClientTest extends Scope $this->assertGreaterThan(0, $templates['body']['total']); $this->assertStringNotContainsString('startCommand', (string) json_encode($templates['body'])); + $this->assertStringNotContainsString('score', (string) json_encode($templates['body'])); $template = $this->getTemplate('starter-for-nextjs'); From 79af0f21fc359269e91fa1485675ecab7a4500a4 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 15:56:07 +0530 Subject: [PATCH 12/13] Filter model rules handed raw arrays, in one place The three endpoints wrapping their own rows were fixing the same thing three times, and the next config-backed list would have leaked again. Coerce in output() instead, restricted to array rules naming one model. That covers every list fed from config while leaving the single-value branch alone, so hashOptions keeps passing through as it does today - filtering it would rename memory_cost to an empty memoryCost. Unions stay excluded: only the branch below can pick their model per item. --- .../Modules/Functions/Http/Templates/XList.php | 5 +---- .../Platform/Modules/Sites/Http/Frameworks/XList.php | 10 +--------- .../Platform/Modules/Sites/Http/Templates/XList.php | 5 +---- src/Appwrite/Utopia/Response.php | 6 ++++++ 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php index 3b1f24c1d2..f334351fef 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Templates/XList.php @@ -81,10 +81,7 @@ class XList extends Base }); $total = $includeTotal ? \count($templates) : 0; - $templates = \array_map( - fn (array $template) => new Document($template), - \array_slice($templates, $offset, $limit) - ); + $templates = \array_slice($templates, $offset, $limit); $response->dynamic(new Document([ 'templates' => $templates, 'total' => $total, diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php index 52ddc1d53e..e49ace4486 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php @@ -79,17 +79,9 @@ class XList extends Base } } - // Response models only filter nested Documents; plain arrays ship every key they carry. - $frameworks = \array_map(fn (array $framework) => new Document(\array_replace($framework, [ - 'adapters' => \array_map( - fn (array $adapter) => new Document($adapter), - $framework['adapters'] ?? [] - ), - ])), \array_values($frameworks)); - $response->dynamic(new Document([ 'total' => count($frameworks), - 'frameworks' => $frameworks + 'frameworks' => \array_values($frameworks) ]), Response::MODEL_FRAMEWORK_LIST); } } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php index 56f7eb0fee..722cf986f8 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Templates/XList.php @@ -84,10 +84,7 @@ class XList extends Base }); $total = \count($templates); - $templates = \array_map( - fn (array $template) => new Document($template), - \array_slice($templates, $offset, $limit) - ); + $templates = \array_slice($templates, $offset, $limit); $response->dynamic(new Document([ 'templates' => $templates, 'total' => $total, diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index aa261a320b..7d48dfd766 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -562,6 +562,12 @@ class Response extends SwooleResponse } foreach ($data[$key] as $index => $item) { + // Config rows arrive as plain arrays and would ship every key they carry. + // Unions are skipped: only the branch below can pick their model per item. + if (\is_array($item) && !\is_array($rule['type']) && self::hasModel($rule['type'])) { + $item = new Document($item); + } + if ($item instanceof Document) { $ruleType = null; From 0d8166264e6129396877d2bbefff88e1b93af2b2 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 15:59:52 +0530 Subject: [PATCH 13/13] Drop the comment on the coercion --- src/Appwrite/Utopia/Response.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 7d48dfd766..d41392e8fb 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -562,8 +562,6 @@ class Response extends SwooleResponse } foreach ($data[$key] as $index => $item) { - // Config rows arrive as plain arrays and would ship every key they carry. - // Unions are skipped: only the branch below can pick their model per item. if (\is_array($item) && !\is_array($rule['type']) && self::hasModel($rule['type'])) { $item = new Document($item); }