diff --git a/src/Appwrite/Auth/Validator/PasswordPwned.php b/src/Appwrite/Auth/Validator/PasswordPwned.php index ea03f3cc86..d50101fe74 100644 --- a/src/Appwrite/Auth/Validator/PasswordPwned.php +++ b/src/Appwrite/Auth/Validator/PasswordPwned.php @@ -46,7 +46,7 @@ class PasswordPwned extends Password $this->threshold = \max(1, (int) ($policy['threshold'] ?? 1)); $this->sessions = (bool) ($policy['sessions'] ?? false); $this->forceReset = (bool) ($policy['forceReset'] ?? false); - $this->failClosed = (bool) ($policy['failClosed'] ?? true); + $this->failClosed = (bool) ($policy['failClosed'] ?? false); $this->cache = $cache; $this->client = $client ?? (new Client()) ->setConnectTimeout(self::CONNECT_TIMEOUT) diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php index 6bde4e883d..c000d212ae 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php @@ -97,7 +97,7 @@ class Create extends Action 'threshold' => 1, 'sessions' => false, 'forceReset' => false, - 'failClosed' => true, + 'failClosed' => false, ], 'disposableEmails' => false, 'canonicalEmails' => false, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php index cb064d294b..3a02a71b9f 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php @@ -142,7 +142,7 @@ class Get extends Action 'threshold' => 1, 'sessions' => false, 'forceReset' => false, - 'failClosed' => true, + 'failClosed' => false, ], $auths['passwordPwned'] ?? [], [ '$id' => 'password-pwned', ])), diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPwned/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPwned/Update.php index 799440ef41..965cbf3e5e 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPwned/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPwned/Update.php @@ -60,7 +60,7 @@ class Update extends Action ->param('threshold', null, new Range(1, PHP_INT_MAX), 'Minimum number of known breaches a password must appear in before it is rejected. Default is 1.', optional: true) ->param('sessions', null, new Boolean(), 'Whether passwords are checked when a session is created. When enabled, signing in records whether the password appears in a known data breach. Default is false.', optional: true) ->param('forceReset', null, new Boolean(), 'Whether signing in with a breached password is blocked until the password is reset. Only applies when sessions are checked. Default is false, which allows the sign-in.', optional: true) - ->param('failClosed', null, new Boolean(), 'Whether passwords are rejected when the breach service cannot be reached. Default is true. Set to false to skip the check instead.', optional: true) + ->param('failClosed', null, new Boolean(), 'Whether passwords are rejected when the breach service cannot be reached. Default is false, which skips the check so an outage never blocks your users. Set to true to reject the password instead.', optional: true) ->inject('response') ->inject('dbForPlatform') ->inject('project') @@ -89,7 +89,7 @@ class Update extends Action 'threshold' => 1, 'sessions' => false, 'forceReset' => false, - 'failClosed' => true, + 'failClosed' => false, ], $auths['passwordPwned'] ?? []); if ($enabled !== null) { diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php index 6b8d8c1073..b13541a8eb 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php @@ -122,7 +122,7 @@ class XList extends Action 'threshold' => 1, 'sessions' => false, 'forceReset' => false, - 'failClosed' => true, + 'failClosed' => false, ], $auths['passwordPwned'] ?? [], [ '$id' => 'password-pwned', ])), diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php index 0176d68605..6a9e4f28f1 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php @@ -94,7 +94,7 @@ class Create extends Action 'threshold' => 1, 'sessions' => false, 'forceReset' => false, - 'failClosed' => true, + 'failClosed' => false, ], 'disposableEmails' => false, 'canonicalEmails' => false, diff --git a/src/Appwrite/Utopia/Response/Model/PolicyPasswordPwned.php b/src/Appwrite/Utopia/Response/Model/PolicyPasswordPwned.php index 2ae371e4da..6fe844740e 100644 --- a/src/Appwrite/Utopia/Response/Model/PolicyPasswordPwned.php +++ b/src/Appwrite/Utopia/Response/Model/PolicyPasswordPwned.php @@ -48,8 +48,8 @@ class PolicyPasswordPwned extends PolicyBase ->addRule('failClosed', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Whether passwords are rejected when the breach service cannot be reached. When false, the check is skipped instead.', - 'default' => true, - 'example' => true, + 'default' => false, + 'example' => false, ]); } diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index ca7cb73fc6..3a195e6232 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -654,7 +654,7 @@ trait PoliciesBase $this->assertSame(1, $policy['body']['threshold']); $this->assertSame(false, $policy['body']['sessions']); $this->assertSame(false, $policy['body']['forceReset']); - $this->assertSame(true, $policy['body']['failClosed']); + $this->assertSame(false, $policy['body']['failClosed']); // Cleanup $this->updatePasswordPwnedPolicy(['enabled' => false]); @@ -686,7 +686,7 @@ trait PoliciesBase $this->assertSame(1, $policy['body']['threshold']); $this->assertSame(false, $policy['body']['sessions']); $this->assertSame(false, $policy['body']['forceReset']); - $this->assertSame(true, $policy['body']['failClosed']); + $this->assertSame(false, $policy['body']['failClosed']); } public function testUpdatePasswordPwnedPolicySessions(): void @@ -713,7 +713,7 @@ trait PoliciesBase 'threshold' => 5, 'sessions' => true, 'forceReset' => true, - 'failClosed' => false, + 'failClosed' => true, ]); $this->assertSame(200, $response['headers']['status-code']); @@ -728,7 +728,7 @@ trait PoliciesBase $this->assertSame(5, $policy['body']['threshold']); $this->assertSame(true, $policy['body']['sessions']); $this->assertSame(true, $policy['body']['forceReset']); - $this->assertSame(false, $policy['body']['failClosed']); + $this->assertSame(true, $policy['body']['failClosed']); // Cleanup $this->resetPasswordPwnedPolicy(); @@ -748,7 +748,7 @@ trait PoliciesBase $this->assertSame(1, $policy['body']['threshold']); $this->assertSame(false, $policy['body']['sessions']); $this->assertSame(false, $policy['body']['forceReset']); - $this->assertSame(true, $policy['body']['failClosed']); + $this->assertSame(false, $policy['body']['failClosed']); } public function testUpdatePasswordPwnedPolicyInvalidType(): void @@ -1497,7 +1497,7 @@ trait PoliciesBase 'threshold' => 1, 'sessions' => false, 'forceReset' => false, - 'failClosed' => true, + 'failClosed' => false, ]); } diff --git a/tests/e2e/Services/Project/PoliciesPasswordPwnedIntegrationTest.php b/tests/e2e/Services/Project/PoliciesPasswordPwnedIntegrationTest.php index a773824c5c..e7d8fc57d3 100644 --- a/tests/e2e/Services/Project/PoliciesPasswordPwnedIntegrationTest.php +++ b/tests/e2e/Services/Project/PoliciesPasswordPwnedIntegrationTest.php @@ -48,7 +48,7 @@ final class PoliciesPasswordPwnedIntegrationTest extends Scope // Breached passwords are rejected out of the box $this->assertTrue($response['body']['enabled']); - $this->assertTrue($response['body']['failClosed']); + $this->assertFalse($response['body']['failClosed']); $this->assertSame(1, $response['body']['threshold']); $this->assertSame('', $response['body']['endpoint']); @@ -468,7 +468,7 @@ final class PoliciesPasswordPwnedIntegrationTest extends Scope $this->assertSame(201, $response['headers']['status-code']); - $this->updatePolicy(['enabled' => false, 'endpoint' => '', 'sessions' => false, 'forceReset' => false, 'failClosed' => true]); + $this->updatePolicy(['enabled' => false, 'endpoint' => '', 'sessions' => false, 'forceReset' => false, 'failClosed' => false]); } public function testForceResetOnSignIn(): void @@ -1153,7 +1153,7 @@ final class PoliciesPasswordPwnedIntegrationTest extends Scope $this->assertSame(400, $response['headers']['status-code']); - $this->updatePolicy(['enabled' => false, 'endpoint' => '', 'sessions' => false, 'forceReset' => false, 'failClosed' => true]); + $this->updatePolicy(['enabled' => false, 'endpoint' => '', 'sessions' => false, 'forceReset' => false, 'failClosed' => false]); } /** diff --git a/tests/unit/Auth/Validator/PasswordPwnedTest.php b/tests/unit/Auth/Validator/PasswordPwnedTest.php index bd7d45b554..167069e56e 100644 --- a/tests/unit/Auth/Validator/PasswordPwnedTest.php +++ b/tests/unit/Auth/Validator/PasswordPwnedTest.php @@ -156,11 +156,28 @@ final class PasswordPwnedTest extends TestCase $this->assertCount(2, $adapter->requests); } - public function testUnreachableServiceFailsClosedByDefault(): void + public function testUnreachableServiceSkipsTheCheckByDefault(): void { $adapter = new RangeAdapter(failure: new \RuntimeException('connection refused')); $validator = $this->validator([], $adapter); + // An outage of the breach service must not stop people setting a password + $this->assertTrue($validator->isValid(self::LEAKED)); + } + + public function testUnexpectedStatusSkipsTheCheckByDefault(): void + { + $adapter = new RangeAdapter(statusCode: 503, body: ''); + $validator = $this->validator([], $adapter); + + $this->assertTrue($validator->isValid(self::LEAKED)); + } + + public function testUnreachableServiceIsRejectedWhenFailingClosed(): void + { + $adapter = new RangeAdapter(failure: new \RuntimeException('connection refused')); + $validator = $this->validator(['failClosed' => true], $adapter); + try { $validator->isValid(self::LEAKED); $this->fail('Expected the check to fail closed'); @@ -169,29 +186,21 @@ final class PasswordPwnedTest extends TestCase } } - public function testUnexpectedStatusFailsClosedByDefault(): void + public function testUnexpectedStatusIsRejectedWhenFailingClosed(): void { $adapter = new RangeAdapter(statusCode: 503, body: ''); - $validator = $this->validator([], $adapter); + $validator = $this->validator(['failClosed' => true], $adapter); $this->expectException(Exception::class); $validator->isValid(self::LEAKED); } - public function testUnreachableServiceSkipsTheCheckWhenFailingOpen(): void - { - $adapter = new RangeAdapter(failure: new \RuntimeException('connection refused')); - $validator = $this->validator(['failClosed' => false], $adapter); - - $this->assertTrue($validator->isValid(self::LEAKED)); - } - public function testFailedLookupIsNotCached(): void { $adapter = new RangeAdapter(failure: new \RuntimeException('connection refused')); $cache = new Cache(new Memory()); - $validator = new PasswordPwned(['enabled' => true, 'failClosed' => false], $cache, self::ENDPOINT, new Client($adapter)); + $validator = new PasswordPwned(['enabled' => true], $cache, self::ENDPOINT, new Client($adapter)); $validator->isValid(self::LEAKED); $validator->isValid(self::LEAKED);