Skip to content

Commit cb3f213

Browse files
Alexander PaliarushOleksii Korshenko
authored andcommitted
MAGETWO-50608: [Github][Security] Able to brute force API token access
1 parent 3f0667b commit cb3f213

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Integration\Cron;
7+
8+
use Magento\Integration\Model\Oauth\Token\RequestLog\WriterInterface as RequestLogWriter;
9+
10+
/**
11+
* Cron class for clearing log of outdated token request authentication failures.
12+
*/
13+
class CleanExpiredAuthenticationFailures
14+
{
15+
/**
16+
* @var RequestLogWriter
17+
*/
18+
private $requestLogWriter;
19+
20+
/**
21+
* Initialize dependencies.
22+
*
23+
* @param RequestLogWriter $requestLogWriter
24+
*/
25+
public function __construct(
26+
RequestLogWriter $requestLogWriter
27+
) {
28+
$this->requestLogWriter = $requestLogWriter;
29+
}
30+
31+
/**
32+
* Clearing log of outdated token request authentication failures.
33+
*
34+
* @return void
35+
*/
36+
public function execute()
37+
{
38+
$this->requestLogWriter->clearExpiredFailures();
39+
}
40+
}

app/code/Magento/Integration/Model/CustomerTokenService.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Integration\Model\Oauth\TokenFactory as TokenModelFactory;
1414
use Magento\Integration\Model\ResourceModel\Oauth\Token\CollectionFactory as TokenCollectionFactory;
1515
use Magento\Integration\Model\Oauth\Token\RequestThrottler;
16+
use Magento\Framework\Exception\AuthenticationException;
1617

1718
class CustomerTokenService implements \Magento\Integration\Api\CustomerTokenServiceInterface
1819
{
@@ -78,7 +79,9 @@ public function createCustomerAccessToken($username, $password)
7879
$customerDataObject = $this->accountManagement->authenticate($username, $password);
7980
} catch (\Exception $e) {
8081
$this->getRequestThrottler()->logAuthenticationFailure($username, RequestThrottler::USER_TYPE_CUSTOMER);
81-
throw $e;
82+
throw new AuthenticationException(
83+
__('You did not sign in correctly or your account is temporarily disabled.')
84+
);
8285
}
8386
$this->getRequestThrottler()->resetAuthenticationFailuresCount($username, RequestThrottler::USER_TYPE_CUSTOMER);
8487
return $this->tokenModelFactory->create()->createCustomerToken($customerDataObject->getId())->getToken();

app/code/Magento/Integration/Model/Oauth/Token/RequestThrottler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public function throttle($userName, $userType)
6666
{
6767
$count = $this->requestLogReader->getFailuresCount($userName, $userType);
6868
if ($count >= $this->requestLogConfig->getMaxFailuresCount()) {
69-
throw new AuthenticationException(__('Provided credentials are invalid or user account is locked.'));
69+
throw new AuthenticationException(
70+
__('You did not sign in correctly or your account is temporarily disabled.')
71+
);
7072
}
7173
}
7274

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
9+
<group id="default">
10+
<job name="outdated_authentication_failures_cleanup" instance="Magento\Integration\Cron\CleanExpiredAuthenticationFailures" method="execute">
11+
<schedule>0 1 * * *</schedule>
12+
</job>
13+
</group>
14+
</config>

0 commit comments

Comments
 (0)