From c03f301a945808c6c0fa39a3348c81c31beb488b Mon Sep 17 00:00:00 2001 From: hyahiaoui-ext <97593234+hyahiaoui-ext@users.noreply.github.com> Date: Thu, 11 Aug 2022 11:23:49 +0100 Subject: [PATCH] SNYK: Sanitize and bind Broker listing queries (#11551) * Sanitizing and binding broker listing queries * applying suggested changes --- .../listCentreonBroker.php | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/www/include/configuration/configCentreonBroker/listCentreonBroker.php b/www/include/configuration/configCentreonBroker/listCentreonBroker.php index 70aa1c9be76..ddfc19d8fa5 100644 --- a/www/include/configuration/configCentreonBroker/listCentreonBroker.php +++ b/www/include/configuration/configCentreonBroker/listCentreonBroker.php @@ -125,6 +125,12 @@ $elemArr = array(); $centreonToken = createCSRFToken(); +$statementBrokerInfo = $pearDB->prepare( + "SELECT COUNT(DISTINCT(config_group_id)) as num " . + "FROM cfg_centreonbroker_info " . + "WHERE config_group = :config_group " . + "AND config_id = :config_id" +); for ($i = 0; $config = $dbResult->fetch(); $i++) { $moptions = ""; @@ -148,23 +154,16 @@ . "style=\"margin-bottom:0px;\" name='dupNbr[" . $config['config_id'] . "]'>"; // Number of output - $res = $pearDB->query( - "SELECT COUNT(DISTINCT(config_group_id)) as num " . - "FROM cfg_centreonbroker_info " . - "WHERE config_group = 'output' " . - "AND config_id = " . $config['config_id'] - ); - $row = $res->fetch(); + $statementBrokerInfo->bindValue(':config_id', (int) $config['config_id'], \PDO::PARAM_INT); + $statementBrokerInfo->bindValue(':config_group', 'output', \PDO::PARAM_STR); + $statementBrokerInfo->execute(); + $row = $statementBrokerInfo->fetch(\PDO::FETCH_ASSOC); $outputNumber = $row["num"]; // Number of input - $res = $pearDB->query( - "SELECT COUNT(DISTINCT(config_group_id)) as num " . - "FROM cfg_centreonbroker_info " . - "WHERE config_group = 'input' " . - "AND config_id = " . $config['config_id'] - ); - $row = $res->fetch(); + $statementBrokerInfo->bindValue(':config_group', 'input', \PDO::PARAM_STR); + $statementBrokerInfo->execute(); + $row = $statementBrokerInfo->fetch(\PDO::FETCH_ASSOC); $inputNumber = $row["num"]; // Number of logger