Skip to content

Commit 2ec46ef

Browse files
committed
Log Unauthorized access attempts
1 parent 04b6be4 commit 2ec46ef

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace ProcessMaker\Events;
4+
5+
use Illuminate\Foundation\Events\Dispatchable;
6+
use ProcessMaker\Contracts\SecurityLogEventInterface;
7+
8+
class UnauthorizedAccessAttempt implements SecurityLogEventInterface
9+
{
10+
use Dispatchable;
11+
12+
private array $data;
13+
14+
/**
15+
* Create a new event instance.
16+
*
17+
*/
18+
public function __construct()
19+
{
20+
$this->data = [
21+
'url' => [
22+
'link' => url()->current(),
23+
'label' => url()->current()
24+
]
25+
];
26+
}
27+
28+
public function getChanges(): array
29+
{
30+
return [];
31+
}
32+
33+
public function getData(): array
34+
{
35+
return $this->data;
36+
}
37+
38+
public function getEventName(): string
39+
{
40+
return 'UnauthorizedAccessAttempt';
41+
}
42+
}

‎ProcessMaker/Exception/Handler.php‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
use Illuminate\Routing\Route;
1010
use Illuminate\Support\Arr;
1111
use Illuminate\Support\Facades\App;
12+
use Illuminate\Support\Facades\Auth;
1213
use Illuminate\Support\Facades\Route as RouteFacade;
14+
use ProcessMaker\Events\UnauthorizedAccessAttempt;
1315
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1416
use Throwable;
1517

@@ -47,6 +49,11 @@ public function report(Throwable $exception)
4749
echo $exception->getFile() . ': Line: ' . $exception->getLine() . "\n";
4850
echo $exception;
4951
}
52+
if ($exception instanceof \Illuminate\Auth\Access\AuthorizationException) {
53+
try {
54+
UnauthorizedAccessAttempt::dispatch();
55+
} catch (\Exception $e){}
56+
}
5057
parent::report($exception);
5158
}
5259

‎ProcessMaker/Providers/EventServiceProvider.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class EventServiceProvider extends ServiceProvider
3636
'ProcessMaker\Events\SettingsUpdated' => [
3737
'ProcessMaker\Listeners\SecurityLogger',
3838
],
39+
'ProcessMaker\Events\UnauthorizedAccessAttempt' => [
40+
'ProcessMaker\Listeners\SecurityLogger',
41+
],
3942
];
4043

4144
/**

0 commit comments

Comments
 (0)