Make WordPress Core

Changeset 49395


Ignore:
Timestamp:
10/29/2020 06:48:02 PM (4 years ago)
Author:
whyisjake
Message:

General: WordPress updates

  • XML-RPC: Improve error messages for unprivileged users.
  • External Libraries: Disable deserialization in Requests_Utility_FilteredIterator
  • Embeds: Disable embeds on deactivated Multisite sites.
  • Coding standards: Modify escaping functions to avoid potential false positives.
  • XML-RPC: Return error message if attachment ID is incorrect.
  • Upgrade/install: Improve logic check when determining installation status.
  • Meta: Sanitize meta key before checking protection status.
  • Themes: Ensure that only privileged users can set a background image when a theme is using the deprecated custom background page.

Brings the changes from [49380,49382-49388] to the 5.1 branch.

Props xknown, zieladam, peterwilsoncc, whyisjake, desrosj, dd32.

Location:
branches/5.1
Files:
1 added
18 edited

Legend:

Unmodified
Added
Removed
  • branches/5.1

  • branches/5.1/src/js/_enqueues/admin/custom-background.js

    r43347 r49395  
    127127                // Grab the selected attachment.
    128128                var attachment = frame.state().get('selection').first();
     129                var nonceValue = $( '#_wpnonce' ).val() || '';
    129130
    130131                // Run an AJAX request to set the background image.
     
    132133                    action: 'set-background-image',
    133134                    attachment_id: attachment.id,
     135                    _ajax_nonce: nonceValue,
    134136                    size: 'full'
    135137                }).done( function() {
  • branches/5.1/src/js/_enqueues/deprecated/media-gallery.js

    r43347 r49395  
    1212     */
    1313    $( 'body' ).bind( 'click.wp-gallery', function(e) {
    14         var target = $( e.target ), id, img_size;
     14        var target = $( e.target ), id, img_size, nonceValue;
    1515
    1616        if ( target.hasClass( 'wp-set-header' ) ) {
     
    2222            id = target.data( 'attachment-id' );
    2323            img_size = $( 'input[name="attachments[' + id + '][image-size]"]:checked').val();
     24            nonceValue = $( '#_wpnonce' ).val() && '';
    2425
    2526            /**
     
    2930                action: 'set-background-image',
    3031                attachment_id: id,
     32                _ajax_nonce: nonceValue,
    3133                size: img_size
    3234            }, function() {
  • branches/5.1/src/wp-admin/admin-header.php

    r44639 r49395  
    7878?>
    7979<script type="text/javascript">
    80 addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
    81 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
    82     pagenow = '<?php echo $current_screen->id; ?>',
    83     typenow = '<?php echo $current_screen->post_type; ?>',
    84     adminpage = '<?php echo $admin_body_class; ?>',
    85     thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
    86     decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
     80addLoadEvent = function(func){if(typeof jQuery!=='undefined')jQuery(document).ready(func);else if(typeof wpOnload!=='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
     81var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>',
     82    pagenow = '<?php echo esc_js( $current_screen->id ); ?>',
     83    typenow = '<?php echo esc_js( $current_screen->post_type ); ?>',
     84    adminpage = '<?php echo esc_js( $admin_body_class ); ?>',
     85    thousandsSeparator = '<?php echo esc_js( $wp_locale->number_format['thousands_sep'] ); ?>',
     86    decimalPoint = '<?php echo esc_js( $wp_locale->number_format['decimal_point'] ); ?>',
    8787    isRtl = <?php echo (int) is_rtl(); ?>;
    8888</script>
  • branches/5.1/src/wp-admin/custom-background.php

    r44331 r49395  
    575575     */
    576576    public function wp_set_background_image() {
     577        check_ajax_referer( 'custom-background' );
     578
    577579        if ( ! current_user_can( 'edit_theme_options' ) || ! isset( $_POST['attachment_id'] ) ) {
    578580            exit;
  • branches/5.1/src/wp-admin/custom-header.php

    r44574 r49395  
    339339<script type="text/javascript">
    340340(function($){
    341     var default_color = '<?php echo $default_color; ?>',
     341    var default_color = '<?php echo esc_js( $default_color ); ?>',
    342342        header_text_fields;
    343343
  • branches/5.1/src/wp-admin/includes/media.php

    r47963 r49395  
    501501<script type="text/javascript">
    502502addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
    503 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
     503var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
    504504isRtl = <?php echo (int) is_rtl(); ?>;
    505505</script>
  • branches/5.1/src/wp-admin/includes/ms.php

    r44574 r49395  
    882882    ?>
    883883<script type="text/javascript">
    884 var tb_pathToImage = "<?php echo includes_url( 'js/thickbox/loadingAnimation.gif', 'relative' ); ?>";
     884var tb_pathToImage = "<?php echo esc_js( includes_url( 'js/thickbox/loadingAnimation.gif', 'relative' ) ); ?>";
    885885</script>
    886886    <?php
  • branches/5.1/src/wp-admin/includes/template.php

    r44643 r49395  
    19131913addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
    19141914function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
    1915 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
    1916     pagenow = '<?php echo $current_screen->id; ?>',
    1917     typenow = '<?php echo $current_screen->post_type; ?>',
    1918     adminpage = '<?php echo $admin_body_class; ?>',
    1919     thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
    1920     decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
     1915var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>',
     1916    pagenow = '<?php echo esc_js( $current_screen->id ); ?>',
     1917    typenow = '<?php echo esc_js( $current_screen->post_type ); ?>',
     1918    adminpage = '<?php echo esc_js( $admin_body_class ); ?>',
     1919    thousandsSeparator = '<?php echo esc_js( $wp_locale->number_format['thousands_sep'] ); ?>',
     1920    decimalPoint = '<?php echo esc_js( $wp_locale->number_format['decimal_point'] ); ?>',
    19211921    isRtl = <?php echo (int) is_rtl(); ?>;
    19221922</script>
  • branches/5.1/src/wp-admin/media-new.php

    r42343 r49395  
    7878
    7979    <script type="text/javascript">
    80     var post_id = <?php echo $post_id; ?>, shortform = 3;
     80    var post_id = <?php echo absint( $post_id ); ?>, shortform = 3;
    8181    </script>
    82     <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
     82    <input type="hidden" name="post_id" id="post_id" value="<?php echo absint( $post_id ); ?>" />
    8383    <?php wp_nonce_field( 'media-form' ); ?>
    8484    <div id="media-items" class="hide-if-no-js"></div>
  • branches/5.1/src/wp-admin/network/site-users.php

    r43571 r49395  
    218218
    219219<script type="text/javascript">
    220 var current_site_id = <?php echo $id; ?>;
     220var current_site_id = <?php echo absint( $id ); ?>;
    221221</script>
    222222
  • branches/5.1/src/wp-includes/Requests/Utility/FilteredIterator.php

    r37428 r49395  
    4343        return $value;
    4444    }
     45
     46    /**
     47     * @inheritdoc
     48     */
     49    public function unserialize( $serialized ) {
     50    }
     51
     52    /**
     53     * @inheritdoc
     54     */
     55    public function __unserialize( $serialized ) { // phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.NewMagicMethods.__unserializeFound
     56        $this->unserialize( $serialized );
     57    }
    4558}
  • branches/5.1/src/wp-includes/class-wp-xmlrpc-server.php

    r44566 r49395  
    38303830        }
    38313831
     3832        if (
     3833            'publish' === get_post_status( $post_id ) &&
     3834            ! current_user_can( 'edit_post', $post_id ) &&
     3835            post_password_required( $post_id )
     3836        ) {
     3837            return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) );
     3838        }
     3839
     3840        if (
     3841            'private' === get_post_status( $post_id ) &&
     3842            ! current_user_can( 'read_post', $post_id )
     3843        ) {
     3844            return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) );
     3845        }
     3846
    38323847        $comment = array(
    38333848            'comment_post_ID' => $post_id,
     
    42344249        do_action( 'xmlrpc_call', 'wp.getMediaItem' );
    42354250
    4236         if ( ! $attachment = get_post( $attachment_id ) ) {
     4251        $attachment = get_post( $attachment_id );
     4252        if ( ! $attachment || 'attachment' !== $attachment->post_type ) {
    42374253            return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
    42384254        }
  • branches/5.1/src/wp-includes/embed.php

    r47963 r49395  
    605605        $site  = reset( $sites );
    606606
    607         if ( $site && (int) $site->blog_id !== get_current_blog_id() ) {
     607        // Do not allow embeds for deleted/archived/spam sites.
     608        if ( ! empty( $site->deleted ) || ! empty( $site->spam ) || ! empty( $site->archived ) ) {
     609            return false;
     610        }
     611
     612        if ( $site && get_current_blog_id() !== (int) $site->blog_id ) {
    608613            switch_to_blog( $site->blog_id );
    609614            $switched_blog = true;
  • branches/5.1/src/wp-includes/functions.php

    r46490 r49395  
    15671567        }
    15681568
    1569         if ( ! $wpdb->get_results( "DESCRIBE $table;" ) ) {
     1569        $described_table = $wpdb->get_results( "DESCRIBE $table;" );
     1570        if ( is_array( $described_table ) && count( $described_table ) === 0 ) {
    15701571            continue;
    15711572        }
  • branches/5.1/src/wp-includes/meta.php

    r43982 r49395  
    10291029 * @return bool Whether the meta key is considered protected.
    10301030 */
    1031 function is_protected_meta( $meta_key, $meta_type = null ) {
    1032     $protected = ( '_' == $meta_key[0] );
     1031function is_protected_meta( $meta_key, $meta_type = '' ) {
     1032    $sanitized_key = preg_replace( "/[^\x20-\x7E\p{L}]/", '', $meta_key );
     1033    $protected     = strlen( $sanitized_key ) > 0 && ( '_' === $sanitized_key[0] );
    10331034
    10341035    /**
  • branches/5.1/tests/phpunit/tests/functions.php

    r44645 r49395  
    236236        $this->assertFalse( is_serialized( 'C:16:"Serialized_Class":6:{a:0:{}}' ) );
    237237    }
    238 
    239238
    240239    /**
  • branches/5.1/tests/phpunit/tests/multisite/site.php

    r47321 r49395  
    475475        }
    476476
     477        function test_content_from_spam_blog_is_not_available() {
     478            $spam_blog_id = self::factory()->blog->create();
     479            switch_to_blog( $spam_blog_id );
     480            $post_data      = array(
     481                'post_title'   => 'Hello World!',
     482                'post_content' => 'Hello world content',
     483            );
     484            $post_id        = self::factory()->post->create( $post_data );
     485            $post           = get_post( $post_id );
     486            $spam_permalink = site_url() . '/?p=' . $post->ID;
     487            $spam_embed_url = get_post_embed_url( $post_id );
     488
     489            restore_current_blog();
     490            $this->assertNotEmpty( $spam_permalink );
     491            $this->assertEquals( $post_data['post_title'], $post->post_title );
     492
     493            update_blog_status( $spam_blog_id, 'spam', 1 );
     494
     495            $post_id = self::factory()->post->create(
     496                array(
     497                    'post_content' => "\n $spam_permalink \n",
     498                )
     499            );
     500            $post    = get_post( $post_id );
     501            $content = apply_filters( 'the_content', $post->post_content );
     502
     503            $this->assertNotContains( $post_data['post_title'], $content );
     504            $this->assertNotContains( "src=\"{$spam_embed_url}#?", $content );
     505        }
     506
    477507        function test_update_blog_status_make_spam_blog_action() {
    478508            global $test_action_counter;
Note: See TracChangeset for help on using the changeset viewer.