]> git.wh0rd.org - tt-rss.git/blobdiff - classes/handler/public.php
login: check for stale session in login handler, instead of authenticate_user()
[tt-rss.git] / classes / handler / public.php
old mode 100644 (file)
new mode 100755 (executable)
index 8440bc3..38a8d74
@@ -465,6 +465,14 @@ class Handler_Public extends Handler {
 
        function login() {
                if (!SINGLE_USER_MODE) {
+                       /* if a session is started here there's a stale login cookie we need to clean */
+
+                       if (session_status() != PHP_SESSION_NONE) {
+                               $_SESSION["login_error_msg"] = __("Stale session cookie found, try logging in again");
+
+                               header("Location: " . get_self_url_prefix());
+                               exit;
+                       }
 
                        $login = clean($_POST["login"]);
                        $password = clean($_POST["password"]);
@@ -476,8 +484,6 @@ class Handler_Public extends Handler {
                                session_set_cookie_params(0);
                        }
 
-                       @session_start();
-
                        if (authenticate_user($login, $password)) {
                                $_POST["password"] = "";
 
@@ -501,7 +507,13 @@ class Handler_Public extends Handler {
                                        }
                                }
                        } else {
-                               $_SESSION["login_error_msg"] = __("Incorrect username or password");
+
+                               // start an empty session to deliver login error message
+                               @session_start();
+
+                               if (!isset($_SESSION["login_error_msg"]))
+                                       $_SESSION["login_error_msg"] = __("Incorrect username or password");
+
                                user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING);
                        }
 
@@ -934,17 +946,17 @@ class Handler_Public extends Handler {
        }
 
        function cached_url() {
-               @$hash = basename($_GET['hash']);
+               @$req_filename = basename($_GET['hash']);
 
                // we don't need an extension to find the file, hash is a complete URL
-               $hash = preg_replace("/\.[^\.]*$/", "", $hash);
+               $hash = preg_replace("/\.[^\.]*$/", "", $req_filename);
 
                if ($hash) {
 
                        $filename = CACHE_DIR . '/images/' . $hash;
 
                        if (file_exists($filename)) {
-                               header("Content-Disposition: inline; filename=\"$hash\"");
+                               header("Content-Disposition: inline; filename=\"$req_filename\"");
 
                                send_local_file($filename);