diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 266cb541c7b..7ef504bbf91 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -104,7 +104,7 @@ function testSqlAndScriptInject($val, $type) $val = preg_replace('//', '', $val); $inj = 0; - // For SQL Injection (only GET are used to be included into bad escaped SQL requests) + // For SQL Injection (only GET are used to scan for such injection strings) if ($type == 1 || $type == 3) { $inj += preg_match('/delete\s+from/i', $val); $inj += preg_match('/create\s+table/i', $val); @@ -114,15 +114,16 @@ function testSqlAndScriptInject($val, $type) $inj += preg_match('/user\s*\(/i', $val); // avoid to use function user() that return current database login $inj += preg_match('/information_schema/i', $val); // avoid to use request that read information_schema database $inj += preg_match('/assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject expected 0b'); + $test = 'This is the union of all for the selection of the best'; + $result=testSqlAndScriptInject($test, 0); + $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject expected 0c'); // Should detect attack $expectedresult=1; @@ -206,6 +209,18 @@ class SecurityTest extends PHPUnit\Framework\TestCase $result=testSqlAndScriptInject($_SERVER["PHP_SELF"], 2); $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject for PHP_SELF that should detect XSS'); + $test = 'select @@version'; + $result=testSqlAndScriptInject($test, 0); + $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject for SQL1a. Should find an attack on POST param and did not.'); + + $test = 'select @@version'; + $result=testSqlAndScriptInject($test, 1); + $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject for SQL1b. Should find an attack on GET param and did not.'); + + $test = '... union ... selection '; + $result=testSqlAndScriptInject($test, 1); + $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject for SQL2. Should find an attack on GET param and did not.'); + $test = 'javascript:'; $result=testSqlAndScriptInject($test, 0); $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject for javascript1. Should find an attack and did not.');