Skip to content

Commit

Permalink
Brute-force attack protection for 2fa codes
Browse files Browse the repository at this point in the history
  • Loading branch information
brusch committed Oct 22, 2019
1 parent 15280ff commit 9f2d075
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 7 additions & 4 deletions bundles/AdminBundle/Controller/Admin/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,25 @@ protected function buildLoginPageViewModel()

/**
* @Route("/login/2fa", name="pimcore_admin_2fa")
*
* @param Request $request
*
* @TemplatePhp()
*/
public function twoFactorAuthenticationAction(Request $request)
public function twoFactorAuthenticationAction(Request $request, BruteforceProtectionHandler $bruteforceProtectionHandler)
{
$view = $this->buildLoginPageViewModel();

if ($request->hasSession()) {

// we have to call the check here manually, because BruteforceProtectionListener uses the 'username' from the request
$bruteforceProtectionHandler->checkProtection($this->getAdminUser()->getName(), $request);

$session = $request->getSession();
$authException = $session->get(Security::AUTHENTICATION_ERROR);
if ($authException instanceof AuthenticationException) {
$session->remove(Security::AUTHENTICATION_ERROR);

$view->error = $authException->getMessage();

$bruteforceProtectionHandler->addEntry($this->getAdminUser()->getName(), $request);
}
} else {
$view->error = 'No session available, it either timed out or cookies are not enabled.';
Expand Down
2 changes: 0 additions & 2 deletions bundles/AdminBundle/Controller/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,6 @@ public function uploadImageAction(Request $request)
*/
public function renew2FaSecretAction(Request $request)
{
$this->checkCsrfToken($request);

$user = $this->getAdminUser();
$proxyUser = $this->getAdminUser(true);

Expand Down

0 comments on commit 9f2d075

Please sign in to comment.