CVE-2017-12064 (published 2017-08-01T05:29Z)

The csv_log_html function in library/edihistory/edih_csv_inc.php in OpenEMR 5.0.0 and prior allows attackers to bypass intended access restrictions via a crafted name.

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

Weakness information:
cwe_id: CWE-116
cwe_name: Improper Encoding or Escaping of Output
description: The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved.
extended_description: 
            Improper encoding or escaping can allow attackers to change the commands that are sent to another component, inserting malicious commands instead.
            Most products follow a certain protocol that uses structured messages for communication between components, such as queries or commands. These structured messages can contain raw data interspersed with metadata or control information. For example, "GET /index.html HTTP/1.1" is a structured message containing a command ("GET") with a single argument ("/index.html") and metadata about which protocol version is being used ("HTTP/1.1").
            If an application uses attacker-supplied inputs to construct a structured message without properly encoding or escaping, then the attacker could insert special characters that will cause the data to be interpreted as control information or metadata. Consequently, the component that receives the output will perform the wrong operations, or otherwise interpret the data incorrectly.
         
         

Fix information:
repo_url: https://github.com/openemr/openemr
commit_details: repo_url: https://github.com/openemr/openemr
author: Brady Miller
author_date: 2017-06-28 18:17:21-07:00
msg: security fix
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: edih_csv_inc.php
change_type: ModificationType.MODIFY
diff: @@ -134,6 +134,7 @@ function csv_edihist_log ( $msg_str ) {
  * @return string
  */
 function csv_log_html($logname='') {
+	check_file_dir_name($logname);
 	$html_str = "<div class='filetext'>".PHP_EOL."<ol class='logview'>".PHP_EOL;
     $fp = csv_edih_basedir().DS.'log'.DS.$logname;
     if ( is_file($fp) ) {

programming_language: PHP
filename: sanitize.inc.php
change_type: ModificationType.MODIFY
diff: @@ -2,30 +2,23 @@
 /**
 * Function to check and/or sanitize things for security such as
 * directories names, file names, etc.
-*
-* Copyright (C) 2012 by following Brady Miller <brady.g.miller@gmail.com>
-*
-* LICENSE: This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 3
-* of the License, or (at your option) any later version.
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
-*
-* @package OpenEMR
-* @author Brady Miller <brady.g.miller@gmail.com>
-* @author Roberto Vasquez <robertogagliotta@gmail.com>
-* @author Shachar Zilbershlag <shaharzi@matrix.co.il>
-* @link http://www.open-emr.org
-*/
+ *
+ * @package OpenEMR
+ * @link    http://www.open-emr.org
+ * @author  Brady Miller <brady.g.miller@gmail.com>
+ * @author  Roberto Vasquez <robertogagliotta@gmail.com>
+ * @author  Shachar Zilbershlag <shaharzi@matrix.co.il>
+ * @copyright Copyright (c) 2012-2017 Brady Miller <brady.g.miller@gmail.com>
+ * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
+ */
+
+
 // If the label contains any illegal characters, then the script will die.
 function check_file_dir_name($label) {
-  if (empty($label) || preg_match('/[^A-Za-z0-9_.-]/', $label))
+  if (empty($label) || preg_match('/[^A-Za-z0-9_.-]/', $label)) {
+    error_log("ERROR: The following variable contains invalid characters:" . $label);
     die(xlt("ERROR: The following variable contains invalid characters").": ". attr($label));
+  }
 }
 
 // Convert all illegal characters to _

programming_language: PHP