Skip to content

Commit

Permalink
Security - validate session
Browse files Browse the repository at this point in the history
  • Loading branch information
markjcrane committed Jan 22, 2024
1 parent fb6e1df commit 2f8bed3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion core/authentication/resources/classes/authentication.php
Expand Up @@ -229,6 +229,9 @@ public function validate() {
$_SESSION["user_uuid"] = $result["user_uuid"];
$_SESSION["context"] = $result['domain_name'];

//used to validate the session
$_SESSION["user_hash"] = hash('sha256', $_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT']);

//user session array
$_SESSION["user"]["domain_uuid"] = $result["domain_uuid"];
$_SESSION["user"]["domain_name"] = $result["domain_name"];
Expand Down Expand Up @@ -266,7 +269,7 @@ public function validate() {
}
}

//get the permissions assigned to the groups that the user is a member of set the permissions in $_SESSION['permissions']
//get the permissions assigned to the groups that the user is a member of set the permissions in $_SESSION['permissions']
if (is_array($_SESSION["groups"]) && @sizeof($_SESSION["groups"]) != 0) {
$x = 0;
$sql = "select distinct(permission_name) from v_group_permissions ";
Expand Down
15 changes: 13 additions & 2 deletions resources/check_auth.php
Expand Up @@ -42,8 +42,19 @@
//define variables
if (!isset($_SESSION['template_content'])) { $_SESSION["template_content"] = null; }

//if session authorized is not set then set the default value to false
if (!isset($_SESSION['authorized'])) {
$_SESSION['authorized'] = false;
}

//validate the session address
if ($_SESSION['authorized'] && $_SESSION["user_hash"] !== hash('sha256', $_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT'])) {
session_destroy();
header("Location: ".PROJECT_PATH."/?path=".urlencode($target_path));
}

//if the session is not authorized then verify the identity
if (!isset($_SESSION['authorized']) || (isset($_SESSION['authorized']) && !$_SESSION['authorized'])) {
if (!$_SESSION['authorized']) {

//clear the menu
unset($_SESSION["menu"]);
Expand Down Expand Up @@ -98,4 +109,4 @@

}

?>
?>

0 comments on commit 2f8bed3

Please sign in to comment.