Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(mon)vunerability in customViews_MASTER
Browse files Browse the repository at this point in the history
Update SQL query to prevent SQL injection in setRotate form

Refs: MON-2129
  • Loading branch information
MatthieuMan authored and loiclau committed Nov 27, 2017
1 parent c9cb217 commit b76dc49
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions www/class/centreonUser.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,26 +433,29 @@ public function setContactParameters($db, $parameters = array())
if (!count($parameters)) {
return null;
}

$queryValues = array();
$keys = array_keys($parameters);

$deleteQuery = 'DELETE FROM contact_param '
. 'WHERE cp_contact_id = ' . $this->user_id . ' '
. 'AND cp_key IN("'
. implode('","', $keys)
. '") ';
$db->query($deleteQuery);

$insertQuery = 'INSERT INTO contact_param (cp_key, cp_value, cp_contact_id) VALUES ';
$first = true;
$deleteQuery = 'DELETE FROM contact_param WHERE cp_contact_id = :cp_contact_id AND cp_key IN( ';
$queryValues[':cp_contact_id'] = $this->user_id;
$queryKey ='';
foreach ($keys as $key) {
$queryKey .=' :cp_key'.$key.',';
$queryValues[':cp_key'.$key] = $key;
}
$queryKey = rtrim($queryKey, ',');
$deleteQuery .= $queryKey .' )';
$stmt = $db->prepare($deleteQuery);
$stmt->execute($queryValues);

$insertQuery = 'INSERT INTO contact_param (cp_key, cp_value, cp_contact_id) VALUES '
. '(:cp_key, :cp_value, :cp_contact_id)';
$sth = $db->prepare($insertQuery);
foreach ($parameters as $key => $value) {
if (!$first) {
$insertQuery .= ',';
}
$insertQuery .= '("' . $key . '","' . $value . '", ' . $this->user_id . ')';
$first = false;
$sth->bindParam(':cp_key', $key, PDO::PARAM_STR);
$sth->bindParam(':cp_value', $value, PDO::PARAM_STR);
$sth->bindParam(':cp_contact_id', $this->user_id, PDO::PARAM_INT);
$sth->execute();
}
$db->query($insertQuery);
}

/**
Expand Down

0 comments on commit b76dc49

Please sign in to comment.