CVE-2020-15255 (published 2020-10-16T17:15Z)

In Anuko Time Tracker before verion 1.19.23.5325, due to not properly filtered user input a CSV export of a report could contain cells that are treated as formulas by spreadsheet software (for example, when a cell value starts with an equal sign). This is fixed in version 1.19.23.5325.

Severity: MEDIUM
CVSS v2 base score: 6.0 (AV:N/AC:M/Au:S/C:P/I:P/A:P)
CVSS v3 base score: 7.3, HIGH (CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-1236
cwe_name: Improper Neutralization of Formula Elements in a CSV File
description: The product saves user-provided information into a Comma-Separated Value (CSV) file, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as a command when the file is opened by a spreadsheet product.
extended_description: User-provided data is often saved to traditional databases.  This data can be exported to a CSV file, which allows users to read the data using spreadsheet software such as Excel, Numbers, or Calc.  This software interprets entries beginning with '=' as formulas, which are then executed by the spreadsheet software.  The software's formula language often allows methods to access hyperlinks or the local command line, and frequently allows enough characters to invoke an entire script. Attackers can populate data fields which, when saved to a CSV file, may attempt information exfiltration or other malicious activity when automatically executed by the spreadsheet software.
			

Fix information:
repo_url: https://github.com/anuko/timetracker
commit_details: repo_url: https://github.com/anuko/timetracker
author: Nik Okuntseff
author_date: 2020-10-11 22:25:28+00:00
msg: Security fix for csv injections.
repository: repo_url: https://github.com/anuko/timetracker
repo_name: anuko/timetracker
description: Simple, easy to use, open source time tracking system.
repo_language: PHP
owner: anuko
file_changes: filename: common.lib.php
change_type: ModificationType.MODIFY
diff: @@ -459,3 +459,12 @@ function ttRandomString($length = 32) {
   }
   return $randomString;
 }
+
+// ttNeutralizeForCsv neutralizes user input for export to CSV files
+// by removing =, +, -, and @ characters from the beginning of cell values.
+// This mitigates a risk of CSV injection, see https://owasp.org/www-community/attacks/CSV_Injection
+// Additionally, it replaces each quote character with a double quote.
+function ttNeutralizeForCsv($val) {
+  $result = ltrim($val, '=+-@');
+  return str_replace('"', '""', $result);
+}

programming_language: PHP
filename: initialize.php
change_type: ModificationType.MODIFY
diff: @@ -37,7 +37,7 @@ error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT); // & ~E_DEPRECATED);
 ini_set('display_errors', 'Off');
 
 // require_once('init_auth.php');
-define("APP_VERSION", "1.19.23.5324");
+define("APP_VERSION", "1.19.23.5325");
 define("APP_DIR", dirname(__FILE__));
 define("LIBRARY_DIR", APP_DIR."/WEB-INF/lib");
 define("TEMPLATE_DIR", APP_DIR."/WEB-INF/templates");

programming_language: PHP
filename: tofile.php
change_type: ModificationType.MODIFY
diff: @@ -218,7 +218,7 @@ if ('csv' == $type) {
       foreach ($custom_fields->userFields as $userField) {
         $field_name = 'user_field_'.$userField['id'];
         $checkbox_control_name = 'show_'.$field_name;
-        if ($bean->getAttribute($checkbox_control_name)) print ',"'.str_replace('"','""',$userField['label']).'"';
+        if ($bean->getAttribute($checkbox_control_name)) print ',"'.ttNeutralizeForCsv($userField['label']).'"';
       }
     }
     if ($bean->getAttribute('chclient')) print ',"'.$i18n->get('label.client').'"';
@@ -229,7 +229,7 @@ if ('csv' == $type) {
       foreach ($custom_fields->timeFields as $timeField) {
         $field_name = 'time_field_'.$timeField['id'];
         $checkbox_control_name = 'show_'.$field_name;
-        if ($bean->getAttribute($checkbox_control_name)) print ',"'.str_replace('"','""',$timeField['label']).'"';
+        if ($bean->getAttribute($checkbox_control_name)) print ',"'.ttNeutralizeForCsv($timeField['label']).'"';
       }
     }
     if ($bean->getAttribute('chstart')) print ',"'.$i18n->get('label.start').'"';
@@ -248,24 +248,24 @@ if ('csv' == $type) {
     // Print items.
     foreach ($items as $item) {
       print '"'.$item['date'].'"';
-      if ($user->can('view_reports') || $user->can('view_all_reports') || $user->isClient()) print ',"'.str_replace('"','""',$item['user']).'"';
+      if ($user->can('view_reports') || $user->can('view_all_reports') || $user->isClient()) print ',"'.ttNeutralizeForCsv($item['user']).'"';
       // User custom fields.
       if ($custom_fields && $custom_fields->userFields) {
         foreach ($custom_fields->userFields as $userField) {
           $field_name = 'user_field_'.$userField['id'];
           $checkbox_control_name = 'show_'.$field_name;
-          if ($bean->getAttribute($checkbox_control_name)) print ',"'.str_replace('"','""',$item[$field_name]).'"';
+          if ($bean->getAttribute($checkbox_control_name)) print ',"'.ttNeutralizeForCsv($item[$field_name]).'"';
         }
       }
-      if ($bean->getAttribute('chclient')) print ',"'.str_replace('"','""',$item['client']).'"';
-      if ($bean->getAttribute('chproject')) print ',"'.str_replace('"','""',$item['project']).'"';
-      if ($bean->getAttribute('chtask')) print ',"'.str_replace('"','""',$item['task']).'"';
+      if ($bean->getAttribute('chclient')) print ',"'.ttNeutralizeForCsv($item['client']).'"';
+      if ($bean->getAttribute('chproject')) print ',"'.ttNeutralizeForCsv($item['project']).'"';
+      if ($bean->getAttribute('chtask')) print ',"'.ttNeutralizeForCsv($item['task']).'"';
       // Time custom fields.
       if ($custom_fields && $custom_fields->timeFields) {
         foreach ($custom_fields->timeFields as $timeField) {
           $field_name = 'time_field_'.$timeField['id'];
           $checkbox_control_name = 'show_'.$field_name;
-          if ($bean->getAttribute($checkbox_control_name)) print ',"'.str_replace('"','""',$item[$field_name]).'"';
+          if ($bean->getAttribute($checkbox_control_name)) print ',"'.ttNeutralizeForCsv($item[$field_name]).'"';
         }
       }
       if ($bean->getAttribute('chstart')) print ',"'.$item['start'].'"';
@@ -277,7 +277,7 @@ if ('csv' == $type) {
         print ',"'.$val.'"';
       }
       if ($bean->getAttribute('chunits')) print ',"'.$item['units'].'"';
-      if ($bean->getAttribute('chnote')) print ',"'.str_replace('"','""',$item['note']).'"';
+      if ($bean->getAttribute('chnote')) print ',"'.ttNeutralizeForCsv($item['note']).'"';
       if ($bean->getAttribute('chcost')) {
         if ($user->can('manage_invoices') || $user->isClient())
           print ',"'.$item['cost'].'"';
@@ -290,8 +290,8 @@ if ('csv' == $type) {
         $ip = $item['modified'] ? $item['modified_ip'].' '.$item['modified'] : $item['created_ip'].' '.$item['created'];
         print ',"'.$ip.'"';
       }
-      if ($bean->getAttribute('chinvoice')) print ',"'.str_replace('"','""',$item['invoice']).'"';
-      if ($bean->getAttribute('chtimesheet')) print ',"'.str_replace('"','""',$item['timesheet_name']).'"';
+      if ($bean->getAttribute('chinvoice')) print ',"'.ttNeutralizeForCsv($item['invoice']).'"';
+      if ($bean->getAttribute('chtimesheet')) print ',"'.ttNeutralizeForCsv($item['timesheet_name']).'"';
       print "\n";
     }
   }

programming_language: PHP