Problem/Motivation

We do not use the static safe list anymore therefore SafeMarkup::setMultiple() and SafeMarkup::getMultiple() are not needed and the storage of safe strings in the batch and forms is not necessary.

However SafeMarkup::checkPlain() still stores strings in the safe strings - but it has no usages in core.

Proposed resolution

Introduce HtmlEscapedText and change SafeMarkup::checkPlain() deprecation to Drupal 9 so that contrib and custom are not broken.

Remaining tasks

(done) Review
(done) Update CR https://www.drupal.org/node/2549395

User interface changes

None

API changes

SafeMarkup::setMultiple() and SafeMarkup::getMultiple() removed
SafeMarkup::checkPlain() returns an EscapedString string object.

Data model changes

None

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new17.37 KB

Status: Needs review » Needs work

The last submitted patch, 2: 2575615-2.patch, failed testing.

The last submitted patch, 2: 2575615-2.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
Issue tags: +SafeMarkup
StatusFileSize
new22.18 KB
new22.18 KB
novitsh’s picture

dawehner’s picture

Great idea, let's don't break even more contrib modules. Removing checkPlain doens't add additional security.

alexpott’s picture

Title: Remove SafeMarkup::setMultiple() and SafeMarkup::getMultiple() » Introduce EscapedString and remove SafeMarkup::setMultiple() and SafeMarkup::getMultiple()
Issue summary: View changes
imiksu’s picture

xjm’s picture

The CR also needs to be updated to include these.

pwolanin’s picture

Title: Introduce EscapedString and remove SafeMarkup::setMultiple() and SafeMarkup::getMultiple() » Introduce EscapedString and remove SafeMarkup::setMultiple() and SafeMarkup::getAll()

fix title

pwolanin’s picture

I made a first pass at updating the CR.

+++ b/core/lib/Drupal/Component/Utility/SafeMarkup.php
@@ -51,82 +38,19 @@ class SafeMarkup {
+    return $string instanceOf SafeStringInterface;

Do we need an is_object() check here? It seems it's ok for scalar variables but not sure if there is any edge case.

stefan.r’s picture

Ah so less double escaping with EscapedString now :)

"Escapes a string for HTML display." is pretty clear, and I think we already document on the interface where *not* to use it, but should we do so here as well?

alexpott’s picture

@stefan.r EscapedString is deprecated.

pwolanin’s picture

Nitpicks:

  1. +++ b/core/lib/Drupal/Component/Utility/SafeMarkup.php
    @@ -51,82 +38,19 @@ class SafeMarkup {
    +   * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
    +   *   Check if an object implements
    +   *   \Drupal\Component\Utility\SafeStringInterface instead.
    

    Should we more literally say this?

    Instead, you should just check if a variable is an instance of \Drupal\Component\Utility\SafeStringInterface
    
  2. +++ b/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php
    @@ -270,8 +159,7 @@ public function __toString() {
    - * SafeMarkupTestSafeString is used to mark text as safe because
    - * SafeMarkup::$safeStrings is a global static that affects all tests.
    + * SafeMarkupTestSafeString is used to mark text as safe.
      */
    

    Remove the "mark" terminology here?

alexpott’s picture

StatusFileSize
new2.12 KB
new22.52 KB

Thanks @pwolanin

pwolanin’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Component/Utility/EscapedString.php
@@ -0,0 +1,32 @@
+class EscapedString implements SafeStringInterface {
+  use SafeStringTrait;
+

don't use this trait or the ::create() method will return any object implementing SafeStringInterface unchanged instead of escaping it.

Working on a fix for this now.

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new24.59 KB
new2.92 KB

inline the methods including a valid ::create() and 2 little test cases.

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Component/Utility/EscapedString.php
@@ -20,7 +20,35 @@
+  /**
+   * Creates a new instance of EscapedString.
+   *
+   * If $string is equal to a blank string then it is not necessary to create an
+   * object.
+   *
+   * @param mixed $string
+   *   The string to escape. This value will be cast to a string.
+   *
+   * @return string|\Drupal\Component\Utility\EscapedString
+   *   A new object wrapping the string, or an empty string.
+   */
+  public static function create($string) {
+    $string = (string) $string;
+    if ($string === '') {
+      return '';
+    }
+    $safe_string = new static();
+    $safe_string->string = $string;
+    return $safe_string;
+  }

Let's just not provide a create

The last submitted patch, 16: 2575615-3-16.patch, failed testing.

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new23.98 KB
new1.03 KB

ok, great

The last submitted patch, 18: 2575615-kill-safestrings-18.patch, failed testing.

The last submitted patch, 18: 2575615-kill-safestrings-18.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 21: 2575615-21.patch, failed testing.

The last submitted patch, 21: 2575615-21.patch, failed testing.

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new26.58 KB
new5.24 KB

oops - missing method. need a constructor instead.

per @alexpott also directly test the class to make sure it behaves the same and simplfy the data provider.

Also, need to use the Component test class, not the core class in the test.

dawehner’s picture

  1. +++ b/core/lib/Drupal/Component/Utility/EscapedString.php
    @@ -0,0 +1,67 @@
    + * @deprecated Will be removed before Drupal 9.0.0. Rely on Twig's
    + *   auto-escaping feature, or use the @link theme_render #plain_text @endlink
    + *   key when constructing a render array that contains plain text in order to
    + *   use the renderer's auto-escaping feature. If neither of these are
    + *   possible, \Drupal\Component\Utility\Html::escape() can be used in places
    + *   where explicit escaping is needed.
    + */
    

    This should not be deprecated, for 9.0.0 given that tokens will use it

  2. +++ b/core/lib/Drupal/Component/Utility/EscapedString.php
    @@ -0,0 +1,67 @@
    +  /**
    +   * Returns the string length.
    +   *
    +   * @return int
    +   *   The length of the string.
    +   */
    ...
    +  /**
    +   * Returns a representation of the object for use in JSON serialization.
    +   *
    +   * @return string
    +   *   The safe string content.
    +   */
    

    {@inheritdoc}

  3. +++ b/core/lib/Drupal/Component/Utility/EscapedString.php
    @@ -0,0 +1,67 @@
    +  }
    +}
    

    Not a nitpick at all: we need a new line

  4. +++ b/core/lib/Drupal/Component/Utility/SafeMarkup.php
    @@ -51,82 +38,19 @@ class SafeMarkup {
       public static function isSafe($string, $strategy = 'html') {
         // Do the instanceof checks first to save unnecessarily casting the object
         // to a string.
    ...
    -  public static function getAll() {
    -    return static::$safeStrings;
    +    return $string instanceOf SafeStringInterface;
       }
     
       /**
    

    beatiful

  5. +++ b/core/lib/Drupal/Core/Form/FormCache.php
    @@ -169,13 +169,6 @@ protected function loadCachedFormState($form_build_id, FormStateInterface $form_
           $form_state->setBuildInfo($build_info);
    

    It is not 100% obvious why we need to reset the build info, given that we almost doesn't change $build_info

  6. +++ b/core/phpunit.xml.dist
    @@ -46,8 +46,6 @@
    -    <listener class="\Drupal\Tests\Listeners\SafeMarkupSideEffects">
    -    </listener>
    

    OMG

+++ b/core/includes/batch.inc
index 16353d8..9feb1ac 100644
--- a/core/includes/form.inc

--- a/core/includes/form.inc
+++ b/core/includes/form.inc

Form.inc: has a reference to -safe_strings still

alexpott’s picture

StatusFileSize
new26.81 KB

Addressing all of @dawehner's feedback in #27 - thank you for the review.

pwolanin’s picture

Status: Needs review » Reviewed & tested by the community

looks great

effulgentsia’s picture

+++ b/core/lib/Drupal/Component/Utility/SafeMarkup.php
@@ -51,82 +38,19 @@ class SafeMarkup {
+   * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
+   *   Instead, you should just check if a variable is an instance of
+   *   \Drupal\Component\Utility\SafeStringInterface.
    */
   public static function isSafe($string, $strategy = 'html') {

And yet, core still calls this from a bunch of places, such as from TwigExtension::escapeFilter(), theme_render_and_autoescape(), PlaceholderTrait::placeholderEscape(), views_pre_render_views_form_views_form(), and more.

Do we want to change all those usages here or in a follow-up? If in a follow-up, is that issue created already? If not, can someone create it?

alexpott’s picture

@effulgentsia SafeMarkup::isSafe() is deprecated for Drupal 9 - I think that we can remove usages at any point in the Drupal 8 cycle - we certainly don't have to do it in this issue or quickly before the rc.

yesct’s picture

https://www.drupal.org/node/2549395 has been updated, removing tag.

yesct’s picture

Title: Introduce EscapedString and remove SafeMarkup::setMultiple() and SafeMarkup::getAll() » Introduce EscapedString and remove SafeMarkup::setMultiple() and SafeMarkup::getAll() and remove the static safeStrings list
Issue summary: View changes

updating remaining tasks in the issue summary

dawehner’s picture

catch’s picture

How does this interact with the SafeString behaviour we added to https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Template%... ?

Looks like we'd:

- escape in EscapedString::__toString()
- convert to plain text with PlainTextOutput::renderFromHtml() (because it was detected as a SafeString)
- escape in AttributeString

at the moment.

catch’s picture

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

Regardless of the answer to that, it would be documented best with explicit test coverage of that interaction.

lauriii’s picture

Sad that we won't get rid of SafeMarkup::checkPlain() but yay for getting rid of the safe list!

alexpott’s picture

@catch this interaction with the return of SafeMarkup::checkPlain() is not new or changed by this patch - are you sure that we need to add additional test coverage here?

I agree that there is a possible optimisation here since we know that the output of EscapedString is always escaped - but can't that be left to followups and API additions?

alexpott’s picture

Status: Needs work » Needs review
catch’s picture

So it isn't changed because SafeMarkup::isSafe() will return TRUE for something returned from SafeMarkup::checkPlain() both before and after this patch.

I guess that is fine. However my other question here is whether we should add EscapedStringInterface so we can type hint/instanceof for that in places like this.

alexpott’s picture

StatusFileSize
new2.32 KB
new27.95 KB

Adding EscapedStringInterface - I'll open a followup to check this in Attribute and then not use the PlainTextOutput::renderFromHtml().

alexpott’s picture

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/lib/Drupal/Component/Utility/EscapedStringInterface.php
@@ -0,0 +1,27 @@
+   * Returns an escaped string..

Nitpick for the commit, two dots.

+++ b/core/lib/Drupal/Component/Utility/EscapedString.php
@@ -0,0 +1,55 @@
+class EscapedString implements EscapedStringInterface {

I'm curious whether for API similarity we should provide a ::create() method much like SafeStringTrait provides.

Novitsh queued 41: 2575615-tng-41.patch for re-testing.

novitsh’s picture

Strangely enough in my local this patch is not applying even after pulling from 8.0.x.
Testbot however is applying with no issues.

+++ b/core/lib/Drupal/Component/Utility/EscapedStringInterface.php<br>@@ -0,0 +1,27 @@<br>+&nbsp;&nbsp; * Returns an escaped string..
#43: agreed. Please remove 1 dot. I would write the patch if my local was not misbehaving :-)

alexpott’s picture

Status: Reviewed & tested by the community » Postponed
Related issues: +#2576533: Rename SafeStringInterface to MarkupInterface and move related classes

Before we proceed with this we should get a decision on #2576533: Rename SafeStringInterface to MarkupInterface and move related classes. Therefore postponing

alexpott’s picture

Status: Postponed » Needs review
StatusFileSize
new6.87 KB
new28.61 KB

So in #2576533: Rename SafeStringInterface to MarkupInterface and move related classes @effulgentsia and @xjm pointed out that EscapedMarkup could be considered a bad name. I'm not certain I see it that way but I'm open to suggestions about what it should be. Patch attached is a reroll on top of #2576533: Rename SafeStringInterface to MarkupInterface and move related classes plus a move into Drupal/Component/Render. I also use EscapedMarkup in the Token utility. Fixed #45 too.

alexpott’s picture

Issue tags: +rc target

We have to get this done before rc to get the full benefit of not having a static safe list.

catch’s picture

Issue title still says escapedstring - that seems fine especially if it implements markupinterface

stefan.r’s picture

Are we expecting to add this to the API after all, i.e. does Token still need this? If we just mark it @internal, then it doesn't really matter what we call it :)

So in this case the input can be either plain text or markup, but the output will always be HTML-escaped HTML text. So it seems this can be used for two purposes:

  1. Converting plain text to HTML text (in which case we have a naming problem as we can't say EscapableMarkup to be consistent with FormattableMarkup et al)
  2. Escaping HTML markup and turning it into HTML text (in which case EscapableMarkup would be sort-of correct and sort-of consistent with the other naming)

EscapedString is confusing but I can't really come up with a better name due to the nature of the thing. I'd still prefer it if this had the word Markup in it somehow, EscapedMarkup at least hints that it implements MarkupInterface and that the __toString outputs HTML-escaped text.

stefan.r’s picture

Well I guess as long as they're @internal EscapedString or EscapableString work despite the ugliness.

alexpott’s picture

Issue tags: -rc target +rc deadline
alexpott’s picture

Issue tags: -Needs tests
StatusFileSize
new8.98 KB
new31.27 KB

EscapableString it is! Added a test for EscapableString too.

stefan.r’s picture

Reviewed this and I think this looks great! It is great to finally get rid of the safe list, which seemed impossible only a month ago.

  1. Discussed the naming on IRC with catch, alexpott and others - EscapableString was the best we could come up with so I think we can just go with that. It's not @internal so do we need to further document its document its behavior and use cases a bit in a followup?
  2. The SafeMarkup class docs are now incorrect - can we rewrite this to something like:
     * Contains deprecated functionality related to sanitization of markup.
     *
     * @deprecated Will be removed before Drupal 9.0.0. Use the appropriate
     * @link sanitization sanitization functions @endlink or the
     * @link theme_render theme and render systems @endlink so that the output can
     * be themed, escaped, and altered properly.
  3. Should we get rid of the @ingroup sanitization on the deprecated SafeMarkup methods?
alexpott’s picture

StatusFileSize
new3.54 KB
new33.25 KB

Thanks for the review @stefan.r

  1. Added This class can be used to provide theme engine-like late escaping functionality.
  2. I agree - implemented.
  3. I agree - implemented.
stefan.r’s picture

Status: Needs review » Reviewed & tested by the community

RTBC assuming this will come back green

alexpott’s picture

StatusFileSize
new4.16 KB
new37.41 KB

@xjm asked if we have test coverage of the safe list removal. I'm not 100% convinced it is necessary since I'm certain many many things would be broken if this was not working - I think existing coverage in Drupal\system\Tests\Batch\ProcessingTest proves this is working. However there is no harm in a few more assertions.

xjm’s picture

@alexpott, FWIW, no batch nor multiform tests failed that I could see in #1825952-139: Turn on twig autoescape by default when the safe list was first added (or the sandbox results earlier). But I may have missed an implicit fail.

David_Rothstein’s picture

Priority: Major » Critical

I think this needs to be critical actually. The patch committed in #2570431: Document that certain (non-"href") attribute values in t() and SafeMarkup::format() are not supported and may be insecure assumed the patch here is already in core. Without it, the advice it gives in the documentation is currently wrong/insecure. For example:

   *   - @variable: When the placeholder replacement value is:
   *     - A string, the replaced value in the returned string will be sanitized
   *       using \Drupal\Component\Utility\Html::escape().
David_Rothstein’s picture

Minor (and could be fixed on commit):

   public static function isSafe($string, $strategy = 'html') {
     // Do the instanceof checks first to save unnecessarily casting the object
     // to a string.
-    return $string instanceOf MarkupInterface || isset(static::$safeStrings[(string) $string][$strategy]) ||
-      isset(static::$safeStrings[(string) $string]['all']);
-  }
....
+    return $string instanceOf MarkupInterface;

The code comment is wrong now and could just be removed.

effulgentsia’s picture

Would it be ok to not add EscapableStringInterface here if nothing in this patch uses it? HEAD doesn't have any other sub-interfaces of MarkupInterface, and I'm not 100% convinced we want one. If we decide on it being useful in #2576523: Add an EscapedStringInterface and use it in Attribute, can we add it in that issue?

As far as naming EscapableString, what about HtmlEscapedText instead? I don't quite follow the nuances in #50. As far as I understand it, if it's "html escaped", then it is text: in the sense of it would all become a single text node within an HTML DOM. Whether the unescaped version of the string has "<" and ">" characters in it doesn't matter, or does it?

effulgentsia’s picture

Status: Reviewed & tested by the community » Needs review

"needs review" for #61. If the answer to #61 is no, then this can be re-RTBC'd.

pwolanin’s picture

I agree that EscapableString is a not a great name. HtmlEscapedText or HtmlEscapedString would be better.

I also agree with effulgentsia that this MarkupInterface interface seems a bit weird, and really does it make any sense to have other implementations?

alexpott’s picture

StatusFileSize
new2.3 KB
new36.58 KB

Wrt to the name EscapableString or HtmlEscapedText or HtmlEscapedString I think they are all fine - to me even EscapedMarkup is fine. Because the important thing is communicated by MarkupInterface + the word escape - which to means means that when represented in markup the string content will be escaped.

I've removed EscapableStringInterface as I only introduced it due to #40. And we can add it back when we need it.

Fixed #60 too.

alexpott’s picture

Title: Introduce EscapedString and remove SafeMarkup::setMultiple() and SafeMarkup::getAll() and remove the static safeStrings list » Introduce HtmlEscapedText and remove SafeMarkup::setMultiple() and SafeMarkup::getAll() and remove the static safeStrings list
Issue summary: View changes
StatusFileSize
new7.4 KB
new36.61 KB

Discussed with @catch and @effulgentsia - decided to change EscapableString to HtmlEscapedText.

alexpott’s picture

StatusFileSize
new572 bytes
new36.62 KB

@xjm and @effulgentsia suggested some improvements to the class docblock.

stefan.r’s picture

Status: Needs review » Reviewed & tested by the community

Liking that last class docs improvement and the name works for me as well. As opposed to some of our other string value objects the name refers to the __toString output, but in a way that's still clearer than "EscapableString" :)

Back to RTBC considering #64 is green and #66 looks to have renamed them all, so this should come back green as well.

alexpott’s picture

StatusFileSize
new4.7 KB
new38.73 KB

Move removal of "SafeString" in test comments and assertion messages.

alexpott’s picture

I've ticked all the credit boxes for people that have discussed this issue at length with me or worked on #2569699: Remove SafeMarkup::checkPlain() for Drupal 9.0.x

alexpott’s picture

Suggested commit message:

git commit -m 'Issue #2575615 by alexpott, pwolanin, stefan.r, catch, dawehner, effulgentsia, xjm, David_Rothstein, iMiksu, lauriii, joelpittet: Introduce HtmlEscapedText and remove SafeMarkup::setMultiple() and SafeMarkup::getAll() and remove the static safeStrings list'

  • effulgentsia committed 0a67ffb on 8.0.x
    Issue #2575615 by alexpott, pwolanin, stefan.r, catch, dawehner,...
effulgentsia’s picture

Title: Introduce HtmlEscapedText and remove SafeMarkup::setMultiple() and SafeMarkup::getAll() and remove the static safeStrings list » [needs CR updates] Introduce HtmlEscapedText and remove SafeMarkup::setMultiple() and SafeMarkup::getAll() and remove the static safeStrings list
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record updates

Pushed to 8.0.x!

I'm assuming there are CRs that need updating, but if I'm wrong about that, then please untag and mark fixed.

plach’s picture

Status: Needs work » Needs review

https://www.drupal.org/node/2549395 is already mentioning this issue and looks more or less up-to-date, at least as far as this issue is concerned.

The last submitted patch, 57: 2575615-tng-57.patch, failed testing.

effulgentsia’s picture

Status: Needs review » Needs work

https://www.drupal.org/node/2549395 is great, but I think the intro of the "Escaping markup (or, how to check_plain() in Drupal 8)" section and its option #3 could be improved a bit. For example,

The most direct replacement for SafeMarkup::checkPlain() is Html::escape(), except that it does not mark the resulting string as safe.

With this issue, the most direct replacement is now new HtmlEscapedText() and that does mark the string as safe. And actually the "mark as safe" terminology might now be wrong as well, since MarkupInterface now has a slightly different semantics than "safe".

Html::escape() and SafeMarkup::format() for render arrays and HTML output

Those aren't symmetrical options, because the output of SafeMarkup::format() is a MarkupInterface object, but the output of Html::escape() is not. Should we change this recommendation to new HtmlEscapedText and new FormattableMarkup instead? Do we want a section on when to use Html::escape() vs. when to use new HtmlEscapedText?

The answers to the above questions aren't obvious (at least not to me), so that's why I'm asking them here instead of updating the CR myself. In fact, should we open a new issue for figuring this out, or does it make sense to keep using this one?

Additionally, it would be great if someone read through all the CRs in https://www.drupal.org/list-changes/published/drupal?keywords_descriptio... and flagged either in this issue or some other one things that are no longer accurate or recommended.

The last submitted patch, 66: 2575615-tng-66.patch, failed testing.

The last submitted patch, 68: 2575615-tng-68.patch, failed testing.

yesct’s picture

I'm familiar with wording changes in this area, so I will start on #75. but i dont know all the answers, so ping to collaborate. :)

yesct’s picture

I didn't answer/make a change for the "Those aren't symmetrical options..." concern. I'm leaning toward opening up another issue for that (normal task?)

for easier reviewing, here are changes

https://www.drupal.org/node/2549395/revisions/view/8949021/8949983

and going through the list https://www.drupal.org/list-changes/published/drupal?keywords_descriptio... from @effulgentsia
(no change to https://www.drupal.org/node/2575573 )
(no change to https://www.drupal.org/node/2574697 )
https://www.drupal.org/node/2571689/revisions/view/8928627/8949999
https://www.drupal.org/node/2560027/revisions/view/8924353/8950021
https://www.drupal.org/node/2549107/revisions/view/8838371/8950037
(no change to https://www.drupal.org/node/2559263 )
https://www.drupal.org/node/2506757/revisions/view/8838455/8950069
(no change to https://www.drupal.org/node/2457593 )
https://www.drupal.org/node/2392803/revisions/view/8838279/8950075 <- not sure what to change the new recommendation to
https://www.drupal.org/node/2445441/revisions/view/8865509/8950101 <- might need more old stuff like examples using SafeMarkup::format() updated
https://www.drupal.org/node/2296163/revisions/view/8928695/8950169 <- a main change record that could use review, and I think a better example of "simple concatenations"
https://www.drupal.org/node/2302363/revisions/view/8838291/8950187
https://www.drupal.org/node/2153775/revisions/view/8844725/8950197
https://www.drupal.org/node/2067859/revisions/view/8844663/8950205
https://www.drupal.org/node/1312890/revisions/view/8837809/8950209

yesct’s picture

Status: Needs work » Needs review

edited the previous comments to have links to all the revisions. They need review.

Also, created #2579655: Document when to use Html::escape() vs. when to use new HtmlEscapedText

chx’s picture

1. The example linked for SafeMarkup::replace() , views_pre_render_views_form_views_form() uses SafeMarkup::isSafe which it shouldn't. At least a () note or find another example.

2. Alternatively, it is possible to escape output in JavaScript instead. has no code example.

Now on to https://www.drupal.org/node/2296163

3. renderPlain is an extremely poor name and we should open a new issue and add a much better name! Anyone sane would expect *plain text* to come out of it but it renders HTML? WTF!

4. ['list_style' => 'comma-list'], is it possible to specify the delimiter or is it hardwired comma

5. FormattableMarkup "will return an object" should mention "implementing MarkupInterface" just to reinforce it's MarkupInterface as mentioned in the SafeMarkup::isSafe replacement

6. If you have a genuine use-case for script tags or other markup stripped by Xss::filerAdmin(), you will need to use proper templates or other APIs such as the Library API. <= example? Isn't library api for attaching libraries? how is this relevant? I am baffled.

yesct’s picture

1.
opened #2579691: Remove usages of SafeMarkup::isSafe()
and #2579697: Remove usages of SafeMarkup::checkPlain() in documentation
and #2579701: remove SafeMarkup class
and added a note about the example using a deprecated method https://www.drupal.org/node/2549395/revisions/view/8949983/8950651

3.
opened #2579709: rename renderPlain to something by making renderPlain a wrapper and adding another better named method

4.
core/modules/system/templates/item-list.html.twig
puts the value of the list type in the css, (so it is not hardcoded)
but, comma is the only list type core uses,
and we have some css for it in
core/themes/bartik/css/components/item-list.css
core/themes/classy/css/components/item-list.css
core/themes/seven/css/components/menus-and-lists.css

5.
and added the object Interface type for clarification
https://www.drupal.org/node/2296163/revisions/view/8950169/8950449

yesct’s picture

2.
https://www.drupal.org/node/2549395/revisions/view/8950651/8950667

added a javascript Drupal.formatString example, but
I’m not sure if the javascript note is general or part of “4. Non-HTML responses" drupal.org/node/2549395
and looking at the issue that was linked, I'm not sure if that is appropriate,
or if
return '<span class="field">' + Drupal.checkPlain(settings.fieldLabel) + '</span>' + Drupal.checkPlain(settings.entityLabel);
in Drupal.theme.quickeditEntityToolbarLabel in core/modules/quickedit/js/theme.js
would be better.

I will try and find something for 6. next, ping to help. :) I'm not sure how successful I will be.
[edit:]
#2273925: Ensure #markup is XSS escaped in Renderer::doRender() might have a clue.
core/lib/Drupal/Core/Render/theme.api.php

 * - #markup: Specifies that the array provides HTML markup directly. Unless
 *   the markup is very simple, such as an explanation in a paragraph tag, it
 *   is normally preferable to use #theme or #type instead, so that the theme
 *   can customize the markup. Note that the value is passed through
 *   \Drupal\Component\Utility\Xss::filterAdmin(), which strips known XSS
 *   vectors while allowing a permissive list of HTML tags that are not XSS
 *   vectors. (I.e, <script> and <style> are not allowed.) See
 *   \Drupal\Component\Utility\Xss::$adminTags for the list of tags that will
 *   be allowed. If your markup needs any of the tags that are not in this
 *   whitelist, then you can implement a theme hook and template file and/or
 *   an asset library. Aternatively, you can use the render array key
 *   #allowed_tags to alter which tags are filtered.
corbacho’s picture

About 2.
formatString example (now in the CR), maybe is not best example. Because formatString not always escapes the text, depends on the arguments as you see here:
http://cgit.drupalcode.org/drupal/tree/core/misc/drupal.js#n296

I would go for your example of .checkPlain

corbacho’s picture

About #83 question. I would consider the JavaScript note to be part of 4. Non HTML responses. It's where it has more sense.

If you are delivering non-escaped HTML from the server to be escaped only in JavaScript (via AJAX), you are doing it wrong

corbacho’s picture

If you are on it, Cathy.. this text needs fix " There are three possibilities:" (Now there are actually 4 possibilities)

pwolanin’s picture

@corbacho - we should remove the ! placeholder in the JS api also. I think that was overlooked.

yesct’s picture

I'm away for a few hours. CR improvements open to anyone. :) edit away! (post revisions links and questions here please)

pwolanin’s picture

Title: [needs CR updates] Introduce HtmlEscapedText and remove SafeMarkup::setMultiple() and SafeMarkup::getAll() and remove the static safeStrings list » Introduce HtmlEscapedText and remove SafeMarkup::setMultiple() and SafeMarkup::getAll() and remove the static safeStrings list
Status: Needs review » Reviewed & tested by the community
Related issues: +#2570101: Remove !placeholder support from Drupal.formatString

Great work by yesCT fixing up the CR and opening follow-up issues. I think may be ready to called this fixed assuming the CR update is all that remained?

I fixed "three possibilities" -> "four possibilities"

For JS turns out we already have #2570101: Remove !placeholder support from Drupal.formatString

corbacho’s picture

Great!
I replaced the JavaScript example to use Drupal.checkPlain() in the CR, I find it more suitable.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 68: 2575615-tng-68.patch, failed testing.

pwolanin’s picture

Status: Needs work » Fixed

Ha, the bot chokes on the patch already being applied. Let's call this fixed then?

yesct’s picture

thanks!

https://www.drupal.org/node/2296163/revisions/view/8950449/8950977 is my best guess right now at addressing 6.

(note, bot is setting to needs work, cause it is trying to apply the patch that was already committed. not sure how to trick it. maybe an empty patch file?) [edit: cross post]

dawehner’s picture

Thanks a lot yesct!

novitsh’s picture

Good enough for me to have this fixed. Who can update https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Utility!Safe... pages ?

chx’s picture

@Novitsh, you need to file core patches for that.

Status: Fixed » Closed (fixed)

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