CVE-2021-21319 (published 2021-10-25T16:15Z)

Galette is a membership management web application geared towards non profit organizations. In versions prior to 0.9.5, malicious javascript code can be stored to be displayed later on self subscription page. The self subscription feature can be disabled as a workaround (this is the default state). Malicious javascript code can be executed (not stored) on login and retrieve password pages. This issue is patched in version 0.9.5.

Severity: LOW
CVSS v2 base score: 3.5 (AV:N/AC:M/Au:S/C:N/I:P/A:N)
CVSS v3 base score: 5.4, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-79
cwe_name: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
description: The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
extended_description: 
            Cross-site scripting (XSS) vulnerabilities occur when:
            
               Untrusted data enters a web application, typically from a web request.
               The web application dynamically generates a web page that contains this untrusted data.
               During page generation, the application does not prevent the data from containing content that is executable by a web browser, such as JavaScript, HTML tags, HTML attributes, mouse events, Flash, ActiveX, etc.
               A victim visits the generated web page through a web browser, which contains malicious script that was injected using the untrusted data.
               Since the script comes from a web page that was sent by the web server, the victim's web browser executes the malicious script in the context of the web server's domain.
               This effectively violates the intention of the web browser's same-origin policy, which states that scripts in one domain should not be able to access resources or run code in a different domain.
            
            There are three main kinds of XSS:
            
               
                  Type 1: Reflected XSS (or Non-Persistent) - 
         			The server reads data directly from the HTTP request and reflects it back in the HTTP response. Reflected XSS exploits occur when an attacker causes a victim to supply dangerous content to a vulnerable web application, which is then reflected back to the victim and executed by the web browser. The most common mechanism for delivering malicious content is to include it as a parameter in a URL that is posted publicly or e-mailed directly to the victim. URLs constructed in this manner constitute the core of many phishing schemes, whereby an attacker convinces a victim to visit a URL that refers to a vulnerable site. After the site reflects the attacker's content back to the victim, the content is executed by the victim's browser.
               
                  Type 2: Stored XSS (or Persistent) - 
               The application stores dangerous data in a database, message forum, visitor log, or other trusted data store. At a later time, the dangerous data is subsequently read back into the application and included in dynamic content. From an attacker's perspective, the optimal place to inject malicious content is in an area that is displayed to either many users or particularly interesting users. Interesting users typically have elevated privileges in the application or interact with sensitive data that is valuable to the attacker. If one of these users executes malicious content, the attacker may be able to perform privileged operations on behalf of the user or gain access to sensitive data belonging to the user. For example, the attacker might inject XSS into a log message, which might not be handled properly when an administrator views the logs.
            
               
                  Type 0: DOM-Based XSS - 
               In DOM-based XSS, the client performs the injection of XSS into the page; in the other types, the server performs the injection. DOM-based XSS generally involves server-controlled, trusted script that is sent to the client, such as Javascript that performs sanity checks on a form before the user submits it. If the server-supplied script processes user-supplied data and then injects it back into the web page (such as with dynamic HTML), then DOM-based XSS is possible.
            
            
            Once the malicious script is injected, the attacker can perform a variety of malicious activities. The attacker could transfer private information, such as cookies that may include session information, from the victim's machine to the attacker. The attacker could send malicious requests to a web site on behalf of the victim, which could be especially dangerous to the site if the victim has administrator privileges to manage that site. Phishing attacks could be used to emulate trusted web sites and trick the victim into entering a password, allowing the attacker to compromise the victim's account on that web site. Finally, the script could exploit a vulnerability in the web browser itself possibly taking over the victim's machine, sometimes referred to as "drive-by hacking."
            In many cases, the attack can be launched without the victim even being aware of it. Even with careful users, attackers frequently use a variety of methods to encode the malicious portion of the attack, such as URL encoding or Unicode, so the request looks less suspicious.
         
         

Fix information:
repo_url: https://github.com/galette/galette
commit_details: repo_url: https://github.com/galette/galette
author: Johan Cwiklinski
author_date: 2021-02-11 06:55:29+01:00
msg: Prevent some possible XSS

Few fixes
Enhance type hinting
repository: repo_url: https://github.com/galette/galette
repo_name: galette/galette
description: Galette membership management web application towards non profit organizations main source code (mirror)
repo_language: PHP
owner: galette
file_changes: filename: AuthController.php
change_type: ModificationType.MODIFY
diff: @@ -305,7 +305,7 @@ class AuthController extends AbstractController
             $login_adh = $adh->login;
         } else {
             $post = $request->getParsedBody();
-            $login_adh = $post['login'];
+            $login_adh = htmlspecialchars($post['login'], ENT_QUOTES);
             $adh = new Adherent($this->zdb, $login_adh);
         }
 

programming_language: PHP
filename: MembersController.php
change_type: ModificationType.MODIFY
diff: @@ -397,7 +397,7 @@ class MembersController extends CrudController
         } else {
             //number of rows to show
             if (isset($post['nbshow'])) {
-                $filters->show = $post['nbshow'];
+                $filters->show = (int)$post['nbshow'];
             }
         }
 
@@ -654,7 +654,7 @@ class MembersController extends CrudController
             }
             //number of rows to show
             if (isset($post['nbshow'])) {
-                $filters->show = $post['nbshow'];
+                $filters->show = (int)$post['nbshow'];
             }
 
             if (isset($post['advanced_filtering'])) {
@@ -674,7 +674,7 @@ class MembersController extends CrudController
                                     trim($f) !== ''
                                     && trim($post['free_text'][$i]) !== ''
                                 ) {
-                                    $fs_search = $post['free_text'][$i];
+                                    $fs_search = htmlspecialchars($post['free_text'][$i], ENT_QUOTES);
                                     $log_op
                                         = (int)$post['free_logical_operator'][$i];
                                     $qry_op
@@ -871,7 +871,7 @@ class MembersController extends CrudController
 
         //numbers of rows to display
         if (isset($post['nbshow']) && is_numeric($post['nbshow'])) {
-            $filters->show = $post['nbshow'];
+            $filters->show = (int)$post['nbshow'];
         }
 
         $members = new Members($filters);
@@ -966,11 +966,11 @@ class MembersController extends CrudController
         }
 
         if (isset($post['gid'])) {
-            $params['the_id'] = $post['gid'];
+            $params['the_id'] = (int)$post['gid'];
         }
 
         if (isset($post['id_adh'])) {
-            $params['excluded'] = $post['id_adh'];
+            $params['excluded'] = (int)$post['id_adh'];
         }
 
         // display page

programming_language: PHP
filename: DynamicTranslationsController.php
change_type: ModificationType.MODIFY
diff: @@ -170,6 +170,7 @@ class DynamicTranslationsController extends AbstractController
     public function doDynamicTranslations(Request $request, Response $response): Response
     {
         $post = $request->getParsedBody();
+        $post['text_orig'] = htmlspecialchars($post['text_orig'], ENT_QUOTES);
         $error_detected = [];
 
         if (isset($post['trans']) && isset($post['text_orig'])) {

programming_language: PHP
filename: GaletteController.php
change_type: ModificationType.MODIFY
diff: @@ -540,7 +540,7 @@ class GaletteController extends AbstractController
 
             $res[$current_cat][] = array(
                 'field_id'  =>  $field,
-                'label'     =>  $post[$field . '_label'],
+                'label'     =>  htmlspecialchars($post[$field . '_label'], ENT_QUOTES),
                 'category'  =>  $post[$field . '_category'],
                 'visible'   =>  $post[$field . '_visible'],
                 'required'  =>  $required

programming_language: PHP
filename: HistoryController.php
change_type: ModificationType.MODIFY
diff: @@ -141,7 +141,7 @@ class HistoryController extends AbstractController
             if (
                 (isset($post['nbshow']) && is_numeric($post['nbshow']))
             ) {
-                $filters->show = $post['nbshow'];
+                $filters->show = (int)$post['nbshow'];
             }
 
             if (isset($post['end_date_filter']) || isset($post['start_date_filter'])) {

programming_language: PHP
filename: PdfController.php
change_type: ModificationType.MODIFY
diff: @@ -580,7 +580,7 @@ class PdfController extends AbstractController
             $type = (int)$post['model_type'];
             $class = PdfModel::getTypeClass($type);
             if (isset($post[PdfModel::PK])) {
-                $model = new $class($this->zdb, $this->preferences, (int)$_POST[PdfModel::PK]);
+                $model = new $class($this->zdb, $this->preferences, (int)$post[PdfModel::PK]);
             } else {
                 $model = new $class($this->zdb, $this->preferences);
             }

programming_language: PHP
filename: PluginsController.php
change_type: ModificationType.MODIFY
diff: @@ -203,8 +203,8 @@ class PluginsController extends AbstractController
             $install->atPreviousStep();
         } elseif (isset($post['install_prefs_ok'])) {
             $install->atEndStep();
-        } elseif (isset($_POST['previous_version'])) {
-            $install->setInstalledVersion($_POST['previous_version']);
+        } elseif (isset($post['previous_version'])) {
+            $install->setInstalledVersion($post['previous_version']);
             $install->atDbUpgradeStep();
         } elseif (isset($post['install_dbperms_ok'])) {
             if ($install->isInstall()) {
@@ -286,7 +286,7 @@ class PluginsController extends AbstractController
                     $update_scripts = Install::getUpdateScripts(
                         $plugin['root'],
                         TYPE_DB,
-                        $_POST['previous_version']
+                        $post['previous_version']
                     );
                 } else {
                     $update_scripts['current'] = TYPE_DB . '.sql';

programming_language: PHP
filename: Adherent.php
change_type: ModificationType.MODIFY
diff: @@ -889,7 +889,7 @@ class Adherent
         if ($id !== false || $nick !== false) {
             $str .= ')';
         }
-        return $str;
+        return strip_tags($str);
     }
 
     /**
@@ -1679,7 +1679,7 @@ class Adherent
                         if ($this->_address_continuation !== '' && $this->_address_continuation !== null) {
                             $address .= "\n" . $this->_address_continuation;
                         }
-                        return $address;
+                        return htmlspecialchars($address, ENT_QUOTES);
                         break;
                     case 'sname':
                         return $this->getNameWithCase($this->_name, $this->_surname);

programming_language: PHP
filename: gestion_adherents.tpl
change_type: ModificationType.MODIFY
diff: @@ -221,16 +221,18 @@ We have to use a template file, so Smarty will do its work (like replacing varia
                         <img src="{base_url}/{$template_subdir}images/icon-empty.png" alt="" width="16" height="16"/>
             {/if}
                         {assign var="mid" value=$member->id}
-                        <a href="{path_for name="member" data=["id" => $member->id]}">{$member->sname}{if $member->company_name} ({$member->company_name}){/if}</a>
+                        <a href="{path_for name="member" data=["id" => $member->id]}">{$member->sname}{if $member->company_name} ({$member->company_name|escape}){/if}</a>
                     </td>
         {else}
             {assign var="lrclass" value=$rclass}
             {assign var="propname" value=$column->propname}
-            {assign var=value value=$member->$propname}
+            {assign var=value value=$member->$propname|escape}
 
-            {if $column->field_id eq 'pseudo_adh'}
+            {if $column->field_id eq 'nom_adh'}
+                {assign var="value" value=$member->sfullname}
+            {elseif $column->field_id eq 'pseudo_adh'}
                 {assign var="lrclass" value="$rclass nowrap"}
-                {assign var=value value=$member->$propname|htmlspecialchars}
+                {assign var=value value=$member->$propname|escape}
             {elseif $column->field_id eq 'tel_adh' or $column->field_id eq 'gsm_adh'}
                 {assign var="lrclass" value="$rclass nowrap"}
             {elseif $column->field_id eq 'id_statut'}

programming_language: PHP
filename: history.tpl
change_type: ModificationType.MODIFY
diff: @@ -26,7 +26,7 @@
             <select name="action_filter" id="action_filter">
                 <option value="0">{_T string="Select an action"}</option>
         {foreach from=$actions item=$action}
-                <option value="{$action}"{if $history->filters->action_filter eq $action} selected="selected"{/if}>{$action}</option>
+                <option value="{$action|escape}"{if $history->filters->action_filter eq $action} selected="selected"{/if}>{$action|escape}</option>
         {/foreach}
             </select>
     {/if}
@@ -126,9 +126,9 @@
                     <td class="nowrap" data-title="{_T string="Date"}">{$log.date_log|date_format:"%a %d/%m/%Y - %R"}</td>
                     <td class="nowrap" data-title="{_T string="IP"}">{$log.ip_log}</td>
                     <td data-title="{_T string="User"}">{$log.adh_log}</td>
-                    <td data-title="{_T string="Action"}">{$log.action_log}</td>
+                    <td data-title="{_T string="Action"}">{$log.action_log|escape}</td>
                     <td data-title="{_T string="Description"}">
-                        {$log.text_log}
+                        {$log.text_log|escape}
         {if $log.sql_log}
                         <span class="sql_log">{$log.sql_log|escape:"htmlall"}</span>
         {/if}

programming_language: PHP
filename: voir_adherent.tpl
change_type: ModificationType.MODIFY
diff: @@ -93,7 +93,7 @@
             <li>
                 <a
                     href="{path_for name="duplicateMember" data=["id_adh" => $member->id]}"
-                    title="{_T string="Create a new member with %name information." pattern="/%name/" replace=$member->sname}"
+                    title="{_T string="Create a new member with %name information." pattern="/%name/" replace=$member->sfullname}"
                     class="button bigbutton tooltip"
                 >
                     <i class="fas fa-clone fa-fw fa-2x" aria-hidden="true"></i>
@@ -143,7 +143,7 @@ We have to use a template file, so Smarty will do its work (like replacing varia
         {assign var="value" value=$member->$propname|escape}
 
         {if $element->field_id eq 'nom_adh'}
-            {assign var="value" value=$member->sfullname|escape}
+            {assign var="value" value=$member->sfullname}
         {elseif $element->field_id eq 'pref_lang'}
             {assign var="value" value=$pref_lang}
         {elseif $element->field_id eq 'adresse_adh'}

programming_language: HTML
repo_url: https://github.com/galette/galette
commit_details: repo_url: https://github.com/galette/galette
author: Johan Cwiklinski
author_date: 2021-03-26 15:20:43+01:00
msg: Fix stored XSS on dynamic fields configuration
repository: repo_url: https://github.com/galette/galette
repo_name: galette/galette
description: Galette membership management web application towards non profit organizations main source code (mirror)
repo_language: PHP
owner: galette
file_changes: filename: DynamicField.php
change_type: ModificationType.MODIFY
diff: @@ -698,7 +698,7 @@ abstract class DynamicField
 
         try {
             $values = array(
-                'field_name'        => $this->name,
+                'field_name'        => strip_tags($this->name),
                 'field_perm'        => $this->perm,
                 'field_required'    => $this->required,
                 'field_width'       => ($this->width === null ? new Expression('NULL') : $this->width),

programming_language: PHP
filename: TranslatableTrait.php
change_type: ModificationType.MODIFY
diff: @@ -66,9 +66,9 @@ trait TranslatableTrait
     public function getName($translated = true)
     {
         if ($translated === true) {
-            return _T($this->name);
+            return _T(strip_tags($this->name));
         } else {
-            return $this->name;
+            return strip_tags($this->name);
         }
     }
 }

programming_language: PHP
filename: configurer_fiche_content.tpl
change_type: ModificationType.MODIFY
diff: @@ -27,21 +27,21 @@
                             class="tooltip action"
                         >
                             <i class="fas fa-user-edit fa-fw" aria-hidden="true"></i>
-                            <span class="sr-only">{_T string="Edit '%s' field" pattern="/%s/" replace=$field->getName()}</span>
+                            <span class="sr-only">{_T string="Edit '%s' field" pattern="/%s/" replace=$field->getName()|escape}</span>
                         </a>
                         <a
                             href="{path_for name="dynamicTranslations" data=["text_orig" => {$field->getName(false)|escape}]}"
                             class="tooltip"
                         >
                             <i class="fas fa-language fa-fw" aria-hidden="true"></i>
-                            <span class="sr-only">{_T string="Translate '%s' field" pattern="/%s/" replace=$field->getName()}</span>
+                            <span class="sr-only">{_T string="Translate '%s' field" pattern="/%s/" replace=$field->getName()|escape}</span>
                         </a>
                         <a
                             href="{path_for name="removeDynamicField" data=["form_name" => $form_name, "id" => $field->getId()]}"
                             class="delete tooltip"
                         >
                             <i class="fas fa-trash" aria-hidden="true"></i>
-                            <span class="sr-only">{_T string="Delete '%s' field" pattern="/%s/" replace=$field->getName()}</span>
+                            <span class="sr-only">{_T string="Delete '%s' field" pattern="/%s/" replace=$field->getName()|escape}</span>
                         </a>
     {if $field->getIndex() eq 1}
                         <i class="fas fa-fw">&nbsp;</i>
@@ -51,7 +51,7 @@
                             class="tooltip action"
                         >
                             <i class="fas fa-caret-up fa-fw"></i>
-                            <span class="sr-only">{_T string="Move up '%s' field" pattern="/%s/" replace=$field->getName()}</span>
+                            <span class="sr-only">{_T string="Move up '%s' field" pattern="/%s/" replace=$field->getName()|escape}</span>
                         </a>
     {/if}
     {if $field->getIndex() eq $fields_list|@count}
@@ -62,7 +62,7 @@
                             class="tooltip"
                         >
                             <i class="fas fa-caret-down fa-fw"></i>
-                            <span class="sr-only">{_T string="Move down '%s' field" pattern="/%s/" replace=$field->getName()}</span>
+                            <span class="sr-only">{_T string="Move down '%s' field" pattern="/%s/" replace=$field->getName()|escape}</span>
                         </a>
     {/if}
                     </td>

programming_language: PHP
repo_url: https://github.com/galette/galette
commit_details: repo_url: https://github.com/galette/galette
author: Johan Cwiklinski
author_date: 2021-02-14 15:19:34+01:00
msg: Add test on stored xss
repository: repo_url: https://github.com/galette/galette
repo_name: galette/galette
description: Galette membership management web application towards non profit organizations main source code (mirror)
repo_language: PHP
owner: galette
file_changes: filename: Adherent.php
change_type: ModificationType.MODIFY
diff: @@ -432,4 +432,24 @@ class Adherent extends GaletteTestCase
         $this->boolean($child->store())->isTrue();
         $this->variable($child->parent)->isNull();
     }
+
+    /**
+     * Test XSS/SQL injection
+     *
+     * @return void
+     */
+    public function testInjection()
+    {
+        $data = [
+            'nom_adh'           => 'Doe',
+            'prenom_adh'        => 'Johny <script>console.log("anything");</script>',
+            'email_adh'         => 'jdoe@doe.com',
+            'login_adh'         => 'jdoe',
+            'info_public_adh'   => 'Any <script>console.log("useful");</script> information'
+        ] + $this->dataAdherentOne();
+        $member = $this->createMember($data);
+
+        $this->string($member->sfullname)->isIdenticalTo('DOE Johny Console.log("anything");');
+        $this->string($member->others_infos)->isIdenticalTo('Any console.log("useful"); information');
+    }
 }

programming_language: PHP