Merge pull request #13330 from appwrite/fix-abuse-param-invalid-type

fix(abuse): handle object params in rate-limit key building
This commit is contained in:
ArnabChatterjee20k authored and GitHub committed 2026-08-25 12:06:15 +05:30
commit c92a1406ab
2 files changed
+27 -2

No files matched your search

+2 -2
View File
@@ -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);
}
}
@@ -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';