bug #2063100 Unknown column Event_priv
[phpmyadmin/crack.git] / libraries / grab_globals.lib.php
blob72a63e56b2c14103093c182c8dc9837b0ad63336
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * This library grabs the names and values of the variables sent or posted to a
5 * script in $_GET, $_POST and $_FILES superglobals and sets simple globals
6 * variables from them. It does the same work for $HTTP_ACCEPT_LANGUAGE and
7 * $HTTP_AUTHORIZATION.
9 * @version $Id$
11 if (! defined('PHPMYADMIN')) {
12 exit;
15 /**
16 * copy values from one array to another, usually from a superglobal into $GLOBALS
18 * @uses $GLOBALS['_import_blacklist']
19 * @uses preg_replace()
20 * @uses array_keys()
21 * @uses array_unique()
22 * @uses stripslashes()
23 * @param array $array values from
24 * @param array $target values to
25 * @param boolean $sanitize prevent importing key names in $_import_blacklist
27 function PMA_recursive_extract($array, &$target, $sanitize = true)
29 if (! is_array($array)) {
30 return false;
33 if ($sanitize) {
34 $valid_variables = preg_replace($GLOBALS['_import_blacklist'], '',
35 array_keys($array));
36 $valid_variables = array_unique($valid_variables);
37 } else {
38 $valid_variables = array_keys($array);
41 foreach ($valid_variables as $key) {
43 if (strlen($key) === 0) {
44 continue;
47 if (is_array($array[$key])) {
48 // there could be a variable coming from a cookie of
49 // another application, with the same name as this array
50 unset($target[$key]);
52 PMA_recursive_extract($array[$key], $target[$key], false);
53 } else {
54 $target[$key] = $array[$key];
57 return true;
61 /**
62 * @var array $_import_blacklist variable names that should NEVER be imported
63 * from superglobals
65 $_import_blacklist = array(
66 '/^cfg$/i', // PMA configuration
67 '/^server$/i', // selected server
68 '/^db$/i', // page to display
69 '/^table$/i', // page to display
70 '/^goto$/i', // page to display
71 '/^back$/i', // the page go back
72 '/^lang$/i', // selected language
73 '/^convcharset$/i', // PMA convert charset
74 '/^collation_connection$/i', //
75 '/^set_theme$/i', //
76 '/^sql_query$/i', // the query to be executed
77 '/^GLOBALS$/i', // the global scope
78 '/^str.*$/i', // PMA localized strings
79 '/^error_handler.*$/i', // the error handler
80 '/^_.*$/i', // PMA does not use variables starting with _ from extern
81 '/^.*\s+.*$/i', // no whitespaces anywhere
82 '/^[0-9]+.*$/i', // numeric variable names
83 //'/^PMA_.*$/i', // other PMA variables
86 if (! empty($_GET)) {
87 PMA_recursive_extract($_GET, $GLOBALS);
90 if (! empty($_POST)) {
91 PMA_recursive_extract($_POST, $GLOBALS);
94 if (! empty($_FILES)) {
95 $_valid_variables = preg_replace($GLOBALS['_import_blacklist'], '', array_keys($_FILES));
96 foreach ($_valid_variables as $name) {
97 if (strlen($name) != 0) {
98 $$name = $_FILES[$name]['tmp_name'];
99 ${$name . '_name'} = $_FILES[$name]['name'];
102 unset($name, $value);
106 * globalize some environment variables
108 $server_vars = array('HTTP_ACCEPT_LANGUAGE', 'HTTP_AUTHORIZATION');
109 foreach ($server_vars as $current) {
110 // it's not important HOW we detect html tags
111 // it's more important to prevent XSS
112 // so it's not important if we result in an invalid string,
113 // it's even better than a XSS capable string
114 if (PMA_getenv($current) && false === strpos(PMA_getenv($current), '<')) {
115 $$current = PMA_getenv($current);
116 // already imported by register_globals?
117 } elseif (! isset($$current) || false !== strpos($$current, '<')) {
118 $$current = '';
121 unset($server_vars, $current, $_import_blacklist);