CVE-2021-43851: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: Anuko Time Tracker is an open source, web-based time tracking application written in PHP. SQL injection vulnerability exist in multiple files in Time Tracker version 1.19.33.5606 and prior due to not properly checking of the "group" and "status" parameters in POST requests. Group parameter is posted along when navigating between organizational subgroups (groups.php file). Status parameter is used in multiple files to change a status of an entity such as making a project, task, or user inactive. This issue has been patched in version 1.19.33.5607. An upgrade is highly recommended. If an upgrade is not practical, introduce ttValidStatus function as in the latest version and start using it user input check blocks wherever status field is used. For groups.php fix, introduce ttValidInteger function as in the latest version and use it in the access check block in the file.
CWE description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
CVSS v3 base score: 8.8
Published: 2021-12-22T00:15Z
Repository: https://github.com/anuko/timetracker
Language: PHP
Files changed: WEB-INF/lib/ttGroupHelper.class.php, initialize.php
Commit date: 2021-10-21 12:29:00 +0000
Commit message: Added additional protection against an sql injection fixed in previous commit.

Diff: diff --git a/WEB-INF/lib/ttGroupHelper.class.php b/WEB-INF/lib/ttGroupHelper.class.php
index aa75a571e..81b0c7f34 100644
--- a/WEB-INF/lib/ttGroupHelper.class.php
+++ b/WEB-INF/lib/ttGroupHelper.class.php
@@ -25,13 +25,17 @@ class ttGroupHelper {
 
   // The getParentGroup determines a parent group for a given group.
   static function getParentGroup($group_id) {
     global $user;
 
+    // Checking parameters for sanity is normally done in access check blocks on pages.
+    // This cast below is just in case we forgot to check $group_id to be an integer.
+    $groupId = (int) $group_id; // Protection against sql injection.
+
     $mdb2 = getConnection();
 
-    $sql = "select parent_id from tt_groups where id = $group_id and org_id = $user->org_id and status = 1";
+    $sql = "select parent_id from tt_groups where id = $groupId and org_id = $user->org_id and status = 1";
     $res = $mdb2->query($sql);
 
     if (!is_a($res, 'PEAR_Error')) {
       $val = $res->fetchRow();
       return $val['parent_id'];
diff --git a/initialize.php b/initialize.php
index 92c907f30..bc05d18d9 100644
--- a/initialize.php
+++ b/initialize.php
@@ -10,11 +10,11 @@ error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT); // & ~E_DEPRECATED);
 // E_ALL tends to change as PHP evolves, therefore we use & here instead of exclusive OR (^).
 
 // Disable displaying errors on screen.
 ini_set('display_errors', 'Off');
 
-define("APP_VERSION", "1.19.31.5602");
+define("APP_VERSION", "1.19.31.5603");
 define("APP_DIR", dirname(__FILE__));
 define("LIBRARY_DIR", APP_DIR."/WEB-INF/lib");
 define("TEMPLATE_DIR", APP_DIR."/WEB-INF/templates");
 // Date format for database and URI parameters.
 define('DB_DATEFORMAT', '%Y-%m-%d');

Vulnerable code:     $sql = "select parent_id from tt_groups where id = $group_id and org_id = $user->org_id and status = 1";
define("APP_VERSION", "1.19.31.5602");
Fixed code:     // Checking parameters for sanity is normally done in access check blocks on pages.
    // This cast below is just in case we forgot to check $group_id to be an integer.
    $groupId = (int) $group_id; // Protection against sql injection.

    $sql = "select parent_id from tt_groups where id = $groupId and org_id = $user->org_id and status = 1";
define("APP_VERSION", "1.19.31.5603");