Comments

harjotsingh created an issue. See original summary.

harjotsingh’s picture

Status: Active » Needs review
StatusFileSize
new658 bytes
wim leers’s picture

Project: Caption filter (D8 backport) » Drupal core
Version: » 8.0.x-dev
Component: Code » filter.module

I think this is what you wanted to do? :)

wim leers’s picture

Title: Remove or document SafeMarkup::set() call » Remove or document SafeMarkup::set() call in FilterCaption
Issue tags: +Novice, +Needs reroll

Can you reupload the patch please?

harjotsingh’s picture

StatusFileSize
new658 bytes

Yes indeed, thanks for help.
Patch re-uploaded.

Status: Needs review » Needs work

The last submitted patch, 5: remove_or_document-2547741-3.diff, failed testing.

harjotsingh’s picture

Assigned: harjotsingh » Unassigned
sdstyles’s picture

Status: Needs work » Needs review
StatusFileSize
new658 bytes

#5 Re-roll

harjotsingh’s picture

StatusFileSize
new658 bytes

The method doesn't work without SafeMarkup::set() call, have to look for a alternative.

The last submitted patch, 8: remove_or_document-2547741-8.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 9: remove_or_document-2547741-9.diff, failed testing.

sdstyles’s picture

Status: Needs work » Needs review
StatusFileSize
new895 bytes
stefan.r’s picture

Priority: Normal » Major
Status: Needs review » Needs work
Issue tags: -Novice, -Needs reroll
+++ b/core/modules/filter/src/Plugin/Filter/FilterCaption.php
@@ -59,7 +60,7 @@ public function process($text, $langcode) {
+          '#node' => SafeString::create($node->C14n()),

C14N()

Otherwise this looks to be OK, this also already has test coverage through FilterUnitTest

sdstyles’s picture

Status: Needs work » Needs review
StatusFileSize
new895 bytes

Fixed typo in #12, thanks.

harjotsingh’s picture

StatusFileSize
new964 bytes

Shouldn't we remove the line
use Drupal\Component\Utility\SafeMarkup;

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

#15: yes, thanks :)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: remove_or_document-2547741-15.patch, failed testing.

wim leers’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new895 bytes

#15: ehm, no, there are other things still using methods on SafeMarkup.

Re-uploading #14 and RTBC'ing it.

The last submitted patch, 2: remove_or_document-2547741-2.diff, failed testing.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/filter/src/Plugin/Filter/FilterCaption.php
@@ -59,7 +60,7 @@ public function process($text, $langcode) {
+          '#node' => SafeString::create($node->C14N()),

So SafeString::create() has some of the same issues that SafeMarkup::set() has since it can easily introduce XSS if used incorrectly. However it is way better because it does not have side effects. I think we should tackle #2544684: Expand @internal documentation on SafeString and SafeStringInterface and introduce ViewsRenderPipelineSafeString first. And document the beejeebus out of when and where to use it because I can't see another way of doing this sanely.

stefan.r’s picture

Status: Needs work » Postponed

Let's postpone on that issue and add a comment explaining why we have to use the unsanitized canonicalized node here?

wim leers’s picture

Why: because this is a text format filter, and after filtering, we always assume the output is safe. We have to. See #2273925: Ensure #markup is XSS escaped in Renderer::doRender(), which added this to \Drupal\filter\Element\ProcessedText::preRenderText():

    // Filtering and sanitizing have been done in
    // \Drupal\filter\Plugin\FilterInterface. $text is not guaranteed to be
    // safe, but it has been passed through the filter system and checked with
    // a text format, so it must be printed as is. (See the note about security
    // in the method documentation above.)
    $element['#markup'] = SafeMarkup::set($text);

This is simply part of that.

stefan.r’s picture

StatusFileSize
new740 bytes
new1.1 KB

Heh, I meant a code comment :)

I misread "document the beejeebus out of when and where to use it" as "document the beejeebus out of whenever and wherever we use it", but actually the latter is not a bad idea either...

stefan.r’s picture

Title: Remove or document SafeMarkup::set() call in FilterCaption » Introduce FilteredString and get rid of the SafeMarkup::set() call in FilterCaption
Status: Postponed » Needs review
StatusFileSize
new1.92 KB
new2.2 KB
wim leers’s picture

I think it'd be a good idea to also change

$element['#markup'] = SafeMarkup::set($text);

to

$element['#markup'] = FilteredString::create($text);

in \Drupal\filter\Element\ProcessedText::preRenderText().

Other than that, I have no remarks :)

stefan.r’s picture

Title: Introduce FilteredString and get rid of the SafeMarkup::set() call in FilterCaption » Introduce FilteredString and get rid of all SafeMarkup::set() calls in the Filter module

I was about to open another issue for that but may as well add that in here :)

stefan.r’s picture

StatusFileSize
new1.06 KB
new3.37 KB
wim leers’s picture

Status: Needs review » Reviewed & tested by the community
stefan.r’s picture

+++ b/core/modules/filter/src/Element/ProcessedText.php
@@ -124,7 +124,7 @@ public static function preRenderText($element) {
+    $element['#markup'] = FilteredString($text);

oops

stefan.r’s picture

StatusFileSize
new654 bytes
new3.38 KB

The last submitted patch, 27: 2547741-27.patch, failed testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 30: 2547741-30.patch, failed testing.

wim leers’s picture

#29: heh, indeed. I also missed it.

Looks like we need one more string cast or equality instead of identicalness assertion.

stefan.r’s picture

Actually the problem is with Views. When we go to test/serialize/node-field?_format=json, in Drupal\views\Plugin\views\field\FieldPluginBase::advancedRender() we call ::renderText(), where we append an empty string to $value SafeString so it becomes unsafe again and gets escaped later on.

stefan.r’s picture

Status: Needs work » Needs review
StatusFileSize
new3.54 KB

Maybe just this workaround to make tests pass and we address the bug in a followup?

stefan.r’s picture

StatusFileSize
new1.11 KB
new4.63 KB
stefan.r’s picture

Status: Needs review » Postponed

@alexpott #30 works when using the patch in that issue so let's postpone this on that issue being committed.

We could then re-RTBC #30 if it's green on re-testing.

The last submitted patch, 35: 2547741-35.patch, failed testing.

Status: Postponed » Needs work

The last submitted patch, 36: 2547741-36.patch, failed testing.

stefan.r’s picture

Status: Needs work » Postponed

Status: Postponed » Needs review

stefan.r queued 36: 2547741-36.patch for re-testing.

wim leers’s picture

sdstyles queued 30: 2547741-30.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 36: 2547741-36.patch, failed testing.

wim leers’s picture

Issue tags: +Needs reroll
stefan.r’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll

No it's fine, I queued the wrong patch -- it's #30 (which is green now) we want to commit , not #36.

wim leers’s picture

Oh, okay. Could you reupload #30 then, to avoid confusion?

sdstyles’s picture

StatusFileSize
new3.38 KB

Re-uploaded #30

alexpott’s picture

Status: Needs review » Needs work

This will need a retest.

The last submitted patch, 49: 2547741-30.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review

stefan.r queued 49: 2547741-30.patch for re-testing.

stefan.r’s picture

I think it did, because 30 is green

alexpott’s picture

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Then we're good to go here :)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Another one bites the dust. Committed 531d0a4 and pushed to 8.0.x. Thanks!

  • alexpott committed 531d0a4 on 8.0.x
    Issue #2547741 by stefan.r, harjotsingh, sdstyles, Wim Leers: Introduce...

Status: Fixed » Closed (fixed)

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