Skip to content

Commit 215ad0d

Browse files
author
Miguel Angel
committed
fix: run session control kill when browser cache is enabled
1 parent c1c10ba commit 215ad0d

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

ProcessMaker/Http/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Kernel extends HttpKernel
3434
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
3535
\ProcessMaker\Http\Middleware\SessionStarted::class,
3636
\ProcessMaker\Http\Middleware\AuthenticateSession::class,
37+
\ProcessMaker\Http\Middleware\SessionControlKill::class,
3738
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
3839
//\ProcessMaker\Http\Middleware\VerifyCsrfToken::class,
3940
\ProcessMaker\Http\Middleware\SetLocale::class, // This is disabled until all routes are handled by our new engine

ProcessMaker/Http/Middleware/SessionControlKill.php

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,27 @@ class SessionControlKill
2525
*/
2626
public function handle(Request $request, Closure $next): Response
2727
{
28-
$user = Auth::user();
29-
$userSession = $request->session()->get('user_session');
30-
31-
if ($userSession) {
32-
$configIP = Setting::configByKey(self::IP_RESTRICTION_KEY);
33-
$configDevice = Setting::configByKey(self::DEVICE_RESTRICTION_KEY);
34-
35-
$session = $this->getActiveSession($user, $userSession);
36-
37-
if ($session) {
38-
// Checks if the session has expired based on the IP address
39-
$isSessionExpiredByIP = $configIP === '2' && $this->isSessionExpiredByIP($session, $request);
40-
// Checks if the session has expired based on the device
41-
$isSessionExpiredByDevice = $configDevice === '2' && $this->isSessionExpiredByDevice($session);
42-
// Checks if the session has expired except the one within the active device
43-
$isAnyRestrictionEnabled = $configIP === '1' || $configDevice === '1';
44-
45-
if ($isSessionExpiredByIP || $isSessionExpiredByDevice || $isAnyRestrictionEnabled) {
46-
return $this->killSessionAndRedirect($session);
28+
if (Auth::check()) {
29+
$user = Auth::user();
30+
$userSession = $request->session()->get('user_session');
31+
32+
if ($userSession) {
33+
$configIP = Setting::configByKey(self::IP_RESTRICTION_KEY);
34+
$configDevice = Setting::configByKey(self::DEVICE_RESTRICTION_KEY);
35+
36+
$session = $this->getActiveSession($user, $userSession);
37+
38+
if ($session) {
39+
// Checks if the session has expired based on the IP address
40+
$isSessionExpiredByIP = $configIP === '2' && $this->isSessionExpiredByIP($session, $request);
41+
// Checks if the session has expired based on the device
42+
$isSessionExpiredByDevice = $configDevice === '2' && $this->isSessionExpiredByDevice($session);
43+
// Checks if the session has expired except the one within the active device
44+
$isAnyRestrictionEnabled = $configIP === '1' || $configDevice === '1';
45+
46+
if ($isSessionExpiredByIP || $isSessionExpiredByDevice || $isAnyRestrictionEnabled) {
47+
return $this->killSessionAndRedirect($session);
48+
}
4749
}
4850
}
4951
}
@@ -57,8 +59,8 @@ private function getActiveSession(User $user, string $userSession): ?UserSession
5759
->where([
5860
['is_active', true],
5961
['token', $userSession],
60-
['expired_date', '!=', null],
6162
])
63+
->whereNotNull('expired_date')
6264
->first();
6365
}
6466

0 commit comments

Comments
 (0)