fix: restore original session limit and password history caps

Session limit and password history policies were switched to
APP_LIMIT_COUNT (5000) during the auth-settings refactor, but sessions
are backed by an unpaginated subquery, so a limit that high risks
degrading the database for the whole project. Restore the previous
caps (APP_LIMIT_USER_SESSIONS_MAX = 100, APP_LIMIT_USER_PASSWORD_HISTORY
= 20) and drop the unlimited/null option for session limit, which was
never supported before.
This commit is contained in:
harsh mahajan committed 2026-07-28 19:08:01 +05:30
1 parent ffd3c7f7a5
commit 189062745e
4 files changed
+12 -27

No files matched your search

+2
View File
@@ -31,6 +31,8 @@ const APP_MODE_ADMIN = 'admin';
const APP_PAGING_LIMIT = 12;
const APP_LIMIT_COUNT = 5000;
const APP_LIMIT_USERS = 10_000;
const APP_LIMIT_USER_PASSWORD_HISTORY = 20;
const APP_LIMIT_USER_SESSIONS_MAX = 100;
const APP_LIMIT_ANTIVIRUS = 20_000_000; //20MB
const APP_LIMIT_ENCRYPTION = 20_000_000; //20MB
const APP_LIMIT_COMPRESSION = 20_000_000; //20MB
@@ -53,7 +53,7 @@ class Update extends Action
)
],
))
->param('total', null, new Nullable(new Range(1, APP_LIMIT_COUNT)), 'Set the password history length per user. Value can be between 1 and ' . APP_LIMIT_COUNT . ', or null to disable the limit.')
->param('total', null, new Nullable(new Range(1, APP_LIMIT_USER_PASSWORD_HISTORY)), 'Set the password history length per user. Value can be between 1 and ' . APP_LIMIT_USER_PASSWORD_HISTORY . ', or null to disable the limit.')
->inject('response')
->inject('dbForPlatform')
->inject('project')
@@ -12,7 +12,6 @@ use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Validator\Authorization;
use Utopia\Platform\Scope\HTTP;
use Utopia\Validator\Nullable;
use Utopia\Validator\Range;
class Update extends Action
@@ -51,7 +50,7 @@ class Update extends Action
)
],
))
->param('total', null, new Nullable(new Range(1, APP_LIMIT_COUNT)), 'Set the maximum number of sessions allowed per user. Value can be between 1 and ' . APP_LIMIT_COUNT . ', or null to disable the limit.')
->param('total', null, new Range(1, APP_LIMIT_USER_SESSIONS_MAX), 'Set the maximum number of sessions allowed per user. Value can be between 1 and ' . APP_LIMIT_USER_SESSIONS_MAX . '.')
->inject('response')
->inject('dbForPlatform')
->inject('project')
@@ -61,7 +60,7 @@ class Update extends Action
}
public function action(
?int $total,
int $total,
Response $response,
Database $dbForPlatform,
Document $project,
@@ -69,12 +68,7 @@ class Update extends Action
Event $queueForEvents,
): void {
$auths = $project->getAttribute('auths', []);
if (\is_null($total)) {
$auths['maxSessions'] = 0;
} else {
$auths['maxSessions'] = $total;
}
$auths['maxSessions'] = $total;
$updates = new Document([
'auths' => $auths,
+6 -17
View File
@@ -405,10 +405,10 @@ trait PoliciesBase
public function testUpdatePasswordHistoryPolicyMax(): void
{
$response = $this->updatePasswordHistoryPolicy(5000);
$response = $this->updatePasswordHistoryPolicy(20);
$this->assertSame(200, $response['headers']['status-code']);
$this->assertSame(5000, $response['body']['authPasswordHistory']);
$this->assertSame(20, $response['body']['authPasswordHistory']);
// Cleanup
$this->updatePasswordHistoryPolicy(null);
@@ -437,7 +437,7 @@ trait PoliciesBase
public function testUpdatePasswordHistoryPolicyAboveMax(): void
{
$response = $this->updatePasswordHistoryPolicy(5001);
$response = $this->updatePasswordHistoryPolicy(21);
$this->assertSame(400, $response['headers']['status-code']);
}
@@ -851,21 +851,10 @@ trait PoliciesBase
public function testUpdateSessionLimitPolicyMax(): void
{
$response = $this->updateSessionLimitPolicy(5000);
$response = $this->updateSessionLimitPolicy(100);
$this->assertSame(200, $response['headers']['status-code']);
$this->assertSame(5000, $response['body']['authSessionsLimit']);
// Cleanup
$this->updateSessionLimitPolicy(10);
}
public function testUpdateSessionLimitPolicyDisable(): void
{
$response = $this->updateSessionLimitPolicy(null);
$this->assertSame(200, $response['headers']['status-code']);
$this->assertSame(0, $response['body']['authSessionsLimit']);
$this->assertSame(100, $response['body']['authSessionsLimit']);
// Cleanup
$this->updateSessionLimitPolicy(10);
@@ -880,7 +869,7 @@ trait PoliciesBase
public function testUpdateSessionLimitPolicyAboveMax(): void
{
$response = $this->updateSessionLimitPolicy(5001);
$response = $this->updateSessionLimitPolicy(101);
$this->assertSame(400, $response['headers']['status-code']);
}