The following functions have been refactored into methods on the XSS and UrlHelper classes, all calls should be replaced with direct calls to the methods specified in their docblocks:

filter_xss()
filter_xss_admin()
filter_xss_bad_protocol()

This is part of #2093143: [meta] Remove calls to @deprecated and "backwards compatibility" procedural functions from core

Reroll instructions

Run these function replacer commands (see #2208607: Write script to automate replacement of deprecated functions where possible):

$ function_replace.php filter_xss 'Drupal\Component\Utility\Xss' UtilityXss filter
$ function_replace.php filter_xss_bad_protocol 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper filterBadProtocol
$ function_replace.php filter_xss_admin 'Drupal\Component\Utility\Xss' UtilityXss filterAdmin

Then manually fix core/modules/views/lib/Drupal/views/Plugin/views/field/Boolean.php to import as UtilityXss if function replacer hasn't picked that up.

Finally apply manual-changes-70.txt

CommentFileSizeAuthor
#74 drupal8.remove-uses-of-deprecated-XSS-filter-functions.2089433-74.patch61.01 KBvisabhishek
#70 diff-52-70.txt10.27 KBianthomas_uk
#70 2089433-70-xss.patch61.04 KBianthomas_uk
#70 manual-changes-70.txt9.87 KBianthomas_uk
#68 2089433-68-xss.patch54.02 KBgrom358
#66 2089433-66-xss.patch54 KBgrom358
#61 drupal.remove-uses-of-deprecated-xss-filter-functions.2089433-61.patch60.8 KBSweetchuck
#59 interdiff-2089433-52-56.txt6.14 KBvisabhishek
#56 drupal.remove-uses-of-deprecated-xss-filter-functions.2089433-56.patch60.81 KBvisabhishek
#56 interdiff-2089433-52-56.patch6.14 KBvisabhishek
#52 2089433-52-filter_xss.patch60.76 KBianthomas_uk
#52 interdiff-51-52.txt14.33 KBianthomas_uk
#51 2089433-51-filter_xss.patch52.95 KBgrom358
#49 2089433-49-filter_xss.patch55.05 KBgrom358
#43 2089433-43-filter_xss.patch43.44 KBgrom358
#37 2089433-remove-filter_xss_admin-37.patch33.93 KBlongwave
#35 2089433-filter_xss_admin-35.patch.txt28.69 KBgrom358
#34 2089433-filter_xss_admin-34.patch.txt28.96 KBgrom358
#33 2089433-remove-filter_xss_admin-33.patch33.98 KBlongwave
#31 2089433-31.patch34.76 KBianthomas_uk
#29 2089433-29.patch34.65 KBherom
#24 2089433-24.patch34.63 KBianthomas_uk
#21 2089433-21.patch34.59 KBianthomas_uk
#19 2089433-19.patch33.33 KBianthomas_uk
#17 2089433-17.patch37.7 KBherom
#16 2089433-16.patch37.97 KBherom
#14 2089433-14.patch37.95 KBherom
#14 interdiff-2089433-11-14.txt2.75 KBherom
#11 2089433-11.patch40.07 KBthedavidmeister
#11 2089433-9-11-interdiff.txt834 bytesthedavidmeister
#9 2089433-9.patch40.07 KBthedavidmeister
#3 2089433-2.patch39.86 KBthedavidmeister
#1 2089433-1.patch39.86 KBthedavidmeister
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

thedavidmeister’s picture

Status: Active » Needs review
FileSize
39.86 KB

patch

Status: Needs review » Needs work

The last submitted patch, 2089433-1.patch, failed testing.

thedavidmeister’s picture

Status: Needs work » Needs review
FileSize
39.86 KB

Status: Needs review » Needs work

The last submitted patch, 2089433-2.patch, failed testing.

thedavidmeister’s picture

there is no fatal for that test on simplytest.me

thedavidmeister’s picture

Status: Needs work » Needs review
Issue tags: -Quick fix, -Novice

#3: 2089433-2.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Quick fix, +Novice

The last submitted patch, 2089433-2.patch, failed testing.

thedavidmeister’s picture

ah, need to fix "Fatal error: Cannot use Drupal\Component\Utility\Xss as Xss because the name is already in use in /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/views/lib/Drupal/views/Plugin/views/field/Boolean.php on line 14"

fair enough.

thedavidmeister’s picture

Status: Needs work » Needs review
FileSize
40.07 KB

Status: Needs review » Needs work

The last submitted patch, 2089433-9.patch, failed testing.

thedavidmeister’s picture

Status: Needs work » Needs review
FileSize
834 bytes
40.07 KB

Status: Needs review » Needs work

The last submitted patch, 2089433-11.patch, failed testing.

thedavidmeister’s picture

Title: Convert all calls to filter_xss_admin() in core to \Drupal\Component\Utility\Xss::filterAdmin() » Remove & deprecate filter_xss_admin() -> \Drupal\Component\Utility\Xss::filterAdmin()
herom’s picture

Status: Needs work » Needs review
FileSize
2.75 KB
37.95 KB

reroll + update patch.
reverted two cases of filter_xss()Xss:filterAdmin(), and fixed a mismatched route.

herom’s picture

Issue summary: View changes

Updated issue summary.

areke’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

The patch needs to be rebased because it doesn't apply.

herom’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
37.97 KB
herom’s picture

FileSize
37.7 KB

reroll.

sun’s picture

Issue tags: +@deprecated
ianthomas_uk’s picture

FileSize
33.33 KB

reroll

Status: Needs review » Needs work

The last submitted patch, 19: 2089433-19.patch, failed testing.

ianthomas_uk’s picture

Status: Needs work » Needs review
FileSize
34.59 KB

For some reason some of the conflicts didn't show in SourceTree. Here's a reroll with all the conflicts fixed.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good, remaining instances of filter_xss_admin after applying are:

$ git grep filter_xss_admin
core/includes/common.inc:function filter_xss_admin($string) {
core/includes/errors.inc:    if (!function_exists('filter_xss_admin')) {

RTBC if bot runs green.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

2089433-21.patch no longer applies.

error: patch failed: core/modules/forum/forum.module:6
error: core/modules/forum/forum.module: patch does not apply

ianthomas_uk’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
FileSize
34.63 KB

Rerolled with updated context in forum.module following String::checkPlain() changes.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 24: 2089433-24.patch, failed testing.

ianthomas_uk’s picture

Status: Needs work » Needs review

24: 2089433-24.patch queued for re-testing.

ianthomas_uk’s picture

Status: Needs review » Reviewed & tested by the community

Testbot ran out of disk space

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

2089433-24.patch no longer applies.

error: patch failed: core/themes/seven/seven.theme:7
error: core/themes/seven/seven.theme: patch does not apply

herom’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
FileSize
34.65 KB

rerolled (auto-merged).

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

2089433-29_0.patch no longer applies.

error: patch failed: core/modules/system/system.admin.inc:149
error: core/modules/system/system.admin.inc: patch does not apply

ianthomas_uk’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
FileSize
34.76 KB

Straight reroll, back to RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

2089433-31.patch no longer applies.

error: patch failed: core/includes/ajax.inc:6
error: core/includes/ajax.inc: patch does not apply

longwave’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
33.98 KB

Straight reroll. All applicable code in ajax.inc was removed in #2203239: Remove ajax_render and co.

grom358’s picture

Just for comparison I have ran my automated script from https://drupal.org/node/2089331 on this issue.

~/function_replacer.php 'Drupal\Component\Utility\Xss' 'UtilityXss' 'filter_xss_admin' 'filterAdmin'

grom358’s picture

FileSize
28.69 KB

Fixed bug with script adding use declaration when it already exists

ianthomas_uk’s picture

Differences between 33 and 35:
- Use statements are reordered by the script. We don't have a coding standard for use statement order, so I think this is just noise and should be removed. There might be an argument to run a script to reorder all use statements in a single patch during the disruptive window. See also #1624564: Coding standards for "use" statements.
- The script doesn't change comments. This is probably a good thing as comments often need a bit more thought. A separate patch can be hand-rolled for them, either on the same issue (so you'd run the script, then apply the comments-only patch) or as a followup issue.
- 33 adds an unnecessary use statement to TextPlainUnitTest.
- 33 uses an alias in Drupal\views\Plugin\views\field\Boolean due to conflict with views plugin.
- 35 misses bartik.theme.

longwave’s picture

FileSize
33.93 KB

Rerolled #33

sun’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/locale/locale.module
@@ -1058,9 +1058,9 @@ function locale_translation_use_remote_source() {
+ * The allowed tag list is like \Drupal\Component\Utility\Xss::filterAdmin(),
+ * but omitting div and img as not needed for translation and likely to cause
+ * layout issues (div) or a possible attack vector (img).
  */
 function locale_string_is_safe($string) {
   return decode_entities($string) == decode_entities(filter_xss($string, array('a', 'abbr', 'acronym', 'address', 'b', 'bdo', 'big', 'blockquote', 'br', 'caption', 'cite', 'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'dl', 'dt', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'ins', 'kbd', 'li', 'ol', 'p', 'pre', 'q', 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'tt', 'ul', 'var')));

Would be cool to create an issue to add Xss::getDefaultAllowedTags() and Xss::getDefaultAdminAllowedTags() methods to the Xss class, so that code like this here does not have to duplicate the full set of admin tags manually, and instead, (1) just get the default admin tags, (2) remove the unwanted, and (3) use the resulting list.

ianthomas_uk’s picture

Status: Reviewed & tested by the community » Needs work

There is still an unnecessary Use statement in TextPlainUnitTest.

However, rather than fixing and rerolling when the patch inevitably doesn't apply, I'd suggest leaving this to #2208607: Write script to automate replacement of deprecated functions where possible, or at the very least rerolling this at a time when we can get several of these removal patches in together.

ianthomas_uk’s picture

grom358’s picture

ianthomas_uk’s picture

Title: Remove & deprecate filter_xss_admin() -> \Drupal\Component\Utility\Xss::filterAdmin() » Remove uses of deprecated XSS filter functions
Issue summary: View changes
grom358’s picture

Status: Needs work » Needs review
FileSize
43.44 KB

Using Function Replacer Part of Write script to automate replacement of deprecated functions where possible.

$ function_replace.php filter_xss 'Drupal\Component\Utility\Xss' UtilityXss filter
$ function_replace.php filter_xss_bad_protocol 'Drupal\Component\Utility\UrlHelper' UtilityUrlHelper filterBadProtocol
$ function_replace.php filter_xss_admin 'Drupal\Component\Utility\Xss' UtilityXss filterAdmin

Status: Needs review » Needs work

The last submitted patch, 43: 2089433-43-filter_xss.patch, failed testing.

grom358’s picture

Status: Needs work » Needs review

43: 2089433-43-filter_xss.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 43: 2089433-43-filter_xss.patch, failed testing.

longwave’s picture

The error is: Fatal error: Cannot use Drupal\Component\Utility\Xss as Xss because the name is already in use in /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/views/lib/Drupal/views/Plugin/views/field/Boolean.php on line 10

This is because the patch adds "use Drupal\Component\Utility\Xss;" which conflicts with the existing \Drupal\views\Plugin\views\field\Xss class in the same namespace as \Drupal\views\Plugin\views\field\Boolean.

Hopefully Function Replacer can be modified to accommodate this situation? In the case where the class to be imported already exists in the same namespace we should use the fallback (UtilityXss in this case).

grom358’s picture

@Longwave thank you. Yes that is current weakness of the script I had not considered. I need to build an index of what classes exist so I can test the use declaration I want to insert against the classes in the current namespace.

grom358’s picture

Status: Needs work » Needs review
FileSize
55.05 KB

Manually fixed core/modules/views/lib/Drupal/views/Plugin/views/field/Boolean.php to import as UtilityXss for now.

grom358’s picture

Status: Needs review » Needs work
grom358’s picture

Status: Needs work » Needs review
FileSize
52.95 KB
ianthomas_uk’s picture

FileSize
14.33 KB
60.76 KB
+++ b/core/includes/common.inc
@@ -3177,7 +3177,7 @@ function _drupal_bootstrap_code() {
-    // filter_xss_admin() is called by the installer and update.php, in which
+    // Xss::filterAdmin() is called by the installer and update.php, in which

That comment is wrong, I've fixed it to refer to the correct function and opened #2222875: Don't set default allowed protocols in _drupal_bootstrap_code() to fix this properly.

I've also corrected a few comments that weren't caught by the script, e.g. because they didn't have the brackets on the function name, and changed comments to fully qualify the class name.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

#52 looks good to me.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

2089433-52-filter_xss.patch no longer applies.

error: core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php: No such file or directory
error: core/modules/menu/lib/Drupal/menu/MenuListController.php: No such file or directory

ianthomas_uk’s picture

I have spoken to webchick and she suggested that she would be available to review/commit this next Monday, 31st March. There's little point in rerolling the patch until the weekend, but if there's a patch here on Monday that applies then I'll review it.

visabhishek’s picture

Now patch is re-rolled.

The last submitted patch, 56: interdiff-2089433-52-56.patch, failed testing.

visabhishek’s picture

Sorry i forget to change the interdiff extension. Corrected interdiff are uploaded.

visabhishek’s picture

FileSize
6.14 KB

Sorry i forget to change the interdiff extension. Corrected interdiff are uploaded.

ianthomas_uk’s picture

Issue summary: View changes

Please see #55 - there is no point rerolling this during Szeged as the patch will just cause other, more important, patches to need rerolls.

Reroll instructions are getting a bit lost in the noise, so I have added them to the issue summary. We should do that this weekend.

Sweetchuck’s picture

ianthomas_uk’s picture

Status: Needs review » Needs work

I compared #61 with #52, because that was the last patch to have been reviewed and was RTBC.

  1. +++ b/core/modules/aggregator/aggregator.module
    @@ -6,6 +6,8 @@
    +//use Drupal\Component\Plugin\Exception\PluginException;
    

    Why are we adding this commented out line?

  2. +++ b/core/modules/node/node.module
    @@ -8,6 +8,8 @@
    +//use Drupal\Component\Utility\String;
    

    Again

  3. +++ b/core/themes/bartik/bartik.theme
    @@ -4,7 +4,7 @@
    -
    

    We still want this whitespace.

Please check your patches before you upload them to save everyone time. These mistakes could also be fixed by following the reroll instructions in the issue summary.

Sweetchuck’s picture

@ianthomas_uk You are really kind. :-(

These lines were unused:
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Utility\String;
I commented them out, and after run the tests I forgot to delete them.

ianthomas_uk’s picture

@sweetchuck sorry if I was a bit blunt, but it's really frustrating to review rerolls with basic mistakes that are obvious when diffing patches. I always go over my patches line-by-line before uploading them, or when doing rerolls I run a diff between the old patch and the new patch.

These lines were unused

This is a common misunderstanding. In #52 these lines were there as context, so that git would know where to put the lines that we were adding. At some point the lines have been removed from HEAD, so git no longer knows where to add the new lines and must mark them as conflicted. The job of a reroller in this instance is to update the context so we are still inserting the same lines in the same place (and sometimes to verify that those lines are still valid).

If you had decided that extra lines could be removed, then that would make it more than a reroll so should be mentioned.

grom358’s picture

Assigned: Unassigned » grom358
grom358’s picture

Status: Needs work » Needs review
FileSize
54 KB

Rerolled

Status: Needs review » Needs work

The last submitted patch, 66: 2089433-66-xss.patch, failed testing.

grom358’s picture

Status: Needs work » Needs review
FileSize
54.02 KB

Whoops forgot to follow my own reroll instructions.

ianthomas_uk’s picture

Status: Needs review » Needs work

That's got a lot of differences compared to #52, I think it still needs to have the interdiff from #52 applied to it.

ianthomas_uk’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
9.87 KB
61.04 KB
10.27 KB

Here is #68 plus the appropriate changes from the interdiff on #52 (RTBC by longwave). I've rerolled that interdiff and attached it as manual-changes-70.txt and updated the reroll instructions accordingly.

diff-52-70.txt shows that this is a good reroll, plus some changes to fully qualified class name.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #52 was RTBC.

I have very carefully reviewed the differences between the patch in #52 and the patch in #70, and they are all fine. Therefore, based on the prior RTBC in #52, this patch is also RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 70: 2089433-70-xss.patch, failed testing.

jhodgdon’s picture

Looks like it needs another reroll. :(

visabhishek’s picture

Status: Needs work » Needs review
FileSize
61.01 KB

Simply re-rolled....

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! Reroll looks good to me.

Status: Reviewed & tested by the community » Needs work
visabhishek’s picture

Status: Needs work » Needs review
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

it is still green.

Status: Reviewed & tested by the community » Needs work
visabhishek’s picture

Status: Needs work » Needs review
ianthomas_uk’s picture

Status: Needs review » Reviewed & tested by the community

it was a random test failure, rather than anything wrong with the patch.

  • Commit 86ae96e on 8.x by webchick:
    Issue #2089433 by ianthomas_uk, grom358, herom, thedavidmeister,...
webchick’s picture

Status: Reviewed & tested by the community » Active
Issue tags: +Missing change record

Ok, getting this in while it's hot!

Committed and pushed to 8.x. Thanks!

However, I somehow missed that there is mysteriously no change notice for this (or at least "filter_xss_admin" etc. yield no results at https://drupal.org/list-changes) before I pushed, so please get on that lickety split so I don't have to roll this back now that it finally applied. :)

ianthomas_uk’s picture

Original issue was #1998466: Convert filter_xss_admin and similar function to an Xss component (really we should have written the CR for that, but better late than never)

xjm’s picture

Thanks @ianthomas_uk. Let's be sure to add both that issue and this one to the draft for the change record.

xjm’s picture

Title: Remove uses of deprecated XSS filter functions » Change record: Remove uses of deprecated XSS filter functions
Priority: Normal » Critical
Issue tags: +beta blocker

Explicitly tagging missing change records as beta blockers.

ParisLiakos’s picture

Title: Change record: Remove uses of deprecated XSS filter functions » Remove uses of deprecated XSS filter functions
Priority: Critical » Normal
Status: Active » Fixed
Issue tags: -Missing change record, -beta blocker
xjm’s picture

Assigned: grom358 » Unassigned

Thanks @ParisLiakos!

Status: Fixed » Closed (fixed)

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