Vulnerability: LimeSurvey 3.21.1 is affected by cross-site scripting (XSS) in the Add Participants Function (First and last name parameters). When the survey participant being edited, e.g. by an administrative user, the JavaScript code will be executed in the browser.
Vulnerability ID: CVE-2020-25797
CWE: CWE-79
Severity score: 2.9
Project: https://github.com/LimeSurvey/LimeSurvey
Published: 2020-12-31
File: application/views/admin/token/tokenform.php
Commit message: Fixed issue #15680: LimeSurvey 3.21.1 Cross Site Scripting Stored
Commit author: lacrioque

Vulnerable version (before fix):
                 <?php eT("First name:"); ?>                 </label>                 <div class="">                 <input class='form-control' type='text' size='30' id='firstname' name='firstname' value="<?php if (isset($firstname)) {echo $firstname; } ?>" />                 </div>             </div>             <div class="form-group">                 <label class=" control-label" for='lastname'>                 <?php eT("Last name:"); ?>                 </label>                 <div class="">                 <input class='form-control' type='text' size='30' id='lastname' name='lastname' value="<?php if (isset($lastname)) {echo $lastname; } ?>" />                 </div>             </div>                  <?php eT("Email:"); ?>             </label>             <div class="">                 <input class='form-control' type='text' maxlength='320' size='50' id='email' name='email' value="<?php if (isset($email)) {echo $email; } ?>" />             </div>             </div>                  <?php eT("Email status:"); ?>             </label>             <div class="">                 <input class='form-control' type='text' maxlength='320' size='50' id='emailstatus' name='emailstatus' placeholder='OK' value="<?php if (isset($emailstatus)) {echo $emailstatus; } else {echo " OK "; }?>" />             </div>             </div> 

Fixed version (after fix):
                 <?php eT("First name:"); ?>                 </label>                 <div class="">                     <?=TbHtml::textField('firstname', $firstname, [                         'class' => 'form-control',                         'size' => '30',                     ]);?>                 </div>             </div>             <div class="form-group">                 <label class=" control-label" for='lastname'>                 <?php eT("Last name:"); ?>                 </label>                 <div class="">                     <?=TbHtml::textField('lastname', $lastname, [                         'class' => 'form-control',                         'size' => '30',                     ]);?>                 </div>             </div>                  <?php eT("Email:"); ?>             </label>             <div class="">                 <?=TbHtml::emailField('email', $email, [                         'class' => 'form-control',                         'size' => '50',                         'maxlength' => '320'                  ]);?>             </div>             </div>                  <?php eT("Email status:"); ?>             </label>             <div class="">                 <?=TbHtml::textField('emailstatus', $emailstatus, [                         'class' => 'form-control',                         'size' => '50',                         'maxlength' => '320',                         'placeholder' => 'OK'                 ]);?>             </div>             </div> 

Patch:
patch: @@ -147,15 +147,21 @@
                 <?php eT("First name:"); ?>
                 </label>
                 <div class="">
-                <input class='form-control' type='text' size='30' id='firstname' name='firstname' value="<?php if (isset($firstname)) {echo $firstname; } ?>" />
+                    <?=TbHtml::textField('firstname', $firstname, [
+                        'class' => 'form-control',
+                        'size' => '30',
+                    ]);?>
                 </div>
             </div>
             <div class="form-group">
                 <label class=" control-label" for='lastname'>
                 <?php eT("Last name:"); ?>
                 </label>
                 <div class="">
-                <input class='form-control' type='text' size='30' id='lastname' name='lastname' value="<?php if (isset($lastname)) {echo $lastname; } ?>" />
+                    <?=TbHtml::textField('lastname', $lastname, [
+                        'class' => 'form-control',
+                        'size' => '30',
+                    ]);?>
                 </div>
             </div>
 
@@ -189,7 +195,11 @@
                 <?php eT("Email:"); ?>
             </label>
             <div class="">
-                <input class='form-control' type='text' maxlength='320' size='50' id='email' name='email' value="<?php if (isset($email)) {echo $email; } ?>" />
+                <?=TbHtml::emailField('email', $email, [
+                        'class' => 'form-control',
+                        'size' => '50',
+                        'maxlength' => '320' 
+                ]);?>
             </div>
             </div>
 
@@ -199,7 +209,12 @@
                 <?php eT("Email status:"); ?>
             </label>
             <div class="">
-                <input class='form-control' type='text' maxlength='320' size='50' id='emailstatus' name='emailstatus' placeholder='OK' value="<?php if (isset($emailstatus)) {echo $emailstatus; } else {echo " OK "; }?>" />
+                <?=TbHtml::textField('emailstatus', $emailstatus, [
+                        'class' => 'form-control',
+                        'size' => '50',
+                        'maxlength' => '320',
+                        'placeholder' => 'OK'
+                ]);?>
             </div>
             </div>
path: application/views/admin/token/tokenform.php