inconsistent use of filter_xss_admin() on $site_slogan and $site_name

grendzy - May 13, 2009 - 20:44
Project:Drupal
Version:7.x-dev
Component:theme system
Category:bug report
Priority:minor
Assigned:Unassigned
Status:needs review
Issue tags:garland, Minelli, needs backport to D6, Novice
Description

(just FYI, this was cleared by the security team for the public issue queue).

In this function:
http://api.drupal.org/api/function/template_preprocess_page/6

$site_slogan and $site_name are not checked by filter_xss_admin(), though $footer_message and $mission are.

Oddly, Garland's page.tpl.php uses check_plain($site_slogan), but Pushbutton does not. I think it's likely that most contrib themes do not check these variables (zen doesn't).

#1

JamesAn - June 6, 2009 - 02:34
Status:active» needs review

Here's the HEAD and 6.x-dev patches.

AttachmentSizeStatusTest resultOperations
461938-1.patch1.35 KBIdleFailed: Failed to apply patch.View details | Re-test
461938-1-D6.patch1.33 KBIgnoredNoneNone

#2

catch - June 7, 2009 - 02:31
Status:needs review» reviewed & tested by the community

Looks good, footer and mission are gone in D7 but this looks like a backport to D6 as well.

#3

System Message - June 13, 2009 - 13:05
Status:reviewed & tested by the community» needs work

The last submitted patch failed testing.

#4

lilou - June 13, 2009 - 13:43
Status:needs work» reviewed & tested by the community

Setting to previous status - testbot was broken.

#5

Dries - June 13, 2009 - 19:35
Version:7.x-dev» 6.x-dev
Status:reviewed & tested by the community» needs review

Committed to CVS HEAD. Moving to D6.

#6

JamesAn - June 13, 2009 - 20:00
Status:needs review» reviewed & tested by the community

The D6 patch was included as well and the changes are identical. Ready for commit?

#7

Gábor Hojtsy - June 18, 2009 - 12:04
Status:reviewed & tested by the community» fixed

Committed to Drupal 6, thanks!

#8

System Message - July 2, 2009 - 12:10
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#9

grendzy - September 1, 2009 - 01:45
Version:6.x-dev» 7.x-dev
Status:closed» needs review

whoops... we missed a few spots in $head_title. Follow-up patch is attached. BTW this seems to be the cause of a number of issues with using an ampersand in site_name.

#535240: Ampersands in site name are not escaped in title tag
#527776: Cannot display ampersand in site title
#167176: ampersand in site title not transformed to HTML leads to invalid html code
#371975: &s and other entities
#258137: $head_title construction lacks check_plain calls

AttachmentSizeStatusTest resultOperations
461938_site_name.patch2.66 KBIdlePassed: 14677 passes, 0 fails, 0 exceptionsView details | Re-test

#10

Kars-T - September 8, 2009 - 13:24
Status:needs review» reviewed & tested by the community

Applied the patch and my D7 HEAD did still function. I added some &%$§ to the head and it works. From the code I'd say its okay.

#11

webchick - September 11, 2009 - 03:13
Status:reviewed & tested by the community» needs work
Issue tags:+Needs tests

Cool, let's get some tests for this please.

#12

Kars-T - September 13, 2009 - 19:21

Okay the test seems quiet easy to me. I just enter some markup for the title like "###< / title > ###". Without the patch the html is broken. With this patch I can check for the escaped string inside the real < title > and everything is fine. Done this by hand and it testable.

But I have a question before I go coding this as I am new to writing tests for core:

Where should it go to?

Is there already a testcase it can be added or should this go in a new file to setup where?

And one more thing just appeared to me:

I thought slogan is now a block? If I activate "slogan" in Garland as this is patched by this patch as well it is added to the site like it was in D6? I mean this is a problem about writing the test. Should I add the slogan block or just activate garlands settings?

#13

Kars-T - September 29, 2009 - 14:12
Status:needs work» needs review

Thanks to stBorchert I figured that I should put this into system.test. So I made a little test to check if site name and slogan are escaped correctly. And I reworked the patch to latest HEAD.

AttachmentSizeStatusTest resultOperations
461938_site_name-v2.patch4.87 KBIdleFailed: Failed to apply patch.View details | Re-test

#14

System Message - September 29, 2009 - 14:22
Status:needs review» needs work

The last submitted patch failed testing.

#15

Kars-T - September 29, 2009 - 16:00
Status:needs work» needs review

wrong path...

AttachmentSizeStatusTest resultOperations
461938_site_name-v3.patch4.79 KBIdleFailed: Invalid PHP syntax in modules/system/system.test.View details | Re-test

#16

grendzy - September 30, 2009 - 03:44
Status:needs review» reviewed & tested by the community

Looks good to me. Thanks for the tests.

#17

grendzy - September 30, 2009 - 17:19
Issue tags:-Needs tests

#18

System Message - October 2, 2009 - 16:40
Status:reviewed & tested by the community» needs work

The last submitted patch failed testing.

#19

Kars-T - October 4, 2009 - 19:18
Status:needs work» needs review

Reroll against latest HEAD.

AttachmentSizeStatusTest resultOperations
461938_site_name-v4.patch5.38 KBIdlePassed: 14700 passes, 0 fails, 0 exceptionsView details | Re-test

#20

grendzy - October 7, 2009 - 22:23
Status:needs review» reviewed & tested by the community

looks good.

#21

webchick - October 9, 2009 - 07:54
Status:reviewed & tested by the community» needs work

I believe we want filter_xss_admin() instead, since these values are entered by the administrator.

Also, could you please add a line of PHPDoc to:

+  function testTitleXSS() {

#22

grendzy - October 9, 2009 - 16:18

webchick: The reason filter_xss_admin isn't used is that tags aren't allowed in the <title>. My patch in #9 actually used

<?php
filter_xss
(variable_get('site_name', 'Drupal'), array())
?>
. It looks like Kars-T removed the array(). I hadn't noticed that, so I'm glad you caught it.

Now that raises the obvious question, why not just use check_plain, or strip_tags?

Check plain escapes tags, so isn't suitable if we allow HTML in site_name. (I think a good argument can be made that HTML shouldn't be allowed at all, since site_name is used in e-mail and other places.) However past versions (at least back to 4.7 I think) have allowed HTML, so I expect some users would see this as a regression.

Ok, so what about strip_tags? strip_tags won't entify ampersands, which is part of what got this whole issue started. If you put &amp; directly in your site_name, then you'll get email like "An administrator created an account for you at stuff &amp; things." (Which I suppose is an argument against allowing HTML here).

So, #9 was intended as a compromise for to accommodate both situations. What do you think? Should we go to check_plain?

#23

Kars-T - October 11, 2009 - 18:50

filter_xss_admin() for slogan and check_plain() for the site_name? If Garland did this before for site_name and it did workout why don't keep this behavior?
Otherwise I fear we would need more context where and why site_name is used or split it up in different variables. Both not really desirable to me.

#24

grendzy - October 11, 2009 - 21:14
Issue tags:+needs backport to D6

filter_xss_admin() for slogan and check_plain() for the site_name?

Fair enough. Kars-T, if you're willing to update the patch I'll do another review. Also, regarding the test:
You could probably shrink it a bit by using variable_set('site_name', 'foo'). I don't think you really need to go through the admin form. Could you also add a test that includes an ampersand in the site name, since there are a number of bug reports for that specifically? Thanks!

#25

Kars-T - October 11, 2009 - 22:21

Sure will do probably tomorrow :)

#26

Kars-T - October 12, 2009 - 15:46

I currently can't test the slogan with garland.
#602372: $site_slogan no longer used in page.tpl.php

I don't know if changing the default theme to stark during the test is an appreciated thing to do. Should tests always use garland?

#27

Garrett Albright - October 21, 2009 - 23:23

D6 patch attached.

AttachmentSizeStatusTest resultOperations
double-escape-garland-D6.patch2.28 KBIgnoredNoneNone

#28

grendzy - October 21, 2009 - 23:38
Issue tags:+needs backport to D6

Garrett: can we keep the backport tag until the version is changed (i.e. the 7.x fix is committed) ? Also per #23 I think we're going ahead with check_plain for site_name.

Kars-T: I would go ahead with the patch, and don't worry about changing the theme. If slogan isn't testable I think we can live with that.

#29

Garrett Albright - October 22, 2009 - 00:19

Okay, here's a patch that uses check_plain() for $site_name.

Incidentally, I ran into this problem when I ran into the ampersand issue as in #9.

AttachmentSizeStatusTest resultOperations
double-escape-garland-2-D6.patch3.14 KBIgnoredNoneNone

#30

Kars-T - October 23, 2009 - 16:25
Status:needs work» needs review

New Patch against latest HEAD.

As discussed site_name is check_plain() and slogan filter_xss_admin(). The test for the slogan is escaped right now. And I did add a short comment.

Why is this tagged with Minelli as it just adds CSS and no tpl files or do I miss something?

AttachmentSizeStatusTest resultOperations
461938_site_name-v4.patch5 KBIdlePassed: 14710 passes, 0 fails, 0 exceptionsView details | Re-test
 
 

Drupal is a registered trademark of Dries Buytaert.