Make WordPress Core


Ignore:
Timestamp:
06/24/2024 03:23:25 PM (10 months ago)
Author:
audrasjb
Message:

Grouped Backports to the 5.9 branch.

  • Editor: Fix Path Traversal issue on Windows in Template-Part Block.
  • Editor: Sanitize Template Part HTML tag on save.

Merges [58470], [58471], [58472] and [58473] to the 5.9 branch.
Props xknown, peterwilsoncc, jorbin, bernhard-reiter, azaozz.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.9/src/wp-includes/blocks.php

    r55774 r58483  
    669669 */
    670670function filter_block_kses( $block, $allowed_html, $allowed_protocols = array() ) {
    671     $block['attrs'] = filter_block_kses_value( $block['attrs'], $allowed_html, $allowed_protocols );
     671    $block['attrs'] = filter_block_kses_value( $block['attrs'], $allowed_html, $allowed_protocols, $block );
    672672
    673673    if ( is_array( $block['innerBlocks'] ) ) {
     
    685685 *
    686686 * @since 5.3.1
     687 * @since 6.5.5 Added the `$block_context` parameter.
    687688 *
    688689 * @param string[]|string $value             The attribute value to filter.
     
    691692 *                                           such as 'post'.
    692693 * @param string[]        $allowed_protocols Array of allowed URL protocols.
     694 * @param array           $block_context     Optional. The block the attribute belongs to, in parsed block array format.
    693695 * @return string[]|string The filtered and sanitized result.
    694696 */
    695 function filter_block_kses_value( $value, $allowed_html, $allowed_protocols = array() ) {
     697function filter_block_kses_value( $value, $allowed_html, $allowed_protocols = array(), $block_context = null ) {
    696698    if ( is_array( $value ) ) {
    697699        foreach ( $value as $key => $inner_value ) {
    698             $filtered_key   = filter_block_kses_value( $key, $allowed_html, $allowed_protocols );
    699             $filtered_value = filter_block_kses_value( $inner_value, $allowed_html, $allowed_protocols );
     700            $filtered_key   = filter_block_kses_value( $key, $allowed_html, $allowed_protocols, $block_context );
     701            $filtered_value = filter_block_kses_value( $inner_value, $allowed_html, $allowed_protocols, $block_context );
     702
     703            if ( isset( $block_context['blockName'] ) && 'core/template-part' === $block_context['blockName'] ) {
     704                $filtered_value = filter_block_core_template_part_attributes( $filtered_value, $filtered_key, $allowed_html );
     705            }
    700706
    701707            if ( $filtered_key !== $key ) {
     
    710716
    711717    return $value;
     718}
     719
     720/**
     721 * Sanitizes the value of the Template Part block's `tagName` attribute.
     722 *
     723 * @since 6.5.5
     724 *
     725 * @param string          $attribute_value   The attribute value to filter.
     726 * @param string          $attribute_name    The attribute name.
     727 * @param array[]|string  $allowed_html      An array of allowed HTML elements and attributes,
     728 *                                           or a context name such as 'post'. See wp_kses_allowed_html()
     729 *                                           for the list of accepted context names.
     730 * @return string The sanitized attribute value.
     731 */
     732function filter_block_core_template_part_attributes( $attribute_value, $attribute_name, $allowed_html ) {
     733    if ( empty( $attribute_value ) || 'tagName' !== $attribute_name ) {
     734        return $attribute_value;
     735    }
     736    if ( ! is_array( $allowed_html ) ) {
     737        $allowed_html = wp_kses_allowed_html( $allowed_html );
     738    }
     739    return isset( $allowed_html[ $attribute_value ] ) ? $attribute_value : '';
    712740}
    713741
Note: See TracChangeset for help on using the changeset viewer.