CVE-2021-43806: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: 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.
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-15T20:15Z
Repository: https://github.com/Enalean/tuleap
Language: PHP
Files changed: src/www/cvs/commit_utils.php
Commit date: 2021-12-07 16:05:44 +0100
Commit message: request #24202: SQL injection via the user settings of the CVS commits browser

Change-Id: I9dff1d45d703de5c9a55182d673a70c21ea53d89

Diff: diff --git a/src/www/cvs/commit_utils.php b/src/www/cvs/commit_utils.php
index bd62c35476b..29881fb99b5 100644
--- a/src/www/cvs/commit_utils.php
+++ b/src/www/cvs/commit_utils.php
@@ -711,27 +711,27 @@ function cvs_get_revisions($project, $offset, $chunksz, $_tag = 100, $_branch =
     // get repository id
     $cvs_repository = db_es('/cvsroot/' . $project->getUnixName(false));
     $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 . " " .
         "$commiter_str " .
             "$commit_str " .
         "$srch_str " .
         "$branch_str ";
 
     $limit = '';
     if (! $pv) {
-        $limit = " LIMIT $offset,$chunksz";
+        $limit = " LIMIT " . db_ei($offset) . ',' . db_ei($chunksz);
     }
 
     if (empty($order_by)) {
         $order_by_sql = ' ORDER BY id desc, f_when desc ';
     } else {

Vulnerable code:     $repo_id        = $repo_id ? $repo_id : -1;
    "AND " . (check_cvs_access(user_getname(), $project->getUnixName(false), '') ? 1 : 0) . " " .
        $limit = " LIMIT $offset,$chunksz";
Fixed code:     $repo_id        = db_ei($repo_id ? $repo_id : -1);
    "AND " . db_ei(check_cvs_access(user_getname(), $project->getUnixName(false), '') ? 1 : 0) . " " .
        $limit = " LIMIT " . db_ei($offset) . ',' . db_ei($chunksz);