The system module documents $head_title as intended for use in the title tag and it's used that way in system and built-in themes (most contrib themes too).
But the $head_title var is not filtered for html markup! This produces invalid html output if a slogan is used and contains markup.

E.g. go to /admin/config/system/site-information and set Slogan with some markup. Look at the browser title bar and the resulting html.
Refer to http://www.w3.org/TR/html4/struct/global.html#h-7.4.2 -- title can contain PCDATA only.

modules/system/html.tpl.php:  <title><?php print $head_title; ?></title>
modules/system/maintenance-page.tpl.php:  <title><?php print $head_title; ?></title>
themes/bartik/templates/maintenance-page.tpl.php:  <title><?php print $head_title; ?></title>
themes/garland/maintenance-page.tpl.php:    <title><?php print $head_title ?></title>
themes/seven/maintenance-page.tpl.php:    <title><?php print $head_title; ?></title>

For reference, the note:
modules/system/html.tpl.php: * - $head_title: A modified version of the page title, for use in the TITLE

the possible addition of invalid markup to $head_title:
includes/theme.inc:      $head_title['slogan'] = filter_xss_admin(variable_get('site_slogan', ''));

TL;DR: $head_title must not contain markup as already noted in the docs for the var.

Needs D6 backport, s.a. http://drupal.org/node/340358

Comments

zany’s picture

StatusFileSize
new887 bytes
marcingy’s picture

Version: 7.4 » 8.x-dev
Priority: Minor » Normal
Status: Active » Needs review
Issue tags: +Needs backport to D7

Marking as needs review and bumping to d8.

Status: Needs review » Needs work

The last submitted patch, system-head_title-1219040.patch, failed testing.

zany’s picture

StatusFileSize
new1007 bytes

Rerolled patch for D8.

zany’s picture

StatusFileSize
new1007 bytes

Renamed for auto testing.

zany’s picture

Status: Needs work » Needs review
marcingy’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

It would be nice have tests for this. Otherwise looks good.

zany’s picture

Thanks. Do you mean SimpleTest or other users testing this? It has been documented to be useful and harmless in the referenced D6 issue. I apply this patch to all my installs since D6 appeared (3 years ago). The situation without strip_tags() is invalid html markup.

marcingy’s picture

My bad the tag indicates the need for simpletests. I'm happy to rbtc otherwise as the patch looks good :) but I think it is a good case for test.

zany’s picture

Status: Needs work » Needs review
StatusFileSize
new2.53 KB

This patch is with tests added.
The test went into system.test PageTitleFiltering test case as testHTMLTitleTag(). The test code fits neatly with the testTitleTags() and testTitleXSS() in there:

HTML in page titles
Tests correct handling or conversion by drupal_set_title() and drupal_get_title() and checks the correct escaping of site name and slogan.

To be clear, this patch removes HTML markup from the slogan when displayed as HTML Title tag. (The slogan is displayed in the html title tag if there is no drupal_set_title() set, i.e. some nodes exist and you view the front page, see node.module's node_page_default() )
We don't use check_plain() so we don't spell out tags in the html title.
There is no simple way to do the same for site-name (i.e strip tags) as in most cases site-name is already check_plain()ed (i.e entity-encoded).

kscheirer’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs backport to D7

The last submitted patch, system-head_title-1219040-10.patch, failed testing.

zany’s picture

Status: Needs work » Needs review
StatusFileSize
new2.64 KB

Reroll with tests for D8.

Status: Needs review » Needs work

The last submitted patch, system-head_title-1219040-13.patch, failed testing.

zany’s picture

Tests fail because the front page now redirects to the user or login -- it used to be the promoted node listing. Is there some (default) path that won't set the title?

zany’s picture

Status: Needs work » Needs review
StatusFileSize
new2.92 KB

Fixed patch from #10 and #13 using a path of node (it's a random page that won't set a title). This requires the views module to be included for the tests. Are there guidelines or opinions on including modules in tests?

Status: Needs review » Needs work

The last submitted patch, 16: system-head_title-1219040-16.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mstrelan’s picture

Status: Needs work » Closed (outdated)
Issue tags: +Bug Smash Initiative

I reviewed this with @quietone and @darvanen as part of the Bug Smash Initiative. We tested in Drupal 9.4, 10.0 and 10.1 across various themes including Stark, Bartik, Olivero, Seven and Claro. We weren't able to determine how to actually make the slogan appear in the <title> tag. I reviewed the relevant code in template_preprocess_html and can see there are 5 separate issues (listed below) that have changed the way head_title works since this issue was reported. Also note if I remove the conditions so we always call $head_title['slogan'] = strip_tags($site_config->get('slogan')); then I can get the slogan in the <title> tag, and the markup is stripped appropriately. Since it seems this has been addressed already I'm closing as outdated.

#2352155: Remove HtmlFragment/HtmlPage
#2369987: Remove SafeMarkup::set() from 'head' title on template_preprocess_html
#2560641: Remove all usages SafeMarkup::checkPlain() from render arrays
#2576533: Rename SafeStringInterface to MarkupInterface and move related classes
#2776975: March 3, 2017: Convert core to array syntax coding standards for Drupal 8.3.x RC phase