From 4fe3650736152ca740ede86b69b740582b20d026 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 13 Jan 2022 18:34:15 +0100 Subject: [PATCH] Fix #hunterf1d1ce3e-ca92-4c7b-b1b8-934e28eaa486 --- htdocs/compta/sociales/list.php | 2 +- test/phpunit/CodingPhpTest.php | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/sociales/list.php b/htdocs/compta/sociales/list.php index 53f293704cf..8d63e52256e 100644 --- a/htdocs/compta/sociales/list.php +++ b/htdocs/compta/sociales/list.php @@ -229,7 +229,7 @@ if (!empty($conf->projet->enabled)) { } } if (!empty($search_users)) { - $sql .= ' AND cs.fk_user IN('.implode(', ', $search_users).')'; + $sql .= ' AND cs.fk_user IN ('.$db->sanitize(implode(', ', $search_users)).')'; } if (!empty($search_type) && $search_type > 0) { $sql .= ' AND cs.fk_mode_reglement='.((int) $search_type); diff --git a/test/phpunit/CodingPhpTest.php b/test/phpunit/CodingPhpTest.php index d24a661a795..597aad1024c 100644 --- a/test/phpunit/CodingPhpTest.php +++ b/test/phpunit/CodingPhpTest.php @@ -392,11 +392,12 @@ class CodingPhpTest extends PHPUnit\Framework\TestCase // Checks with IN - // Check string 'IN (".xxx' or 'IN (\'.xxx' with xxx that is not '$this->db->sanitize' and not '$db->sanitize'. It means we forget a db->sanitize when forging sql request. + // Check string ' IN (".xxx' or ' IN (\'.xxx' with xxx that is not '$this->db->sanitize' and not '$db->sanitize'. It means we forget a db->sanitize when forging sql request. $ok=true; $matches=array(); - preg_match_all('/ IN \([\'"]\s*\.\s*(.........)/i', $filecontent, $matches, PREG_SET_ORDER); + preg_match_all('/\s+IN\s*\([\'"]\s*\.\s*(.........)/i', $filecontent, $matches, PREG_SET_ORDER); foreach ($matches as $key => $val) { + //var_dump($val); if (!in_array($val[1], array('$db->sani', '$this->db', 'getEntity', 'WON\',\'L', 'self::STA', 'Commande:', 'CommandeF', 'Entrepot:', 'Facture::', 'FactureFo', 'ExpenseRe', 'Societe::', 'Ticket::S'))) { $ok=false; break; @@ -407,11 +408,12 @@ class CodingPhpTest extends PHPUnit\Framework\TestCase $this->assertTrue($ok, 'Found non sanitized string in building of a IN or NOT IN sql request '.$file['relativename'].' - Bad.'); //exit; - // Check string 'IN (\'".xxx' with xxx that is not '$this->db->sanitize' and not '$db->sanitize'. It means we forget a db->sanitize when forging sql request. + // Check string ' IN (\'".xxx' with xxx that is not '$this->db->sanitize' and not '$db->sanitize'. It means we forget a db->sanitize when forging sql request. $ok=true; $matches=array(); - preg_match_all('/ IN \(\'"\s*\.\s*(.........)/i', $filecontent, $matches, PREG_SET_ORDER); + preg_match_all('/\s+IN\s*\(\'"\s*\.\s*(.........)/i', $filecontent, $matches, PREG_SET_ORDER); foreach ($matches as $key => $val) { + //var_dump($val); if (!in_array($val[1], array('$db->sani', '$this->db', 'getEntity', 'WON\',\'L', 'self::STA', 'Commande:', 'CommandeF', 'Entrepot:', 'Facture::', 'FactureFo', 'ExpenseRe', 'Societe::', 'Ticket::S'))) { $ok=false; break;