From 80f64f03f0dcc399505033988609c82f0f32580d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org>
Date: Wed, 10 Jun 2020 12:30:26 +0200
Subject: [PATCH] :ambulance: fix(core) Improve HTML escaping from translation
 text

issue #6071
---
 ihtml/themes/breezy/framework.tpl                 |  2 +-
 ihtml/themes/breezy/login.tpl                     |  2 +-
 .../breezy/management/filter-element-date.tpl     |  2 +-
 .../breezy/management/filter-element-fixed.tpl    |  2 +-
 ihtml/themes/breezy/management/filter-element.tpl |  2 +-
 ihtml/themes/breezy/management/management.tpl     |  6 +++---
 ihtml/themes/breezy/msg_dialog.tpl                |  2 +-
 ihtml/themes/breezy/sizelimit.tpl                 |  6 +++---
 ihtml/themes/legacy/login.tpl                     |  2 +-
 include/class_ldapSizeLimit.inc                   |  8 ++------
 include/class_logging.inc                         |  6 +++---
 include/class_msg_dialog.inc                      | 15 +++++++--------
 include/class_pluglist.inc                        |  6 +++---
 include/login/class_LoginCAS.inc                  |  4 ++--
 include/login/class_LoginHTTPHeader.inc           |  4 ++--
 include/simpleplugin/class_multiPlugin.inc        |  8 ++++----
 include/simpleplugin/class_simplePlugin.inc       |  8 ++++----
 plugins/admin/aclrole/acleditiondialog.tpl        |  2 +-
 plugins/admin/departments/class_department.inc    |  6 +++---
 plugins/admin/groups/class_ogroup.inc             |  6 +++---
 setup/setup_frame.tpl                             |  2 +-
 21 files changed, 48 insertions(+), 53 deletions(-)

diff --git a/ihtml/themes/breezy/framework.tpl b/ihtml/themes/breezy/framework.tpl
index 88bde8e1b..9b039f798 100644
--- a/ihtml/themes/breezy/framework.tpl
+++ b/ihtml/themes/breezy/framework.tpl
@@ -15,7 +15,7 @@
           <img src="geticon.php?context=actions&amp;icon=application-exit&amp;size=22" alt=""/>&nbsp;{t}Sign out{/t}
         </a>
         <a class="plugtop">
-          <img src="{$headline_image|escape}" alt=""/>{t}{$headline|escape}{/t}
+          <img src="{$headline_image|escape}" alt=""/>{$headline|escape}
         </a>
       </div>
       <div id="header-right">
diff --git a/ihtml/themes/breezy/login.tpl b/ihtml/themes/breezy/login.tpl
index 4fc417281..ecbcb401b 100644
--- a/ihtml/themes/breezy/login.tpl
+++ b/ihtml/themes/breezy/login.tpl
@@ -61,7 +61,7 @@
   <div id="window-footer" class="plugbottom">
     <div>
       <!-- Display error message on demand -->
-      {$message}
+      {$message|escape}
     </div>
     <div>
       <input type="submit" name="login" value="{t}Sign in{/t}" title="{t}Click here to log in{/t}"/>
diff --git a/ihtml/themes/breezy/management/filter-element-date.tpl b/ihtml/themes/breezy/management/filter-element-date.tpl
index 74d7bf65b..4a153f1c7 100644
--- a/ihtml/themes/breezy/management/filter-element-date.tpl
+++ b/ihtml/themes/breezy/management/filter-element-date.tpl
@@ -1,4 +1,4 @@
-<fieldset><legend>{$NAME}</legend>
+<fieldset><legend>{$NAME|escape}</legend>
   <label for="nt_{$attribute}" title="{t 1=$NAME}Minimum date for %1{/t}">
     {t}Newer than{/t}
     <input type="date" id="nt_{$attribute}" name="nt_{$attribute}" value="{$nt_value}"/>
diff --git a/ihtml/themes/breezy/management/filter-element-fixed.tpl b/ihtml/themes/breezy/management/filter-element-fixed.tpl
index 9123f6367..134d2285c 100644
--- a/ihtml/themes/breezy/management/filter-element-fixed.tpl
+++ b/ihtml/themes/breezy/management/filter-element-fixed.tpl
@@ -1,4 +1,4 @@
-<fieldset><legend>{$NAME}</legend>
+<fieldset><legend>{$NAME|escape}</legend>
   {foreach from=$INPUTS key="key" item="input"}
     <label title="{$input.desc|escape}">
       {if isset($input.icon)}
diff --git a/ihtml/themes/breezy/management/filter-element.tpl b/ihtml/themes/breezy/management/filter-element.tpl
index 152e0c9fc..c0aa75438 100644
--- a/ihtml/themes/breezy/management/filter-element.tpl
+++ b/ihtml/themes/breezy/management/filter-element.tpl
@@ -1,4 +1,4 @@
-<fieldset><legend>{$NAME}</legend>
+<fieldset><legend>{$NAME|escape}</legend>
   {foreach from=$INPUTS key="key" item="input"}
     <label for="{$key}" title="{$input.desc|escape}">
       <input type="checkbox" id="{$key}" name="{$key}" value="1"
diff --git a/ihtml/themes/breezy/management/management.tpl b/ihtml/themes/breezy/management/management.tpl
index 71c3ddf30..16d68f8bd 100644
--- a/ihtml/themes/breezy/management/management.tpl
+++ b/ihtml/themes/breezy/management/management.tpl
@@ -3,7 +3,7 @@
     <tr>
       <td class="list">
         <div class="contentboxh">
-          <p class="contentboxh">&nbsp;{$HEADLINE}&nbsp;{$SIZELIMIT}</p>
+          <p class="contentboxh">&nbsp;{$HEADLINE|escape}&nbsp;{$SIZELIMIT}</p>
         </div>
 
         <div class="contentboxb">
@@ -14,9 +14,9 @@
                   <td class="{$action.class}">
                   {if $action.enabled}
                     <input type="image" src="{$action.icon|escape}"
-                      name="{$action.id}" title="{$action.desc}" alt="{$action.name}"/>
+                      name="{$action.id}" title="{$action.desc|escape}" alt="{$action.name|escape}"/>
                   {else}
-                    <img src="{$action.icon|escape}&amp;disabled=1" alt="{$action.name}"/>
+                    <img src="{$action.icon|escape}&amp;disabled=1" alt="{$action.name|escape}"/>
                   {/if}
                   &nbsp;</td>
                 {/foreach}
diff --git a/ihtml/themes/breezy/msg_dialog.tpl b/ihtml/themes/breezy/msg_dialog.tpl
index 4dbf6a6b5..9f2d7d614 100644
--- a/ihtml/themes/breezy/msg_dialog.tpl
+++ b/ihtml/themes/breezy/msg_dialog.tpl
@@ -23,7 +23,7 @@
           {elseif $dialog.type == $smarty.const.INFO_DIALOG || $dialog.type == $smarty.const.CONFIRM_DIALOG}
             <img src="geticon.php?context=status&amp;icon=dialog-information&amp;size=32" class="center" alt="{t}Information{/t}"/>
           {/if}
-          {$dialog.title}
+          {$dialog.title|escape}
         </p>
       </div>
 
diff --git a/ihtml/themes/breezy/sizelimit.tpl b/ihtml/themes/breezy/sizelimit.tpl
index 7f61e5f1c..273dc5364 100644
--- a/ihtml/themes/breezy/sizelimit.tpl
+++ b/ihtml/themes/breezy/sizelimit.tpl
@@ -1,9 +1,9 @@
-<h1>{$warning}</h1>
+<h1>{$warning|escape}</h1>
 <p>
   {t}The size limit option makes LDAP operations faster and saves the LDAP server from getting too much load. The easiest way to handle big databases without long timeouts would be to limit your search to smaller values and use filters to get the entries you are looking for.{/t}
 </p>
 <p>
-  <b>{t}Please choose the way to react for this session{/t}:</b>
+  <b>{t}Please choose the way to react for this session:{/t}</b>
 </p>
 
 <input type="radio" name="action" value="ignore" id="ignore"/>
@@ -11,7 +11,7 @@
 <input type="radio" name="action" value="limited" checked="checked" id="limited"/>
   <label for="limited">{t}ignore this error and show all entries that fit into the defined sizelimit and let me use filters instead{/t}</label><br/>
 <input type="radio" name="action" value="newlimit" id="newlimit"/>
-  {$limit_message}
+  {$limit_message|escape}
 
 <p class="plugbottom">
  <input type=submit name="set_size_action" value="{t}Set{/t}"/>
diff --git a/ihtml/themes/legacy/login.tpl b/ihtml/themes/legacy/login.tpl
index ffea89670..b3de6c82e 100644
--- a/ihtml/themes/legacy/login.tpl
+++ b/ihtml/themes/legacy/login.tpl
@@ -61,7 +61,7 @@
   <div id="window-footer" class="plugbottom">
     <div>
       <!-- Display error message on demand -->
-      {$message}
+      {$message|escape}
     </div>
     <div>
       <input type="submit" name="login" value="{t}Sign in{/t}" title="{t}Click here to log in{/t}"/>
diff --git a/include/class_ldapSizeLimit.inc b/include/class_ldapSizeLimit.inc
index 198bc409d..3d8c6000a 100644
--- a/include/class_ldapSizeLimit.inc
+++ b/include/class_ldapSizeLimit.inc
@@ -127,13 +127,9 @@ class ldapSizeLimit
    */
   function renderWarning ()
   {
-    if (($this->sizeLimit >= 10000000) || $this->limitExceeded) {
-      $config = '<input type="submit" name="edit_sizelimit" value="'._('Configure').'" formnovalidate="formnovalidate"/>';
-    } else {
-      $config = '';
-    }
     if ($this->limitExceeded) {
-      return '('._('incomplete').") $config";
+      $config = '<input type="submit" name="edit_sizelimit" value="'.htmlescape(_('Configure')).'" formnovalidate="formnovalidate"/>';
+      return '('.htmlescape(_('incomplete')).') '.$config;
     }
     return '';
   }
diff --git a/include/class_logging.inc b/include/class_logging.inc
index a3a111dbe..9feccb6c0 100644
--- a/include/class_logging.inc
+++ b/include/class_logging.inc
@@ -210,9 +210,9 @@ class logging
       $baseObject->fdAuditAttributes  = $entry['changes'];
       $baseObject->fdAuditResult      = $entry['result'];
       $baseObject->base               = $config->current['BASE'];
-      $message = $tabObject->save();
-      if (!empty($message)) {
-        msg_dialog::displayChecks($message);
+      $errors = $tabObject->save();
+      if (!empty($errors)) {
+        msg_dialog::displayChecks($errors);
       }
     } catch (FusionDirectoryException $e) {
       msg_dialog::display(_('Error'), sprintf(_('Failed to log event (%s - %s): %s'), $entry['action'], $entry['objecttype'], $e->getMessage()), ERROR_DIALOG);
diff --git a/include/class_msg_dialog.inc b/include/class_msg_dialog.inc
index 4ffc80ce3..c06cdd6d6 100644
--- a/include/class_msg_dialog.inc
+++ b/include/class_msg_dialog.inc
@@ -46,9 +46,9 @@ class msg_dialog
   /*!
    * \brief Message dialog constructor
    *
-   * \param string $title The title of the message dialog
+   * \param string $title The title of the message dialog (plain string)
    *
-   * \param string $message The message of the message dialog
+   * \param string $message The message of the message dialog (HTML)
    *
    * \param int $type The type of the message dialog, by default = INFO_DIALOG
    *
@@ -168,8 +168,7 @@ class msg_dialog
     global $config;
 
     $display =
-      '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
-      "http://www.w3.org/TR/html4/transitional.dtd">
+      '<!DOCTYPE html>
       <html><head>
       <title>FusionDirectory startup failed</title>
       </head><body>';
@@ -182,12 +181,12 @@ class msg_dialog
       '<table style="width:100%; border:2px solid red;">
         <tr>
           <td style="vertical-align:top;padding:10px">
-            <img src="geticon.php?context=status&amp;icon=dialog-error&amp;size=32" alt="'._('Error').'"/>
+            <img src="geticon.php?context=status&amp;icon=dialog-error&amp;size=32" alt="'.htmlescape(_('Error')).'"/>
           </td>
           <td style="width:100%">
-            <b>'.$this->s_Title.'</b><br/>
-            '.$this->s_Message.'<br><br/>
-            '._('Please fix the above error and reload the page.').'
+            <b>'.htmlescape($this->s_Title).'</b><br/>
+            '.$this->s_Message.'<br/><br/>
+            '.htmlescape(_('Please fix the above error and reload the page.')).'
           </td>
         </tr>
       </table></body></html>';
diff --git a/include/class_pluglist.inc b/include/class_pluglist.inc
index 0a80246f0..d468eff04 100644
--- a/include/class_pluglist.inc
+++ b/include/class_pluglist.inc
@@ -377,12 +377,12 @@ class pluglist
           }
 
           $entries .= '<li class="menuitem" id="menuitem_'.$id.'">';
-          $entries .= '<a href="'.$href.'" title="'.$plDescription.'">'.$plHeadline.'</a></li>'."\n";
+          $entries .= '<a href="'.$href.'" title="'.htmlescape($plDescription).'">'.htmlescape($plHeadline).'</a></li>'."\n";
         }
 
         /* Append to menu */
         if ($entries != "") {
-          $this->menu .= '<li><a>'.$section_infos['NAME']."</a>\n<ul>\n".$entries."\n</ul></li>\n";
+          $this->menu .= '<li><a>'.htmlescape($section_infos['NAME'])."</a>\n<ul>\n".$entries."\n</ul></li>\n";
         }
       }
       $this->menu .= '</ul>'."\n";
@@ -420,7 +420,7 @@ class pluglist
       foreach ($config->data['SECTIONS'] as $section => $section_infos) {
         $entries      = '';
         $sectionMenu  = '<div class="iconmenu-section"><h1 class="menuheader">';
-        $sectionMenu  .= $section_infos['NAME']."</h1>\n";
+        $sectionMenu  .= htmlescape($section_infos['NAME'])."</h1>\n";
 
         foreach ($config->data['MENU'][$section] as $info) {
           if (!$this->check_access($info)) {
diff --git a/include/login/class_LoginCAS.inc b/include/login/class_LoginCAS.inc
index 98a838628..8d87d6f01 100644
--- a/include/login/class_LoginCAS.inc
+++ b/include/login/class_LoginCAS.inc
@@ -100,11 +100,11 @@ class LoginCAS extends LoginMethod
       if (!empty($message)) {
         msg_dialog::display(
           _('Error'),
-          sprintf(
+          htmlescape(sprintf(
             _('Login with user "%s" triggered error: %s'),
             static::$username,
             $message
-          ),
+          )),
           FATAL_ERROR_DIALOG
         );
       }
diff --git a/include/login/class_LoginHTTPHeader.inc b/include/login/class_LoginHTTPHeader.inc
index 6b45ec330..30cdd15f5 100644
--- a/include/login/class_LoginHTTPHeader.inc
+++ b/include/login/class_LoginHTTPHeader.inc
@@ -96,11 +96,11 @@ class LoginHTTPHeader extends LoginMethod
       if (!empty($message)) {
         msg_dialog::display(
           _('Error'),
-          sprintf(
+          htmlescape(sprintf(
             _('Login with user "%s" triggered error: %s'),
             static::$username,
             $message
-          ),
+          )),
           FATAL_ERROR_DIALOG
         );
       }
diff --git a/include/simpleplugin/class_multiPlugin.inc b/include/simpleplugin/class_multiPlugin.inc
index 9e3ba393e..85b31d008 100644
--- a/include/simpleplugin/class_multiPlugin.inc
+++ b/include/simpleplugin/class_multiPlugin.inc
@@ -134,17 +134,17 @@ class multiPlugin extends simplePlugin
 
   function check (): array
   {
-    $message = parent::check();
+    $errors = parent::check();
 
     foreach ($this->plugin as &$plug) {
       if ($plug->isActive()) {
-        $tmp      = $plug->check();
-        $message  = array_merge($message, $tmp);
+        $tmp    = $plug->check();
+        $errors = array_merge($errors, $tmp);
       }
     }
     unset($plug);
 
-    return $message;
+    return $errors;
   }
 
   function set_acl_category (string $cat)
diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc
index f4b7b5e65..3beb15081 100644
--- a/include/simpleplugin/class_simplePlugin.inc
+++ b/include/simpleplugin/class_simplePlugin.inc
@@ -2239,18 +2239,18 @@ class simplePlugin implements SimpleTab
         /* save changes to LDAP and disable edit mode */
         if (isset($_POST['edit_finish'])) {
           /* Perform checks */
-          $message = $tabObject->save();
+          $errors = $tabObject->save();
 
           /* No errors, save object */
-          if (count($message) == 0) {
+          if (count($errors) == 0) {
             del_lock($entry_dn);
             session::un_set('edit');
 
             /* Remove from session */
             session::un_set($classname);
           } else {
-            /* Errors found, show message */
-            msg_dialog::displayChecks($message);
+            /* Errors found, show errors */
+            msg_dialog::displayChecks($errors);
           }
         }
       }
diff --git a/plugins/admin/aclrole/acleditiondialog.tpl b/plugins/admin/aclrole/acleditiondialog.tpl
index 36174c6ee..8ac0384b3 100644
--- a/plugins/admin/aclrole/acleditiondialog.tpl
+++ b/plugins/admin/aclrole/acleditiondialog.tpl
@@ -1,4 +1,4 @@
-  <h1>{$headline}</h1>
+  <h1>{$headline|escape}</h1>
   {$aclEdition}
 
 {if $dialogState eq 'create'}
diff --git a/plugins/admin/departments/class_department.inc b/plugins/admin/departments/class_department.inc
index 5ab4a8815..25fed2e6d 100644
--- a/plugins/admin/departments/class_department.inc
+++ b/plugins/admin/departments/class_department.inc
@@ -162,18 +162,18 @@ class department extends simplePlugin
   /* Check values */
   function check (): array
   {
-    $message = parent::check();
+    $errors = parent::check();
 
     $namingAttr = static::$namingAttr;
 
     if (($namingAttr == 'ou') && tests::is_department_name_reserved($this->$namingAttr)) {
-      $message[] = new SimplePluginCheckError(
+      $errors[] = new SimplePluginCheckError(
         $this,
         htmlescape(msgPool::reserved(_('Name')))
       );
     }
 
-    return $message;
+    return $errors;
   }
 
   function get_allowed_bases (): array
diff --git a/plugins/admin/groups/class_ogroup.inc b/plugins/admin/groups/class_ogroup.inc
index 094598b3b..7aa7ec620 100644
--- a/plugins/admin/groups/class_ogroup.inc
+++ b/plugins/admin/groups/class_ogroup.inc
@@ -245,16 +245,16 @@ class ogroup extends simplePlugin
 
   function check (): array
   {
-    $message = parent::check();
+    $errors = parent::check();
     $this->reload();
     if (preg_match('/W/', $this->gosaGroupObjects) && preg_match('/T/', $this->gosaGroupObjects)) {
-      $message[] = new SimplePluginCheckError(
+      $errors[] = new SimplePluginCheckError(
         $this,
         htmlescape(_('Putting both workstations and terminals in the same group is not allowed'))
       );
     }
 
-    return $message;
+    return $errors;
   }
 
   function ldap_save (): array
diff --git a/setup/setup_frame.tpl b/setup/setup_frame.tpl
index ba450cb00..6016c45be 100644
--- a/setup/setup_frame.tpl
+++ b/setup/setup_frame.tpl
@@ -6,7 +6,7 @@
       <div id="header-left">
         <img id="fd-logo" class="optional" src="geticon.php?context=applications&amp;icon=fusiondirectory&amp;size=48" alt="FusionDirectory logo"/>
         <a class="plugtop">
-          <img src="{$headline_image|escape}" alt=""/>{t}{$headline}{/t}
+          <img src="{$headline_image|escape}" alt=""/>{$headline|escape}
         </a>
       </div>
       <div id="header-right">
-- 
GitLab