diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index a27ead10152..f34ec1264cb 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -62,26 +62,40 @@ if (function_exists('get_magic_quotes_gpc')) // magic_quotes_* removed in PHP6 } } -// Security: SQL Injection and XSS Injection (scripts) protection (Filters on GET, POST) -function test_sql_and_script_inject($val,$get) + +/** + * Security: SQL Injection and XSS Injection (scripts) protection (Filters on GET, POST, PHP_SELF) + * + * @param string $val Value + * @param string $type 1=GET, 0=POST, 2=PHP_SELF + * @return boolean true if there is an injection + */ +function test_sql_and_script_inject($val, $type) { $sql_inj = 0; - // For SQL Injection - $sql_inj += preg_match('/delete[\s]+from/i', $val); - $sql_inj += preg_match('/create[\s]+table/i', $val); - $sql_inj += preg_match('/update.+set.+=/i', $val); - $sql_inj += preg_match('/insert[\s]+into/i', $val); - $sql_inj += preg_match('/select.+from/i', $val); - $sql_inj += preg_match('/union.+select/i', $val); - $sql_inj += preg_match('/(\.\.%2f)+/i', $val); + // For SQL Injection (onyl GET and POST are used to be included into bad escaped SQL requests) + if ($type != 2) + { + $sql_inj += preg_match('/delete[\s]+from/i', $val); + $sql_inj += preg_match('/create[\s]+table/i', $val); + $sql_inj += preg_match('/update.+set.+=/i', $val); + $sql_inj += preg_match('/insert[\s]+into/i', $val); + $sql_inj += preg_match('/select.+from/i', $val); + $sql_inj += preg_match('/union.+select/i', $val); + $sql_inj += preg_match('/(\.\.%2f)+/i', $val); + } // For XSS Injection done by adding javascript with script - $sql_inj += preg_match('/