Make WordPress Core


Ignore:
Timestamp:
06/24/2024 03:15:02 PM (3 months ago)
Author:
audrasjb
Message:

Grouped Backports to the 6.1 branch.

  • Editor: Fix Path Traversal issue on Windows in Template-Part Block.
  • Editor: Sanitize Template Part HTML tag on save.
  • HTML API: Run URL attributes through esc_url().

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

File:
1 edited

Legend:

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

    r55771 r58480  
    836836 */
    837837function filter_block_kses( $block, $allowed_html, $allowed_protocols = array() ) {
    838     $block['attrs'] = filter_block_kses_value( $block['attrs'], $allowed_html, $allowed_protocols );
     838    $block['attrs'] = filter_block_kses_value( $block['attrs'], $allowed_html, $allowed_protocols, $block );
    839839
    840840    if ( is_array( $block['innerBlocks'] ) ) {
     
    852852 *
    853853 * @since 5.3.1
     854 * @since 6.5.5 Added the `$block_context` parameter.
    854855 *
    855856 * @param string[]|string $value             The attribute value to filter.
     
    859860 * @param string[]        $allowed_protocols Optional. Array of allowed URL protocols.
    860861 *                                           Defaults to the result of wp_allowed_protocols().
     862 * @param array           $block_context     Optional. The block the attribute belongs to, in parsed block array format.
    861863 * @return string[]|string The filtered and sanitized result.
    862864 */
    863 function filter_block_kses_value( $value, $allowed_html, $allowed_protocols = array() ) {
     865function filter_block_kses_value( $value, $allowed_html, $allowed_protocols = array(), $block_context = null ) {
    864866    if ( is_array( $value ) ) {
    865867        foreach ( $value as $key => $inner_value ) {
    866             $filtered_key   = filter_block_kses_value( $key, $allowed_html, $allowed_protocols );
    867             $filtered_value = filter_block_kses_value( $inner_value, $allowed_html, $allowed_protocols );
     868            $filtered_key   = filter_block_kses_value( $key, $allowed_html, $allowed_protocols, $block_context );
     869            $filtered_value = filter_block_kses_value( $inner_value, $allowed_html, $allowed_protocols, $block_context );
     870
     871            if ( isset( $block_context['blockName'] ) && 'core/template-part' === $block_context['blockName'] ) {
     872                $filtered_value = filter_block_core_template_part_attributes( $filtered_value, $filtered_key, $allowed_html );
     873            }
    868874
    869875            if ( $filtered_key !== $key ) {
     
    878884
    879885    return $value;
     886}
     887
     888/**
     889 * Sanitizes the value of the Template Part block's `tagName` attribute.
     890 *
     891 * @since 6.5.5
     892 *
     893 * @param string          $attribute_value   The attribute value to filter.
     894 * @param string          $attribute_name    The attribute name.
     895 * @param array[]|string  $allowed_html      An array of allowed HTML elements and attributes,
     896 *                                           or a context name such as 'post'. See wp_kses_allowed_html()
     897 *                                           for the list of accepted context names.
     898 * @return string The sanitized attribute value.
     899 */
     900function filter_block_core_template_part_attributes( $attribute_value, $attribute_name, $allowed_html ) {
     901    if ( empty( $attribute_value ) || 'tagName' !== $attribute_name ) {
     902        return $attribute_value;
     903    }
     904    if ( ! is_array( $allowed_html ) ) {
     905        $allowed_html = wp_kses_allowed_html( $allowed_html );
     906    }
     907    return isset( $allowed_html[ $attribute_value ] ) ? $attribute_value : '';
    880908}
    881909
Note: See TracChangeset for help on using the changeset viewer.