Add csrf token check, destroy session on timeout

This commit is contained in:
billz 2025-01-22 00:11:22 -08:00
parent 50ed5f9f4b
commit ec0dd304ee
2 changed files with 7 additions and 1 deletions

5
ajax/session/do_check_session.php Normal file → Executable file
View File

@ -10,6 +10,11 @@ $lastActivity = $_SESSION['lastActivity'] ?? time();
$sessionLifetime = time() - $lastActivity;
$status = $sessionLifetime >= RASPI_SESSION_TIMEOUT ? 'session_expired' : 'active';
if ($status = 'session_expired') {
session_unset(); // unset all session variables
session_destroy(); // destroy the session
}
// send response
header('Content-Type: application/json');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');

View File

@ -678,7 +678,8 @@ function checkSession() {
if (window.location.pathname === '/login') {
return;
}
$.get('ajax/session/do_check_session.php', function (data) {
var csrfToken = $('meta[name=csrf_token]').attr('content');
$.post('ajax/session/do_check_session.php',{'csrf_token': csrfToken},function (data) {
if (data.status === 'session_expired') {
clearInterval(sessionCheckInterval);
showSessionExpiredModal();