diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 8019d5aa40..e71c780b7e 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); } } @@ -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); } } 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';