Skip to content
Browse files

Use one token for all

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@601 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 55a12f4 commit 815eb26e571d9aa652120cbb1c03170006065b86 jakubvrana committed May 8, 2009
Showing with 11 additions and 27 deletions.
  1. +1 −1 _compile.php
  2. +6 −5 auth.inc.php
  3. +2 −5 design.inc.php
  4. +0 −13 functions.inc.php
  5. +2 −3 index.php
View
2 _compile.php
@@ -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'));
View
11 auth.inc.php
@@ -8,6 +8,7 @@
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,28 +17,28 @@
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;
} else {
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.'));
}
}
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);
?>
View
7 design.inc.php
@@ -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>
View
13 functions.inc.php
@@ -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;
}
View
5 index.php
@@ -45,7 +45,6 @@ function save_coverage() {
}
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 @@ function save_coverage() {
} 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"];
}

0 comments on commit 815eb26

Please sign in to comment.
Something went wrong with that request. Please try again.