Escaping the Values of Meta Tags

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Escaping the Values of Meta Tags

Post by cmb » Tue Sep 18, 2012 3:04 pm

Hello Community,

I've just noticed (again :?), that the values of the meta tags (e.g. keywords, description) and the title of the website are not properly escaped, and will produce invalid (X)HTML, if those contain special characters (i.e. '<', '>', '&', '"'). Of course it could be left to the user to manually escape those charaters, but IMO that doesn't make much sense.

The following patch might suffice:

Code: Select all

Index: cmsimple/cms.php
===================================================================
--- cmsimple/cms.php    (revision 278)
+++ cmsimple/cms.php    (working copy)
@@ -721,7 +721,7 @@
     global $cf, $print;
     $exclude = array('robots', 'keywords', 'description');
     if ($cf['meta'][$n] != '' && !($print && in_array($n, $exclude)))
-        return tag('meta name="' . $n . '" content="' . $cf['meta'][$n] . '"') . "\n";
+        return tag('meta name="' . $n . '" content="' . htmlspecialchars($cf['meta'][$n], ENT_COMPAT, 'UTF-8') . '"') . "\n";
 }
 
 function ml($i) {
@@ -946,8 +946,8 @@
 
 function head() {
     global $title, $cf, $pth, $tx, $txc, $hjs;
-    if (isset($cf['site']['title']) && $cf['site']['title'] != '')
-        $t = $cf['site']['title'] . ' - ' . $title; // changed by LM CMSimple_XH 1.1
+    if (!empty($cf['site']['title']))
+        $t = htmlspecialchars($cf['site']['title'], ENT_COMPAT, 'UTF-8') . ' - ' . $title;
     else
         $t = $title;
     $t = '<title>' . strip_tags($t) . '</title>' . "\n"; 
Christoph
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply