Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new3.23 KB

Let's see if this breaks any tests.

alexpott’s picture

StatusFileSize
new1.17 KB
new3.25 KB

Fixing the filter tips page.

The last submitted patch, 2: 2547851.2.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 3: 2547851.3.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new852 bytes
new4.09 KB

So this is the SafeMarkup::set() side effect problem in a nutshell. We're not escaping the markup in between the code tags as we should because it is marked safe when it should not be.

dawehner’s picture

  1. +++ b/core/lib/Drupal/Component/Utility/SafeMarkup.php
    index 054d101..4beb133 100644
    --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php
    
    --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php
    +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php
    
    +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php
    +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php
    @@ -114,7 +114,7 @@ public function set($property_name, $value, $notify = TRUE) {
    
    @@ -114,7 +114,7 @@ public function set($property_name, $value, $notify = TRUE) {
        */
    

    You can remove the use statement now, yeah!

  2. +++ b/core/modules/filter/src/Plugin/Filter/FilterHtml.php
    @@ -145,7 +145,7 @@ public function tips($long = FALSE) {
    -          array('data' => SafeMarkup::format($tips[$tag][1]), 'class' => array('get'))
    +          array('data' => ['#markup' => $tips[$tag][1]], 'class' => array('get'))
    

    Yeah this call was effectively a SafemMarkup::set() call, right? On the other hand #markup will be ran through Xss::filterAdmin() which supports a supersets of these tags:

    array_diff($tips, $a);
    => []
  3. +++ b/core/modules/filter/src/Tests/FilterAdminTest.php
    @@ -372,8 +372,8 @@ function testFilterTipHtmlEscape() {
         $link = '<a href="' . $base_url . '">' . SafeMarkup::checkPlain(\Drupal::config('system.site')->get('name')) . '</a>';
    ...
    +    $link_as_code = '<code>' . htmlspecialchars($link, ENT_QUOTES, 'UTF-8') . '

    ';
    + $ampersand_as_code = '' . htmlspecialchars($ampersand, ENT_QUOTES, 'UTF-8') . '';

    Doesn't that result into double escaping now? It is just a test, but still ...

alexpott’s picture

Priority: Normal » Major
StatusFileSize
new561 bytes
new4.34 KB
  1. Yep - fixed.
  2. Yes exactly
  3. Actually we want what is in between the code tags to (single) escaped. At the moment we are relying in the fact that browser escape things between code tags for us. This is a regression from Drupal 7... it's code looks like this (spaces added to the code tags to make this work...:
      foreach ($entities as $entity) {
        $rows[] = array(
          array('data' => $entity[0], 'class' => array('description')),
          array('data' => '< code >' . check_plain($entity[1]) . '</ code >', 'class' => array('type')),
          array('data' => $entity[1], 'class' => array('get'))
        );
      }
    
  4. Making this major like all the other SafeMarkup::set() removals and because of the regression.
alexpott’s picture

StatusFileSize
new4.6 KB
new7.25 KB

In fact we can get to the point where FilterHtml is no longer marking any of the help text safe which has got to be saner!

alexpott’s picture

StatusFileSize
new7.25 KB

Wrong patch in #9. Here's the correct patch.

dawehner’s picture

+++ b/core/modules/filter/src/Plugin/Filter/FilterHtml.php
@@ -144,7 +143,9 @@ public function tips($long = FALSE) {
+          // The markup must be escaped.

@@ -175,7 +176,9 @@ public function tips($long = FALSE) {
+        // The markup must be escaped.

Should it be explained why? ... because you want to see the tag for itself?

xjm’s picture

Issue tags: +Needs change record
alexpott’s picture

alexpott’s picture

StatusFileSize
new1.73 KB
new7.48 KB

Improved documentation.

joelpittet’s picture

Status: Needs review » Needs work

This looks great and is hilarious that this was done so many times!

There are a few things in the patch that seem a bit out of the scope of the issue.

  1. +++ b/core/modules/filter/src/Plugin/Filter/FilterHtml.php
    @@ -102,7 +101,7 @@ public function tips($long = FALSE) {
    -      'a' => array($this->t('Anchors are used to make links to other pages.'), '<a href="' . $base_url . '">' . SafeMarkup::checkPlain(\Drupal::config('system.site')->get('name')) . '</a>'),
    +      'a' => array($this->t('Anchors are used to make links to other pages.'), '<a href="' . $base_url . '">' . htmlspecialchars(\Drupal::config('system.site')->get('name'), ENT_QUOTES, 'UTF-8') . '</a>'),
    

    Not format, shouldn't be part of this patch.

  2. +++ b/core/modules/filter/src/Plugin/Filter/FilterHtml.php
    @@ -144,8 +143,10 @@ public function tips($long = FALSE) {
    -          array('data' => SafeMarkup::format('<code>@var

    ', array('@var' => $tips[$tag][1])), 'class' => array('type')),
    ...
    + array('data' => ['#prefix' => '', '#markup' => htmlspecialchars($tips[$tag][1], ENT_QUOTES, 'UTF-8'), '#suffix' => ''], 'class' => array('type')),

    This one has arguments, doesn't count.

  3. +++ b/core/modules/filter/src/Plugin/Filter/FilterHtml.php
    @@ -144,8 +143,10 @@ public function tips($long = FALSE) {
    -          array('data' => SafeMarkup::format($tips[$tag][1]), 'class' => array('get'))
    ...
    +          // The markup must not be escaped.
    +          array('data' => ['#markup' => $tips[$tag][1]], 'class' => array('get'))
    

    implicit admin xss filter?

  4. +++ b/core/modules/filter/src/Plugin/Filter/FilterHtml.php
    @@ -175,8 +176,10 @@ public function tips($long = FALSE) {
    -        array('data' => SafeMarkup::format('<code>@var

    ', array('@var' => $entity[1])), 'class' => array('type')),
    ...
    + array('data' => ['#prefix' => '', '#markup' => htmlspecialchars($entity[1], ENT_QUOTES, 'UTF-8'), '#suffix' => ''], 'class' => array('type')),

    Same has arguments, out of scope.

  5. +++ b/core/modules/filter/src/Plugin/Filter/FilterHtml.php
    @@ -175,8 +176,10 @@ public function tips($long = FALSE) {
    +        array('data' => ['#markup' => $entity[1]], 'class' => array('get'))
    

    These could get a nice comma at the end.

  6. +++ b/core/modules/filter/src/Tests/FilterAdminTest.php
    @@ -368,12 +368,15 @@ function testFilterTipHtmlEscape() {
    -    $link = '<a href="' . $base_url . '">' . SafeMarkup::checkPlain(\Drupal::config('system.site')->get('name')) . '</a>';
    +    $link = '<a href="' . $base_url . '">' . htmlspecialchars($site_name_with_markup, ENT_QUOTES, 'UTF-8') . '</a>';
    

    This is out of scope, not SafeMarkup::format()

  7. +++ b/core/modules/filter/src/Tests/FilterAdminTest.php
    @@ -368,12 +368,15 @@ function testFilterTipHtmlEscape() {
    -    $link_as_code = '<code>' . $link . '

    ';
    - $ampersand_as_code = '' . $ampersand . '';
    + $link_as_code = '' . htmlspecialchars($link, ENT_QUOTES, 'UTF-8') . '';
    + $ampersand_as_code = '' . htmlspecialchars($ampersand, ENT_QUOTES, 'UTF-8') . '';

    SafeMarkup::checkPlain? till that other issue gets in.

alexpott’s picture

Status: Needs work » Postponed
Issue tags: -Needs change record

Use SafeMarkup::checkPlain when the string does not need to be added to the safe list is bug. Postponing on #2504529: SafeMarkup does not escape some filter tips - remove SafeMarkup usage from FilterHtml which will handle FilterHtml and then this will be a three line or so patch.

joelpittet’s picture

Status: Postponed » Needs review
StatusFileSize
new3.71 KB
new5.1 KB

This doesn't need to be postponed on that, they are not related to the title of this.

joelpittet’s picture

This is a really good self contained fix that should just get in.

Status: Needs review » Needs work

The last submitted patch, 17: safemarkup_format-2547851-17.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new2.38 KB
new4.75 KB

Not sure how this passed before really but code values need to be escaped. And now with this change it's probably does need to be postponed.

joelpittet’s picture

Status: Needs review » Postponed
joelpittet’s picture

Status: Postponed » Needs review
StatusFileSize
new1.93 KB
new5.42 KB
joelpittet’s picture

StatusFileSize
new904 bytes
new5.41 KB

Better escaping testing with assertEscaped()

alexpott’s picture

joelpittet’s picture

Issue tags: +SafeMarkup, +D8 Accelerate

RTBC from me, just need to find someone to second it.

stefan.r’s picture

Seconding, this seems like a good idea!

The method documentation still looks good and grepping the code for any SafeMarkup::set() without test coverage and a second argument I found nothing.

Maybe this could use an assert('$args !== array()') if we wanted to also disallow SafeMarkup::checkPlain($string, array());?

dawehner’s picture

I'm wondering whether there could be generic code which does not know its placeholders, so it maybe an empty array. For them the assert() would make it a bit harder.

alexpott’s picture

StatusFileSize
new5.49 KB
new7.79 KB

We can add the assert later... but lets also fix format_string() to work the same way.

stefan.r’s picture

Status: Needs review » Reviewed & tested by the community

Looks like we have all the format_string() calls here, so RTBC

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.0.x. Thanks!

  • webchick committed fa2724a on 8.0.x
    Issue #2547851 by alexpott, joelpittet, dawehner, stefan.r, xjm:...

Status: Fixed » Closed (fixed)

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

stefan.r’s picture

So contrib is now doing lovely things like this to work around the SafeMarkup::set removal

+++ b/src/EntityComparisonBase.php
@@ -83,7 +83,7 @@ class EntityComparisonBase extends ControllerBase {
-    $this->nonBreakingSpace = SafeMarkup::set('&nbsp;');
+    $this->nonBreakingSpace = SafeMarkup::format('&nbsp;', array());

https://www.drupal.org/node/2563017

joelpittet’s picture

Wow, dx be darned.

They haven't used SafeString:create() yet. At least that would only open up xss for their module instead of on the Safemakup sting list and all the site