Vulnerability: Tuleap is a Libre and Open Source tool for end to end traceability of application and system developments. In affected versions Tuleap does not sanitize properly user settings when constructing the SQL query to browse and search commits in the CVS repositories. A authenticated malicious user with read access to a CVS repository could execute arbitrary SQL queries. Tuleap instances without an active CVS repositories are not impacted. The following versions contain the fix: Tuleap Community Edition 13.2.99.155, Tuleap Enterprise Edition 13.1-7, and Tuleap Enterprise Edition 13.2-6.
Vulnerability ID: CVE-2021-43806
CWE: CWE-89
Severity score: 6.4
Project: https://github.com/Enalean/tuleap
Published: 2021-12-15
File: src/www/cvs/commit_utils.php
Commit message: request #24202: SQL injection via the user settings of the CVS commits browser

Change-Id: I9dff1d45d703de5c9a55182d673a70c21ea53d89
Commit author: Thomas Gerbet

Vulnerable version (before fix):
 function cvs_get_revisions($project, $offset, $chunksz, $_tag = 100, $_branch =     $query          = "SELECT id from cvs_repositories where cvs_repositories.repository='$cvs_repository' ";     $rs             = db_query($query);     $repo_id        = db_result($rs, 0, 0);     $repo_id        = $repo_id ? $repo_id : -1;      $select = 'SELECT distinct cvs_checkins.commitid as id, cvs_checkins.commitid as revision, cvs_descs.id as did, cvs_descs.description, cvs_commits.comm_when as c_when, cvs_commits.comm_when as date, cvs_commits.comm_when as f_when, user.user_name as who ';     $from   = "FROM cvs_descs, cvs_checkins, user, cvs_commits ";     $where  = "WHERE cvs_checkins.descid=cvs_descs.id " .     "AND " . (check_cvs_access(user_getname(), $project->getUnixName(false), '') ? 1 : 0) . " " .         "AND cvs_checkins.commitid=cvs_commits.id " .         "AND user.user_id=cvs_checkins.whoid " .             "AND cvs_checkins.repositoryid=" . $repo_id . " " . function cvs_get_revisions($project, $offset, $chunksz, $_tag = 100, $_branch =      $limit = '';     if (! $pv) {         $limit = " LIMIT $offset,$chunksz";     }      if (empty($order_by)) {

Fixed version (after fix):
 function cvs_get_revisions($project, $offset, $chunksz, $_tag = 100, $_branch =     $query          = "SELECT id from cvs_repositories where cvs_repositories.repository='$cvs_repository' ";     $rs             = db_query($query);     $repo_id        = db_result($rs, 0, 0);     $repo_id        = db_ei($repo_id ? $repo_id : -1);      $select = 'SELECT distinct cvs_checkins.commitid as id, cvs_checkins.commitid as revision, cvs_descs.id as did, cvs_descs.description, cvs_commits.comm_when as c_when, cvs_commits.comm_when as date, cvs_commits.comm_when as f_when, user.user_name as who ';     $from   = "FROM cvs_descs, cvs_checkins, user, cvs_commits ";     $where  = "WHERE cvs_checkins.descid=cvs_descs.id " .     "AND " . db_ei(check_cvs_access(user_getname(), $project->getUnixName(false), '') ? 1 : 0) . " " .         "AND cvs_checkins.commitid=cvs_commits.id " .         "AND user.user_id=cvs_checkins.whoid " .             "AND cvs_checkins.repositoryid=" . $repo_id . " " . function cvs_get_revisions($project, $offset, $chunksz, $_tag = 100, $_branch =      $limit = '';     if (! $pv) {         $limit = " LIMIT " . db_ei($offset) . ',' . db_ei($chunksz);     }      if (empty($order_by)) {

Patch:
patch: @@ -713,12 +713,12 @@ function cvs_get_revisions($project, $offset, $chunksz, $_tag = 100, $_branch =
     $query          = "SELECT id from cvs_repositories where cvs_repositories.repository='$cvs_repository' ";
     $rs             = db_query($query);
     $repo_id        = db_result($rs, 0, 0);
-    $repo_id        = $repo_id ? $repo_id : -1;
+    $repo_id        = db_ei($repo_id ? $repo_id : -1);
 
     $select = 'SELECT distinct cvs_checkins.commitid as id, cvs_checkins.commitid as revision, cvs_descs.id as did, cvs_descs.description, cvs_commits.comm_when as c_when, cvs_commits.comm_when as date, cvs_commits.comm_when as f_when, user.user_name as who ';
     $from   = "FROM cvs_descs, cvs_checkins, user, cvs_commits ";
     $where  = "WHERE cvs_checkins.descid=cvs_descs.id " .
-    "AND " . (check_cvs_access(user_getname(), $project->getUnixName(false), '') ? 1 : 0) . " " .
+    "AND " . db_ei(check_cvs_access(user_getname(), $project->getUnixName(false), '') ? 1 : 0) . " " .
         "AND cvs_checkins.commitid=cvs_commits.id " .
         "AND user.user_id=cvs_checkins.whoid " .
             "AND cvs_checkins.repositoryid=" . $repo_id . " " .
@@ -729,7 +729,7 @@ function cvs_get_revisions($project, $offset, $chunksz, $_tag = 100, $_branch =
 
     $limit = '';
     if (! $pv) {
-        $limit = " LIMIT $offset,$chunksz";
+        $limit = " LIMIT " . db_ei($offset) . ',' . db_ei($chunksz);
     }
 
     if (empty($order_by)) {
path: src/www/cvs/commit_utils.php