From 4951fd1c854d88e22935fd55d342fcb1670dc8e4 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 17 Aug 2010 16:21:37 +0200 Subject: [PATCH 01/19] Fix XSS on delimiter in db_sql.php. --- db_sql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db_sql.php b/db_sql.php index 6c582c3d3981..32d30e406cd4 100644 --- a/db_sql.php +++ b/db_sql.php @@ -36,7 +36,7 @@ /** * Query box, bookmark, insert data from textfile */ -PMA_sqlQueryForm(true, false, isset($_REQUEST['delimiter']) ? $_REQUEST['delimiter'] : ';'); +PMA_sqlQueryForm(true, false, isset($_REQUEST['delimiter']) ? htmlspecialchars($_REQUEST['delimiter']) : ';'); /** * Displays the footer From 110c44a7a3117b94b065742606cc6f7bc05f8cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 17 Aug 2010 16:23:09 +0200 Subject: [PATCH 02/19] Fix XSS on delimiter in tbl_sql.php. --- tbl_sql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tbl_sql.php b/tbl_sql.php index f27a3b9aaad7..f9c71d809185 100644 --- a/tbl_sql.php +++ b/tbl_sql.php @@ -37,7 +37,7 @@ /** * Query box, bookmark, insert data from textfile */ -PMA_sqlQueryForm(true, false, isset($_REQUEST['delimiter']) ? $_REQUEST['delimiter'] : ';'); +PMA_sqlQueryForm(true, false, isset($_REQUEST['delimiter']) ? htmlspecialchars($_REQUEST['delimiter']) : ';'); /** * Displays the footer From 08e27b89077df26a0f7f0390322bbe80e0437aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 17 Aug 2010 16:31:03 +0200 Subject: [PATCH 03/19] Secure handling of sort_by and sort_order in server_databases.php. --- server_databases.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server_databases.php b/server_databases.php index b9b8898b0e43..2b3e0a5de6ce 100644 --- a/server_databases.php +++ b/server_databases.php @@ -287,11 +287,11 @@ unset($column_order, $stat_name, $stat, $databases, $table_columns); if ($is_superuser || $cfg['AllowUserDropDatabase']) { - $common_url_query = PMA_generate_common_url() . '&sort_by=' . $sort_by . '&sort_order=' . $sort_order . '&dbstats=' . $dbstats; + $common_url_query = PMA_generate_common_url(array('sort_by' => $sort_by, 'sort_order' => $sort_order, 'dbstats' => $dbstats)); echo '' . $strWithChecked . '' . "\n" - . '' . "\n" + . '' . "\n" . ' ' . $strCheckAll . ' / ' . "\n" - . '' . "\n" + . '' . "\n" . ' ' . $strUncheckAll . '' . "\n" . '' . $strWithChecked . '' . "\n"; PMA_buttonOrImage('drop_selected_dbs', 'mult_submit', 'drop_selected_dbs', $strDrop, 'b_deltbl.png'); From c910f4c9ec9af876675d96df3fa65d7fc4551cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 17 Aug 2010 16:33:30 +0200 Subject: [PATCH 04/19] Fix handling of unknown sort order. --- libraries/database_interface.lib.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php index 9a40c554b136..b7d122ce4be5 100644 --- a/libraries/database_interface.lib.php +++ b/libraries/database_interface.lib.php @@ -208,6 +208,10 @@ function PMA_usort_comparison_callback($a, $b) } else { $sorter = 'strcasecmp'; } + /* No sorting when key is not present */ + if (!isset($a[$GLOBALS['callback_sort_by']]) || ! isset($b[$GLOBALS['callback_sort_by']])) { + return 0; + } // produces f.e.: // return -1 * strnatcasecmp($a["SCHEMA_TABLES"], $b["SCHEMA_TABLES"]) return ($GLOBALS['callback_sort_order'] == 'ASC' ? 1 : -1) * $sorter($a[$GLOBALS['callback_sort_by']], $b[$GLOBALS['callback_sort_by']]); From c69fca50ee81ff74cda860aad339d4185d32e194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 17 Aug 2010 16:09:07 +0200 Subject: [PATCH 05/19] Add option to escape PMA_sanitize output. This is required when it is used in form values. --- libraries/sanitizing.lib.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/sanitizing.lib.php b/libraries/sanitizing.lib.php index 388ca1397526..abac19da906a 100644 --- a/libraries/sanitizing.lib.php +++ b/libraries/sanitizing.lib.php @@ -17,7 +17,7 @@ * * @access public */ -function PMA_sanitize($message) +function PMA_sanitize($message, $escape = false) { $replace_pairs = array( '<' => '<', @@ -65,6 +65,10 @@ function PMA_sanitize($message) $message = preg_replace($pattern, '', $message); } + if ($escape) { + $message = htmlspecialchars($message); + } + return $message; } ?> From a4a54da173440d4c5097aececef56c28c14dc52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 17 Aug 2010 16:10:27 +0200 Subject: [PATCH 06/19] Escape html chars in form values. --- sql.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sql.php b/sql.php index 35bdab51d9bd..2a744c57c2f4 100644 --- a/sql.php +++ b/sql.php @@ -175,14 +175,14 @@ .PMA_generate_common_hidden_inputs($db, $table); ?> - + - - - - - - + + + + + + ' . "\n" .' ' . $strDoYouReally . '' From 0fe30236fac3c00ff123b9d48cc0b4b2ff6a7746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 18 Aug 2010 11:42:08 +0200 Subject: [PATCH 07/19] Document PMA_sanitize. --- libraries/sanitizing.lib.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/sanitizing.lib.php b/libraries/sanitizing.lib.php index abac19da906a..3ba7224b90c6 100644 --- a/libraries/sanitizing.lib.php +++ b/libraries/sanitizing.lib.php @@ -7,11 +7,20 @@ /** * Sanitizes $message, taking into account our special codes - * for formatting + * for formatting. + * + * If you want to include result in element attribute, you should escape it. + * + * Examples: + * + *

+ * + *
bar * * @uses preg_replace() * @uses strtr() * @param string the message + * @param boolean whether to escape html in result * * @return string the sanitized message * From 8b8ce64792bb981cefc37a19f29f28f112df1c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 18 Aug 2010 12:22:19 +0200 Subject: [PATCH 08/19] Fix XSS on dbname. --- server_privileges.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server_privileges.php b/server_privileges.php index 23d174b986d1..1e6d64edc1bc 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -1595,7 +1595,7 @@ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0) { } else { echo ' - ' . $GLOBALS['strDatabase']; } - $url_dbname = urlencode(str_replace('\_', '_', $dbname)); + $url_dbname = htmlspecialchars(urlencode(str_replace('\_', '_', $dbname))); echo ' ' . htmlspecialchars($dbname) . '' . "\n"; if (isset($tablename) && strlen($tablename)) { echo ' - ' . $GLOBALS['strTable'] . ' ' . htmlspecialchars($tablename) . '' . "\n"; @@ -1841,14 +1841,14 @@ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0) { . ' '; printf($link_edit, urlencode($username), urlencode($hostname), - urlencode((! isset($dbname) || ! strlen($dbname)) ? $row['Db'] : $dbname), + htmlspecialchars(urlencode((! isset($dbname) || ! strlen($dbname)) ? $row['Db'] : $dbname)), urlencode((! isset($dbname) || ! strlen($dbname)) ? '' : $row['Table_name'])); echo '' . "\n" . ' '; if (! empty($row['can_delete']) || isset($row['Table_name']) && strlen($row['Table_name'])) { printf($link_revoke, urlencode($username), urlencode($hostname), - urlencode((! isset($dbname) || ! strlen($dbname)) ? $row['Db'] : $dbname), + htmlspecialchars(urlencode((! isset($dbname) || ! strlen($dbname)) ? $row['Db'] : $dbname)), urlencode((! isset($dbname) || ! strlen($dbname)) ? '' : $row['Table_name'])); } echo '' . "\n" From 1fe1aa6c0e2d85bed1343f4be21d672368e0a9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 18 Aug 2010 12:23:13 +0200 Subject: [PATCH 09/19] Fix XSS on tablename and pred_tablename. --- server_privileges.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server_privileges.php b/server_privileges.php index 1e6d64edc1bc..da1c248f9ee6 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -1598,7 +1598,7 @@ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0) { $url_dbname = htmlspecialchars(urlencode(str_replace('\_', '_', $dbname))); echo ' ' . htmlspecialchars($dbname) . '' . "\n"; if (isset($tablename) && strlen($tablename)) { - echo ' - ' . $GLOBALS['strTable'] . ' ' . htmlspecialchars($tablename) . '' . "\n"; + echo ' - ' . $GLOBALS['strTable'] . ' ' . htmlspecialchars($tablename) . '' . "\n"; } unset($url_dbname); } From 8b7f07cd954221f276ab11e2c3d98f18deb2f551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 18 Aug 2010 12:25:35 +0200 Subject: [PATCH 10/19] Fix XSS on username. --- server_privileges.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server_privileges.php b/server_privileges.php index da1c248f9ee6..188dfb77854b 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -602,7 +602,7 @@ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0) { . $spaces . ' ' . "\n" . $spaces . ' ' . "\n" . $spaces . '' . "\n" - . $spaces . '' . "\n" + . $spaces . '' . "\n" . $spaces . '' . "\n" . $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . '
' . "\n" . $spaces . '