CSRF Token

Upon login, issue the user a CSRF token (in their session). This token should be provided when completing sensitive actions (e.g. deleting companies/clients, changing their password, etc.)

Ref: https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#synchronizer-token-pattern
This commit is contained in:
Marcus Hill
2022-05-01 18:43:53 +01:00
parent eee7c0b204
commit 61777116a9
9 changed files with 42 additions and 4 deletions

View File

@@ -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 <strong>$company_name</strong> 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