CVE-2023-3551 (published 2023-07-08T09:15Z)

 Code Injection in GitHub repository nilsteampassnet/teampass prior to 3.0.10.

CVSS v3 base score: 7.2, HIGH (CVSS:3.1/AV:N/AC:L/PR:H/UI:N/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/nilsteampassnet/teampass
commit_details: repo_url: https://github.com/nilsteampassnet/teampass
author: nilsteampassnet
author_date: 2023-07-08 10:02:56+02:00
msg: 3.0.10

Fix for #3779, #3775
Fix for improper handling of input in admin setting pages
repository: repo_url: https://github.com/nilsteampassnet/teampass
repo_name: nilsteampassnet/TeamPass
description: Collaborative Passwords Manager
repo_language: PHP
owner: nilsteampassnet
file_changes: filename: functions.js
change_type: ModificationType.MODIFY
diff: @@ -395,10 +395,10 @@ function simplePurifier(
     bHtml = false,
     bSvg = false,
     bSvgFilters = false
-)
+) 
 {
     return DOMPurify.sanitize(
-        text
+        sanitizeDom(text)
             .replaceAll('&lt;', '<')
             .replaceAll('&#x3C;', '<')
             .replaceAll('&#60;', '<')
@@ -515,6 +515,7 @@ function fieldDomPurifierWithWarning(
     bHtml = false,
     bSvg = false,
     bSvgFilters = false,
+    bSetting = false,
 )
 {
     if (field === undefined || field === '') {
@@ -523,10 +524,22 @@ function fieldDomPurifierWithWarning(
     if ($(field).val() === '') {
         return '';
     }
-    let string = '';
+    let string = '',
+        currentString = $(field).val();
+
+    // if bSetting is true, we use the setting value
+    // remove any closing ', string that could corrupt the setting
+    if (bSetting === true) {
+        currentString = currentString.replace(/',/g, '');
+    }
 
     // Purify string
-    string = simplePurifier($(field).val(), bHtml, bSvg, bSvgFilters);
+    string = simplePurifier(
+        sanitizeDom(currentString),
+        bHtml,
+        bSvg,
+        bSvgFilters
+    );
     
     // Clear field if string is empty and warn user
     if (string === '') {
@@ -543,4 +556,12 @@ function fieldDomPurifierWithWarning(
     }
 
     return string;
+}
+
+const sanitizeDom = (str) => {
+    const div = document.createElement('div');
+    div.textContent = str;
+    newString = div.innerHTML;
+    div.remove();
+    return newString;
 }
\ No newline at end of file

programming_language: JavaScript
filename: AntiXSS.php
change_type: ModificationType.MODIFY
diff: @@ -455,6 +455,7 @@ final class AntiXSS
     {
         $this->_initNeverAllowedStr();
         $this->_initNeverAllowedRegex();
+        UTF8::checkForSupport();
     }
 
     /**

programming_language: TypeScript
filename: 2fa.js.php
change_type: ModificationType.MODIFY
diff: @@ -55,34 +55,15 @@ if (checkUser($_SESSION['user_id'], $_SESSION['key'], '2fa', $SETTINGS) === fals
 <script type='text/javascript'>
     //<![CDATA[
 
-    console.log('2FA loaded')
-
-    $(document).on('click', '.generate-key', function() {
-        var size = $(this).data('length'),
-            target = $(this).closest('.input-group').find('input').attr('id');
-
-        $.post(
-            'sources/main.queries.php', {
-                type: 'generate_new_key',
-                type_category: 'action_key',
-                size: size
-            },
-            function(data) {
-                $('#' + target).val(data[0].key);
-            },
-            'json'
-        );
-    })
-
-
     $(document).on('click', '#button-duo-config-check', function() {
-        var data = "{\"ikey\":\"" + sanitizeString($("#duo_ikey").val()) + "\", \"skey\":\"" + sanitizeString($("#duo_skey").val()) + "\", \"host\":\"" + sanitizeString($("#duo_host").val()) + "\"}";
+        toastr
+            .info('<?php echo langHdl('loading_item'); ?> ... <i class="fas fa-circle-notch fa-spin fa-2x"></i>');
 
         // Prepare data
         var data = {
-            'duo_ikey': $('#duo_ikey').val(),
-            'duo_skey': $('#duo_skey').val(),
-            'duo_host': $('#duo_host').val()
+            'duo_ikey': sanitizeString($('#duo_ikey').val()),
+            'duo_skey': sanitizeString($('#duo_skey').val()),
+            'duo_host': sanitizeString($('#duo_host').val())
         }
         console.log(data);
 
@@ -110,7 +91,7 @@ if (checkUser($_SESSION['user_id'], $_SESSION['key'], '2fa', $SETTINGS) === fals
                 } else {
                     // Inform user
                     toastr.remove();
-                    toastr.info(
+                    toastr.success(
                         '<?php echo langHdl('duo-config-check-success'); ?>',
                         '', {
                             timeOut: 5000

programming_language: PHP
filename: 2fa.php
change_type: ModificationType.MODIFY
diff: @@ -157,7 +157,7 @@ require_once $SETTINGS['cpassman_dir'] . '/sources/main.functions.php';
                                         </small>
                                     </div>
                                     <div class="col-3">
-                                        <input type="text" class="form-control form-control-sm" id="ga_website_name" value="<?php echo isset($SETTINGS['ga_website_name']) === true ? $SETTINGS['ga_website_name'] : ''; ?>">
+                                        <input type="text" class="form-control form-control-sm purify" data-field="label" id="ga_website_name" value="<?php echo isset($SETTINGS['ga_website_name']) === true ? $SETTINGS['ga_website_name'] : ''; ?>">
                                     </div>
                                 </div>
 
@@ -205,7 +205,7 @@ require_once $SETTINGS['cpassman_dir'] . '/sources/main.functions.php';
                                         <?php echo langHdl('admin_duo_ikey'); ?>
                                     </div>
                                     <div class="col-7">
-                                        <input type="text" class="form-control form-control-sm" id="duo_ikey" value="<?php echo isset($SETTINGS['duo_ikey']) === true ? $SETTINGS['duo_ikey'] : ''; ?>">
+                                        <input type="text" class="form-control form-control-sm purify" data-field="label" id="duo_ikey" value="<?php echo isset($SETTINGS['duo_ikey']) === true ? $SETTINGS['duo_ikey'] : ''; ?>">
                                     </div>
                                 </div>
                                 <div class="row mb-2">
@@ -213,7 +213,7 @@ require_once $SETTINGS['cpassman_dir'] . '/sources/main.functions.php';
                                         <?php echo langHdl('admin_duo_skey'); ?>
                                     </div>
                                     <div class="col-7">
-                                        <input type="text" class="form-control form-control-sm" id="duo_skey" value="<?php echo isset($SETTINGS['duo_skey']) === true ? $SETTINGS['duo_skey'] : ''; ?>">
+                                        <input type="text" class="form-control form-control-sm purify" data-field="label" id="duo_skey" value="<?php echo isset($SETTINGS['duo_skey']) === true ? $SETTINGS['duo_skey'] : ''; ?>">
                                     </div>
                                 </div>
                                 <div class="row mb-2">
@@ -221,7 +221,7 @@ require_once $SETTINGS['cpassman_dir'] . '/sources/main.functions.php';
                                         <?php echo langHdl('admin_duo_host'); ?>
                                     </div>
                                     <div class="col-7">
-                                        <input type="text" class="form-control form-control-sm" id="duo_host" value="<?php echo isset($SETTINGS['duo_host']) === true ? $SETTINGS['duo_host'] : ''; ?>">
+                                        <input type="text" class="form-control form-control-sm purify" data-field="label" id="duo_host" value="<?php echo isset($SETTINGS['duo_host']) === true ? $SETTINGS['duo_host'] : ''; ?>">
                                     </div>
                                 </div>
 

programming_language: PHP
filename: admin.js.php
change_type: ModificationType.MODIFY
diff: @@ -135,7 +135,7 @@ declare(strict_types=1);
         }
 
         // Sanitize value
-        value = fieldDomPurifierWithWarning('#' + field);
+        value = fieldDomPurifierWithWarning('#' + field, false, false, false, true);
         if (value === false) {
             return false;
         }

programming_language: PHP
filename: users.js.php
change_type: ModificationType.MODIFY
diff: @@ -898,7 +898,7 @@ if (checkUser($_SESSION['user_id'], $_SESSION['key'], 'folders', $SETTINGS) ===
 
                 // Mandatory?
                 var validated = true,
-                    validEmailRegex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
+                    validEmailRegex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,15})+$/;
                 $('.required').each(function(i, obj) {
                     if ($(this).val() === '' && $(this).hasClass('select2') === false) {
                         $(this).addClass('is-invalid');

programming_language: PHP
filename: logs.datatables.php
change_type: ModificationType.MODIFY
diff: @@ -838,7 +838,7 @@ if (isset($_GET['action']) === true && $_GET['action'] === 'connections') {
     }
 } elseif (isset($_GET['action']) && $_GET['action'] === 'tasks_in_progress') {
     //Columns name
-    $aColumns = ['increment_id', 'created_at', 'updated_at', 'process_type', 'is_in_progress'];
+    $aColumns = ['p.increment_id', 'p.created_at', 'p.updated_at', 'p.process_type', 'p.is_in_progress'];
     //Ordering
     if (isset($_GET['order'][0]['dir']) === true
         && in_array($_GET['order'][0]['dir'], $aSortTypes) === true
@@ -854,7 +854,7 @@ if (isset($_GET['action']) === true && $_GET['action'] === 'connections') {
             $aColumns[0].' DESC';
     }
 
-    $sWhere = ' WHERE ((finished_at = "")';
+    $sWhere = ' WHERE ((p.finished_at = "")';
     if (isset($_GET['search']['value']) === true && $_GET['search']['value'] !== '') {
         $sWhere .= ' AND (';
         for ($i = 0; $i < count($aColumns); ++$i) {
@@ -865,13 +865,13 @@ if (isset($_GET['action']) === true && $_GET['action'] === 'connections') {
     $sWhere .= ') ';
     DB::debugmode(false);
     $iTotal = DB::queryFirstField(
-    'SELECT COUNT(increment_id)
+    'SELECT COUNT(p.increment_id)
         FROM '.prefixTable('processes').' AS p 
         LEFT JOIN '.prefixTable('users').' AS u ON u.id = json_extract(p.arguments, "$[0]")'.
         $sWhere
     );
     $rows = DB::query(
-        'SELECT *
+        'SELECT p.*
             FROM '.prefixTable('processes').' AS p 
             LEFT JOIN '.prefixTable('users').' AS u ON u.id = json_extract(p.arguments, "$[0]")'.
             $sWhere.
@@ -951,14 +951,14 @@ if (isset($_GET['action']) === true && $_GET['action'] === 'connections') {
     
     DB::debugmode(false);
     $iTotal = DB::queryFirstField(
-        'SELECT COUNT(increment_id)
+        'SELECT COUNT(p.increment_id)
             FROM '.prefixTable('processes').' AS p 
             LEFT JOIN '.prefixTable('users').' AS u ON u.id = json_extract(p.arguments, "$[0]")'.
             $sWhere
     );
 
     $rows = DB::query(
-        'SELECT *
+        'SELECT p.*
             FROM '.prefixTable('processes').' AS p 
             LEFT JOIN '.prefixTable('users').' AS u ON u.id = json_extract(p.arguments, "$[0]")'.
             $sWhere.

programming_language: PHP