Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.529
diff -u -r1.529 theme.inc
--- includes/theme.inc	3 Oct 2009 19:27:44 -0000	1.529
+++ includes/theme.inc	4 Oct 2009 17:51:45 -0000
@@ -2163,12 +2163,12 @@
 
   // Construct page title.
   if (drupal_get_title()) {
-    $head_title = array(strip_tags(drupal_get_title()), variable_get('site_name', 'Drupal'));
+    $head_title = array(strip_tags(drupal_get_title()), filter_xss(variable_get('site_name', 'Drupal')));
   }
   else {
-    $head_title = array(variable_get('site_name', 'Drupal'));
+    $head_title = array(filter_xss(variable_get('site_name', 'Drupal')));
     if (variable_get('site_slogan', '')) {
-      $head_title[] = variable_get('site_slogan', '');
+      $head_title[] = filter_xss(variable_get('site_slogan', ''));
     }
   }
   $variables['head_title'] = implode(' | ', $head_title);
Index: modules/system/system.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.test,v
retrieving revision 1.81
diff -u -r1.81 system.test
--- modules/system/system.test	3 Oct 2009 19:16:04 -0000	1.81
+++ modules/system/system.test	4 Oct 2009 19:08:08 -0000
@@ -763,7 +763,7 @@
   public static function getInfo() {
     return array(
       'name' => 'HTML in page titles',
-      'description' => 'Tests correct handling or conversion by drupal_set_title() and drupal_get_title().',
+      'description' => 'Tests correct handling or conversion by drupal_set_title() and drupal_get_title() and checks the correct escaping of site name and slogan.',
       'group' => 'System'
     );
   }
@@ -774,7 +774,7 @@
   function setUp() {
     parent::setUp();
 
-    $this->content_user = $this->drupalCreateUser(array('create page content', 'access content'));
+    $this->content_user = $this->drupalCreateUser(array('create page content', 'access content', 'administer site configuration'));
     $this->drupalLogin($this->content_user);
     $this->saved_title = drupal_get_title();
   }
@@ -816,6 +816,43 @@
     $this->drupalGet("node/" . $node->nid);
     $this->assertText(check_plain($edit['title']), 'Check to make sure tags in the node title are converted.');
   }
+
+  function testTitleXSS() {
+    // Set some title with JavaScript.
+    $title = '</title><script type="text/javascript">alert("Title XSS!");</script>';
+    $title_filtered = filter_xss($title);
+
+    $slogan = '<script type="text/javascript">alert("Slogan XSS!");</script>';
+    $slogan_filtered = filter_xss($slogan);
+
+    // Activate needed appearance settings.
+    $edit = array(
+      'toggle_name'           => TRUE,
+      'toggle_slogan'         => TRUE,
+      'toggle_main_menu'      => TRUE,
+      'toggle_secondary_menu' => TRUE,
+    );
+    $this->drupalPost('admin/appearance/settings', $edit, t('Save configuration'));
+
+    // Set title and slogan.
+    $edit = array(
+       'site_name'    => $title,
+       'site_slogan'  => $slogan,
+    );
+    $this->drupalPost('admin/config/system/site-information', $edit, t('Save configuration'));
+
+    // Load frontpage.
+    $this->drupalGet('');
+
+    // Test the title.
+    $this->assertNoRaw($title, 'Check for the unfiltered version of the title.');
+    // Adding </title> so we do not test the escaped version from drupal_set_title().
+    $this->assertRaw($title_filtered . '</title>', 'Check for the filtered version of the title.');
+
+    // Test the slogan.
+    $this->assertNoRaw($slogan, 'Check for the unfiltered version of the slogan.');
+    $this->assertRaw($slogan_filtered, 'Check for the filtered version of the slogan.');
+  }
 }
 
 /**
Index: themes/garland/maintenance-page.tpl.php
===================================================================
RCS file: /cvs/drupal/drupal/themes/garland/maintenance-page.tpl.php,v
retrieving revision 1.12
diff -u -r1.12 maintenance-page.tpl.php
--- themes/garland/maintenance-page.tpl.php	21 Sep 2009 06:36:54 -0000	1.12
+++ themes/garland/maintenance-page.tpl.php	4 Oct 2009 19:12:41 -0000
@@ -38,10 +38,10 @@
           // Prepare header
           $site_fields = array();
           if ($site_name) {
-            $site_fields[] = check_plain($site_name);
+            $site_fields[] = $site_name;
           }
           if ($site_slogan) {
-            $site_fields[] = check_plain($site_slogan);
+            $site_fields[] = $site_slogan;
           }
           $site_title = implode(' ', $site_fields);
           if ($site_fields) {
Index: themes/garland/template.php
===================================================================
RCS file: /cvs/drupal/drupal/themes/garland/template.php,v
retrieving revision 1.31
diff -u -r1.31 template.php
--- themes/garland/template.php	15 Sep 2009 17:10:39 -0000	1.31
+++ themes/garland/template.php	4 Oct 2009 19:13:37 -0000
@@ -69,10 +69,10 @@
   // Prepare header
   $site_fields = array();
   if (!empty($vars['site_name'])) {
-    $site_fields[] = check_plain($vars['site_name']);
+    $site_fields[] = $vars['site_name'];
   }
   if (!empty($vars['site_slogan'])) {
-    $site_fields[] = check_plain($vars['site_slogan']);
+    $site_fields[] = $vars['site_slogan'];
   }
   $vars['site_title'] = implode(' ', $site_fields);
   if (!empty($site_fields)) {
