From 37dccb3932a5341ff93abb42216eb453fedff631 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 10 Feb 2016 13:42:55 +0000 Subject: [PATCH 1/3] First effort in bringing some sanity --- html/includes/vars.inc.php | 10 +++++----- html/index.php | 8 -------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/html/includes/vars.inc.php b/html/includes/vars.inc.php index 369a13a74..8d3c3b6c2 100644 --- a/html/includes/vars.inc.php +++ b/html/includes/vars.inc.php @@ -7,7 +7,7 @@ foreach ($_GET as $key => $get_var) { $value = 'yes'; } - $vars[$name] = $value; + $vars[$name] = htmlentities($value); } } @@ -23,7 +23,7 @@ else { foreach ($segments as $pos => $segment) { $segment = urldecode($segment); if ($pos == '0') { - $vars['page'] = $segment; + $vars['page'] =htmlentities( $segment); } else { list($name, $value) = explode('=', $segment); @@ -31,15 +31,15 @@ foreach ($segments as $pos => $segment) { $vars[$name] = yes; } else { - $vars[$name] = $value; + $vars[$name] = htmlentities($value); } } } foreach ($_GET as $name => $value) { - $vars[$name] = $value; + $vars[$name] = htmlentities($value); } foreach ($_POST as $name => $value) { - $vars[$name] = $value; + $vars[$name] = htmlentities($value); } diff --git a/html/index.php b/html/index.php index 46164c663..494d6c3de 100644 --- a/html/index.php +++ b/html/index.php @@ -214,14 +214,6 @@ else {
"); - print_r($_GET); - print_r($vars); - echo(""); -} - if ($_SESSION['authenticated']) { // Authenticated. Print a page. if (isset($vars['page']) && !strstr("..", $vars['page']) && is_file("pages/" . $vars['page'] . ".inc.php")) { From a6bca987bf927d36c91df980c42a777e643cee72 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 10 Feb 2016 13:52:43 +0000 Subject: [PATCH 2/3] Enforce sanity before returning from database --- html/includes/vars.inc.php | 2 +- includes/common.php | 10 ++++++++++ includes/dbFacile.mysql.php | 2 ++ includes/dbFacile.mysqli.php | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/html/includes/vars.inc.php b/html/includes/vars.inc.php index 8d3c3b6c2..a633cef72 100644 --- a/html/includes/vars.inc.php +++ b/html/includes/vars.inc.php @@ -23,7 +23,7 @@ else { foreach ($segments as $pos => $segment) { $segment = urldecode($segment); if ($pos == '0') { - $vars['page'] =htmlentities( $segment); + $vars['page'] = htmlentities($segment); } else { list($name, $value) = explode('=', $segment); diff --git a/includes/common.php b/includes/common.php index 8b59ba774..1162b819a 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1255,3 +1255,13 @@ function get_port_id ($ports_mapped, $port, $port_association_mode) { return $port_id; } + +/** + * Sanitize + * @param mixed $item Reference to Item + * @param mixed $key Key + * @return void + */ +function sanitize_array(&$item, $key) { + $item = htmlentities($item); +} diff --git a/includes/dbFacile.mysql.php b/includes/dbFacile.mysql.php index f2bb56c0b..d9372cbb6 100644 --- a/includes/dbFacile.mysql.php +++ b/includes/dbFacile.mysql.php @@ -266,6 +266,7 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']); } + array_walk_recursive($rows,'sanitize_array'); return $rows; } @@ -333,6 +334,7 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']); } + array_walk_recursive($row,'sanitize_array'); return $row; } else { diff --git a/includes/dbFacile.mysqli.php b/includes/dbFacile.mysqli.php index 15a48962c..70c4651e7 100644 --- a/includes/dbFacile.mysqli.php +++ b/includes/dbFacile.mysqli.php @@ -267,6 +267,7 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']); } + array_walk_recursive($rows,'sanitize_array'); return $rows; } @@ -334,6 +335,7 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']); } + array_walk_recursive($row,'sanitize_array'); return $row; } else { From 8d9b522bdbb6f7664f42051037ff52fe1bc8a168 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 10 Feb 2016 13:54:22 +0000 Subject: [PATCH 3/3] Remove redundant calls --- html/includes/vars.inc.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/html/includes/vars.inc.php b/html/includes/vars.inc.php index a633cef72..c9008d217 100644 --- a/html/includes/vars.inc.php +++ b/html/includes/vars.inc.php @@ -7,7 +7,7 @@ foreach ($_GET as $key => $get_var) { $value = 'yes'; } - $vars[$name] = htmlentities($value); + $vars[$name] = $value; } } @@ -23,7 +23,7 @@ else { foreach ($segments as $pos => $segment) { $segment = urldecode($segment); if ($pos == '0') { - $vars['page'] = htmlentities($segment); + $vars['page'] = $segment; } else { list($name, $value) = explode('=', $segment); @@ -31,15 +31,17 @@ foreach ($segments as $pos => $segment) { $vars[$name] = yes; } else { - $vars[$name] = htmlentities($value); + $vars[$name] = $value; } } } foreach ($_GET as $name => $value) { - $vars[$name] = htmlentities($value); + $vars[$name] = $value; } foreach ($_POST as $name => $value) { - $vars[$name] = htmlentities($value); + $vars[$name] = $value; } + +array_walk_recursive($vars,'sanitize_array');