mirror of
https://github.com/hyzendust/freedoms4-backend-public.git
synced 2026-09-19 10:43:06 +02:00
Fix: auto-logout sessions + another minor hardening
This commit is contained in:
10
comments.php
10
comments.php
@@ -84,6 +84,7 @@ function db_connect(): PDO {
|
||||
|
||||
function start_session(): void {
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
ini_set('session.gc_maxlifetime', (string) SESSION_TTL);
|
||||
session_name(SESSION_NAME);
|
||||
session_set_cookie_params([
|
||||
'lifetime' => 0,
|
||||
@@ -171,6 +172,15 @@ function send_notification(string $type, string $actor, string $body, string $po
|
||||
|
||||
function logged_in_user(): ?array {
|
||||
if (empty($_SESSION['user_id']) || empty($_SESSION['username'])) return null;
|
||||
|
||||
// Enforce same TTL as auth.php
|
||||
$last_seen = $_SESSION['last_seen'] ?? 0;
|
||||
if (time() - $last_seen > SESSION_TTL) {
|
||||
$_SESSION = [];
|
||||
session_destroy();
|
||||
return null;
|
||||
}
|
||||
|
||||
// Verify the user still exists in the DB (handles deleted accounts / wiped DB)
|
||||
try {
|
||||
$pdo = db_connect();
|
||||
|
||||
Reference in New Issue
Block a user