summaryrefslogtreecommitdiffstats
path: root/core/Controller/LoginController.php
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2016-07-20 18:36:15 +0200
committerLukas Reschke <lukas@statuscode.ch>2016-07-20 22:08:56 +0200
commitba4f12baa02dfb55ec8822687896d643261440c4 (patch)
tree5dc95ab54a2ae169951693a43ba7aa6920d6f36a /core/Controller/LoginController.php
parent7cdf6402ff9a0e07866ca8bcfcffd0e0897b646a (diff)
downloadnextcloud-server-ba4f12baa02dfb55ec8822687896d643261440c4.tar.gz
nextcloud-server-ba4f12baa02dfb55ec8822687896d643261440c4.zip
Implement brute force protection
Class Throttler implements the bruteforce protection for security actions in Nextcloud. It is working by logging invalid login attempts to the database and slowing down all login attempts from the same subnet. The max delay is 30 seconds and the starting delay are 200 milliseconds. (after the first failed login)
Diffstat (limited to 'core/Controller/LoginController.php')
-rw-r--r--core/Controller/LoginController.php27
1 files changed, 19 insertions, 8 deletions
diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php
index 7806e1de904..c453bd20a23 100644
--- a/core/Controller/LoginController.php
+++ b/core/Controller/LoginController.php
@@ -22,7 +22,9 @@
namespace OC\Core\Controller;
+use OC\AppFramework\Utility\TimeFactory;
use OC\Authentication\TwoFactorAuth\Manager;
+use OC\Security\Bruteforce\Throttler;
use OC\User\Session;
use OC_App;
use OC_Util;
@@ -37,24 +39,20 @@ use OCP\IUser;
use OCP\IUserManager;
class LoginController extends Controller {
-
/** @var IUserManager */
private $userManager;
-
/** @var IConfig */
private $config;
-
/** @var ISession */
private $session;
-
/** @var Session */
private $userSession;
-
/** @var IURLGenerator */
private $urlGenerator;
-
/** @var Manager */
private $twoFactorManager;
+ /** @var Throttler */
+ private $throttler;
/**
* @param string $appName
@@ -65,9 +63,17 @@ class LoginController extends Controller {
* @param Session $userSession
* @param IURLGenerator $urlGenerator
* @param Manager $twoFactorManager
+ * @param Throttler $throttler
*/
- function __construct($appName, IRequest $request, IUserManager $userManager, IConfig $config, ISession $session,
- Session $userSession, IURLGenerator $urlGenerator, Manager $twoFactorManager) {
+ function __construct($appName,
+ IRequest $request,
+ IUserManager $userManager,
+ IConfig $config,
+ ISession $session,
+ Session $userSession,
+ IURLGenerator $urlGenerator,
+ Manager $twoFactorManager,
+ Throttler $throttler) {
parent::__construct($appName, $request);
$this->userManager = $userManager;
$this->config = $config;
@@ -75,6 +81,7 @@ class LoginController extends Controller {
$this->userSession = $userSession;
$this->urlGenerator = $urlGenerator;
$this->twoFactorManager = $twoFactorManager;
+ $this->throttler = $throttler;
}
/**
@@ -171,6 +178,8 @@ class LoginController extends Controller {
* @return RedirectResponse
*/
public function tryLogin($user, $password, $redirect_url) {
+ $this->throttler->sleepDelay($this->request->getRemoteAddress());
+
$originalUser = $user;
// TODO: Add all the insane error handling
/* @var $loginResult IUser */
@@ -184,6 +193,8 @@ class LoginController extends Controller {
}
}
if ($loginResult === false) {
+ $this->throttler->registerAttempt('login', $this->request->getRemoteAddress(), ['user' => $originalUser]);
+
$this->session->set('loginMessages', [
['invalidpassword']
]);