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

Commit

Permalink
fix(security): use user id instead of session id in session page (#8876)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjaouen committed Jul 30, 2020
1 parent 07fd1b7 commit da19665
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
31 changes: 8 additions & 23 deletions www/api/class/centreon_ldap_synchro.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,44 +75,29 @@ public function postRequestLdapSynchro(): bool
$result = false;

$contactId = filter_var(
$_POST['contactId'] ?? null,
$_POST['contactId'] ?? false,
FILTER_VALIDATE_INT
);
$sessionId = filter_var(
$_POST['sessionId'] ?? null,
FILTER_SANITIZE_STRING
);

if (!$this->isLdapEnabled()) {
return $result;
}

if (empty($contactId) && empty($sessionId)) {
if ($contactId === false) {
$this->centreonLog->insertLog(
3, //ldap.log
"LDAP MANUAL SYNC : Error - Chosen contact data are missing."
"LDAP MANUAL SYNC : Error - Chosen contact id is not consistent."
);
return $result;
}

$this->pearDB->beginTransaction();
try {
// getting the contact name and ID for the logs
if ($contactId) {
// (getting the contactId to homogenize the next request's bindValue variable name)
$resUser = $this->pearDB->prepare(
'SELECT `contact_id`, `contact_name` FROM `contact`
WHERE `contact_id` = :contactId'
);
$resUser->bindValue(':contactId', $contactId, PDO::PARAM_INT);
} elseif ($sessionId) {
$resUser = $this->pearDB->prepare(
'SELECT `contact_id`, `contact_name` FROM contact
LEFT JOIN session ON session.user_id = contact.contact_id
WHERE session.session_id = :userSessionId'
);
$resUser->bindValue(':userSessionId', $sessionId, PDO::PARAM_STR);
}
$resUser = $this->pearDB->prepare(
'SELECT `contact_id`, `contact_name` FROM `contact`
WHERE `contact_id` = :contactId'
);
$resUser->bindValue(':contactId', $contactId, PDO::PARAM_INT);
$resUser->execute();
$contact = $resUser->fetch();

Expand Down
20 changes: 10 additions & 10 deletions www/include/options/session/connected_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,26 @@
FILTER_SANITIZE_STRING
);

$selectedUserSid = filter_var(
$_GET['session'] ?? null, // the sessionId of the chosen user
FILTER_SANITIZE_STRING
$selectedUserId = filter_var(
$_GET['user'] ?? null,
FILTER_VALIDATE_INT
);

$currentPage = filter_var(
$_GET['p'] ?? $_POST['p'] ?? 0,
FILTER_VALIDATE_INT
);

if ($selectedUserSid) {
if ($selectedUserId) {
$msg = new CentreonMsg();
$msg->setTextStyle("bold");
$msg->setTimeOut("3");

switch ($action) {
// logout action
case KICK_USER:
$stmt = $pearDB->prepare("DELETE FROM session WHERE session_id = :userSessionId");
$stmt->bindValue(':userSessionId', $selectedUserSid, \PDO::PARAM_STR);
$stmt = $pearDB->prepare("DELETE FROM session WHERE user_id = :userId");
$stmt->bindValue(':userId', $selectedUserId, \PDO::PARAM_INT);
$stmt->execute();
$msg->setText(_("User kicked"));
break;
Expand Down Expand Up @@ -122,7 +122,7 @@
if ($centreon->user->admin) {
// adding the link to be able to kick the user
$session_data[$cpt]["actions"] =
"<a href='./main.php?p=" . $p . "&o=k&session=" . $r['session_id'] . "'>" .
"<a href='./main.php?p=" . $p . "&o=k&user=" . $r['user_id'] . "'>" .
"<img src='./img/icons/delete.png' border='0' alt='" . _("Kick User") .
"' title='" . _("Kick User") . "'>" .
"</a>";
Expand All @@ -139,7 +139,7 @@
"<a href='#'>" .
"<img src='./img/icons/refresh.png' border='0' " .
"alt='" . _("Synchronize LDAP") . "' title='" . _("Synchronize LDAP") . "' " .
"onclick='submitSync(" . $currentPage . ", \"" . $r['session_id'] . "\")'>" .
"onclick='submitSync(" . $currentPage . ", \"" . $r['user_id'] . "\")'>" .
"</a>";
} else {
// hiding the synchronization option and details
Expand Down Expand Up @@ -171,7 +171,7 @@
formatDateMoment();

// ask for confirmation when requesting to resynchronize contact data from the LDAP
function submitSync(p, sessionId) {
function submitSync(p, contactId) {
// msg = localized message to be displayed in the confirmation popup
let msg = "<?= _('All this contact sessions will be closed. Are you sure you want to request a ' .
'synchronization at the next login of this Contact ?'); ?>";
Expand All @@ -181,7 +181,7 @@ function submitSync(p, sessionId) {
url: './api/internal.php?object=centreon_ldap_synchro&action=requestLdapSynchro',
type: 'POST',
async: false,
data: {sessionId: sessionId},
data: {contactId: contactId},
success: function(data) {
if (data === true) {
window.location.href = "?p=" + p;
Expand Down

0 comments on commit da19665

Please sign in to comment.