Make WordPress Core


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

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

File:
1 edited

Legend:

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

    r57071 r58475  
    12271227 */
    12281228function filter_block_kses( $block, $allowed_html, $allowed_protocols = array() ) {
    1229     $block['attrs'] = filter_block_kses_value( $block['attrs'], $allowed_html, $allowed_protocols );
     1229    $block['attrs'] = filter_block_kses_value( $block['attrs'], $allowed_html, $allowed_protocols, $block );
    12301230
    12311231    if ( is_array( $block['innerBlocks'] ) ) {
     
    12431243 *
    12441244 * @since 5.3.1
     1245 * @since 6.5.5 Added the `$block_context` parameter.
    12451246 *
    12461247 * @param string[]|string $value             The attribute value to filter.
     
    12501251 * @param string[]        $allowed_protocols Optional. Array of allowed URL protocols.
    12511252 *                                           Defaults to the result of wp_allowed_protocols().
     1253 * @param array           $block_context     Optional. The block the attribute belongs to, in parsed block array format.
    12521254 * @return string[]|string The filtered and sanitized result.
    12531255 */
    1254 function filter_block_kses_value( $value, $allowed_html, $allowed_protocols = array() ) {
     1256function filter_block_kses_value( $value, $allowed_html, $allowed_protocols = array(), $block_context = null ) {
    12551257    if ( is_array( $value ) ) {
    12561258        foreach ( $value as $key => $inner_value ) {
    1257             $filtered_key   = filter_block_kses_value( $key, $allowed_html, $allowed_protocols );
    1258             $filtered_value = filter_block_kses_value( $inner_value, $allowed_html, $allowed_protocols );
     1259            $filtered_key   = filter_block_kses_value( $key, $allowed_html, $allowed_protocols, $block_context );
     1260            $filtered_value = filter_block_kses_value( $inner_value, $allowed_html, $allowed_protocols, $block_context );
     1261
     1262            if ( isset( $block_context['blockName'] ) && 'core/template-part' === $block_context['blockName'] ) {
     1263                $filtered_value = filter_block_core_template_part_attributes( $filtered_value, $filtered_key, $allowed_html );
     1264            }
    12591265
    12601266            if ( $filtered_key !== $key ) {
     
    12691275
    12701276    return $value;
     1277}
     1278
     1279/**
     1280 * Sanitizes the value of the Template Part block's `tagName` attribute.
     1281 *
     1282 * @since 6.5.5
     1283 *
     1284 * @param string          $attribute_value   The attribute value to filter.
     1285 * @param string          $attribute_name    The attribute name.
     1286 * @param array[]|string  $allowed_html      An array of allowed HTML elements and attributes,
     1287 *                                           or a context name such as 'post'. See wp_kses_allowed_html()
     1288 *                                           for the list of accepted context names.
     1289 * @return string The sanitized attribute value.
     1290 */
     1291function filter_block_core_template_part_attributes( $attribute_value, $attribute_name, $allowed_html ) {
     1292    if ( empty( $attribute_value ) || 'tagName' !== $attribute_name ) {
     1293        return $attribute_value;
     1294    }
     1295    if ( ! is_array( $allowed_html ) ) {
     1296        $allowed_html = wp_kses_allowed_html( $allowed_html );
     1297    }
     1298    return isset( $allowed_html[ $attribute_value ] ) ? $attribute_value : '';
    12711299}
    12721300
Note: See TracChangeset for help on using the changeset viewer.