Documentation for filter_xss_admin says:

Allows all tags that can be used inside an HTML body, save for scripts and styles.

But that is untrue. Currently it doesn't allow fieldset or legend at the very least.

Personally, I would rather the function be patched to allow them, rather then correcting the documentation. Patch to that end attached.

Comments

drumm’s picture

Version: 5.x-dev » 7.x-dev
Issue tags: +Security improvements

Changes should be made against the development version and backported from there.

Status: Needs review » Needs work

The last submitted patch failed testing.

jhodgdon’s picture

Title: Documentation problem with filter_xss_admin » filter_xss_admin should allow more tags
Component: documentation » filter.module

Given the above suggestions and patch, this is not a documentation bug, but a report that filter_xss_admin() is too aggressive and should allow more tags.

tostinni’s picture

Upss...
Sorry I just read http://drupal.org/node/448554#comment-1533946 so forget about the style attribute :(
Thanks

jhodgdon’s picture

Component: filter.module » base system
Status: Needs work » Needs review
StatusFileSize
new1.25 KB

Seems like a resonable idea to add legend and fieldset to filter_xss_admin. Here's a reroll (above patch wouldn't apply, partly because it wasn't well-formed, and partly because the function is in a different place now, namely common.inc rather than filter.module).

mikeker’s picture

If we are going to change the function to match the documentation, we're also missing other form related elements as well as embedded objects such as iframe, object and embed. I can see the arguments for not including embedded objects as they could open security issues.

But adding the remaining form tags seems safe to me. They would include:

<form>
<input>
<textarea>
<label>
<select>
<optgroup>
<option>
<button>

I'll try and roll a patch later this evening to include those.

mikeker’s picture

StatusFileSize
new1.33 KB

Attached is a patch that adds the following tags to filter_xss_admin():

<button>
<fieldset>
<form>
<input>
<label>
<legend>
<optgroup>
<option>
<select>
<textarea>
sreynen’s picture

Status: Needs review » Reviewed & tested by the community

#7 is good. It would be nice to add HTML5 tags at some point, but that should probably be done in a separate patch.

dries’s picture

Would love to have sign off from the security team on this.

sun’s picture

Status: Reviewed & tested by the community » Needs review

With this patch -- what elements are we actually blocking?

sreynen’s picture

@sun, can you clarify your question? It's a whitelist, so it's blocking everything not listed. Probably most importantly, it blocks <script> and <link>, but it also blocks <foo>, <bar>, and so on. It's impossible to list them all.

jhodgdon’s picture

bump. This is an API change and it apparently needs a security review. If it doesn't make it into D7, it will likely be moved to D8.

droplet’s picture

Status: Needs review » Closed (duplicate)
David_Rothstein’s picture

Title: filter_xss_admin should allow more tags » filter_xss_admin should allow more tags (such as fieldset, legend, and other form-related tags)
Version: 7.x-dev » 8.x-dev
Status: Closed (duplicate) » Needs review

I don't agree this is a duplicate. The goal here is to allow some more basic HTML tags, but the other issue is about HTML5. It only looks like a possible duplicate because that issue wound up talking about allowing the list to be variable... but even if that's the direction it goes in, it still doesn't solve this issue in the general case.

For this patch, I'm wondering about the security of allowing <form> tags. Seems like a low-level site administrator with filter_xss_admin() access could use that to build a form that posts to an external website (e.g. to harvest credit card numbers or that kind of thing)?

One problem is that it's not totally clear what filter_xss_admin() is and isn't supposed to protect against; the documentation is not as specific as it could be. But I sort of interpret it to mean that it allows a rogue site administrator to completely deface the content of a website, but isn't supposed to let them do anything that can directly harm the site's users, in which case <form> does seem pretty scary at a first glance.

sun’s picture

Given #732992: Allow filter_xss_admin() to accept HTML5 tags and other issues, wouldn't it make sense to turn the whitelist into a blacklist?

I.e., filter out what we know to be harmful and want to get rid off, but leave everything else?

sreynen’s picture

Until we can reliably update the list as quickly as new tag support is being added to browsers, a blacklist seems like a big security risk. Consider if we had a blacklist currently Drupal would be allowing unsafe HTML5 tags through. And the actual whitelist functionality happens at a lower level in filter_xss, so this would be allowing XSS attacks beyond just admin users.

greggles’s picture

I agree that a blacklist is not a good long term solution.

If we want to be really confident that the tags we're adding are not introducing XSS I think using the tests from http://htmlpurifier.org/ or building new tests using the examples on http://html5sec.org/ would be a great solution.

kscheirer’s picture

Status: Needs review » Needs work

The last submitted patch, 605664-updated.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.

catch’s picture

Title: filter_xss_admin should allow more tags (such as fieldset, legend, and other form-related tags) » Allow form tags in Xss::filterAdmin()
Issue summary: View changes
Issue tags: +Bug Smash Initiative

I agree with David Rothstein here and think this is won't fix:

For this patch, I'm wondering about the security of allowing
tags. Seems like a low-level site administrator with filter_xss_admin() access could use that to build a form that posts to an external website (e.g. to harvest credit card numbers or that kind of thing)?

You could argue that form hijacking isn't an XSS issue, and you'd be right, but still doesn't seem like a good idea.

There are other issues open for other tags, like #2776667: Review/update $adminTags variable for new html elements to be allowed so we should just deal with forms here.

longwave’s picture

+1 to won't fix - this issue has been open 12 years, there has been little activity on this issue suggesting it hasn't been a problem for most users, there doesn't seem to be a good argument for allowing form elements except for "the docs are wrong", and there is a good security-related reason for not allowing it.

larowlan’s picture

Status: Needs work » Closed (works as designed)

Agree with catch, sun, longwave and David

Thanks everyone for your input