Skip to content

Commit 5cfa531

Browse files
committed
Grouped backports to the 5.5 branch.
- Media: Prevent CSRF setting attachment thumbnails. - Embeds: Add protocol validation for WordPress Embed code. - I18N: Introduce sanitization function for locale. - Editor: Ensure block comments are of a valid form. Merges [55760-55764] to the 5.5 branch. Props dd32, isabel_brison, martinkrcho, matveb, ocean90, paulkevan, peterwilsoncc, timothyblynjacobs, xknown, youknowriad. git-svn-id: https://develop.svn.wordpress.org/branches/5.5@55782 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ac58b56 commit 5cfa531

File tree

13 files changed

+217
-5
lines changed

13 files changed

+217
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "WordPress",
3-
"version": "5.5.11",
3+
"version": "5.5.12",
44
"description": "WordPress is open source software you can use to create a beautiful website, blog, or app.",
55
"repository": {
66
"type": "svn",

src/js/_enqueues/wp/embed.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
var iframes = document.querySelectorAll( 'iframe[data-secret="' + data.secret + '"]' ),
4646
blockquotes = document.querySelectorAll( 'blockquote[data-secret="' + data.secret + '"]' ),
47+
allowedProtocols = new RegExp( '^https?:$', 'i' ),
4748
i, source, height, sourceURL, targetURL;
4849

4950
for ( i = 0; i < blockquotes.length; i++ ) {
@@ -79,6 +80,11 @@
7980
sourceURL.href = source.getAttribute( 'src' );
8081
targetURL.href = data.value;
8182

83+
/* Only follow link if the protocol is in the allow list. */
84+
if ( ! allowedProtocols.test( targetURL.protocol ) ) {
85+
continue;
86+
}
87+
8288
/* Only continue if link hostname matches iframe's hostname. */
8389
if ( targetURL.host === sourceURL.host ) {
8490
if ( document.activeElement === source ) {

src/js/media/views/frame/video-details.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ VideoDetails = MediaDetails.extend(/** @lends wp.media.view.MediaFrame.VideoDeta
106106

107107
wp.ajax.send( 'set-attachment-thumbnail', {
108108
data : {
109+
_ajax_nonce: wp.media.view.settings.nonce.setAttachmentThumbnail,
109110
urls: urls,
110111
thumbnail_id: attachment.get( 'id' )
111112
}

src/wp-admin/about.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@
6464
<div class="about__section has-subtle-background-color">
6565
<div class="column">
6666
<h2><?php _e( 'Maintenance and Security Releases' ); ?></h2>
67+
<p>
68+
<?php
69+
printf(
70+
/* translators: %s: WordPress version number */
71+
__( '<strong>Version %s</strong> addressed some security issues.' ),
72+
'5.5.12'
73+
);
74+
?>
75+
<?php
76+
printf(
77+
/* translators: %s: HelpHub URL */
78+
__( 'For more information, see <a href="%s">the release notes</a>.' ),
79+
sprintf(
80+
/* translators: %s: WordPress version */
81+
esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
82+
sanitize_title( '5.5.12' )
83+
)
84+
);
85+
?>
86+
</p>
6787
<p>
6888
<?php
6989
printf(

src/wp-admin/includes/ajax-actions.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,6 +2723,10 @@ function wp_ajax_set_attachment_thumbnail() {
27232723
wp_send_json_error();
27242724
}
27252725

2726+
if ( false === check_ajax_referer( 'set-attachment-thumbnail', '_ajax_nonce', false ) ) {
2727+
wp_send_json_error();
2728+
}
2729+
27262730
$post_ids = array();
27272731
// For each URL, try to find its corresponding post ID.
27282732
foreach ( $_POST['urls'] as $url ) {

src/wp-includes/blocks.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ function serialize_blocks( $blocks ) {
485485
function filter_block_content( $text, $allowed_html = 'post', $allowed_protocols = array() ) {
486486
$result = '';
487487

488+
if ( false !== strpos( $text, '<!--' ) && false !== strpos( $text, '--->' ) ) {
489+
$text = preg_replace_callback( '%<!--(.*?)--->%', '_filter_block_content_callback', $text );
490+
}
491+
488492
$blocks = parse_blocks( $text );
489493
foreach ( $blocks as $block ) {
490494
$block = filter_block_kses( $block, $allowed_html, $allowed_protocols );
@@ -494,6 +498,19 @@ function filter_block_content( $text, $allowed_html = 'post', $allowed_protocols
494498
return $result;
495499
}
496500

501+
/**
502+
* Callback used for regular expression replacement in filter_block_content().
503+
*
504+
* @private
505+
* @since 6.2.1
506+
*
507+
* @param array $matches Array of preg_replace_callback matches.
508+
* @return string Replacement string.
509+
*/
510+
function _filter_block_content_callback( $matches ) {
511+
return '<!--' . rtrim( $matches[1], '-' ) . '-->';
512+
}
513+
497514
/**
498515
* Filters and sanitizes a parsed block to remove non-allowable HTML from block
499516
* attribute values.

src/wp-includes/formatting.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,6 +2368,29 @@ function sanitize_html_class( $class, $fallback = '' ) {
23682368
return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback );
23692369
}
23702370

2371+
/**
2372+
* Strips out all characters not allowed in a locale name.
2373+
*
2374+
* @since 6.2.1
2375+
*
2376+
* @param string $locale_name The locale name to be sanitized.
2377+
* @return string The sanitized value.
2378+
*/
2379+
function sanitize_locale_name( $locale_name ) {
2380+
// Limit to A-Z, a-z, 0-9, '_', '-'.
2381+
$sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $locale_name );
2382+
2383+
/**
2384+
* Filters a sanitized locale name string.
2385+
*
2386+
* @since 6.2.1
2387+
*
2388+
* @param string $sanitized The sanitized locale name.
2389+
* @param string $locale_name The locale name before sanitization.
2390+
*/
2391+
return apply_filters( 'sanitize_locale_name', $sanitized, $locale_name );
2392+
}
2393+
23712394
/**
23722395
* Converts lone & characters into `&#038;` (a.k.a. `&amp;`)
23732396
*

src/wp-includes/l10n.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function determine_locale() {
145145
}
146146

147147
if ( ! empty( $_GET['wp_lang'] ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
148-
$determined_locale = sanitize_text_field( $_GET['wp_lang'] );
148+
$determined_locale = sanitize_locale_name( wp_unslash( $_GET['wp_lang'] ) );
149149
}
150150

151151
/**

src/wp-includes/media.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4133,7 +4133,8 @@ function wp_enqueue_media( $args = array() ) {
41334133
/** This filter is documented in wp-admin/includes/media.php */
41344134
'captions' => ! apply_filters( 'disable_captions', '' ),
41354135
'nonce' => array(
4136-
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
4136+
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
4137+
'setAttachmentThumbnail' => wp_create_nonce( 'set-attachment-thumbnail' ),
41374138
),
41384139
'post' => array(
41394140
'id' => 0,

0 commit comments

Comments
 (0)