improved too many emails for firewall
This commit is contained in:
parent
09ee5a667c
commit
8b305a94c3
@ -5,7 +5,6 @@ namespace App\Listeners\Email;
|
|||||||
use Akaunting\Firewall\Events\AttackDetected;
|
use Akaunting\Firewall\Events\AttackDetected;
|
||||||
use Akaunting\Firewall\Traits\Helper;
|
use Akaunting\Firewall\Traits\Helper;
|
||||||
use App\Events\Email\TooManyEmailsSent as Event;
|
use App\Events\Email\TooManyEmailsSent as Event;
|
||||||
use Illuminate\Support\Facades\Config;
|
|
||||||
|
|
||||||
class TellFirewallTooManyEmailsSent
|
class TellFirewallTooManyEmailsSent
|
||||||
{
|
{
|
||||||
@ -17,9 +16,7 @@ class TellFirewallTooManyEmailsSent
|
|||||||
$this->middleware = 'too_many_emails_sent';
|
$this->middleware = 'too_many_emails_sent';
|
||||||
$this->user_id = $event->user_id;
|
$this->user_id = $event->user_id;
|
||||||
|
|
||||||
$this->loadConfig();
|
if ($this->skip()) {
|
||||||
|
|
||||||
if ($this->skip($event)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,40 +25,7 @@ class TellFirewallTooManyEmailsSent
|
|||||||
event(new AttackDetected($log));
|
event(new AttackDetected($log));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadConfig(): void
|
public function skip(): bool
|
||||||
{
|
|
||||||
if (! empty(Config::get('firewall.middleware.' . $this->middleware))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$config = array_merge_recursive(
|
|
||||||
Config::get('firewall'),
|
|
||||||
[
|
|
||||||
'middleware' => [
|
|
||||||
$this->middleware => [
|
|
||||||
'enabled' => env('FIREWALL_MIDDLEWARE_' . strtoupper($this->middleware) . '_ENABLED', Config::get('firewall.enabled', true)),
|
|
||||||
|
|
||||||
'methods' => ['post'],
|
|
||||||
|
|
||||||
'routes' => [
|
|
||||||
'only' => [], // i.e. 'contact'
|
|
||||||
'except' => [], // i.e. 'admin/*'
|
|
||||||
],
|
|
||||||
|
|
||||||
'auto_block' => [
|
|
||||||
'attempts' => env('FIREWALL_MIDDLEWARE_' . strtoupper($this->middleware) . '_AUTO_BLOCK_ATTEMPTS', 20),
|
|
||||||
'frequency' => 1 * 60, // 1 minute
|
|
||||||
'period' => 30 * 60, // 30 minutes
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
Config::set('firewall', $config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function skip($event): bool
|
|
||||||
{
|
{
|
||||||
if ($this->isDisabled()) {
|
if ($this->isDisabled()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -436,6 +436,24 @@ return [
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// Custom middleware
|
||||||
|
'too_many_emails_sent' => [
|
||||||
|
'enabled' => env('FIREWALL_MIDDLEWARE_TOO_MANY_EMAILS_SENT_ENABLED', env('FIREWALL_ENABLED', true)),
|
||||||
|
|
||||||
|
'methods' => ['post'],
|
||||||
|
|
||||||
|
'routes' => [
|
||||||
|
'only' => [], // i.e. 'contact'
|
||||||
|
'except' => [], // i.e. 'admin/*'
|
||||||
|
],
|
||||||
|
|
||||||
|
'auto_block' => [
|
||||||
|
'attempts' => env('FIREWALL_MIDDLEWARE_TOO_MANY_EMAILS_SENT_AUTO_BLOCK_ATTEMPTS', 20),
|
||||||
|
'frequency' => 1 * 60, // 1 minute
|
||||||
|
'period' => 30 * 60, // 30 minutes
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
@ -11,7 +11,7 @@ class TooManyEmailsSentTest extends FeatureTestCase
|
|||||||
{
|
{
|
||||||
$this->loginAs();
|
$this->loginAs();
|
||||||
|
|
||||||
config(['firewall.enabled' => true]);
|
config(['firewall.middleware.too_many_emails_sent.enabled' => true]);
|
||||||
|
|
||||||
for ($i = 0; $i < 19; $i++) {
|
for ($i = 0; $i < 19; $i++) {
|
||||||
event(new TooManyEmailsSent(user_id()));
|
event(new TooManyEmailsSent(user_id()));
|
||||||
@ -31,7 +31,7 @@ class TooManyEmailsSentTest extends FeatureTestCase
|
|||||||
{
|
{
|
||||||
$this->loginAs();
|
$this->loginAs();
|
||||||
|
|
||||||
config(['firewall.enabled' => true]);
|
config(['firewall.middleware.too_many_emails_sent.enabled' => true]);
|
||||||
|
|
||||||
for ($i = 0; $i < 20; $i++) {
|
for ($i = 0; $i < 20; $i++) {
|
||||||
event(new TooManyEmailsSent(user_id()));
|
event(new TooManyEmailsSent(user_id()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user