-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: temporarily lock out local accounts after failed logins #41805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oc-tmueller
wants to merge
1
commit into
master
Choose a base branch
from
fix/oc10-153-account-lockout-master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| Security: Temporarily lock out local accounts after repeated failed logins | ||
|
|
||
| We've added throttling of password authentication for local accounts. Core did | ||
| not limit the number of failed password attempts, so an account with a weak | ||
| password could be brute-forced online without any additional app installed. | ||
| After five failed attempts within 15 minutes an account is now locked for ten | ||
| minutes, and the login form explains when it can be tried again. The lockout | ||
| always expires on its own - no administrative unlock is needed and no account is | ||
| ever disabled permanently. A successful login clears the counter immediately. | ||
| Accounts of an external backend such as LDAP/AD are not affected, they are | ||
| throttled by their identity provider. The thresholds can be adjusted with the | ||
| new `account_lockout.*` config parameters. | ||
|
|
||
| https://github.com/owncloud/core/pull/41805 | ||
| https://doc.owncloud.com/server/next/admin_manual/configuration/server/config_sample_php_parameters.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| <?php | ||
| /** | ||
| * @author Thomas Müller <thomas.mueller@tmit.eu> | ||
| * | ||
| * @copyright Copyright (c) 2026, ownCloud GmbH | ||
| * @license AGPL-3.0 | ||
| * | ||
| * This code is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License, version 3, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License, version 3, | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/> | ||
| * | ||
| */ | ||
| namespace OC\Migrations; | ||
|
|
||
| use Doctrine\DBAL\Schema\Schema; | ||
| use OCP\Migration\ISchemaMigration; | ||
|
|
||
| /** | ||
| * Table holding the failed login attempt counters which drive the temporary | ||
| * lockout of local accounts. | ||
| */ | ||
| class Version20260904090000 implements ISchemaMigration { | ||
| public function changeSchema(Schema $schema, array $options) { | ||
| $prefix = $options['tablePrefix']; | ||
| if (!$schema->hasTable("{$prefix}account_lockouts")) { | ||
| $table = $schema->createTable("{$prefix}account_lockouts"); | ||
| $table->addColumn('id', 'bigint', [ | ||
| 'autoincrement' => true, | ||
| 'notnull' => true, | ||
| 'length' => 20, | ||
| ]); | ||
| // the lockout key: the resolved account uid, or - for a login name | ||
| // which does not resolve to an account - the normalised login name. | ||
| // Longer than users.uid on purpose, login names are attacker supplied. | ||
| $table->addColumn('uid', 'string', [ | ||
| 'notnull' => true, | ||
| 'length' => 128, | ||
| ]); | ||
| $table->addColumn('fail_count', 'integer', [ | ||
| 'notnull' => true, | ||
| 'length' => 4, | ||
| 'default' => 0, | ||
| ]); | ||
| // unix timestamp; null or in the past means not locked | ||
| $table->addColumn('locked_until', 'bigint', [ | ||
| 'notnull' => false, | ||
| 'length' => 20, | ||
| ]); | ||
| // unix timestamp of the most recent failure, drives the counter decay | ||
| $table->addColumn('last_fail_at', 'bigint', [ | ||
| 'notnull' => true, | ||
| 'length' => 20, | ||
| 'default' => 0, | ||
| ]); | ||
| $table->setPrimaryKey(['id']); | ||
| $table->addUniqueIndex(['uid'], 'acc_lockouts_uid_idx'); | ||
| $table->addIndex(['last_fail_at'], 'acc_lockouts_fail_at_idx'); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php | ||
| /** | ||
| * @author Thomas Müller <thomas.mueller@tmit.eu> | ||
| * | ||
| * @copyright Copyright (c) 2026, ownCloud GmbH | ||
| * @license AGPL-3.0 | ||
| * | ||
| * This code is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License, version 3, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License, version 3, | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/> | ||
| * | ||
| */ | ||
| namespace OC\Migrations; | ||
|
|
||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\ISimpleMigration; | ||
|
|
||
| /** | ||
| * Fresh installations get the job from Setup::installBackgroundJobs(), existing | ||
| * installations need it added here. | ||
| */ | ||
| class Version20260904090001 implements ISimpleMigration { | ||
| /** | ||
| * @param IOutput $out | ||
| */ | ||
| public function run(IOutput $out) { | ||
| // spelled exactly like in Setup::installBackgroundJobs(), the job list | ||
| // compares the class name verbatim when it deduplicates | ||
| \OC::$server->getJobList()->add('\OC\Authentication\AccountLockout\ExpireLockoutsJob'); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
lib/private/Authentication/AccountLockout/AccountLockedException.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
| /** | ||
| * @author Thomas Müller <thomas.mueller@tmit.eu> | ||
| * | ||
| * @copyright Copyright (c) 2026, ownCloud GmbH | ||
| * @license AGPL-3.0 | ||
| * | ||
| * This code is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License, version 3, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License, version 3, | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/> | ||
| * | ||
| */ | ||
|
|
||
| namespace OC\Authentication\AccountLockout; | ||
|
|
||
| use OC\User\LoginException; | ||
|
|
||
| /** | ||
| * Thrown when a login is refused because the account is temporarily locked | ||
| * after too many failed password attempts. | ||
| * | ||
| * It is a LoginException so that existing callers which already render a | ||
| * LoginException - most importantly the DAV backend, which turns it into a | ||
| * 401 - keep working unchanged. | ||
| */ | ||
| class AccountLockedException extends LoginException { | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way this is implemented, I can, for example:
Within any 15-minute window there was never more than 2 failed login attempts, the 5 attempts were across a 48-minute window.
I suppose it is OK to do it that way. Some attempts that seem to be very slow still trigger a lockout every hour or so. The alternative would be to remember the actual time of every failed attempt so that old attempts could be removed from the accumulated count when they age beyond the attempt window. That would be significant overhead to keep track - both computing all the time intervals and the extra database activity to store and retrieve that data.