From 19dff5c9748a0300aa43be5878f13d876d87ce0b Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 13:17:18 +0530 Subject: [PATCH] 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([