CVE-2022-2824 (published 2022-08-15T16:15Z)

Authorization Bypass Through User-Controlled Key in GitHub repository openemr/openemr prior to 7.0.0.1.\n\n

CVSS v3 base score: 5.4, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-639
cwe_name: Authorization Bypass Through User-Controlled Key
description: The system's authorization functionality does not prevent one user from gaining access to another user's data or record by modifying the key value identifying the data.
extended_description: 
            Retrieval of a user record occurs in the system based on some key value that is under user control. The key would typically identify a user-related record stored in the system and would be used to lookup that record for presentation to the user. It is likely that an attacker would have to be an authenticated user in the system. However, the authorization process would not properly check the data access operation to ensure that the authenticated user performing the operation has sufficient entitlements to perform the requested data access, hence bypassing any other authorization checks present in the system.
            For example, attackers can look at places where user specific data is retrieved (e.g. search screens) and determine whether the key for the item being looked up is controllable externally. The key may be a hidden field in the HTML form field, might be passed as a URL parameter or as an unencrypted cookie variable, then in each of these cases it will be possible to tamper with the key value.
            One manifestation of this weakness is when a system uses sequential or otherwise easily-guessable session IDs that would allow one user to easily switch to another user's session and read/modify their data.
         
         

Fix information:
repo_url: https://github.com/openemr/openemr
commit_details: repo_url: https://github.com/openemr/openemr
author: stephen waite
author_date: 2022-08-05 08:31:02-04:00
msg: bug fix and php8.1 fixes (#5664)

* bug fix and php8.1 fixes

* styling
repository: repo_url: https://github.com/openemr/openemr
repo_name: openemr/openemr
description: The most popular open source electronic health records and medical practice management solution.
repo_language: PHP
owner: openemr
file_changes: filename: Criteria.php
change_type: ModificationType.MODIFY
diff: @@ -223,63 +223,63 @@ class Criteria
                             $this->_where .= $this->_where_delim . ' ' . $filter->GetWhere($this);
                             $this->_where_delim = " and";
                         }
-                    } elseif (substr($prop, - 7) == "_Equals" && strlen($this->$prop)) {
+                    } elseif (substr($prop, - 7) == "_Equals" && strlen($this->$prop ?? '')) {
                         $dbfield = $this->GetFieldFromProp(str_replace("_Equals", "", $prop));
                         $this->_where .= $this->_where_delim . " " . $dbfield . " = " . $this->GetQuotedSql($val) . "";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 10) == "_NotEquals" && strlen($this->$prop)) {
+                    } elseif (substr($prop, - 10) == "_NotEquals" && strlen($this->$prop ?? '')) {
                         $dbfield = $this->GetFieldFromProp(str_replace("_NotEquals", "", $prop));
                         $this->_where .= $this->_where_delim . " " . $dbfield . " != " . $this->GetQuotedSql($val) . "";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 8) == "_IsEmpty" && $this->$prop) {
+                    } elseif (substr($prop, - 8) == "_IsEmpty" && $this->$prop ?? '') {
                         $dbfield = $this->GetFieldFromProp(str_replace("_IsEmpty", "", $prop));
                         $this->_where .= $this->_where_delim . " " . $dbfield . " = ''";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 11) == "_IsNotEmpty" && $this->$prop) {
+                    } elseif (substr($prop, - 11) == "_IsNotEmpty" && $this->$prop ?? '') {
                         $dbfield = $this->GetFieldFromProp(str_replace("_IsNotEmpty", "", $prop));
                         $this->_where .= $this->_where_delim . " " . $dbfield . " != ''";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 7) == "_IsLike" && strlen($this->$prop)) {
+                    } elseif (substr($prop, - 7) == "_IsLike" && strlen($this->$prop ?? '')) {
                         $dbfield = $this->GetFieldFromProp(str_replace("_IsLike", "", $prop));
                         $this->_where .= $this->_where_delim . " " . $dbfield . " like '%" . $this->Escape($val) . "%'";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 10) == "_IsNotLike" && strlen($this->$prop)) {
+                    } elseif (substr($prop, - 10) == "_IsNotLike" && strlen($this->$prop ?? '')) {
                         $dbfield = $this->GetFieldFromProp(str_replace("_IsNotLike", "", $prop));
                         $this->_where .= $this->_where_delim . " " . $dbfield . " not like '%" . $this->Escape($val) . "%'";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 11) == "_BeginsWith" && strlen($this->$prop)) {
+                    } elseif (substr($prop, - 11) == "_BeginsWith" && strlen($this->$prop ?? '')) {
                         $dbfield = $this->GetFieldFromProp(str_replace("_BeginsWith", "", $prop));
                         $this->_where .= $this->_where_delim . " " . $dbfield . " like '" . $this->Escape($val) . "%'";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 9) == "_EndsWith" && strlen($this->$prop)) {
+                    } elseif (substr($prop, - 9) == "_EndsWith" && strlen($this->$prop ?? '')) {
                         $dbfield = $this->GetFieldFromProp(str_replace("_EndsWith", "", $prop));
                         $this->_where .= $this->_where_delim . " " . $dbfield . " like '%" . $this->Escape($val) . "'";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 12) == "_GreaterThan" && strlen($this->$prop)) {
+                    } elseif (substr($prop, - 12) == "_GreaterThan" && strlen($this->$prop ?? '')) {
                         $dbfield = $this->GetFieldFromProp(str_replace("_GreaterThan", "", $prop));
                         $this->_where .= $this->_where_delim . " " . $dbfield . " > " . $this->GetQuotedSql($val) . "";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 19) == "_GreaterThanOrEqual" && strlen($this->$prop)) {
+                    } elseif (substr($prop, - 19) == "_GreaterThanOrEqual" && strlen($this->$prop ?? '')) {
                         $dbfield = $this->GetFieldFromProp(str_replace("_GreaterThanOrEqual", "", $prop));
                         $this->_where .= $this->_where_delim . " " . $dbfield . " >= " . $this->GetQuotedSql($val) . "";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 9) == "_LessThan" && strlen($this->$prop)) {
+                    } elseif (substr($prop, - 9) == "_LessThan" && strlen($this->$prop ?? '')) {
                         $dbfield = $this->GetFieldFromProp(str_replace("_LessThan", "", $prop));
                         $this->_where .= $this->_where_delim . " " . $dbfield . " < " . $this->GetQuotedSql($val) . "";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 16) == "_LessThanOrEqual" && strlen($this->$prop)) {
+                    } elseif (substr($prop, - 16) == "_LessThanOrEqual" && strlen($this->$prop ?? '')) {
                         $dbfield = $this->GetFieldFromProp(str_replace("_LessThanOrEqual", "", $prop));
                         $this->_where .= $this->_where_delim . " " . $dbfield . " <= " . $this->GetQuotedSql($val) . "";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 10) == "_BitwiseOr" && strlen($this->$prop)) {
+                    } elseif (substr($prop, - 10) == "_BitwiseOr" && strlen($this->$prop ?? '')) {
                         $dbfield = $this->GetFieldFromProp(str_replace("_BitwiseOr", "", $prop));
                         $this->_where .= $this->_where_delim . " (" . $dbfield . " | '" . $this->Escape($val) . ")";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 11) == "_BitwiseAnd" && strlen($this->$prop)) {
+                    } elseif (substr($prop, - 11) == "_BitwiseAnd" && strlen($this->$prop ?? '')) {
                         $dbfield = $this->GetFieldFromProp(str_replace("_BitwiseAnd", "", $prop));
                         $this->_where .= $this->_where_delim . " (" . $dbfield . " & " . $this->Escape($val) . ")";
                         $this->_where_delim = " and";
-                    } elseif (substr($prop, - 16) == "_LiteralFunction" && strlen($this->$prop)) {
+                    } elseif (substr($prop, - 16) == "_LiteralFunction" && strlen($this->$prop ?? '')) {
                         $dbfield = $this->GetFieldFromProp(str_replace("_LiteralFunction", "", $prop));
                         $this->_where .= $this->_where_delim . " (" . $dbfield . " " . $val . ")";
                         $this->_where_delim = " and";

programming_language: PHP
filename: DataPage.php
change_type: ModificationType.MODIFY
diff: @@ -46,10 +46,12 @@ class DataPage implements Iterator
      *
      * @return Phreezable
      */
+    #[\ReturnTypeWillChange]
     public function Next()
     {
         return next($this->Rows);
     }
+    #[\ReturnTypeWillChange]
     public function rewind()
     {
         reset($this->Rows);
@@ -59,14 +61,17 @@ class DataPage implements Iterator
      *
      * @return Phreezable
      */
+    #[\ReturnTypeWillChange]
     public function current()
     {
         return current($this->Rows);
     }
+    #[\ReturnTypeWillChange]
     public function key()
     {
         return key($this->Rows);
     }
+    #[\ReturnTypeWillChange]
     public function valid()
     {
         return $this->current() !== false;

programming_language: PHP
filename: DataSet.php
change_type: ModificationType.MODIFY
diff: @@ -93,6 +93,7 @@ class DataSet implements Iterator // @TODO implement Countable, ArrayAccess
      * @access public
      * @return Preezable
      */
+    #[\ReturnTypeWillChange]
     function Next()
     {
         if ($this->UnableToCache) {
@@ -147,6 +148,7 @@ class DataSet implements Iterator // @TODO implement Countable, ArrayAccess
     {
         return $this->_phreezer->DataAdapter->Execute($this->_sql);
     }
+    #[\ReturnTypeWillChange]
     public function rewind()
     {
         $this->_rs = null;
@@ -156,6 +158,7 @@ class DataSet implements Iterator // @TODO implement Countable, ArrayAccess
         $this->_verifyRs();
         $this->Next(); // we have to get the party started for php iteration
     }
+    #[\ReturnTypeWillChange]
     public function current()
     {
         // php iteration calls next then gets the current record. The DataSet
@@ -163,10 +166,12 @@ class DataSet implements Iterator // @TODO implement Countable, ArrayAccess
         // laster iteration to make it work properly
         return ($this->key() == $this->Count()) ? $this->_last : $this->_current;
     }
+    #[\ReturnTypeWillChange]
     public function key()
     {
         return $this->_counter;
     }
+    #[\ReturnTypeWillChange]
     public function valid()
     {
         return $this->key() <= $this->Count();

programming_language: PHP
filename: Phreezable.php
change_type: ModificationType.MODIFY
diff: @@ -431,7 +431,7 @@ abstract class Phreezable implements Serializable
                             break;
                         case FM_TYPE_DATE:
                         case FM_TYPE_DATETIME:
-                            if (strtotime($this->$prop) === '') {
+                            if (strtotime(($this->$prop ?? '')) === '') {
                                 $this->AddValidationError($prop, "$prop is not a valid date/time value.");
                             }
                             break;
@@ -787,4 +787,10 @@ abstract class Phreezable implements Serializable
     {
         throw new Exception("Unknown property: $key");
     }
+
+    function __serialize()
+    {}
+
+    function __unserialize($data)
+    {}
 }

programming_language: PHP
filename: Reporter.php
change_type: ModificationType.MODIFY
diff: @@ -342,4 +342,10 @@ abstract class Reporter implements Serializable
     protected function OnLoad()
     {
     }
+
+    function __serialize()
+    {}
+
+    function __unserialize($data)
+    {}
 }

programming_language: PHP
filename: PortalPatientController.php
change_type: ModificationType.MODIFY
diff: @@ -195,7 +195,9 @@ class PortalPatientController extends AppBasePortalController
             $patient->Fitness = $this->SafeGetVal($json, 'fitness', $patient->Fitness);
             $patient->ReferralSource = $this->SafeGetVal($json, 'referralSource', $patient->ReferralSource);
             $patient->Pricelevel = $this->SafeGetVal($json, 'pricelevel', $patient->Pricelevel);*/
-            $patient->Regdate = date('Y-m-d', strtotime($this->SafeGetVal($json, 'regdate', $patient->Regdate)));
+            if (!empty($patient->Regdate)) {
+                $patient->Regdate = date('Y-m-d', strtotime($this->SafeGetVal($json, 'regdate', $patient->Regdate)));
+            }
             /*$patient->Contrastart = date('Y-m-d', strtotime($this->SafeGetVal($json, 'contrastart', $patient->Contrastart)));
             $patient->CompletedAd = $this->SafeGetVal($json, 'completedAd', $patient->CompletedAd);
             $patient->AdReviewed = date('Y-m-d', strtotime($this->SafeGetVal($json, 'adReviewed', $patient->AdReviewed)));

programming_language: PHP
filename: OnsiteActivityViewListView.tpl.php
change_type: ModificationType.MODIFY
diff: @@ -10,11 +10,18 @@
  * @license   https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
  */
 
-    $this->assign('title', xlt('Portal') . ' | ' . xlt('Activity'));
-    $this->assign('nav', 'onsiteactivityviews');
+$this->assign('title', xlt('Portal') . ' | ' . xlt('Activity'));
+$this->assign('nav', 'onsiteactivityviews');
 
-    $this->display('_FormsHeader.tpl.php');
-    echo "<script>var cuser='" . $this->cuser . "';</script>";
+use OpenEMR\Common\Acl\AclMain;
+
+if (!AclMain::aclCheckCore('patientportal', 'portal')) {
+    die(xlt("Unauthorized"));
+    exit;
+}
+
+$this->display('_FormsHeader.tpl.php');
+echo "<script>var cuser='" . $this->cuser . "';</script>";
 ?>
 <script>
     $LAB.script("<?php echo $GLOBALS['web_root']; ?>/portal/patient/scripts/app/onsiteactivityviews.js?v=<?php echo $GLOBALS['v_js_includes']; ?>").wait(function(){

programming_language: PHP
filename: ProviderHome.tpl.php
change_type: ModificationType.MODIFY
diff: @@ -13,8 +13,14 @@
 $this->assign('title', xlt("Portal Dashboard") . " | " . xlt("Home"));
 $this->assign('nav', 'home');
 
+use OpenEMR\Common\Acl\AclMain;
 use OpenEMR\Core\Header;
 
+if (!AclMain::aclCheckCore('patientportal', 'portal')) {
+    die(xlt("Unauthorized"));
+    exit;
+}
+
 ?>
 <!DOCTYPE html>
 <!-- Language grabbed by PDF var that has the correct format !-->

programming_language: PHP
filename: portal_patient_report.php
change_type: ModificationType.MODIFY
diff: @@ -470,7 +470,7 @@ while ($prow = sqlFetchArray($pres)) {
         if ($result["form_name"] == "New Patient Encounter") {
             if ($isfirst == 0) {
                 foreach ($registry_form_name as $var) {
-                    if ($toprint = $html_strings[$var]) {
+                    if ($toprint = ($html_strings[$var] ?? '')) {
                         foreach ($toprint as $var) {
                             print $var;
                         }

programming_language: PHP
filename: save-signature.php
change_type: ModificationType.MODIFY
diff: @@ -39,6 +39,18 @@ if ($isPortal) {
 }
 require_once("../../../interface/globals.php");
 
+if (!$isPortal) {
+    $userManipulatedFlag = false;
+    if ($user != $_SESSION['authUserID']) {
+        $userManipulatedFlag = true;
+    }
+
+    if ($userManipulatedFlag) {
+        echo js_escape("error");
+        exit();
+    }
+}
+
 if ($type === 'witness-signature') {
     echo(js_escape('Done'));
     exit();

programming_language: PHP
filename: show-signature.php
change_type: ModificationType.MODIFY
diff: @@ -38,6 +38,18 @@ if ($isPortal) {
 }
 require_once("../../../interface/globals.php");
 
+if (!$isPortal) {
+    $userManipulatedFlag = false;
+    if ($user != $_SESSION['authUserID']) {
+        $userManipulatedFlag = true;
+    }
+
+    if ($userManipulatedFlag) {
+        echo js_escape("error");
+        exit();
+    }
+}
+
 $created = time();
 $lastmod = date('Y-m-d H:i:s');
 $status = 'filed';
@@ -57,7 +69,7 @@ if ($req_pid === 0 || empty($user)) {
     }
 }
 
-if ($data['mode'] === 'fetch_info') {
+if (($data['mode'] ?? null) === 'fetch_info') {
     $stmt = "Select CONCAT(IFNULL(fname,''), ' ',IFNULL(lname,'')) as userName From users Where id = ?";
     $user_result = sqlQuery($stmt, array($user)) ?: [];
     $stmt = "Select CONCAT(IFNULL(fname,''), ' ',IFNULL(lname,'')) as ptName From patient_data Where pid = ?";
@@ -87,20 +99,20 @@ if ($isAdmin) {
     $row = sqlQuery("SELECT pid,status,sig_image,type,user FROM onsite_signatures WHERE pid=? And user=?", array($req_pid, $user));
 }
 
-if (!$row['pid'] && !$row['user']) {
+if (!($row['pid'] ?? null) && !($row['user'] ?? null)) {
     $status = 'waiting';
     $qstr = "INSERT INTO onsite_signatures (pid,lastmod,status,type,user,signator,created) VALUES (?,?,?,?,?,?,?)";
     sqlStatement($qstr, array($req_pid, $lastmod, $status, $type, $user, $signer, $created));
 }
 
-if ($row['status'] == 'filed') {
-    if ($data['mode'] === 'fetch_info') {
+if (($row['status'] ?? null) == 'filed') {
+    if (($data['mode'] ?? null) === 'fetch_info') {
         $info_query['signature'] = $row['sig_image'];
         echo js_escape($info_query);
         exit();
     }
     echo js_escape($row['sig_image']);
-} elseif ($row['status'] == 'waiting' || $status == 'waiting') {
+} elseif (($row['status'] ?? null) == 'waiting' || $status == 'waiting') {
     $info_query['message'] = 'waiting';
     echo js_escape($info_query);
 }

programming_language: PHP
filename: Gacl.php
change_type: ModificationType.MODIFY
diff: @@ -566,6 +566,9 @@ class Gacl {
 			} else {
                                 if ($return_all) {
 			                // Permission denied.
+                            if(!is_array($retarr)) {
+                                $retarr = [];
+                            }
 			                $retarr[] = array('acl_id' => NULL, 'return_value' => NULL, 'allow' => FALSE);
                                 }
                                 else {

programming_language: PHP