Skip to content

Commit

Permalink
Update Firewall.php
Browse files Browse the repository at this point in the history
  • Loading branch information
mlantz committed Nov 3, 2023
1 parent 2320c84 commit 2d54fa1
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/Middleware/Firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,37 @@ public function handle($request, Closure $next)
if (! $session->get('mission-control.validated-actor')) {
$session->put('mission-control.ip', $ipAddress);

[$ip, $geo] = $service->lookup($ipAddress);
try {
[$ip, $geo] = $service->lookup($ipAddress);

if (! $session->get('mission-control.valid-ip') && $ip) {
// ip is whitelisted, or they are not in the blacklist
$session->put('mission-control.valid-ip', true);
}
if (! $session->get('mission-control.valid-ip') && $ip) {
// ip is whitelisted, or they are not in the blacklist
$session->put('mission-control.valid-ip', true);
}

if (! $session->get('mission-control.valid-geo') && $geo) {
// geo is good (not in a blocked country)
$session->put('mission-control.valid-geo', true);
}
if (! $session->get('mission-control.valid-geo') && $geo) {
// geo is good (not in a blocked country)
$session->put('mission-control.valid-geo', true);
}

// If any checks fail then set as bad actor.
foreach (['geo', 'ip'] as $check) {
if (! $session->get("mission-control.valid-{$check}")) {
$threat = $service->recordThreat("invalid-{$check}", $request->input());
$session->put('mission-control.bad-actor', true);
}
}

// If any checks fail then set as bad actor.
foreach (['geo', 'ip'] as $check) {
if (! $session->get("mission-control.valid-{$check}")) {
$threat = $service->recordThreat("invalid-{$check}", $request->input());
// is a malcious action
if ($malicious = $service->isMalicious($request)) {
$threat = $malicious;
$session->put('mission-control.bad-actor', true);
}
}

// is a malcious action
if ($malicious = $service->isMalicious($request)) {
$threat = $malicious;
$session->put('mission-control.bad-actor', true);
$session->put('mission-control.validated-actor', true);
} catch (\Throwable $th) {
logger('Firewall: '.$th->getMessage());
}

$session->put('mission-control.validated-actor', true);
}

if (! is_null($threat) && is_array($threat) && $session->get('mission-control.bad-actor')) {
Expand Down

0 comments on commit 2d54fa1

Please sign in to comment.