From edb815973a4359c05d9ad1ae85706b79b128487e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Mon, 19 Sep 2022 16:06:41 +0200 Subject: [PATCH] Check user is still valid on session validity check --- src/Session.php | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/Session.php b/src/Session.php index fb80f68e1b1..4b620115af1 100644 --- a/src/Session.php +++ b/src/Session.php @@ -863,6 +863,7 @@ public static function redirectIfNotLoggedIn() **/ public static function checkValidSessionId() { + global $DB; if ( !isset($_SESSION['valid_id']) @@ -870,10 +871,53 @@ public static function checkValidSessionId() ) { Html::redirectToLogin('error=3'); } + + $user_id = self::getLoginUserID(); + $profile_id = $_SESSION['glpiactiveprofile']['id'] ?? null; + $entity_id = $_SESSION['glpiactive_entity'] ?? null; + + $valid_user = true; + + if (!is_numeric($user_id) || $profile_id === null || $entity_id === null) { + $valid_user = false; + } else { + $user_table = User::getTable(); + $pu_table = Profile_User::getTable(); + $result = $DB->request( + [ + 'COUNT' => 'count', + 'FROM' => $user_table, + 'LEFT JOIN' => [ + $pu_table => [ + 'FKEY' => [ + Profile_User::getTable() => 'users_id', + $user_table => 'id' + ] + ] + ], + 'WHERE' => [ + $user_table . '.id' => $user_id, + $user_table . '.is_active' => 1, + $user_table . '.is_deleted' => 0, + $pu_table . '.profiles_id' => $profile_id, + $pu_table . '.entities_id' => $entity_id, + ], + ] + ); + if ($result->current()['count'] === 0) { + $valid_user = false; + } + } + + if (!$valid_user) { + Session::destroy(); + Auth::setRememberMeCookie(''); + Html::redirectToLogin(); + } + return true; } - /** * Check if I have access to the central interface *