Problem/Motivation

drupal_render_children() calls Markup::create() which is only for internal use and might cause security problems by marking the entire render array output as safe and returning it, which means (as far as I know) that any unsafe strings in the render array will never get sanitized by Twig either.

Proposed resolution

Now that we have |without filter we should be able to deprecate drupal_render_children() and remove all usages in Drupal core.

This is part of Critical meta #2280965: [meta] Remove every SafeMarkup::set() call and is postponing #2501455: Remove SafeMarkup::set() in drupal_render_children() and replace it with SafeString

Remaining tasks

  • Document drupal_render_children() as deprecated and to be removed before 9.0.0
  • Remove all the usages of drupal_render_children() in Drupal core (only in Toolbar)
  • Review

User interface changes

-

API changes

drupal_render_children() will be marked as deprecated.

Data model changes

-

Comments

lauriii’s picture

Assigned: Unassigned » lauriii

Hammering this for a moment

jrearick’s picture

Issue summary: View changes

Updated issue summary to remember to update the parent issue when resolved and documenting what this issue is postponing.

xjm’s picture

Issue tags: +SafeMarkup
wim leers’s picture

+10

lauriii’s picture

So when I've been looking at the child issues I've seen that this is used in a use cases where a render element has other render elements as children. Without using drupal_render_children they won't be rendered as render elements.

joelpittet’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: -blocker, -SafeMarkup +rc target triage
StatusFileSize
new2.67 KB

#1847198: Update the structure returned by hook_toolbar() This introduced the toolbar's drupal_render_children(). And there was a bit of discussion but nothing resolved around why it's needed.

It's really tricky to remove early rendering because ToolbarItem is trying to pass it's properties upwards. (really the ToolbarItem should not be a render element and just be in toolbar, but that is D9 stuff)

Anyways here is a fix to remove the last drupal_render_children() call in core.

lauriii’s picture

Assigned: lauriii » Unassigned
claudiu.cristea’s picture

Nits.

  1. +++ b/core/includes/common.inc
    @@ -884,6 +884,9 @@ function drupal_render(&$elements, $is_recursive_call = FALSE) {
    + * @deprecated in Drupal 8.0.x and will be removed before 9.0.0. Avoid early
    + * rendering or loop through the elements and render them as they are available.
    

    The second line needs 2 spaces indentation.

  2. +++ b/core/modules/toolbar/toolbar.module
    @@ -87,11 +87,20 @@ function template_preprocess_toolbar(&$variables) {
    +    // Early rendering to collect the wrapper attributes from
    +    // ToolbarItem elements.
    

    Wrapping too early?

  3. +++ b/core/modules/toolbar/toolbar.module
    @@ -87,11 +87,20 @@ function template_preprocess_toolbar(&$variables) {
    +      Drupal::service('renderer')->render($element[$key]);
    

    \Drupal::. Missed the leading backslash.

star-szr’s picture

Unfortunately I think removing that would be a regression for certain contrib modules that want to add things to the toolbar or toolbar tray. We need a way for render elements to be able to have things added to them and still be rendered in the Twig template.

joelpittet’s picture

Cottser ping me if you are confused. I'm just moving the render. Not removing. Toolbar is super weird in that it renders early so the pre-render adds extra stuff to the render array so toolbaritem can pass things up to the toolbar template.

star-szr’s picture

Cool I reviewed it on my phone so wasn't super thorough. As long as we're keeping that it sounds good :)

joelpittet’s picture

Title: Deprecate drupal_render_children() and remove all usages in Drupal core » Deprecate drupal_render_children()
Issue tags: +Novice

Thanks @Cottser, this one just needs to have the doc comment and nits fixed by @claudiu.cristea in #8

#2544176: Remove drupal_render_children() usage in Drupal\toolbar\Element\Toolbar has the usage removal. So we can remove the usage from toolbar in this issue.

joelpittet’s picture

Issue tags: -Novice
StatusFileSize
new648 bytes
new732 bytes

Touched up the docs as per #8 and removed the toolbar usage removal.

Hopefully the new text is clear. Please feel free to update if you have a more clear way of stating the alternative to this function.

lauriii’s picture

Status: Needs review » Postponed
xjm’s picture

Issue tags: -rc target triage +rc eligible

Since this only changes docs once #2544176: Remove drupal_render_children() usage in Drupal\toolbar\Element\Toolbar goes in, it can be "rc eligible" rather than an rc target. Reference: https://www.drupal.org/core/d8-allowed-changes#rc

lauriii’s picture

Status: Postponed » Needs review

Back to NR since this is not blocked anymore

The last submitted patch, 6: deprecate-2544156-6.patch, failed testing.

lauriii’s picture

Status: Needs review » Reviewed & tested by the community

The last submitted patch, 6: deprecate-2544156-6.patch, failed testing.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

  • catch committed d47dab1 on 8.0.x
    Issue #2544156 by joelpittet: Deprecate drupal_render_children()
    
wim leers’s picture

Just this:

<3

wim leers’s picture

Component: theme system » render system
Issue tags: +DX (Developer Experience)

Render system sanity.

Status: Fixed » Closed (fixed)

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