Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch to fix IDOR vulnerability in userinfo.php #1541

Draft
wants to merge 8 commits into
base: 2.0.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions htdocs/libraries/icms/member/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ public function &getUser($id) {
return $this->_members[$id];
}

/**
* retrieve a user by hash_uid
*
* @param string $hash_uid for the user
* @return object icms_member_user_Object {@link icms_member_user_Object} reference to the user
*/

public function &getUserHash($hash_uid) {
if (! isset($this->_members[$hash_uid])) {
$this->_members[$hash_uid] = & $this->_uHandler->getHash($hash_uid);
}
return $this->_members[$hash_uid];
}

/**
* delete a group
*
Expand Down
18 changes: 18 additions & 0 deletions htdocs/libraries/icms/member/user/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ public function &get($id) {
return $user;
}

/**
* retrieve a user from hash_uid
*
* @param string $hash_uid hash_uid of the user
* @return mixed reference to the {@link icms_member_user_Object} object, FALSE if failed
*/
public function &getHash($hash_uid) {
$user = FALSE;
$sql = "SELECT * FROM " . $this->db->prefix('users') . " WHERE hash_uid = '" . $hash_uid . "'";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hash_uid should be escaped in case of SQL Injection. $this->db->quote($hash_uid) or $this->db->quoteString($hash_uid) should be used here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Àdding LIMIT 1 to then end of this SQL can improve execution speed

if (!$result = $this->db->query($sql)) {return $user;}
$numrows = $this->db->getRowsNum($result);
if ($numrows == 1) {
$user = new icms_member_user_Object();
$user->assignVars($this->db->fetchArray($result));
}
return $user;
}

/**
* insert a new user in the database
*
Expand Down
6 changes: 3 additions & 3 deletions htdocs/userinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

$xoopsOption['pagetype'] = 'user';
include 'mainfile.php';
$hash_uid = (int) $_GET['uid'];
$hash_uid = $_GET['uid'];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The input should be filtered and tested before using. In the original code, we force it to be an integer before proceeding

Copy link
Contributor

@skenow skenow Dec 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little better. I recommend reviewing the icms_core_DataFilter::checkVar() method. Strings can still be malicious and validating input and access are the best defense against breaches. You can view how we've utilized it in a lot of places - includes/finduser.php is a good example.

if (icms_get_module_status("profile")) {
$module = icms::handler("icms_module")->getByDirName("profile", true);
Expand Down Expand Up @@ -85,7 +85,7 @@
'lang_deleteaccount' => $icmsConfigUser['self_delete'] ? _US_DELACCOUNT : ''));
$thisUser = icms::$user;
} else {
$thisUser = icms::handler('icms_member')->getUser($uid);
$thisUser = icms::handler('icms_member')->getUserHash($hash_uid);
if (!is_object($thisUser) || !$thisUser->isActive()) {
redirect_header('index.php', 3, _US_SELECTNG);
}
Expand All @@ -94,7 +94,7 @@
$icmsTpl->assign('user_ownpage', false);
}
} else {
$thisUser = icms::handler('icms_member')->getUser($uid);
$thisUser = icms::handler('icms_member')->getUserHash($hash_uid);
if (!is_object($thisUser) || !$thisUser->isActive()) {
redirect_header('index.php', 3, _US_SELECTNG);
}
Expand Down