CVE-2022-27157 (published 2022-04-15T18:15Z)

pearweb < 1.32 is suffers from a Weak Password Recovery Mechanism via include/users/passwordmanage.php.

Severity: HIGH
CVSS v2 base score: 7.5 (AV:N/AC:L/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-640
cwe_name: Weak Password Recovery Mechanism for Forgotten Password
description: The product contains a mechanism for users to recover or change their passwords without knowing the original password, but the mechanism is weak.
extended_description: 
            It is common for an application to have a mechanism that provides a means for a user to gain access to their account in the event they forget their password. Very often the password recovery mechanism is weak, which has the effect of making it more likely that it would be possible for a person other than the legitimate system user to gain access to that user's account. Weak password recovery schemes completely undermine a strong password authentication scheme.
            This weakness may be that the security question is too easy to guess or find an answer to (e.g. because the question is too common, or the answers can be found using social media). Or there might be an implementation weakness in the password recovery mechanism code that may for instance trick the system into e-mailing the new password to an e-mail account other than that of the user. There might be no throttling done on the rate of password resets so that a legitimate user can be denied service by an attacker if an attacker tries to recover their password in a rapid succession. The system may send the original password to the user rather than generating a new temporary password. In summary, password recovery functionality, if not carefully designed and implemented can often become the system's weakest link that can be misused in a way that would allow an attacker to gain unauthorized access to the system.
         
         

Fix information:
repo_url: https://github.com/pear/pearweb
commit_details: repo_url: https://github.com/pear/pearweb
author: Ken Guest
author_date: 2021-08-04 00:07:22+01:00
msg: Be cautious about what can be unserialized
repository: repo_url: https://github.com/pear/pearweb
repo_name: pear/pearweb
repo_language: PHP
owner: pear
file_changes: filename: pear-bug-accountrequest.php
change_type: ModificationType.MODIFY
diff: @@ -236,7 +236,11 @@ class PEAR_Bug_Accountrequest
         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);

programming_language: PHP
filename: pear-database-user.php
change_type: ModificationType.MODIFY
diff: @@ -46,7 +46,11 @@ class user
         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);

programming_language: PHP
filename: pepr-ppvote.php
change_type: ModificationType.MODIFY
diff: @@ -57,7 +57,14 @@ class ppVote
             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;
     }
@@ -71,7 +78,10 @@ class ppVote
         }
         $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;

programming_language: PHP
filename: passwordmanage.php
change_type: ModificationType.MODIFY
diff: @@ -55,7 +55,12 @@ class Users_PasswordManage
     {
         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
@@ -91,4 +96,4 @@ PEAR Quality Assurance.'), array('username' => $user, 'salt' => $salt));
         }
         return $errors;
     }
-}
\ No newline at end of file
+}

programming_language: PHP
filename: pearweb.php
change_type: ModificationType.MODIFY
diff: @@ -145,8 +145,13 @@ class pearweb_postinstall
             $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');
             }
@@ -355,4 +360,4 @@ class pearweb_postinstall
         $this->_ui->outputData('...done');
         return true;
     }
-}
\ No newline at end of file
+}

programming_language: PHP
filename: pearweb_election.php
change_type: ModificationType.MODIFY
diff: @@ -138,8 +138,12 @@ class pearweb_election_postinstall
             $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');
             }
@@ -166,4 +170,4 @@ class pearweb_election_postinstall
         }
         return true;
     }
-}
\ No newline at end of file
+}

programming_language: PHP
filename: pearweb_pepr.php
change_type: ModificationType.MODIFY
diff: @@ -145,8 +145,12 @@ class pearweb_pepr_postinstall
             $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');
             }
@@ -322,4 +326,4 @@ class pearweb_pepr_postinstall
         $this->_ui->outputData('...done');
         return true;
     }
-}
\ No newline at end of file
+}

programming_language: PHP
filename: index.php
change_type: ModificationType.MODIFY
diff: @@ -267,7 +267,15 @@ do {
         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'] . ' &lt;' . $requser['email'] . '&gt;', "100%", '', 2, true);
         $bb->horizHeadRow("Requested username:", $requser['handle']);
@@ -511,8 +519,8 @@ foreach ($reasons as $reason) {
             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;

programming_language: PHP
filename: rollback.php
change_type: ModificationType.MODIFY
diff: @@ -74,7 +74,16 @@ class Pearweb_Rollback
             $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,

programming_language: PHP
filename: rollbackProposal.php
change_type: ModificationType.MODIFY
diff: @@ -74,7 +74,16 @@ class Pearweb_Rollback
             $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,

programming_language: PHP