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

pearweb < 1.32 suffers from Deserialization of Untrusted Data.

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-502
cwe_name: Deserialization of Untrusted Data
description: The product deserializes untrusted data without sufficiently verifying that the resulting data will be valid.
extended_description: 
            It is often convenient to serialize objects for communication or to save them for later use. However, deserialized data or code can often be modified without using the provided accessor functions if it does not use cryptography to protect itself. Furthermore, any cryptography would still be client-side security -- which is a dangerous security assumption.
            Data that is untrusted can not be trusted to be well-formed.
            When developers place no restrictions on "gadget chains," or series of instances and method invocations that can self-execute during the deserialization process (i.e., before the object is returned to the caller), it is sometimes possible for attackers to leverage them to perform unauthorized actions, like generating a shell.
         
         

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