Make WordPress Core

Changeset 55771


Ignore:
Timestamp:
05/16/2023 03:13:50 PM (10 months ago)
Author:
audrasjb
Message:

Grouped backports to the 6.1 branch.

  • Media: Prevent CSRF setting attachment thumbnails.
  • Embeds: Add protocol validation for WordPress Embed code.
  • I18N: Introduce sanitization function for locale.
  • Editor: Ensure block comments are of a valid form.
  • Editor: Remove shortcode support from block templates.

Merges [55760-55764] to the 6.1 branch.
Props dd32, isabel_brison, martinkrcho, matveb, ocean90, paulkevan, peterwilsoncc, timothyblynjacobs, xknown, youknowriad.

Location:
branches/6.1
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • branches/6.1/src/js/_enqueues/wp/embed.js

    r52132 r55771  
    5050        var iframes = document.querySelectorAll( 'iframe[data-secret="' + data.secret + '"]' ),
    5151            blockquotes = document.querySelectorAll( 'blockquote[data-secret="' + data.secret + '"]' ),
     52            allowedProtocols = new RegExp( '^https?:$', 'i' ),
    5253            i, source, height, sourceURL, targetURL;
    5354
     
    8485                sourceURL.href = source.getAttribute( 'src' );
    8586                targetURL.href = data.value;
     87
     88                /* Only follow link if the protocol is in the allow list. */
     89                if ( ! allowedProtocols.test( targetURL.protocol ) ) {
     90                    continue;
     91                }
    8692
    8793                /* Only continue if link hostname matches iframe's hostname. */
  • branches/6.1/src/js/media/views/frame/video-details.js

    r43309 r55771  
    107107            wp.ajax.send( 'set-attachment-thumbnail', {
    108108                data : {
     109                    _ajax_nonce: wp.media.view.settings.nonce.setAttachmentThumbnail,
    109110                    urls: urls,
    110111                    thumbnail_id: attachment.get( 'id' )
  • branches/6.1/src/wp-admin/about.php

    r55371 r55771  
    4646            <div class="column">
    4747                <h2><?php _e( 'Maintenance and Security Releases' ); ?></h2>
     48                <p>
     49                    <?php
     50                    printf(
     51                        __( '<strong>Version %s</strong> addressed some security issues.' ),
     52                        '6.1.2'
     53                    );
     54                    ?>
     55                    <?php
     56                    printf(
     57                        /* translators: %s: HelpHub URL. */
     58                        __( 'For more information, see <a href="%s">the release notes</a>.' ),
     59                        sprintf(
     60                            /* translators: %s: WordPress version. */
     61                            esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
     62                            sanitize_title( '6.1.2' )
     63                        )
     64                    );
     65                    ?>
     66                </p>
     67
    4868                <p>
    4969                    <?php
  • branches/6.1/src/wp-admin/includes/ajax-actions.php

    r54524 r55771  
    27722772    }
    27732773
     2774    if ( false === check_ajax_referer( 'set-attachment-thumbnail', '_ajax_nonce', false ) ) {
     2775        wp_send_json_error();
     2776    }
     2777
    27742778    $post_ids = array();
    27752779    // For each URL, try to find its corresponding post ID.
  • branches/6.1/src/wp-includes/block-template.php

    r54818 r55771  
    241241    $content = wptexturize( $content );
    242242    $content = convert_smilies( $content );
    243     $content = shortcode_unautop( $content );
    244243    $content = wp_filter_content_tags( $content );
    245     $content = do_shortcode( $content );
    246244    $content = str_replace( ']]>', ']]&gt;', $content );
    247245
  • branches/6.1/src/wp-includes/blocks.php

    r54520 r55771  
    795795    $result = '';
    796796
     797    if ( false !== strpos( $text, '<!--' ) && false !== strpos( $text, '--->' ) ) {
     798        $text = preg_replace_callback( '%<!--(.*?)--->%', '_filter_block_content_callback', $text );
     799    }
     800
    797801    $blocks = parse_blocks( $text );
    798802    foreach ( $blocks as $block ) {
     
    802806
    803807    return $result;
     808}
     809
     810/**
     811 * Callback used for regular expression replacement in filter_block_content().
     812 *
     813 * @private
     814 * @since 6.2.1
     815 *
     816 * @param array $matches Array of preg_replace_callback matches.
     817 * @return string Replacement string.
     818 */
     819function _filter_block_content_callback( $matches ) {
     820    return '<!--' . rtrim( $matches[1], '-' ) . '-->';
    804821}
    805822
  • branches/6.1/src/wp-includes/formatting.php

    r54814 r55771  
    24342434
    24352435/**
     2436 * Strips out all characters not allowed in a locale name.
     2437 *
     2438 * @since 6.2.1
     2439 *
     2440 * @param string $locale_name The locale name to be sanitized.
     2441 * @return string The sanitized value.
     2442 */
     2443function sanitize_locale_name( $locale_name ) {
     2444    // Limit to A-Z, a-z, 0-9, '_', '-'.
     2445    $sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $locale_name );
     2446
     2447    /**
     2448     * Filters a sanitized locale name string.
     2449     *
     2450     * @since 6.2.1
     2451     *
     2452     * @param string $sanitized   The sanitized locale name.
     2453     * @param string $locale_name The locale name before sanitization.
     2454     */
     2455    return apply_filters( 'sanitize_locale_name', $sanitized, $locale_name );
     2456}
     2457
     2458/**
    24362459 * Converts lone & characters into `&#038;` (a.k.a. `&amp;`)
    24372460 *
  • branches/6.1/src/wp-includes/l10n.php

    r54682 r55771  
    150150
    151151    if ( ! empty( $_GET['wp_lang'] ) ) {
    152         $wp_lang = sanitize_text_field( $_GET['wp_lang'] );
     152        $wp_lang = sanitize_locale_name( wp_unslash( $_GET['wp_lang'] ) );
    153153    } elseif ( ! empty( $_COOKIE['wp_lang'] ) ) {
    154         $wp_lang = sanitize_text_field( $_COOKIE['wp_lang'] );
     154        $wp_lang = sanitize_locale_name( wp_unslash( $_COOKIE['wp_lang'] ) );
    155155    }
    156156
  • branches/6.1/src/wp-includes/media.php

    r54807 r55771  
    45174517        'captions'          => ! apply_filters( 'disable_captions', '' ),
    45184518        'nonce'             => array(
    4519             'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
     4519            'sendToEditor'           => wp_create_nonce( 'media-send-to-editor' ),
     4520            'setAttachmentThumbnail' => wp_create_nonce( 'set-attachment-thumbnail' ),
    45204521        ),
    45214522        'post'              => array(
  • branches/6.1/src/wp-includes/version.php

    r54847 r55771  
    1717 * @global string $wp_version
    1818 */
    19 $wp_version = '6.1.2-alpha-54847-src';
     19$wp_version = '6.1.2-src';
    2020
    2121/**
  • branches/6.1/tests/phpunit/tests/ajax/Attachments.php

    r53701 r55771  
    104104        $this->assertSame( $expected, $response['data'] );
    105105    }
     106
     107    public function test_wp_ajax_set_attachment_thumbnail_success() {
     108        // Become an administrator.
     109        $post    = $_POST;
     110        $user_id = self::factory()->user->create(
     111            array(
     112                'role'       => 'administrator',
     113                'user_login' => 'user_36578_administrator',
     114                'user_email' => 'user_36578_administrator@example.com',
     115            )
     116        );
     117        wp_set_current_user( $user_id );
     118        $_POST = array_merge( $_POST, $post );
     119
     120        // Upload the attachment itself.
     121        $filename = DIR_TESTDATA . '/uploads/small-audio.mp3';
     122        $contents = file_get_contents( $filename );
     123
     124        $upload     = wp_upload_bits( wp_basename( $filename ), null, $contents );
     125        $attachment = $this->_make_attachment( $upload );
     126
     127        // Upload the thumbnail.
     128        $filename = DIR_TESTDATA . '/images/waffles.jpg';
     129        $contents = file_get_contents( $filename );
     130
     131        $upload    = wp_upload_bits( wp_basename( $filename ), null, $contents );
     132        $thumbnail = $this->_make_attachment( $upload );
     133
     134        // Set up a default request.
     135        $_POST['_ajax_nonce']  = wp_create_nonce( 'set-attachment-thumbnail' );
     136        $_POST['thumbnail_id'] = $thumbnail;
     137        $_POST['urls']         = array( wp_get_attachment_url( $attachment ) );
     138
     139        // Make the request.
     140        try {
     141            $this->_handleAjax( 'set-attachment-thumbnail' );
     142        } catch ( WPAjaxDieContinueException $e ) {
     143            unset( $e );
     144        }
     145
     146        // Get the response.
     147        $response = json_decode( $this->_last_response, true );
     148
     149        // Ensure everything is correct.
     150        $this->assertTrue( $response['success'] );
     151    }
     152
     153    public function test_wp_ajax_set_attachment_thumbnail_missing_nonce() {
     154        // Become an administrator.
     155        $post    = $_POST;
     156        $user_id = self::factory()->user->create(
     157            array(
     158                'role'       => 'administrator',
     159                'user_login' => 'user_36578_administrator',
     160                'user_email' => 'user_36578_administrator@example.com',
     161            )
     162        );
     163        wp_set_current_user( $user_id );
     164        $_POST = array_merge( $_POST, $post );
     165
     166        // Upload the attachment itself.
     167        $filename = DIR_TESTDATA . '/uploads/small-audio.mp3';
     168        $contents = file_get_contents( $filename );
     169
     170        $upload     = wp_upload_bits( wp_basename( $filename ), null, $contents );
     171        $attachment = $this->_make_attachment( $upload );
     172
     173        // Upload the thumbnail.
     174        $filename = DIR_TESTDATA . '/images/waffles.jpg';
     175        $contents = file_get_contents( $filename );
     176
     177        $upload    = wp_upload_bits( wp_basename( $filename ), null, $contents );
     178        $thumbnail = $this->_make_attachment( $upload );
     179
     180        // Set up a default request.
     181        $_POST['thumbnail_id'] = $thumbnail;
     182        $_POST['urls']         = array( wp_get_attachment_url( $attachment ) );
     183
     184        // Make the request.
     185        try {
     186            $this->_handleAjax( 'set-attachment-thumbnail' );
     187        } catch ( WPAjaxDieContinueException $e ) {
     188            unset( $e );
     189        }
     190
     191        // Get the response.
     192        $response = json_decode( $this->_last_response, true );
     193
     194        // Check that success is false without sending nonce.
     195        $this->assertFalse( $response['success'] );
     196    }
    106197}
Note: See TracChangeset for help on using the changeset viewer.