From 426fd9b998ee2ac8d1630733ca852f32a3bd3b49 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 25 Aug 2026 11:18:26 +0530 Subject: [PATCH 1/3] fix(abuse): stringify object params before setting rate-limit template values The abuse hook registers every request param as a TimeLimit template value, but only converted arrays to JSON. An empty JSON object in a request body is decoded as stdClass, which fell through to Adapter::setParam() and threw a TypeError since it requires a string. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Kk65HXZhw3oTWybzCYHP3G --- app/controllers/shared/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 8019d5aa40..000a0e369e 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -539,7 +539,7 @@ Http::init() foreach ($request->getParams() as $key => $value) { if (! empty($value)) { - $timeLimit->setParam('{param-' . $key . '}', (\is_array($value)) ? \json_encode($value) : $value); + $timeLimit->setParam('{param-' . $key . '}', (\is_array($value) || \is_object($value)) ? \json_encode($value) : $value); } } From 4241f5f4cbb6e44619c2f3106f00da5f92d3446a Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 25 Aug 2026 11:24:55 +0530 Subject: [PATCH 2/3] fix(abuse): stringify object params in the abuse-reset shutdown hook too The reset hook mirrors the init hook's param loop but still passed objects directly to the string-only setParam(), so a successful request with an object param would throw before reset() ran, leaving stale rate-limit state. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Kk65HXZhw3oTWybzCYHP3G --- app/controllers/shared/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 000a0e369e..e71c780b7e 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -919,7 +919,7 @@ Http::shutdown() foreach ($request->getParams() as $key => $value) { // Set request params as potential abuse keys if (! empty($value)) { - $timeLimit->setParam('{param-' . $key . '}', (\is_array($value)) ? \json_encode($value) : $value); + $timeLimit->setParam('{param-' . $key . '}', (\is_array($value) || \is_object($value)) ? \json_encode($value) : $value); } } From c355c4d6fffa32f58038e404c999891df6b89f91 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 25 Aug 2026 11:34:08 +0530 Subject: [PATCH 3/3] test(account): regression for object params in the abuse rate-limit hook Sends an empty JSON object as an extra body param, which decodes to a stdClass. Before the fix this threw a TypeError in the abuse init hook before the action ran; the request should return 201 instead. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Kk65HXZhw3oTWybzCYHP3G --- tests/e2e/Services/Account/AccountBase.php | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 021a03472b..b2ccf12cda 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -139,6 +139,31 @@ trait AccountBase ]; } + /** + * Regression: the abuse hook stringifies every request param into the + * rate-limit key. An empty JSON object in the body decodes to a stdClass, + * which used to be passed straight to the string-only setParam() and threw + * a TypeError before the action ran. The request must succeed instead of + * returning a 500. + */ + public function testCreateAccountWithObjectParam(): void + { + $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'userId' => ID::unique(), + 'email' => uniqid() . 'objectparam@localhost.test', + 'password' => 'password', + 'name' => 'User Name', + 'metadata' => (object) [], // serializes to `{}`, decoded as stdClass + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + } + public function testEmailOTPSession(): void { $isConsoleProject = $this->getProject()['$id'] === 'console';