Changeset 56867 for branches/6.1
- Timestamp:
- 10/12/2023 02:54:10 PM (13 months ago)
- Location:
- branches/6.1
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.1
- Property svn:mergeinfo changed
/trunk merged: 56833-56838
- Property svn:mergeinfo changed
-
branches/6.1/src/wp-admin/includes/ajax-actions.php
r55771 r56867 3853 3853 $shortcode = wp_unslash( $_POST['shortcode'] ); 3854 3854 3855 // Only process previews for media related shortcodes: 3856 $found_shortcodes = get_shortcode_tags_in_content( $shortcode ); 3857 $media_shortcodes = array( 3858 'audio', 3859 'embed', 3860 'playlist', 3861 'video', 3862 'gallery', 3863 ); 3864 3865 $other_shortcodes = array_diff( $found_shortcodes, $media_shortcodes ); 3866 3867 if ( ! empty( $other_shortcodes ) ) { 3868 wp_send_json_error(); 3869 } 3870 3855 3871 if ( ! empty( $_POST['post_ID'] ) ) { 3856 3872 $post = get_post( (int) $_POST['post_ID'] ); … … 3859 3875 // The embed shortcode requires a post. 3860 3876 if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { 3861 if ( 'embed' === $shortcode) {3877 if ( in_array( 'embed', $found_shortcodes, true ) ) { 3862 3878 wp_send_json_error(); 3863 3879 } -
branches/6.1/src/wp-admin/includes/class-wp-comments-list-table.php
r54378 r56867 637 637 638 638 $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID ); 639 640 $edit_post_cap = $post ? 'edit_post' : 'edit_posts'; 641 if ( 642 current_user_can( $edit_post_cap, $comment->comment_post_ID ) || 643 ( 644 empty( $post->post_password ) && 645 current_user_can( 'read_post', $comment->comment_post_ID ) 646 ) 647 ) { 648 // The user has access to the post 649 } else { 650 return false; 651 } 639 652 640 653 echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>"; -
branches/6.1/src/wp-admin/includes/class-wp-list-table.php
r54378 r56867 812 812 $pending_comments_number 813 813 ); 814 815 $post_object = get_post( $post_id ); 816 $edit_post_cap = $post_object ? 'edit_post' : 'edit_posts'; 817 if ( 818 current_user_can( $edit_post_cap, $post_id ) || 819 ( 820 empty( $post_object->post_password ) && 821 current_user_can( 'read_post', $post_id ) 822 ) 823 ) { 824 // The user has access to the post and thus can see comments 825 } else { 826 return false; 827 } 814 828 815 829 if ( ! $approved_comments && ! $pending_comments ) { -
branches/6.1/src/wp-admin/includes/dashboard.php
r54638 r56867 1092 1092 echo '<ul id="the-comment-list" data-wp-lists="list:comment">'; 1093 1093 foreach ( $comments as $comment ) { 1094 _wp_dashboard_recent_comments_row( $comment ); 1094 1095 $comment_post = get_post( $comment->comment_post_ID ); 1096 if ( 1097 current_user_can( 'edit_post', $comment->comment_post_ID ) || 1098 ( 1099 empty( $comment_post->post_password ) && 1100 current_user_can( 'read_post', $comment->comment_post_ID ) 1101 ) 1102 ) { 1103 _wp_dashboard_recent_comments_row( $comment ); 1104 } 1095 1105 } 1096 1106 echo '</ul>'; -
branches/6.1/src/wp-admin/includes/user.php
r53458 r56867 607 607 * 608 608 * @since 5.6.0 609 * @since 6.2.0 Allow insecure HTTP connections for the local environment. 610 * @since 6.3.2 Validates the success and reject URLs to prevent javascript pseudo protocol being executed. 609 611 * 610 612 * @param array $request { … … 622 624 $error = new WP_Error(); 623 625 624 if ( ! empty( $request['success_url'] ) ) { 625 $scheme = wp_parse_url( $request['success_url'], PHP_URL_SCHEME ); 626 627 if ( 'http' === $scheme ) { 626 if ( isset( $request['success_url'] ) ) { 627 $validated_success_url = wp_is_authorize_application_redirect_url_valid( $request['success_url'] ); 628 if ( is_wp_error( $validated_success_url ) ) { 628 629 $error->add( 629 'invalid_redirect_scheme',630 __( 'The success URL must be served over a secure connection.')630 $validated_success_url->get_error_code(), 631 $validated_success_url->get_error_message() 631 632 ); 632 633 } 633 634 } 634 635 635 if ( ! empty( $request['reject_url'] ) ) { 636 $scheme = wp_parse_url( $request['reject_url'], PHP_URL_SCHEME ); 637 638 if ( 'http' === $scheme ) { 636 if ( isset( $request['reject_url'] ) ) { 637 $validated_reject_url = wp_is_authorize_application_redirect_url_valid( $request['reject_url'] ); 638 if ( is_wp_error( $validated_reject_url ) ) { 639 639 $error->add( 640 'invalid_redirect_scheme',641 __( 'The rejection URL must be served over a secure connection.')640 $validated_reject_url->get_error_code(), 641 $validated_reject_url->get_error_message() 642 642 ); 643 643 } … … 668 668 return true; 669 669 } 670 671 /** 672 * Validates the redirect URL protocol scheme. The protocol can be anything except http and javascript. 673 * 674 * @since 6.3.2 675 * 676 * @param string $url - The redirect URL to be validated. 677 * 678 * @return true|WP_Error True if the redirect URL is valid, a WP_Error object otherwise. 679 */ 680 function wp_is_authorize_application_redirect_url_valid( $url ) { 681 $bad_protocols = array( 'javascript', 'data' ); 682 if ( empty( $url ) ) { 683 return true; 684 } 685 686 // Based on https://www.rfc-editor.org/rfc/rfc2396#section-3.1 687 $valid_scheme_regex = '/^[a-zA-Z][a-zA-Z0-9+.-]*:/'; 688 if ( ! preg_match( $valid_scheme_regex, $url ) ) { 689 return new WP_Error( 690 'invalid_redirect_url_format', 691 __( 'Invalid URL format.' ) 692 ); 693 } 694 695 /** 696 * Filters the list of invalid protocols used in applications redirect URLs. 697 * 698 * @since 6.3.2 699 * 700 * @param string[] $bad_protocols Array of invalid protocols. 701 * @param string $url The redirect URL to be validated. 702 */ 703 $invalid_protocols = array_map( 'strtolower', apply_filters( 'wp_authorize_application_redirect_url_invalid_protocols', $bad_protocols, $url ) ); 704 705 $scheme = wp_parse_url( $url, PHP_URL_SCHEME ); 706 $host = wp_parse_url( $url, PHP_URL_HOST ); 707 $is_local = 'local' === wp_get_environment_type(); 708 709 // validates if the proper URI format is applied to the $url 710 if ( empty( $host ) || empty( $scheme ) || in_array( strtolower( $scheme ), $invalid_protocols, true ) ) { 711 return new WP_Error( 712 'invalid_redirect_url_format', 713 __( 'Invalid URL format.' ) 714 ); 715 } 716 717 if ( 'http' === $scheme && ! $is_local ) { 718 return new WP_Error( 719 'invalid_redirect_scheme', 720 __( 'The URL must be served over a secure connection.' ) 721 ); 722 } 723 724 return true; 725 } -
branches/6.1/src/wp-includes/Requests/Hooks.php
r52328 r56867 66 66 return true; 67 67 } 68 69 public function __wakeup() { 70 throw new \LogicException( __CLASS__ . ' should never be unserialized' ); 71 } 68 72 } -
branches/6.1/src/wp-includes/Requests/IRI.php
r52328 r56867 706 706 } 707 707 708 public function __wakeup() { 709 $class_props = get_class_vars( __CLASS__ ); 710 $string_props = array( 'scheme', 'iuserinfo', 'ihost', 'port', 'ipath', 'iquery', 'ifragment' ); 711 $array_props = array( 'normalization' ); 712 foreach ( $class_props as $prop => $default_value ) { 713 if ( in_array( $prop, $string_props, true ) && ! is_string( $this->$prop ) ) { 714 throw new UnexpectedValueException(); 715 } elseif ( in_array( $prop, $array_props, true ) && ! is_array( $this->$prop ) ) { 716 throw new UnexpectedValueException(); 717 } 718 $this->$prop = null; 719 } 720 } 721 708 722 /** 709 723 * Set the entire IRI. Returns true on success, false on failure (if there -
branches/6.1/src/wp-includes/Requests/Session.php
r52328 r56867 230 230 } 231 231 232 public function __wakeup() { 233 throw new \LogicException( __CLASS__ . ' should never be unserialized' ); 234 } 235 232 236 /** 233 237 * Merge a request's data with the default data -
branches/6.1/src/wp-includes/class-wp-block-patterns-registry.php
r54133 r56867 189 189 } 190 190 191 public function __wakeup() { 192 if ( ! $this->registered_patterns ) { 193 return; 194 } 195 if ( ! is_array( $this->registered_patterns ) ) { 196 throw new UnexpectedValueException(); 197 } 198 foreach ( $this->registered_patterns as $value ) { 199 if ( ! is_array( $value ) ) { 200 throw new UnexpectedValueException(); 201 } 202 } 203 $this->registered_patterns_outside_init = array(); 204 } 205 191 206 /** 192 207 * Utility method to retrieve the main instance of the class. -
branches/6.1/src/wp-includes/class-wp-block-type-registry.php
r54133 r56867 169 169 } 170 170 171 public function __wakeup() { 172 if ( ! $this->registered_block_types ) { 173 return; 174 } 175 if ( ! is_array( $this->registered_block_types ) ) { 176 throw new UnexpectedValueException(); 177 } 178 foreach ( $this->registered_block_types as $value ) { 179 if ( ! $value instanceof WP_Block_Type ) { 180 throw new UnexpectedValueException(); 181 } 182 } 183 } 184 171 185 /** 172 186 * Utility method to retrieve the main instance of the class. -
branches/6.1/src/wp-includes/class-wp-theme.php
r54236 r56867 719 719 720 720 /** 721 * Perform reinitialization tasks. 722 * 723 * Prevents a callback from being injected during unserialization of an object. 724 * 725 * @return void 726 */ 727 public function __wakeup() { 728 if ( $this->parent && ! $this->parent instanceof self ) { 729 throw new UnexpectedValueException(); 730 } 731 if ( $this->headers && ! is_array( $this->headers ) ) { 732 throw new UnexpectedValueException(); 733 } 734 foreach ( $this->headers as $value ) { 735 if ( ! is_string( $value ) ) { 736 throw new UnexpectedValueException(); 737 } 738 } 739 $this->headers_sanitized = array(); 740 } 741 742 /** 721 743 * Adds theme data to cache. 722 744 * … … 1779 1801 return strnatcasecmp( $a->name_translated, $b->name_translated ); 1780 1802 } 1803 1804 private static function _check_headers_property_has_correct_type( $headers ) { 1805 if ( ! is_array( $headers ) ) { 1806 return false; 1807 } 1808 foreach ( $headers as $key => $value ) { 1809 if ( ! is_string( $key ) || ! is_string( $value ) ) { 1810 return false; 1811 } 1812 } 1813 return true; 1814 } 1781 1815 } -
branches/6.1/src/wp-includes/media.php
r55771 r56867 2454 2454 } 2455 2455 } elseif ( ! empty( $atts['exclude'] ) ) { 2456 $post_parent_id = $id; 2456 2457 $attachments = get_children( 2457 2458 array( … … 2466 2467 ); 2467 2468 } else { 2469 $post_parent_id = $id; 2468 2470 $attachments = get_children( 2469 2471 array( … … 2476 2478 ) 2477 2479 ); 2480 } 2481 2482 if ( ! empty( $post_parent_id ) ) { 2483 $post_parent = get_post( $post_parent_id ); 2484 2485 // terminate the shortcode execution if user cannot read the post or password-protected 2486 if ( 2487 ( ! is_post_publicly_viewable( $post_parent->ID ) && ! current_user_can( 'read_post', $post_parent->ID ) ) 2488 || post_password_required( $post_parent ) ) { 2489 return ''; 2490 } 2478 2491 } 2479 2492 … … 2804 2817 } 2805 2818 2819 if ( ! empty( $args['post_parent'] ) ) { 2820 $post_parent = get_post( $id ); 2821 2822 // terminate the shortcode execution if user cannot read the post or password-protected 2823 if ( ! current_user_can( 'read_post', $post_parent->ID ) || post_password_required( $post_parent ) ) { 2824 return ''; 2825 } 2826 } 2827 2806 2828 if ( empty( $attachments ) ) { 2807 2829 return ''; -
branches/6.1/src/wp-includes/rest-api.php
r54518 r56867 1069 1069 1070 1070 if ( ! $result ) { 1071 add_filter( 'rest_send_nocache_headers', '__return_true', 20 ); 1071 1072 return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie check failed' ), array( 'status' => 403 ) ); 1072 1073 } -
branches/6.1/src/wp-includes/rest-api/class-wp-rest-server.php
r54339 r56867 360 360 361 361 /** 362 * Filters whether to send nocache headers on a REST API request.363 *364 * @since 4.4.0365 *366 * @param bool $rest_send_nocache_headers Whether to send no-cache headers.367 */368 $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );369 if ( $send_no_cache_headers ) {370 foreach ( wp_get_nocache_headers() as $header => $header_value ) {371 if ( empty( $header_value ) ) {372 $this->remove_header( $header );373 } else {374 $this->send_header( $header, $header_value );375 }376 }377 }378 379 /**380 362 * Filters whether the REST API is enabled. 381 363 * … … 431 413 * header. 432 414 */ 415 $method_overridden = false; 433 416 if ( isset( $_GET['_method'] ) ) { 434 417 $request->set_method( $_GET['_method'] ); 435 418 } elseif ( isset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) { 436 419 $request->set_method( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ); 420 $method_overridden = true; 437 421 } 438 422 … … 493 477 */ 494 478 $served = apply_filters( 'rest_pre_serve_request', false, $result, $request, $this ); 479 480 /** 481 * Filters whether to send nocache headers on a REST API request. 482 * 483 * @since 4.4.0 484 * @since 6.x.x Moved the block to catch the filter added on rest_cookie_check_errors() from rest-api.php 485 * 486 * @param bool $rest_send_nocache_headers Whether to send no-cache headers. 487 */ 488 $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() ); 489 490 // send no cache headers if the $send_no_cache_headers is true 491 // OR if the HTTP_X_HTTP_METHOD_OVERRIDE is used but resulted a 4xx response code. 492 if ( $send_no_cache_headers || ( true === $method_overridden && strpos( $code, '4' ) === 0 ) ) { 493 foreach ( wp_get_nocache_headers() as $header => $header_value ) { 494 if ( empty( $header_value ) ) { 495 $this->remove_header( $header ); 496 } else { 497 $this->send_header( $header, $header_value ); 498 } 499 } 500 } 495 501 496 502 if ( ! $served ) { -
branches/6.1/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r54317 r56867 319 319 320 320 if ( ! empty( $prepared_args['search'] ) ) { 321 if ( ! current_user_can( 'list_users' ) ) { 322 $prepared_args['search_columns'] = array( 'ID', 'user_login', 'user_nicename', 'display_name' ); 323 } 321 324 $prepared_args['search'] = '*' . $prepared_args['search'] . '*'; 322 325 } -
branches/6.1/src/wp-includes/shortcodes.php
r54319 r56867 167 167 } 168 168 return false; 169 } 170 171 /** 172 * Returns a list of registered shortcode names found in the given content. 173 * 174 * Example usage: 175 * 176 * get_shortcode_tags_in_content( '[audio src="file.mp3"][/audio] [foo] [gallery ids="1,2,3"]' ); 177 * // array( 'audio', 'gallery' ) 178 * 179 * @since 6.3.2 180 * 181 * @param string $content The content to check. 182 * @return string[] An array of registered shortcode names found in the content. 183 */ 184 function get_shortcode_tags_in_content( $content ) { 185 if ( false === strpos( $content, '[' ) ) { 186 return array(); 187 } 188 189 preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER ); 190 if ( empty( $matches ) ) { 191 return array(); 192 } 193 194 $tags = array(); 195 foreach ( $matches as $shortcode ) { 196 $tags[] = $shortcode[2]; 197 198 if ( ! empty( $shortcode[5] ) ) { 199 $deep_tags = get_shortcode_tags_in_content( $shortcode[5] ); 200 if ( ! empty( $deep_tags ) ) { 201 $tags = array_merge( $tags, $deep_tags ); 202 } 203 } 204 } 205 206 return $tags; 169 207 } 170 208
Note: See TracChangeset
for help on using the changeset viewer.