Skip to content

Commit

Permalink
Be cautious about what can be unserialized
Browse files Browse the repository at this point in the history
  • Loading branch information
kenguest authored and ashnazg committed Mar 13, 2022
1 parent d40fe6d commit 6447c17
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 20 deletions.
6 changes: 5 additions & 1 deletion include/bugs/pear-bug-accountrequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ function confirmRequest($handle, $password, $name)
if (!isset($user['registered'])) {
return false;
}
@$arr = unserialize($user['userinfo']);
try {
@$arr = unserialize($user['userinfo'], ['allowed_classes' => false]);
} catch (Exception $ex) {
$arr = false;
}

include_once 'pear-database-note.php';
note::removeAll($handle);
Expand Down
6 changes: 5 additions & 1 deletion include/pear-database-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ static function activate($uid, $karmalevel = 'pear.dev')
if (!isset($user['registered'])) {
return false;
}
@$arr = unserialize($user['userinfo']);
try {
@$arr = unserialize($user['userinfo'], ['allowed_classes' => false]);
} catch (Exception $ex) {
$arr = false;
}

include_once 'pear-database-note.php';
note::removeAll($uid);
Expand Down
14 changes: 12 additions & 2 deletions include/pepr/pepr-ppvote.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ function get(&$dbh, $proposalId, $handle)
return null;
}
$set = $res->fetchRow(DB_FETCHMODE_ASSOC);
$set['reviews'] = unserialize($set['reviews']);
try {
$unserialised = unserialize($set['reviews'], ['allowed_classes' => false]);
if ($unserialised !== false) {
$set['reviews'] = $unserialised;
}
} catch (Exception $ex) {
$set['reviews'] = array();
}
$vote = new ppVote($set);
return $vote;
}
Expand All @@ -71,7 +78,10 @@ function &getAll(&$dbh, $proposalId)
}
$votes = array();
while ($set = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
$set['reviews'] = unserialize($set['reviews']);
$uReviews = unserialize($set['reviews'], ['allowed_classes' => false]);
if ($uReviews !== false) {
$set['reviews'] = $uReviews;
}
$votes[$set['user_handle']] = new ppVote($set);
}
return $votes;
Expand Down
9 changes: 7 additions & 2 deletions include/users/passwordmanage.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ function resetPassword($user, $pass1, $pass2)
{
require_once 'Damblan/Mailer.php';
$errors = array();
$salt = md5(mt_rand(4,13) . $user . time() . $pass1);
$random_bytes = openssl_random_pseudo_bytes(16, $strong);
if ($random_bytes === false || $strong === false) {
$errors[] = "Could not generate a safe password token";
return $errors;
}
$salt = md5($rand_bytes);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$this->_dbh->query('DELETE FROM lostpassword WHERE handle=?', array($user));
$e = $this->_dbh->query('INSERT INTO lostpassword
Expand Down Expand Up @@ -91,4 +96,4 @@ function resetPassword($user, $pass1, $pass2)
}
return $errors;
}
}
}
11 changes: 8 additions & 3 deletions pearweb.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ function initializeDatabase($answers)
$oldversion = false;
}
if ($oldversion) {
$curdef = unserialize(file_get_contents($updir .
$answers['database'] . '-' . $oldversion . '.ser'));
$sFile = $updir . $answers['database'] . '-' . $oldversion . '.ser';
try {
$curdef = unserialize(file_get_contents($sFile), ['allowed_classes' => false]);
} catch (Exception $ex) {
$curdef = false;
}

if (!is_array($curdef)) {
$this->_ui->outputData('invalid data returned from previous version');
}
Expand Down Expand Up @@ -355,4 +360,4 @@ function setupHttpdconf($answers)
$this->_ui->outputData('...done');
return true;
}
}
}
10 changes: 7 additions & 3 deletions pearweb_election.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ function initializeDatabase($answers)
$oldversion = false;
}
if ($oldversion) {
$curdef = unserialize(file_get_contents('@www-dir@/sql/.pearweb-upgrade/' .
$answers['database'] . '-' . $oldversion . '.ser'));
$sFile = '@www-dir@/sql/.pearweb-upgrade/' . $answers['database'] . '-' . $oldversion . '.ser';
try {
$curdef = unserialize(file_get_contents($sFile), ['allowed_classes' => false]);
} catch (Exception $ex) {
$curdef = false;
}
if (!is_array($curdef)) {
$this->_ui->outputData('invalid data returned from previous version');
}
Expand All @@ -166,4 +170,4 @@ function initializeDatabase($answers)
}
return true;
}
}
}
10 changes: 7 additions & 3 deletions pearweb_pepr.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ function initializeDatabase($answers)
$oldversion = false;
}
if ($oldversion) {
$curdef = unserialize(file_get_contents('@www-dir@/sql/.pearweb-upgrade/' .
$answers['database'] . '-' . $oldversion . '.ser'));
try {
$sFile = '@www-dir@/sql/.pearweb-upgrade/' . $answers['database'] . '-' . $oldversion . '.ser';
$curdef = unserialize(file_get_contents($sFile), ['allowed_classes' => false]);
} catch (Exception $ex) {
$curdef = false;
}
if (!is_array($curdef)) {
$this->_ui->outputData('invalid data returned from previous version');
}
Expand Down Expand Up @@ -322,4 +326,4 @@ function setupHttpdconf($answers)
$this->_ui->outputData('...done');
return true;
}
}
}
14 changes: 11 additions & 3 deletions public_html/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,15 @@ function updateRejectReason(selectObj) {
if (empty($requser['name']) || $requser['from_site'] == 'pecl') {
break;
}
list($purpose, $moreinfo) = @unserialize($requser['userinfo']);
try {
$uInfo = @unserialize($requser['userinfo'], ['allowed_classes' => false]);
if ($uInfo !== false) {
list($purpose, $moreinfo) = $uInfo;
}
} catch (Exception $ex) {
$purpose = 'n/a';
$moreinfo = 'n/a';
}

$bb = new BorderBox('Account request from ' . $requser['name'] . ' <' . $requser['email'] . '>', "100%", '', 2, true);
$bb->horizHeadRow("Requested username:", $requser['handle']);
Expand Down Expand Up @@ -511,8 +519,8 @@ function setCmdInput(mode)
list($name, $note, $userinfo) = $data;

// Grab userinfo/request purpose
if (@unserialize($userinfo)) {
$userinfo = @unserialize($userinfo);
if (@unserialize($userinfo, ['allowed_classes' => false])) {
$userinfo = @unserialize($userinfo, ['allowed_classes' => false]);
$account_purpose = $userinfo[0];
} else {
$account_purpose = $userinfo;
Expand Down
11 changes: 10 additions & 1 deletion rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ protected function moveVotes()
$comment = "Original vote: {$row->value}\n";
$comment .= "Conditional vote: " . ($row->is_conditional != 0)?'yes':'no' . "\n";
$comment .= "Comment on vote: " . $row->comment . "\n\n";
$comment .= "Reviewed: " . implode(", ", unserialize($row->reviews));
$reviewed = "Reviewed: n/a";
try {
$uInfo = unserialize($row->reviews, ['allowed_classes' => false]);
if ($uInfo !== false) {
$reviewed = "Reviewed: " . implode(", ", $uInfo);
}
} catch (Exception $ex) {
// do nothing
}
$comment .= $reviewed;

$sql = sprintf(
$insert,
Expand Down
11 changes: 10 additions & 1 deletion scripts/rollbackProposal.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ protected function moveVotes()
$comment = "Original vote: {$row->value}\n";
$comment .= "Conditional vote: " . (($row->is_conditional != 0)?'yes':'no') . "\n";
$comment .= "Comment on vote: " . $row->comment . "\n";
$comment .= "Reviewed: " . implode(", ", unserialize($row->reviews));
$reviewed = "Reviewed: n/a";
try {
$uInfo = unserialize($row->reviews, ['allowed_classes' => false]);
if ($uInfo !== false) {
$reviewed = "Reviewed: " . implode(", ", $uInfo);
}
} catch (Exception $ex) {
// do nothing
}
$comment .= $reviewed;

$sql = sprintf(
$insert,
Expand Down

0 comments on commit 6447c17

Please sign in to comment.