Make WordPress Core


Ignore:
Timestamp:
06/24/2024 03:17:32 PM (20 months ago)
Author:
audrasjb
Message:

Grouped Backports to the 6.0 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 6.0 branch.
Props xknown, peterwilsoncc, jorbin, bernhard-reiter, azaozz.

File:
1 edited

Legend:

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

    r55773 r58481  
    688688 */
    689689function filter_block_kses( $block, $allowed_html, $allowed_protocols = array() ) {
    690     $block['attrs'] = filter_block_kses_value( $block['attrs'], $allowed_html, $allowed_protocols );
     690    $block['attrs'] = filter_block_kses_value( $block['attrs'], $allowed_html, $allowed_protocols, $block );
    691691
    692692    if ( is_array( $block['innerBlocks'] ) ) {
     
    704704 *
    705705 * @since 5.3.1
     706 * @since 6.5.5 Added the `$block_context` parameter.
    706707 *
    707708 * @param string[]|string $value             The attribute value to filter.
     
    710711 *                                           such as 'post'.
    711712 * @param string[]        $allowed_protocols Array of allowed URL protocols.
     713 * @param array           $block_context     Optional. The block the attribute belongs to, in parsed block array format.
    712714 * @return string[]|string The filtered and sanitized result.
    713715 */
    714 function filter_block_kses_value( $value, $allowed_html, $allowed_protocols = array() ) {
     716function filter_block_kses_value( $value, $allowed_html, $allowed_protocols = array(), $block_context = null ) {
    715717    if ( is_array( $value ) ) {
    716718        foreach ( $value as $key => $inner_value ) {
    717             $filtered_key   = filter_block_kses_value( $key, $allowed_html, $allowed_protocols );
    718             $filtered_value = filter_block_kses_value( $inner_value, $allowed_html, $allowed_protocols );
     719            $filtered_key   = filter_block_kses_value( $key, $allowed_html, $allowed_protocols, $block_context );
     720            $filtered_value = filter_block_kses_value( $inner_value, $allowed_html, $allowed_protocols, $block_context );
     721
     722            if ( isset( $block_context['blockName'] ) && 'core/template-part' === $block_context['blockName'] ) {
     723                $filtered_value = filter_block_core_template_part_attributes( $filtered_value, $filtered_key, $allowed_html );
     724            }
    719725
    720726            if ( $filtered_key !== $key ) {
     
    729735
    730736    return $value;
     737}
     738
     739/**
     740 * Sanitizes the value of the Template Part block's `tagName` attribute.
     741 *
     742 * @since 6.5.5
     743 *
     744 * @param string          $attribute_value   The attribute value to filter.
     745 * @param string          $attribute_name    The attribute name.
     746 * @param array[]|string  $allowed_html      An array of allowed HTML elements and attributes,
     747 *                                           or a context name such as 'post'. See wp_kses_allowed_html()
     748 *                                           for the list of accepted context names.
     749 * @return string The sanitized attribute value.
     750 */
     751function filter_block_core_template_part_attributes( $attribute_value, $attribute_name, $allowed_html ) {
     752    if ( empty( $attribute_value ) || 'tagName' !== $attribute_name ) {
     753        return $attribute_value;
     754    }
     755    if ( ! is_array( $allowed_html ) ) {
     756        $allowed_html = wp_kses_allowed_html( $allowed_html );
     757    }
     758    return isset( $allowed_html[ $attribute_value ] ) ? $attribute_value : '';
    731759}
    732760
Note: See TracChangeset for help on using the changeset viewer.