Updated validateCSRFToken to automatically grab and compare get or post csrf token no longer need to pass an argument to the function which fixed the issue if no hash was present

This commit is contained in:
johnnyq
2026-07-24 13:40:37 -04:00
parent dd358da65d
commit af51c4316f
80 changed files with 519 additions and 517 deletions

View File

@@ -177,9 +177,11 @@ function apiEncryptCredentialEntry(#[\SensitiveParameter]$credential_cleartext,
// 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'])) {
function validateCSRFToken(?string $token = null) {
// Read the token straight from the request when the caller doesn't pass one
$token ??= $_POST['csrf_token'] ?? $_GET['csrf_token'] ?? '';
if ($token !== '' && hash_equals($_SESSION['csrf_token'] ?? '', $token)) {
return true;
} else {
$_SESSION['alert_type'] = "warning";