From 5bf39b8fd2bdb2cf1434fedf40f3649f661cf2d8 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 28 Jul 2026 19:48:54 +0530 Subject: [PATCH] fix: restore remaining auth-policy limits dropped in the refactor Three more accidental regressions from the same auth-settings refactor that swapped policy limits to the generic APP_LIMIT_COUNT: - User limit max was halved: 10,000 (APP_LIMIT_USERS) -> 5,000 (APP_LIMIT_COUNT copy-paste). Restore Range(0, APP_LIMIT_USERS), keeping 0 as the original "unlimited" sentinel. - Default session cap for new projects silently became unlimited (APP_LIMIT_USER_SESSIONS_DEFAULT dropped, default flipped to 0, and the enforcement fallback in shared/api.php followed suit). Restore the constant (10) and use it in both project-create paths and the fallback. - Session duration minimum was loosened from 60 to 5 seconds to speed up an integration test, not as a deliberate product decision. Restore the 60-second floor and adjust the test's polling windows. --- app/controllers/shared/api.php | 2 +- app/init/constants.php | 1 + .../Organization/Http/Projects/Create.php | 2 +- .../Policies/SessionDuration/Update.php | 2 +- .../Project/Policies/UserLimit/Update.php | 2 +- .../Modules/Projects/Http/Projects/Create.php | 2 +- tests/e2e/Services/Project/PoliciesBase.php | 22 +++++++++++++------ ...PoliciesSessionDurationIntegrationTest.php | 12 +++++----- 8 files changed, 27 insertions(+), 18 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 211128c499..21c4c7397b 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -774,7 +774,7 @@ Http::shutdown() ->inject('project') ->inject('dbForProject') ->action(function (Request $request, Response $response, Document $project, Database $dbForProject) { - $sessionLimit = $project->getAttribute('auths', [])['maxSessions'] ?? 0; + $sessionLimit = $project->getAttribute('auths', [])['maxSessions'] ?? APP_LIMIT_USER_SESSIONS_DEFAULT; if ($sessionLimit === 0) { return; diff --git a/app/init/constants.php b/app/init/constants.php index 53ae5c9c32..b12d7997a6 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -33,6 +33,7 @@ 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_USER_SESSIONS_DEFAULT = 10; const APP_LIMIT_ANTIVIRUS = 20_000_000; //20MB const APP_LIMIT_ENCRYPTION = 20_000_000; //20MB const APP_LIMIT_COMPRESSION = 20_000_000; //20MB diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php index 90c3781701..c2eeaa7f30 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php @@ -86,7 +86,7 @@ class Create extends Action $auth = Config::getParam('auth', []); $auths = [ 'limit' => 0, - 'maxSessions' => 0, + 'maxSessions' => APP_LIMIT_USER_SESSIONS_DEFAULT, 'passwordHistory' => 0, 'passwordDictionary' => false, 'duration' => TOKEN_EXPIRATION_LOGIN_LONG, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php index 10eabb57cd..8b34dafe81 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionDuration/Update.php @@ -50,7 +50,7 @@ class Update extends Action ) ], )) - ->param('duration', null, new Range(5, 31536000), 'Maximum session length in seconds. Minium allowed value is 5 second, and maximum is 1 year, which is 31536000 seconds.') + ->param('duration', null, new Range(60, 31536000), 'Maximum session length in seconds. Minium allowed value is 60 seconds, and maximum is 1 year, which is 31536000 seconds.') ->inject('response') ->inject('dbForPlatform') ->inject('project') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php index b3f430b779..5419c93e3e 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/UserLimit/Update.php @@ -51,7 +51,7 @@ class Update extends Action ) ], )) - ->param('total', null, new Nullable(new Range(1, APP_LIMIT_COUNT)), 'Set the maximum number of users allowed in the project. Value can be between 1 and ' . APP_LIMIT_COUNT . ', or null to disable the limit.') + ->param('total', null, new Nullable(new Range(0, APP_LIMIT_USERS)), 'Set the maximum number of users allowed in the project. Value can be between 0 and ' . APP_LIMIT_USERS . '. Use 0 or null to disable the limit.') ->inject('response') ->inject('dbForPlatform') ->inject('project') diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php index 28405fe1da..82279824be 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php @@ -82,7 +82,7 @@ class Create extends Action $auth = Config::getParam('auth', []); $auths = [ 'limit' => 0, - 'maxSessions' => 0, + 'maxSessions' => APP_LIMIT_USER_SESSIONS_DEFAULT, 'passwordStrength' => [ 'min' => 8, 'uppercase' => false, diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index e865671cd9..d4b37e8aea 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -707,10 +707,10 @@ trait PoliciesBase public function testUpdateSessionDurationPolicyMin(): void { - $response = $this->updateSessionDurationPolicy(5); + $response = $this->updateSessionDurationPolicy(60); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(5, $response['body']['authDuration']); + $this->assertSame(60, $response['body']['authDuration']); // Cleanup $this->updateSessionDurationPolicy(31536000); @@ -726,7 +726,7 @@ trait PoliciesBase public function testUpdateSessionDurationPolicyBelowMin(): void { - $response = $this->updateSessionDurationPolicy(4); + $response = $this->updateSessionDurationPolicy(59); $this->assertSame(400, $response['headers']['status-code']); } @@ -930,10 +930,10 @@ trait PoliciesBase public function testUpdateUserLimitPolicyMax(): void { - $response = $this->updateUserLimitPolicy(5000); + $response = $this->updateUserLimitPolicy(10000); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(5000, $response['body']['authLimit']); + $this->assertSame(10000, $response['body']['authLimit']); // Cleanup $this->updateUserLimitPolicy(null); @@ -953,16 +953,24 @@ trait PoliciesBase $this->assertSame(0, $project['body']['authLimit']); } - public function testUpdateUserLimitPolicyBelowMin(): void + public function testUpdateUserLimitPolicyZeroMeansUnlimited(): void { $response = $this->updateUserLimitPolicy(0); + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame(0, $response['body']['authLimit']); + } + + public function testUpdateUserLimitPolicyBelowMin(): void + { + $response = $this->updateUserLimitPolicy(-1); + $this->assertSame(400, $response['headers']['status-code']); } public function testUpdateUserLimitPolicyAboveMax(): void { - $response = $this->updateUserLimitPolicy(5001); + $response = $this->updateUserLimitPolicy(10001); $this->assertSame(400, $response['headers']['status-code']); } diff --git a/tests/e2e/Services/Project/PoliciesSessionDurationIntegrationTest.php b/tests/e2e/Services/Project/PoliciesSessionDurationIntegrationTest.php index 84ffad1850..69356d221a 100644 --- a/tests/e2e/Services/Project/PoliciesSessionDurationIntegrationTest.php +++ b/tests/e2e/Services/Project/PoliciesSessionDurationIntegrationTest.php @@ -41,8 +41,8 @@ final class PoliciesSessionDurationIntegrationTest extends Scope $this->assertSame($seconds, $response['body']['authDuration']); }; - // Step 1: Set session duration to 5 seconds - $setDuration(5); + // Step 1: Set session duration to 60 seconds (the policy minimum) + $setDuration(60); // Step 2: Create user and a session $email = 'duration_' . uniqid() . '@localhost.test'; @@ -73,14 +73,14 @@ final class PoliciesSessionDurationIntegrationTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/account', $accountHeaders); $this->assertSame(200, $response['headers']['status-code']); - // Step 3: Poll until the 5s TTL elapses - session should expire + // Step 3: Poll until the 60s TTL elapses - session should expire $this->assertEventually(function () use ($accountHeaders) { $response = $this->client->call(Client::METHOD_GET, '/account', $accountHeaders); $this->assertSame(401, $response['headers']['status-code']); - }, 15_000, 500); + }, 75_000, 500); - // Step 4: Raise duration to 10s - same session should still not be usable - $setDuration(10); + // Step 4: Raise duration to 120s - same session should still not be usable + $setDuration(120); $response = $this->client->call(Client::METHOD_GET, '/account', $accountHeaders); $this->assertSame(401, $response['headers']['status-code']);