mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
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:
2 files changed
+27
-2
No files matched your search
@@ -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';
|
||||
|
||||
Reference in new issue
Block a user