|
|
@@ -54,6 +54,9 @@ class Minz_Session {
|
|
|
|
|
|
session_name($name);
|
|
|
|
|
|
+ // A browser session from before FreshRSS 1.29.0
|
|
|
+ $hasDuplicatedCookie = self::hasDuplicatedSessionCookie($name);
|
|
|
+
|
|
|
// Reject an uninitialized (e.g. attacker-supplied) session ID
|
|
|
ini_set('session.use_strict_mode', '1');
|
|
|
|
|
|
@@ -62,6 +65,11 @@ class Minz_Session {
|
|
|
session_write_close();
|
|
|
// Use cookie only the first time the session is started to avoid resending HTTP headers
|
|
|
ini_set('session.use_cookies', '0');
|
|
|
+
|
|
|
+ if ($hasDuplicatedCookie) {
|
|
|
+ // Must be done after session_start(), which replaces the pending Set-Cookie header
|
|
|
+ self::deleteLegacyCookie($name);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -199,14 +207,28 @@ class Minz_Session {
|
|
|
return $cookie_dir;
|
|
|
}
|
|
|
|
|
|
- /** Delete legacy cookie (before 1.29.0) if it exists */
|
|
|
- public static function deleteLegacyCookie(string $name): void {
|
|
|
+ /**
|
|
|
+ * Delete legacy cookie (before 1.29.0) if it exists
|
|
|
+ * @return bool true if the cookie has been expired
|
|
|
+ */
|
|
|
+ public static function deleteLegacyCookie(string $name): bool {
|
|
|
if (isset($_COOKIE[$name])) {
|
|
|
$legacyDir = self::getLegacyCookieDir();
|
|
|
if ($legacyDir !== '' && $legacyDir !== '/') {
|
|
|
setcookie($name, '', ['expires' => 1, 'path' => $legacyDir]);
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Whether the request carries the session cookie twice, which happens when a browser profile
|
|
|
+ * has the legacy cookie next to the current one with two different paths.
|
|
|
+ */
|
|
|
+ protected static function hasDuplicatedSessionCookie(string $name): bool {
|
|
|
+ $header = $_SERVER['HTTP_COOKIE'] ?? null;
|
|
|
+ return is_string($header) && substr_count($header, $name . '=') > 1;
|
|
|
}
|
|
|
|
|
|
/**
|