]> git.joonet.de Git - adminer.git/commitdiff
Use one token for all
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 8 May 2009 05:13:51 +0000 (05:13 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 8 May 2009 05:13:51 +0000 (05:13 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@601 7c3ca157-0c34-0410-bff1-cbf682f78f5c

_compile.php
auth.inc.php
design.inc.php
functions.inc.php
index.php

index f685f7b21d751c30f7246c318f7cc4afeb0a9b43..c72ff1152c807a76f08d26332400008490bfab4c 100644 (file)
@@ -76,7 +76,7 @@ function short_identifier($number, $chars) {
 
 // Based on Dgx's PHP shrinker
 function php_shrink($input) {
-       $special_variables = array_flip(array('$TOKENS', '$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
+       $special_variables = array_flip(array('$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
        static $short_variables = array();
        $shortening = true;
        $special_functions = array_flip(array('Min_MySQLi', 'Min_MySQLResult', '__construct'));
index 5db786deca443dea1576d4755a52e4ad83366f73..7a92b16f69692e37e1ea90cf11882ff8d80c192d 100644 (file)
@@ -8,6 +8,7 @@ if (isset($_POST["server"])) {
                session_regenerate_id();
                $_SESSION["usernames"][$_POST["server"]] = $_POST["username"];
                $_SESSION["passwords"][$_POST["server"]] = $_POST["password"];
+               $_SESSION["tokens"][$_POST["server"]] = rand(1, 1e6);
                if (count($_POST) == count($ignore)) {
                        $location = ((string) $_GET["server"] === $_POST["server"] ? remove_from_uri() : preg_replace('~^[^?]*/([^?]*).*~', '\\1', $_SERVER["REQUEST_URI"]) . (strlen($_POST["server"]) ? '?server=' . urlencode($_POST["server"]) : ''));
                        if (!isset($_COOKIE[session_name()])) {
@@ -16,10 +17,13 @@ if (isset($_POST["server"])) {
                        header("Location: " . (strlen($location) ? $location : "."));
                        exit;
                }
+               if ($_POST["token"]) {
+                       $_POST["token"] = $_SESSION["tokens"][$_POST["server"]];
+               }
        }
        $_GET["server"] = $_POST["server"];
 } elseif (isset($_POST["logout"])) {
-       if ($_POST["token"] != $_SESSION["tokens"][$_GET["server"]]["?logout"]) {
+       if ($_POST["token"] != $_SESSION["tokens"][$_GET["server"]]) {
                page_header(lang('Logout'), lang('Invalid CSRF token. Send the form again.'));
                page_footer("db");
                exit;
@@ -27,7 +31,7 @@ if (isset($_POST["server"])) {
                unset($_SESSION["usernames"][$_GET["server"]]);
                unset($_SESSION["passwords"][$_GET["server"]]);
                unset($_SESSION["databases"][$_GET["server"]]);
-               $_SESSION["tokens"][$_GET["server"]] = array();
+               unset($_SESSION["tokens"][$_GET["server"]]);
                redirect(substr($SELF, 0, -1), lang('Logout successful.'));
        }
 }
@@ -35,9 +39,6 @@ if (isset($_POST["server"])) {
 function auth_error() {
        global $ignore;
        $username = $_SESSION["usernames"][$_GET["server"]];
-       if ($_POST["token"] && !isset($username)) {
-               $_POST["token"] = token();
-       }
        unset($_SESSION["usernames"][$_GET["server"]]);
        page_header(lang('Login'), (isset($username) ? lang('Invalid credentials.') : (isset($_POST["server"]) ? lang('Sessions must be enabled.') : ($_POST ? lang('Session expired, please login again.') : ""))), null);
        ?>
index 06b1eefcd3cd6ad2cc6f0484d6ac4221fe795d2b..41a92741d962281afc2d9cb8541d88ac5e30c179 100644 (file)
@@ -9,7 +9,7 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta http-equiv="Content-Script-Type" content="text/javascript" />
 <meta name="robots" content="noindex" />
-<title><?php echo $title . (strlen($title2) ? ": " . htmlspecialchars($title2) : "") . " - " . lang('phpMinAdmin') . " 1.10.1-dev"; ?></title>
+<title><?php echo $title . (strlen($title2) ? ": " . htmlspecialchars($title2) : "") . " - " . lang('phpMinAdmin') . " 1.10.2-dev"; ?></title>
 <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
 <link rel="stylesheet" type="text/css" href="<?php echo (file_exists("phpMinAdmin.css") ? "phpMinAdmin.css" : "default.css"); // Ondrej Valka, http://valka.info ?>" />
 </head>
@@ -46,9 +46,6 @@ function toggle(id) {
                echo "<p class='message'>" . implode("</p>\n<p class='message'>", $_SESSION["messages"]) . "</p>\n";
                $_SESSION["messages"] = array();
        }
-       if (!$_SESSION["tokens"][$_GET["server"]]["?logout"]) {
-               $_SESSION["tokens"][$_GET["server"]]["?logout"] = rand(1, 1e6);
-       }
        $databases = &$_SESSION["databases"][$_GET["server"]];
        if (strlen($_GET["db"]) && $databases && !in_array($_GET["db"], $databases, true)) {
                $databases = null;
@@ -74,7 +71,7 @@ function page_footer($missing = false) {
 <p>
 <a href="<?php echo htmlspecialchars($SELF); ?>sql="><?php echo lang('SQL command'); ?></a>
 <a href="<?php echo htmlspecialchars($SELF); ?>dump=<?php echo urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]); ?>"><?php echo lang('Dump'); ?></a>
-<input type="hidden" name="token" value="<?php echo $_SESSION["tokens"][$_GET["server"]]["?logout"]; ?>" />
+<input type="hidden" name="token" value="<?php echo $_SESSION["tokens"][$_GET["server"]]; ?>" />
 <input type="submit" name="logout" value="<?php echo lang('Logout'); ?>" />
 </p>
 </form>
index 83d324ed93c1c04c83eee6af33d882394bb0d6fb..c5a01df12ba34e597db842fd6fed41c7cfc1b9ab 100644 (file)
@@ -183,23 +183,10 @@ function collations() {
        return $return;
 }
 
-function token() {
-       return ($GLOBALS["TOKENS"][] = rand(1, 1e6));
-}
-
-function token_delete() {
-       if ($_POST["token"] && ($pos = array_search($_POST["token"], (array) $GLOBALS["TOKENS"])) !== false) {
-               unset($GLOBALS["TOKENS"][$pos]);
-               return true;
-       }
-       return false;
-}
-
 function redirect($location, $message = null) {
        if (isset($message)) {
                $_SESSION["messages"][] = $message;
        }
-       token_delete();
        if (strlen(SID)) {
                $location .= (strpos($location, "?") === false ? "?" : "&") . SID;
        }
index e213d7ff93816d8ae4e4c6b9f579365c7564cf84..3e8d8814d76352a7c34f6b2ee35d84face3dc867 100644 (file)
--- a/index.php
+++ b/index.php
@@ -45,7 +45,6 @@ if (get_magic_quotes_gpc()) {
 }
 set_magic_quotes_runtime(false);
 $SELF = preg_replace('~^[^?]*/([^?]*).*~', '\\1?', $_SERVER["REQUEST_URI"]) . (strlen($_GET["server"]) ? 'server=' . urlencode($_GET["server"]) . '&' : '') . (strlen($_GET["db"]) ? 'db=' . urlencode($_GET["db"]) . '&' : '');
-$TOKENS = &$_SESSION["tokens"][$_GET["server"]][$_SERVER["REQUEST_URI"]];
 
 include "./functions.inc.php";
 include "./lang.inc.php";
@@ -88,14 +87,14 @@ if (isset($_GET["download"])) {
        } elseif (isset($_GET["privileges"])) {
                include "./privileges.inc.php";
        } else { // uses CSRF token
+               $token = $_SESSION["tokens"][$_GET["server"]];
                if ($_POST) {
-                       if (!in_array($_POST["token"], (array) $TOKENS)) {
+                       if ($_POST["token"] != $token) {
                                $error = lang('Invalid CSRF token. Send the form again.');
                        }
                } elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
                        $error = lang('Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.');
                }
-               $token = ($_POST && !$error ? $_POST["token"] : token());
                if (isset($_GET["default"])) {
                        $_GET["edit"] = $_GET["default"];
                }