|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of Biurad opensource projects. |
|
7
|
|
|
* |
|
8
|
|
|
* PHP version 7.4 and above required |
|
9
|
|
|
* |
|
10
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
|
11
|
|
|
* @copyright 2019 Biurad Group (https://biurad.com/) |
|
12
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause License |
|
13
|
|
|
* |
|
14
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
15
|
|
|
* file that was distributed with this source code. |
|
16
|
|
|
* |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Biurad\Security\RateLimiter; |
|
20
|
|
|
|
|
21
|
|
|
use Biurad\Http\Request as HttpRequest; |
|
22
|
|
|
use Biurad\Security\Helper; |
|
23
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
24
|
|
|
use Symfony\Component\RateLimiter\RateLimiterFactory; |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* A default login throttling limiter. |
|
28
|
|
|
* |
|
29
|
|
|
* This limiter prevents breadth-first attacks by enforcing |
|
30
|
|
|
* a limit on username+IP and a (higher) limit on IP. |
|
31
|
|
|
* |
|
32
|
|
|
* @author Wouter de Jong <[email protected]> |
|
33
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
|
34
|
|
|
*/ |
|
35
|
|
|
final class DefaultLoginRateLimiter extends AbstractRequestRateLimiter |
|
36
|
|
|
{ |
|
37
|
|
|
private RateLimiterFactory $globalFactory; |
|
38
|
|
|
private RateLimiterFactory $localFactory; |
|
39
|
|
|
private string $userParameter; |
|
40
|
|
|
|
|
41
|
|
|
public function __construct(RateLimiterFactory $globalFactory, RateLimiterFactory $localFactory, string $userId = '_identifier') |
|
42
|
|
|
{ |
|
43
|
|
|
$this->globalFactory = $globalFactory; |
|
44
|
|
|
$this->localFactory = $localFactory; |
|
45
|
|
|
$this->userParameter = $userId; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
protected function getLimiters(ServerRequestInterface $request): array |
|
49
|
|
|
{ |
|
50
|
|
|
if ($request instanceof HttpRequest) { |
|
51
|
|
|
$ip = $request->getRequest()->getClientIp(); |
|
52
|
|
|
$username = $request->getRequest()->get($this->userParameter); |
|
53
|
|
|
} else { |
|
54
|
|
|
$username = Helper::getParameterValue($request, $this->userParameter); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$limiters = [$this->globalFactory->create($ip ?? $request->getServerParams()['REMOTE_ADDR'])]; |
|
58
|
|
|
|
|
59
|
|
|
if (!empty($username)) { |
|
60
|
|
|
$username = \preg_match('//u', $username) ? \mb_strtolower($username, 'UTF-8') : \strtolower($username); |
|
61
|
|
|
$limiters[] = $this->localFactory->create($username . '-' . $ip ?? $request->getServerParams()['REMOTE_ADDR']); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $limiters; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths