From 03372aee6e10d1f91c3240eabcbfcec7122c3e1f Mon Sep 17 00:00:00 2001 From: whyisjake Date: Thu, 29 Oct 2020 19:15:11 +0000 Subject: [PATCH] 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 3.9 branch. Props xknown, zieladam, peterwilsoncc, whyisjake, desrosj, dd32. Built from https://develop.svn.wordpress.org/branches/3.9@49407 git-svn-id: http://core.svn.wordpress.org/branches/3.9@49166 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-header.php | 14 +++++++------- wp-admin/custom-background.php | 1 + wp-admin/custom-header.php | 2 +- wp-admin/includes/media.php | 2 +- wp-admin/includes/template.php | 12 ++++++------ wp-admin/js/custom-background.js | 2 ++ wp-admin/js/custom-background.min.js | 2 +- wp-admin/js/media-gallery.js | 4 +++- wp-admin/js/media-gallery.min.js | 2 +- wp-admin/media-new.php | 4 ++-- wp-admin/network/site-users.php | 2 +- wp-includes/class-wp-xmlrpc-server.php | 20 +++++++++++++++++++- wp-includes/meta.php | 5 +++-- 13 files changed, 48 insertions(+), 24 deletions(-) diff --git a/wp-admin/admin-header.php b/wp-admin/admin-header.php index 10349750eb..73023809f7 100644 --- a/wp-admin/admin-header.php +++ b/wp-admin/admin-header.php @@ -58,13 +58,13 @@ wp_enqueue_script( 'svg-painter' ); $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix); ?> diff --git a/wp-admin/custom-background.php b/wp-admin/custom-background.php index e53cd7d244..d5ac973a7b 100644 --- a/wp-admin/custom-background.php +++ b/wp-admin/custom-background.php @@ -411,6 +411,7 @@ if ( current_theme_supports( 'custom-background', 'default-color' ) ) } public function wp_set_background_image() { + check_ajax_referer( 'custom-background' ); if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit; $attachment_id = absint($_POST['attachment_id']); /** This filter is documented in wp-admin/includes/media.php */ diff --git a/wp-admin/custom-header.php b/wp-admin/custom-header.php index 1c9971f5aa..d9efac036e 100644 --- a/wp-admin/custom-header.php +++ b/wp-admin/custom-header.php @@ -329,7 +329,7 @@ class Custom_Image_Header { diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 95177f84e3..fd2be9941b 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -1480,12 +1480,12 @@ wp_enqueue_style( 'colors' ); //', - pagenow = 'id; ?>', - typenow = 'post_type; ?>', - adminpage = '', - thousandsSeparator = 'number_format['thousands_sep'] ); ?>', - decimalPoint = 'number_format['decimal_point'] ); ?>', +var ajaxurl = '', + pagenow = 'id ); ?>', + typenow = 'post_type ); ?>', + adminpage = '', + thousandsSeparator = 'number_format['thousands_sep'] ); ?>', + decimalPoint = 'number_format['decimal_point'] ); ?>', isRtl = ; //]]> diff --git a/wp-admin/js/custom-background.js b/wp-admin/js/custom-background.js index 81fd59170c..8d15e69193 100644 --- a/wp-admin/js/custom-background.js +++ b/wp-admin/js/custom-background.js @@ -56,11 +56,13 @@ frame.on( 'select', function() { // Grab the selected attachment. var attachment = frame.state().get('selection').first(); + var nonceValue = $( '#_wpnonce' ).val() || ''; // Run an AJAX request to set the background image. $.post( ajaxurl, { action: 'set-background-image', attachment_id: attachment.id, + _ajax_nonce: nonceValue, size: 'full' }).done( function() { // When the request completes, reload the window. diff --git a/wp-admin/js/custom-background.min.js b/wp-admin/js/custom-background.min.js index f53e02cae7..f8a0456964 100644 --- a/wp-admin/js/custom-background.min.js +++ b/wp-admin/js/custom-background.min.js @@ -1 +1 @@ -!function(a){a(document).ready(function(){var b,c=a("#custom-background-image");a("#background-color").wpColorPicker({change:function(a,b){c.css("background-color",b.color.toString())},clear:function(){c.css("background-color","")}}),a('input[name="background-position-x"]').change(function(){c.css("background-position",a(this).val()+" top")}),a('input[name="background-repeat"]').change(function(){c.css("background-repeat",a(this).val())}),a("#choose-from-library-link").click(function(c){var d=a(this);return c.preventDefault(),b?void b.open():(b=wp.media.frames.customBackground=wp.media({title:d.data("choose"),library:{type:"image"},button:{text:d.data("update"),close:!1}}),b.on("select",function(){var c=b.state().get("selection").first();a.post(ajaxurl,{action:"set-background-image",attachment_id:c.id,size:"full"}).done(function(){window.location.reload()})}),void b.open())})})}(jQuery); \ No newline at end of file +!function(a){a(document).ready(function(){var b,c=a("#custom-background-image");a("#background-color").wpColorPicker({change:function(a,b){c.css("background-color",b.color.toString())},clear:function(){c.css("background-color","")}}),a('input[name="background-position-x"]').change(function(){c.css("background-position",a(this).val()+" top")}),a('input[name="background-repeat"]').change(function(){c.css("background-repeat",a(this).val())}),a("#choose-from-library-link").click(function(c){var d=a(this);return c.preventDefault(),b?void b.open():(b=wp.media.frames.customBackground=wp.media({title:d.data("choose"),library:{type:"image"},button:{text:d.data("update"),close:!1}}),b.on("select",function(){var c=b.state().get("selection").first(),d=a("#_wpnonce").val()||"";a.post(ajaxurl,{action:"set-background-image",attachment_id:c.id,_ajax_nonce:d,size:"full"}).done(function(){window.location.reload()})}),void b.open())})})}(jQuery); \ No newline at end of file diff --git a/wp-admin/js/media-gallery.js b/wp-admin/js/media-gallery.js index 52da393dcc..8489d5c447 100644 --- a/wp-admin/js/media-gallery.js +++ b/wp-admin/js/media-gallery.js @@ -1,7 +1,7 @@ /* global ajaxurl */ jQuery(function($){ $( 'body' ).bind( 'click.wp-gallery', function(e){ - var target = $( e.target ), id, img_size; + var target = $( e.target ), id, img_size, nonceValue; if ( target.hasClass( 'wp-set-header' ) ) { ( window.dialogArguments || opener || parent || top ).location.href = target.data( 'location' ); @@ -9,10 +9,12 @@ jQuery(function($){ } else if ( target.hasClass( 'wp-set-background' ) ) { id = target.data( 'attachment-id' ); img_size = $( 'input[name="attachments[' + id + '][image-size]"]:checked').val(); + nonceValue = $( '#_wpnonce' ).val() && ''; jQuery.post(ajaxurl, { action: 'set-background-image', attachment_id: id, + _ajax_nonce: nonceValue, size: img_size }, function(){ var win = window.dialogArguments || opener || parent || top; diff --git a/wp-admin/js/media-gallery.min.js b/wp-admin/js/media-gallery.min.js index dc66a26cd0..ae7dcb752d 100644 --- a/wp-admin/js/media-gallery.min.js +++ b/wp-admin/js/media-gallery.min.js @@ -1 +1 @@ -jQuery(function(a){a("body").bind("click.wp-gallery",function(b){var c,d,e=a(b.target);e.hasClass("wp-set-header")?((window.dialogArguments||opener||parent||top).location.href=e.data("location"),b.preventDefault()):e.hasClass("wp-set-background")&&(c=e.data("attachment-id"),d=a('input[name="attachments['+c+'][image-size]"]:checked').val(),jQuery.post(ajaxurl,{action:"set-background-image",attachment_id:c,size:d},function(){var a=window.dialogArguments||opener||parent||top;a.tb_remove(),a.location.reload()}),b.preventDefault())})}); \ No newline at end of file +jQuery(function(a){a("body").bind("click.wp-gallery",function(b){var c,d,e,f=a(b.target);f.hasClass("wp-set-header")?((window.dialogArguments||opener||parent||top).location.href=f.data("location"),b.preventDefault()):f.hasClass("wp-set-background")&&(c=f.data("attachment-id"),d=a('input[name="attachments['+c+'][image-size]"]:checked').val(),e=a("#_wpnonce").val()&&"",jQuery.post(ajaxurl,{action:"set-background-image",attachment_id:c,_ajax_nonce:e,size:d},function(){var a=window.dialogArguments||opener||parent||top;a.tb_remove(),a.location.reload()}),b.preventDefault())})}); \ No newline at end of file diff --git a/wp-admin/media-new.php b/wp-admin/media-new.php index ac96e8a118..b07a88d70a 100644 --- a/wp-admin/media-new.php +++ b/wp-admin/media-new.php @@ -72,9 +72,9 @@ if ( get_user_setting('uploader') || isset( $_GET['browser-uploader'] ) ) - +
diff --git a/wp-admin/network/site-users.php b/wp-admin/network/site-users.php index 4e2c6c9d92..a6ee7c82b4 100644 --- a/wp-admin/network/site-users.php +++ b/wp-admin/network/site-users.php @@ -178,7 +178,7 @@ require( ABSPATH . 'wp-admin/admin-header.php' ); ?> diff --git a/wp-includes/class-wp-xmlrpc-server.php b/wp-includes/class-wp-xmlrpc-server.php index bb12304a10..cf52248cee 100644 --- a/wp-includes/class-wp-xmlrpc-server.php +++ b/wp-includes/class-wp-xmlrpc-server.php @@ -3283,6 +3283,22 @@ class wp_xmlrpc_server extends IXR_Server { if ( ! get_post($post_id) ) return new IXR_Error( 404, __( 'Invalid post ID.' ) ); + if ( + 'publish' === get_post_status( $post_id ) && + ! current_user_can( 'edit_post', $post_id ) && + post_password_required( $post_id ) + ) { + return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) ); + } + + if ( + 'private' === get_post_status( $post_id ) && + ! current_user_can( 'read_post', $post_id ) + ) { + return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) ); + } + + $comment = array(); $comment['comment_post_ID'] = $post_id; if ( $logged_in ) { @@ -3605,8 +3621,10 @@ class wp_xmlrpc_server extends IXR_Server { /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'wp.getMediaItem' ); - if ( ! $attachment = get_post($attachment_id) ) + $attachment = get_post( $attachment_id ); + if ( ! $attachment || 'attachment' !== $attachment->post_type ) { return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); + } return $this->_prepare_media_item( $attachment ); } diff --git a/wp-includes/meta.php b/wp-includes/meta.php index 0f3aaa979d..361ef5123a 100644 --- a/wp-includes/meta.php +++ b/wp-includes/meta.php @@ -1113,8 +1113,9 @@ function _get_meta_table($type) { * @param string $meta_key Meta key * @return bool True if the key is protected, false otherwise. */ -function is_protected_meta( $meta_key, $meta_type = null ) { - $protected = ( '_' == $meta_key[0] ); +function is_protected_meta( $meta_key, $meta_type = '' ) { + $sanitized_key = preg_replace( "/[^\x20-\x7E\p{L}]/", '', $meta_key ); + $protected = strlen( $sanitized_key ) > 0 && ( '_' === $sanitized_key[0] ); /** * Filter whether a meta key is protected.