CVE-2023-7101 (published 2023-12-24T22:15Z)

Spreadsheet::ParseExcel version 0.65 is a Perl module used for parsing Excel files. Spreadsheet::ParseExcel is vulnerable to an arbitrary code execution (ACE) vulnerability due to passing unvalidated input from a file into a string-type “eval”. Specifically, the issue stems from the evaluation of Number format strings (not to be confused with printf-style format strings) within the Excel parsing logic. \n

CVSS v3 base score: 7.8, HIGH (CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-94
cwe_name: Improper Control of Generation of Code ('Code Injection')
description: The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
extended_description: 
            When a product allows a user's input to contain code syntax, it might be possible for an attacker to craft the code in such a way that it will alter the intended control flow of the product. Such an alteration could lead to arbitrary code execution.
            Injection problems encompass a wide variety of issues -- all mitigated in very different ways. For this reason, the most effective way to discuss these weaknesses is to note the distinct features which classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed. The most classic instantiations of this category of weakness are SQL injection and format string vulnerabilities.
         
         

Fix information:
repo_url: https://github.com/jmcnamara/spreadsheet-parseexcel
commit_details: repo_url: https://github.com/jmcnamara/spreadsheet-parseexcel
author: Daniel Ruoso
author_date: 2023-12-28 11:56:10-05:00
msg: Do not use string eval for conditional formatting
repository: repo_url: https://github.com/jmcnamara/spreadsheet-parseexcel
repo_name: jmcnamara/spreadsheet-parseexcel
description: Perl module to read Excel binary files
repo_language: Perl
owner: jmcnamara
file_changes: filename: Utility.pm
change_type: ModificationType.MODIFY
diff: @@ -78,10 +78,12 @@ sub ExcelFmt {
     $format_str = '@' if uc($format_str) eq "GENERAL";
 
     # Check for a conditional at the start of the format. See notes above.
-    my $conditional;
-    if ( $format_str =~ /^\[([<>=][^\]]+)\](.*)$/ ) {
-        $conditional = $1;
-        $format_str  = $2;
+    my $conditional_op;
+    my $conditional_value;
+    if ( $format_str =~ /^\[([<>=]+)([^\]]+)\](.*)$/ ) {
+        $conditional_op = $1;
+        $conditional_value = $2;
+        $format_str = $3;
     }
 
     # Ignore the underscore token which is used to indicate a padding space.
@@ -166,12 +168,23 @@ sub ExcelFmt {
     }
 
     # Override the previous choice if the format is conditional.
-    if ($conditional) {
-
-        # TODO. Replace string eval with a function.
-        $section = eval "$number $conditional" ? 0 : 1;
+    if ($conditional_op) {
+        if ($conditional_op eq '>') {
+            $section = $number > $conditional_value ? 0 : 1;
+        } elsif ($conditional_op eq '>=') {
+            $section = $number >= $conditional_value ? 0 : 1;
+        } elsif ($conditional_op eq '<') {
+            $section = $number < $conditional_value ? 0 : 1;
+        } elsif ($conditional_op eq '<=') {
+            $section = $number <= $conditional_value ? 0 : 1;
+        } elsif ($conditional_op eq '=') {
+            $section = $number == $conditional_value ? 0 : 1;
+        } elsif ($conditional_op eq '==') {
+            $section = $number == $conditional_value ? 0 : 1;
+        } elsif ($conditional_op eq '<>') {
+            $section = $number != $conditional_value ? 0 : 1;
+        }
     }
-
     # We now have the required format.
     $format = $formats[$section];
 

programming_language: Perl