Skip to content

Commit

Permalink
Merge branch 'release/1.7.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ClassyBot committed Oct 14, 2023
2 parents 7a86479 + b221c84 commit e4723e4
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 28 deletions.
20 changes: 20 additions & 0 deletions wp-admin/about.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ classicpress_version()
);
?>
</p>
<p>
<?php
printf(
/* translators: %s: WordPress version number */
__( '<strong>Version %s</strong> addressed some security issues.' ),
'4.9.24'
);
?>
<?php
printf(
/* translators: %s: HelpHub URL */
__( 'For more information, see <a href="%s">the release notes</a>.' ),
sprintf(
/* translators: %s: WordPress version */
esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
sanitize_title( '4.9.24' )
)
);
?>
</p>
<p>
<?php
printf(
Expand Down
18 changes: 17 additions & 1 deletion wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3487,13 +3487,29 @@ function wp_ajax_parse_media_shortcode() {

$shortcode = wp_unslash( $_POST['shortcode'] );

// Only process previews for media related shortcodes:
$found_shortcodes = get_shortcode_tags_in_content( $shortcode );
$media_shortcodes = array(
'audio',
'embed',
'playlist',
'video',
'gallery',
);

$other_shortcodes = array_diff( $found_shortcodes, $media_shortcodes );

if ( ! empty( $other_shortcodes ) ) {
wp_send_json_error();
}

if ( ! empty( $_POST['post_ID'] ) ) {
$post = get_post( (int) $_POST['post_ID'] );
}

// the embed shortcode requires a post
if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
if ( 'embed' === $shortcode ) {
if ( in_array( 'embed', $found_shortcodes, true ) ) {
wp_send_json_error();
}
} else {
Expand Down
13 changes: 13 additions & 0 deletions wp-admin/includes/class-wp-comments-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,19 @@ public function single_row( $item ) {
}
$this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );

$edit_post_cap = $post ? 'edit_post' : 'edit_posts';
if (
current_user_can( $edit_post_cap, $comment->comment_post_ID ) ||
(
empty( $post->post_password ) &&
current_user_can( 'read_post', $comment->comment_post_ID )
)
) {
// The user has access to the post
} else {
return false;
}

echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
$this->single_row_columns( $comment );
echo "</tr>\n";
Expand Down
15 changes: 14 additions & 1 deletion wp-admin/includes/class-wp-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,20 @@ protected function comments_bubble( $post_id, $pending_comments ) {
$approved_phrase = sprintf( _n( '%s approved comment', '%s approved comments', $approved_comments ), $approved_comments_number );
$pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_comments ), $pending_comments_number );

// No comments at all.
$post_object = get_post( $post_id );
$edit_post_cap = $post_object ? 'edit_post' : 'edit_posts';
if (
current_user_can( $edit_post_cap, $post_id ) ||
(
empty( $post_object->post_password ) &&
current_user_can( 'read_post', $post_id )
)
) {
// The user has access to the post and thus can see comments
} else {
return false;
}

if ( ! $approved_comments && ! $pending_comments ) {
printf(
'<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',
Expand Down
11 changes: 10 additions & 1 deletion wp-admin/includes/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,16 @@ function wp_dashboard_recent_comments( $total_items = 5 ) {

echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
foreach ( $comments as $comment ) {
_wp_dashboard_recent_comments_row( $comment );
$comment_post = get_post( $comment->comment_post_ID );
if (
current_user_can( 'edit_post', $comment->comment_post_ID ) ||
(
empty( $comment_post->post_password ) &&
current_user_can( 'read_post', $comment->comment_post_ID )
)
) {
_wp_dashboard_recent_comments_row( $comment );
}
}
echo '</ul>';

Expand Down
6 changes: 5 additions & 1 deletion wp-includes/Requests/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ public function dispatch($hook, $parameters = array()) {

return true;
}
}

public function __wakeup() {
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
}
}
14 changes: 14 additions & 0 deletions wp-includes/Requests/IRI.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,20 @@ public function is_valid() {
return true;
}

public function __wakeup() {
$class_props = get_class_vars( __CLASS__ );
$string_props = array( 'scheme', 'iuserinfo', 'ihost', 'port', 'ipath', 'iquery', 'ifragment' );
$array_props = array( 'normalization' );
foreach ( $class_props as $prop => $default_value ) {
if ( in_array( $prop, $string_props, true ) && ! is_string( $this->$prop ) ) {
throw new UnexpectedValueException();
} elseif ( in_array( $prop, $array_props, true ) && ! is_array( $this->$prop ) ) {
throw new UnexpectedValueException();
}
$this->$prop = null;
}
}

/**
* Set the entire IRI. Returns true on success, false on failure (if there
* are any invalid characters).
Expand Down
4 changes: 4 additions & 0 deletions wp-includes/Requests/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ public function request_multiple($requests, $options = array()) {
return Requests::request_multiple($requests, $options);
}

public function __wakeup() {
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
}

/**
* Merge a request's data with the default data
*
Expand Down
34 changes: 34 additions & 0 deletions wp-includes/class-wp-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,28 @@ public function parent() {
return isset( $this->parent ) ? $this->parent : false;
}

/**
* Perform reinitialization tasks.
*
* Prevents a callback from being injected during unserialization of an object.
*
* @return void
*/
public function __wakeup() {
if ( $this->parent && ! $this->parent instanceof self ) {
throw new UnexpectedValueException();
}
if ( $this->headers && ! is_array( $this->headers ) ) {
throw new UnexpectedValueException();
}
foreach ( $this->headers as $value ) {
if ( ! is_string( $value ) ) {
throw new UnexpectedValueException();
}
}
$this->headers_sanitized = array();
}

/**
* Adds theme data to cache.
*
Expand Down Expand Up @@ -1638,4 +1660,16 @@ private static function _name_sort_i18n( $a, $b ) {
// Don't mark up; Do translate.
return strnatcasecmp( $a->display( 'Name', false, true ), $b->display( 'Name', false, true ) );
}

private static function _check_headers_property_has_correct_type( $headers ) {
if ( ! is_array( $headers ) ) {
return false;
}
foreach ( $headers as $key => $value ) {
if ( ! is_string( $key ) || ! is_string( $value ) ) {
return false;
}
}
return true;
}
}
26 changes: 24 additions & 2 deletions wp-includes/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,8 @@ function gallery_shortcode( $attr ) {
$attachments[ $val->ID ] = $_attachments[ $key ];
}
} elseif ( ! empty( $atts['exclude'] ) ) {
$attachments = get_children(
$post_parent_id = $id;
$attachments = get_children(
array(
'post_parent' => $id,
'exclude' => $atts['exclude'],
Expand All @@ -2109,7 +2110,8 @@ function gallery_shortcode( $attr ) {
)
);
} else {
$attachments = get_children(
$post_parent_id = $id;
$attachments = get_children(
array(
'post_parent' => $id,
'post_status' => 'inherit',
Expand All @@ -2121,6 +2123,17 @@ function gallery_shortcode( $attr ) {
);
}

if ( ! empty( $post_parent_id ) ) {
$post_parent = get_post( $post_parent_id );

// terminate the shortcode execution if user cannot read the post or password-protected
if (
( ! is_post_publicly_viewable( $post_parent->ID ) && ! current_user_can( 'read_post', $post_parent->ID ) )
|| post_password_required( $post_parent ) ) {
return '';
}
}

if ( empty( $attachments ) ) {
return '';
}
Expand Down Expand Up @@ -2431,6 +2444,15 @@ function wp_playlist_shortcode( $attr ) {
$attachments = get_children( $args );
}

if ( ! empty( $args['post_parent'] ) ) {
$post_parent = get_post( $id );

// terminate the shortcode execution if user cannot read the post or password-protected
if ( ! current_user_can( 'read_post', $post_parent->ID ) || post_password_required( $post_parent ) ) {
return '';
}
}

if ( empty( $attachments ) ) {
return '';
}
Expand Down
1 change: 1 addition & 0 deletions wp-includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ function rest_cookie_check_errors( $result ) {
$result = wp_verify_nonce( $nonce, 'wp_rest' );

if ( ! $result ) {
add_filter( 'rest_send_nocache_headers', '__return_true', 20 );
return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie nonce is invalid' ), array( 'status' => 403 ) );
}

Expand Down
42 changes: 24 additions & 18 deletions wp-includes/rest-api/class-wp-rest-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,24 +238,6 @@ public function serve_request( $path = null ) {
$this->send_header( 'Access-Control-Expose-Headers', 'X-WP-Total, X-WP-TotalPages' );
$this->send_header( 'Access-Control-Allow-Headers', 'Authorization, Content-Type' );

/**
* Send nocache headers on authenticated requests.
*
* @since WP-4.4.0
*
* @param bool $rest_send_nocache_headers Whether to send no-cache headers.
*/
$send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
if ( $send_no_cache_headers ) {
foreach ( wp_get_nocache_headers() as $header => $header_value ) {
if ( empty( $header_value ) ) {
$this->remove_header( $header );
} else {
$this->send_header( $header, $header_value );
}
}
}

/**
* Filters whether the REST API is enabled.
*
Expand Down Expand Up @@ -317,10 +299,12 @@ public function serve_request( $path = null ) {
* $_GET['_method']. If that is not set, we check for the HTTP_X_HTTP_METHOD_OVERRIDE
* header.
*/
$method_overridden = false;
if ( isset( $_GET['_method'] ) ) {
$request->set_method( $_GET['_method'] );
} elseif ( isset( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ) {
$request->set_method( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] );
$method_overridden = true;
}

$result = $this->check_authentication();
Expand Down Expand Up @@ -379,6 +363,28 @@ public function serve_request( $path = null ) {
*/
$served = apply_filters( 'rest_pre_serve_request', false, $result, $request, $this );

/**
* Filters whether to send nocache headers on a REST API request.
*
* @since 4.4.0
* @since 6.x.x Moved the block to catch the filter added on rest_cookie_check_errors() from rest-api.php
*
* @param bool $rest_send_nocache_headers Whether to send no-cache headers.
*/
$send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );

// send no cache headers if the $send_no_cache_headers is true
// OR if the HTTP_X_HTTP_METHOD_OVERRIDE is used but resulted a 4xx response code.
if ( $send_no_cache_headers || ( true === $method_overridden && strpos( $code, '4' ) === 0 ) ) {
foreach ( wp_get_nocache_headers() as $header => $header_value ) {
if ( empty( $header_value ) ) {
$this->remove_header( $header );
} else {
$this->send_header( $header, $header_value );
}
}
}

if ( ! $served ) {
if ( 'HEAD' === $request->get_method() ) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ public function get_items( $request ) {
}

if ( ! empty( $prepared_args['search'] ) ) {
if ( ! current_user_can( 'list_users' ) ) {
$prepared_args['search_columns'] = array( 'ID', 'user_login', 'user_nicename', 'display_name' );
}
$prepared_args['search'] = '*' . $prepared_args['search'] . '*';
}
/**
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function classicpress_asset_version( $type = 'script', $handle = null ) {
static $default_version;

if ( empty( $default_version ) ) {
$default_version = 'cp_523c1399';
$default_version = 'cp_3f437b6b';
}

/**
Expand Down
Loading

0 comments on commit e4723e4

Please sign in to comment.