Skip to content

Commit 7534e48

Browse files
committed
feat: add action_by and environment to privilege escalation email
Signed-off-by: romanetar <roman_ag@hotmail.com>
1 parent 0678685 commit 7534e48

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

app/Mail/MonitoredSecurityGroupNotificationEmail.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ final class MonitoredSecurityGroupNotificationEmail extends Mailable
3434
*/
3535
public $action;
3636

37+
/**
38+
* @var string
39+
*/
40+
public $action_by;
41+
3742
/**
3843
* @var int
3944
*/
@@ -79,6 +84,7 @@ final class MonitoredSecurityGroupNotificationEmail extends Mailable
7984
/**
8085
* @param string $email
8186
* @param string $action
87+
* @param string $action_by
8288
* @param int $user_id
8389
* @param string $user_email
8490
* @param string $user_name
@@ -90,6 +96,7 @@ public function __construct
9096
(
9197
string $email,
9298
string $action,
99+
string $action_by,
93100
int $user_id,
94101
string $user_email,
95102
string $user_name,
@@ -100,6 +107,7 @@ public function __construct
100107
{
101108
$this->email = $email;
102109
$this->action = $action;
110+
$this->action_by = $action_by;
103111
$this->user_id = $user_id;
104112
$this->user_email = $user_email;
105113
$this->user_name = $user_name;
@@ -111,9 +119,10 @@ public function __construct
111119
(
112120
sprintf
113121
(
114-
"MonitoredSecurityGroupNotificationEmail::constructor email %s action %s user_id %s user_email %s user_name %s group_id %s group_name %s group_slug %s",
122+
"MonitoredSecurityGroupNotificationEmail::constructor email %s action %s action_by %s user_id %s user_email %s user_name %s group_id %s group_name %s group_slug %s",
115123
$email,
116124
$action,
125+
$action_by,
117126
$user_id,
118127
$user_email,
119128
$user_name,
@@ -126,15 +135,19 @@ public function __construct
126135

127136
public function build()
128137
{
138+
$action_by_phrase = $this->action_by ? " by $this->action_by" : "";
139+
129140
$this->subject = sprintf
130141
(
131-
"[%s] Monitored Security Groups - User %s (%s) has been %s - Group %s (%s)"
142+
"[%s] Monitored Security Groups - User %s (%s) has been %s%s - Group %s (%s) - Environment: %s"
132143
,Config::get('app.app_name')
133144
,$this->user_name
134145
,$this->user_email
135146
,$this->action
147+
,$action_by_phrase
136148
,$this->group_name
137149
,$this->group_id
150+
,Config::get('app.env')
138151
);
139152
Log::debug(sprintf("MonitoredSecurityGroupNotificationEmail::build to %s", $this->email));
140153
return $this->from(Config::get("mail.from"))

app/Services/OpenId/UserService.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
use Illuminate\Support\Facades\Storage;
3838
use models\exceptions\EntityNotFoundException;
3939
use models\exceptions\ValidationException;
40-
use Models\OAuth2\Client;
4140
use models\utils\IEntity;
4241
use OAuth2\IResourceServerContext;
4342
use OAuth2\Models\IClient;
@@ -483,6 +482,14 @@ public function notifyMonitoredSecurityGroupActivity(string $action, int $user_i
483482
return;
484483
}
485484

485+
$action_by = '';
486+
$current_user = !empty($this->server_ctx->getCurrentUserId()) ?
487+
$this->repository->getById($this->server_ctx->getCurrentUserId()) : null;
488+
489+
if (!is_null($current_user)) {
490+
$action_by = sprintf("%s %s", $current_user->getFirstName(), $current_user->getLastName());
491+
}
492+
486493
$notified_users = [];
487494
foreach ($watcher_groups as $watcher_group_slug) {
488495
Log::debug(sprintf("UserService::notifyMonitoredSecurityGroupActivity processing %s", $watcher_group_slug));
@@ -504,6 +511,7 @@ public function notifyMonitoredSecurityGroupActivity(string $action, int $user_i
504511
(
505512
$user->getEmail(),
506513
$action,
514+
$action_by,
507515
$user_id,
508516
$user_email,
509517
$user_name,
@@ -514,6 +522,5 @@ public function notifyMonitoredSecurityGroupActivity(string $action, int $user_i
514522
);
515523
}
516524
}
517-
518525
}
519526
}

0 commit comments

Comments
 (0)