diff --git a/client_delete_modal.php b/client_delete_modal.php index df047c83..c3edb244 100644 --- a/client_delete_modal.php +++ b/client_delete_modal.php @@ -22,7 +22,7 @@ - Yes, Delete! + Yes, Delete! diff --git a/companies.php b/companies.php index fb71a6b2..614b7c66 100644 --- a/companies.php +++ b/companies.php @@ -101,7 +101,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
Archive - Delete + Delete diff --git a/functions.php b/functions.php index 50f6bad0..7e4006f1 100644 --- a/functions.php +++ b/functions.php @@ -405,4 +405,18 @@ function getDomainExpirationDate($name){ return '0000-00-00'; } +// Cross-Site Request Forgery check for sensitive functions +// Validates the CSRF token provided matches the one in the users session +function validateCSRFToken($token){ + if(hash_equals($token, $_SESSION['csrf_token'])){ + return true; + } + else{ + $_SESSION['alert_type'] = "warning"; + $_SESSION['alert_message'] = "CSRF token verification failed. Try again, or log out to refresh your token."; + header("Location: index.php"); + exit(); + } +} + ?> diff --git a/login.php b/login.php index 1567ab4e..3f013a72 100644 --- a/login.php +++ b/login.php @@ -63,6 +63,9 @@ if(isset($_POST['login'])){ $user_name = $row['user_name']; $user_id = $row['user_id']; + // CSRF Token + $_SESSION['csrf_token'] = keygen(); + // Setup encryption session key if (isset($row['user_specific_encryption_ciphertext']) && $row['user_role'] > 1) { $user_encryption_ciphertext = $row['user_specific_encryption_ciphertext']; diff --git a/post.php b/post.php index 8e4c9ebc..d3263fbe 100644 --- a/post.php +++ b/post.php @@ -58,6 +58,9 @@ if(isset($_POST['add_user'])){ exit(); } + // CSRF Check + validateCSRFToken($_POST['csrf_token']); + $name = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']))); $email = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['email']))); $password = password_hash($_POST['password'], PASSWORD_DEFAULT); @@ -140,6 +143,9 @@ if(isset($_POST['edit_user'])){ exit(); } + // CSRF Check + validateCSRFToken($_POST['csrf_token']); + $user_id = intval($_POST['user_id']); $name = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']))); $email = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['email']))); @@ -238,6 +244,9 @@ if(isset($_POST['edit_profile'])){ exit(); } + // CSRF Check + validateCSRFToken($_POST['csrf_token']); + $user_id = intval($_POST['user_id']); $name = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']))); $email = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['email']))); @@ -375,6 +384,9 @@ if(isset($_GET['archive_user'])){ exit(); } + // CSRF Check + validateCSRFToken($_GET['csrf_token']); + // Variables from GET $user_id = intval($_GET['archive_user']); $password = password_hash(key32gen(), PASSWORD_DEFAULT); @@ -695,6 +707,9 @@ if(isset($_GET['delete_company'])){ exit(); } + // CSRF Check + validateCSRFToken($_GET['csrf_token']); + $company_id = intval($_GET['delete_company']); //Get Company Name @@ -760,7 +775,7 @@ if(isset($_GET['delete_company'])){ $_SESSION['alert_type'] = "danger"; $_SESSION['alert_message'] = "Company $company_name deleted"; - header("Location: logout.php"); + header("Location: post.php?logout"); } @@ -1456,6 +1471,9 @@ if(isset($_GET['delete_client'])){ exit(); } + // CSRF Check + validateCSRFToken($_GET['csrf_token']); + $client_id = intval($_GET['delete_client']); //Get Client Name diff --git a/settings-user.php b/settings-user.php index 695dc40a..147ac6c4 100644 --- a/settings-user.php +++ b/settings-user.php @@ -21,6 +21,7 @@ $sql_recent_logs = mysqli_query($mysqli,"SELECT * FROM logs