Make WordPress Core

Changeset 49397


Ignore:
Timestamp:
10/29/2020 06:52:29 PM (6 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 4.9 branch.

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

Location:
branches/4.9
Files:
1 added
18 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-admin/admin-header.php

    r39326 r49397  
    7676?>
    7777<script type="text/javascript">
    78 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();}}};
    79 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
    80         pagenow = '<?php echo $current_screen->id; ?>',
    81         typenow = '<?php echo $current_screen->post_type; ?>',
    82         adminpage = '<?php echo $admin_body_class; ?>',
    83         thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
    84         decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
     78addLoadEvent = 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();}}};
     79var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>',
     80        pagenow = '<?php echo esc_js( $current_screen->id ); ?>',
     81        typenow = '<?php echo esc_js( $current_screen->post_type ); ?>',
     82        adminpage = '<?php echo esc_js( $admin_body_class ); ?>',
     83        thousandsSeparator = '<?php echo esc_js( $wp_locale->number_format['thousands_sep'] ); ?>',
     84        decimalPoint = '<?php echo esc_js( $wp_locale->number_format['decimal_point'] ); ?>',
    8585        isRtl = <?php echo (int) is_rtl(); ?>;
    8686</script>
  • branches/4.9/src/wp-admin/custom-background.php

    r41161 r49397  
    542542         */
    543543        public function wp_set_background_image() {
     544                check_ajax_referer( 'custom-background' );
    544545                if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit;
    545546                $attachment_id = absint($_POST['attachment_id']);
  • branches/4.9/src/wp-admin/custom-header.php

    r42811 r49397  
    323323<script type="text/javascript">
    324324(function($){
    325         var default_color = '<?php echo $default_color; ?>',
     325        var default_color = '<?php echo esc_js( $default_color ); ?>',
    326326                header_text_fields;
    327327
  • branches/4.9/src/wp-admin/includes/media.php

    r47967 r49397  
    474474<script type="text/javascript">
    475475addLoadEvent = 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();}}};
    476 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
     476var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
    477477isRtl = <?php echo (int) is_rtl(); ?>;
    478478</script>
  • branches/4.9/src/wp-admin/includes/ms.php

    r41289 r49397  
    746746?>
    747747<script type="text/javascript">
    748 var tb_pathToImage = "<?php echo includes_url( 'js/thickbox/loadingAnimation.gif', 'relative' ); ?>";
     748var tb_pathToImage = "<?php echo esc_js( includes_url( 'js/thickbox/loadingAnimation.gif', 'relative' ) ); ?>";
    749749</script>
    750750<?php
  • branches/4.9/src/wp-admin/includes/template.php

    r43496 r49397  
    16421642addLoadEvent = 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();}}};
    16431643function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
    1644 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
    1645         pagenow = '<?php echo $current_screen->id; ?>',
    1646         typenow = '<?php echo $current_screen->post_type; ?>',
    1647         adminpage = '<?php echo $admin_body_class; ?>',
    1648         thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
    1649         decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
     1644var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>',
     1645        pagenow = '<?php echo esc_js( $current_screen->id ); ?>',
     1646        typenow = '<?php echo esc_js( $current_screen->post_type ); ?>',
     1647        adminpage = '<?php echo esc_js( $admin_body_class ); ?>',
     1648        thousandsSeparator = '<?php echo esc_js( $wp_locale->number_format['thousands_sep'] ); ?>',
     1649        decimalPoint = '<?php echo esc_js( $wp_locale->number_format['decimal_point'] ); ?>',
    16501650        isRtl = <?php echo (int) is_rtl(); ?>;
    16511651</script>
  • branches/4.9/src/wp-admin/js/custom-background.js

    r40914 r49397  
    123123                                // Grab the selected attachment.
    124124                                var attachment = frame.state().get('selection').first();
     125                                var nonceValue = $( '#_wpnonce' ).val() || '';
    125126
    126127                                // Run an AJAX request to set the background image.
     
    128129                                        action: 'set-background-image',
    129130                                        attachment_id: attachment.id,
     131                                        _ajax_nonce: nonceValue,
    130132                                        size: 'full'
    131133                                }).done( function() {
  • branches/4.9/src/wp-admin/js/media-gallery.js

    r38293 r49397  
    1010         */
    1111        $( 'body' ).bind( 'click.wp-gallery', function(e) {
    12                 var target = $( e.target ), id, img_size;
     12                var target = $( e.target ), id, img_size, nonceValue;
    1313
    1414                if ( target.hasClass( 'wp-set-header' ) ) {
     
    2020                        id = target.data( 'attachment-id' );
    2121                        img_size = $( 'input[name="attachments[' + id + '][image-size]"]:checked').val();
     22                        nonceValue = $( '#_wpnonce' ).val() && '';
    2223
    2324                        /**
     
    2728                                action: 'set-background-image',
    2829                                attachment_id: id,
     30                                _ajax_nonce: nonceValue,
    2931                                size: img_size
    3032                        }, function() {
  • branches/4.9/src/wp-admin/media-new.php

    r38725 r49397  
    7373
    7474        <script type="text/javascript">
    75         var post_id = <?php echo $post_id; ?>, shortform = 3;
     75        var post_id = <?php echo absint( $post_id ); ?>, shortform = 3;
    7676        </script>
    77         <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
     77        <input type="hidden" name="post_id" id="post_id" value="<?php echo absint( $post_id ); ?>" />
    7878        <?php wp_nonce_field('media-form'); ?>
    7979        <div id="media-items" class="hide-if-no-js"></div>
  • branches/4.9/src/wp-admin/network/site-users.php

    r42811 r49397  
    212212
    213213<script type="text/javascript">
    214 var current_site_id = <?php echo $id; ?>;
     214var current_site_id = <?php echo absint( $id ); ?>;
    215215</script>
    216216
  • branches/4.9/src/wp-includes/Requests/Utility/FilteredIterator.php

    r37428 r49397  
    4343                return $value;
    4444        }
     45
    4546}
  • branches/4.9/src/wp-includes/class-wp-xmlrpc-server.php

    r42811 r49397  
    36393639                }
    36403640
     3641                if (
     3642                        'publish' === get_post_status( $post_id ) &&
     3643                        ! current_user_can( 'edit_post', $post_id ) &&
     3644                        post_password_required( $post_id )
     3645                ) {
     3646                        return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) );
     3647                }
     3648
     3649                if (
     3650                        'private' === get_post_status( $post_id ) &&
     3651                        ! current_user_can( 'read_post', $post_id )
     3652                ) {
     3653                        return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) );
     3654                }
     3655
    36413656                $comment = array(
    36423657                        'comment_post_ID' => $post_id,
     
    40244039                do_action( 'xmlrpc_call', 'wp.getMediaItem' );
    40254040
    4026                 if ( ! $attachment = get_post($attachment_id) )
     4041                $attachment = get_post( $attachment_id );
     4042                if ( ! $attachment || 'attachment' !== $attachment->post_type ) {
    40274043                        return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
     4044                }
    40284045
    40294046                return $this->_prepare_media_item( $attachment );
  • branches/4.9/src/wp-includes/embed.php

    r41634 r49397  
    10951095                $site  = reset( $sites );
    10961096
    1097                 if ( $site && (int) $site->blog_id !== get_current_blog_id() ) {
     1097                // Do not allow embeds for deleted/archived/spam sites.
     1098                if ( ! empty( $site->deleted ) || ! empty( $site->spam ) || ! empty( $site->archived ) ) {
     1099                        return false;
     1100                }
     1101
     1102                if ( $site && get_current_blog_id() !== (int) $site->blog_id ) {
    10981103                        switch_to_blog( $site->blog_id );
    10991104                        $switched_blog = true;
  • branches/4.9/src/wp-includes/formatting.php

    r47648 r49397  
    10911091 */
    10921092function utf8_uri_encode( $utf8_string, $length = 0 ) {
    1093         $unicode = '';
    1094         $values = array();
    1095         $num_octets = 1;
     1093        $unicode        = '';
     1094        $values         = array();
     1095        $num_octets     = 1;
    10961096        $unicode_length = 0;
    10971097
     
    11051105
    11061106                if ( $value < 128 ) {
    1107                         if ( $length && ( $unicode_length >= $length ) )
     1107                        if ( $length && ( $unicode_length >= $length ) ) {
    11081108                                break;
    1109                         $unicode .= chr($value);
     1109                        }
     1110                        $unicode .= chr( $value );
    11101111                        $unicode_length++;
    11111112                } else {
     
    20082009                        $title = mb_strtolower($title, 'UTF-8');
    20092010                }
    2010                 $title = utf8_uri_encode($title, 200);
     2011                $title = utf8_uri_encode( $title, 200 );
    20112012        }
    20122013
  • branches/4.9/src/wp-includes/meta.php

    r43557 r49397  
    924924 * @return bool True if the key is protected, false otherwise.
    925925 */
    926 function is_protected_meta( $meta_key, $meta_type = null ) {
    927         $protected = ( '_' == $meta_key[0] );
     926function is_protected_meta( $meta_key, $meta_type = '' ) {
     927        $sanitized_key = preg_replace( "/[^\x20-\x7E\p{L}]/", '', $meta_key );
     928        $protected     = strlen( $sanitized_key ) > 0 && ( '_' === $sanitized_key[0] );
    928929
    929930        /**
  • branches/4.9/tests/phpunit/tests/formatting/Utf8UriEncode.php

    r25002 r49397  
    1313         */
    1414        function test_percent_encodes_non_reserved_characters( $utf8, $urlencoded ) {
    15                 $this->assertEquals($urlencoded, utf8_uri_encode( $utf8 ) );
     15                $this->assertEquals( $urlencoded, utf8_uri_encode( $utf8 ) );
    1616        }
    1717
  • branches/4.9/tests/phpunit/tests/multisite/site.php

    r41883 r49397  
    444444
    445445                remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 );
     446        }
     447
     448        function test_content_from_spam_blog_is_not_available() {
     449                $spam_blog_id = self::factory()->blog->create();
     450                switch_to_blog( $spam_blog_id );
     451                $post_data      = array(
     452                        'post_title'   => 'Hello World!',
     453                        'post_content' => 'Hello world content',
     454                );
     455                $post_id        = self::factory()->post->create( $post_data );
     456                $post           = get_post( $post_id );
     457                $spam_permalink = site_url() . '/?p=' . $post->ID;
     458                $spam_embed_url = get_post_embed_url( $post_id );
     459
     460                restore_current_blog();
     461                $this->assertNotEmpty( $spam_permalink );
     462                $this->assertEquals( $post_data['post_title'], $post->post_title );
     463
     464                update_blog_status( $spam_blog_id, 'spam', 1 );
     465
     466                $post_id = self::factory()->post->create(
     467                        array(
     468                                'post_content' => "\n $spam_permalink \n",
     469                        )
     470                );
     471                $post    = get_post( $post_id );
     472                $content = apply_filters( 'the_content', $post->post_content );
     473
     474                $this->assertNotContains( $post_data['post_title'], $content );
     475                $this->assertNotContains( "src=\"{$spam_embed_url}#?", $content );
    446476        }
    447477
Note: See TracChangeset for help on using the changeset viewer.