Skip to content

Commit 6ce0453

Browse files
committed
Grouped backports to the 5.3 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.3 branch. Props dd32, isabel_brison, martinkrcho, matveb, ocean90, paulkevan, peterwilsoncc, timothyblynjacobs, xknown, youknowriad. git-svn-id: https://develop.svn.wordpress.org/branches/5.3@55788 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f8cfad9 commit 6ce0453

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.3.14",
3+
"version": "5.3.15",
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
@@ -51,6 +51,26 @@
5151
<div class="about__section changelog">
5252
<div class="column">
5353
<h2><?php _e( 'Maintenance and Security Releases' ); ?></h2>
54+
<p>
55+
<?php
56+
printf(
57+
/* translators: %s: WordPress version number */
58+
__( '<strong>Version %s</strong> addressed some security issues.' ),
59+
'5.3.15'
60+
);
61+
?>
62+
<?php
63+
printf(
64+
/* translators: %s: HelpHub URL */
65+
__( 'For more information, see <a href="%s">the release notes</a>.' ),
66+
sprintf(
67+
/* translators: %s: WordPress version */
68+
esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
69+
sanitize_title( '5.3.15' )
70+
)
71+
);
72+
?>
73+
</p>
5474
<p>
5575
<?php
5676
printf(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,10 @@ function wp_ajax_set_attachment_thumbnail() {
26942694
wp_send_json_error();
26952695
}
26962696

2697+
if ( false === check_ajax_referer( 'set-attachment-thumbnail', '_ajax_nonce', false ) ) {
2698+
wp_send_json_error();
2699+
}
2700+
26972701
$post_ids = array();
26982702
// For each URL, try to find its corresponding post ID.
26992703
foreach ( $_POST['urls'] as $url ) {

src/wp-includes/blocks.php

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

274+
if ( false !== strpos( $text, '<!--' ) && false !== strpos( $text, '--->' ) ) {
275+
$text = preg_replace_callback( '%<!--(.*?)--->%', '_filter_block_content_callback', $text );
276+
}
277+
274278
$blocks = parse_blocks( $text );
275279
foreach ( $blocks as $block ) {
276280
$block = filter_block_kses( $block, $allowed_html, $allowed_protocols );
@@ -280,6 +284,19 @@ function filter_block_content( $text, $allowed_html = 'post', $allowed_protocols
280284
return $result;
281285
}
282286

287+
/**
288+
* Callback used for regular expression replacement in filter_block_content().
289+
*
290+
* @private
291+
* @since 6.2.1
292+
*
293+
* @param array $matches Array of preg_replace_callback matches.
294+
* @return string Replacement string.
295+
*/
296+
function _filter_block_content_callback( $matches ) {
297+
return '<!--' . rtrim( $matches[1], '-' ) . '-->';
298+
}
299+
283300
/**
284301
* Filters and sanitizes a parsed block to remove non-allowable HTML from block
285302
* attribute values.

src/wp-includes/formatting.php

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

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

src/wp-includes/l10n.php

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

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

150150
/**

src/wp-includes/media.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3752,7 +3752,8 @@ function wp_enqueue_media( $args = array() ) {
37523752
/** This filter is documented in wp-admin/includes/media.php */
37533753
'captions' => ! apply_filters( 'disable_captions', '' ),
37543754
'nonce' => array(
3755-
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
3755+
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
3756+
'setAttachmentThumbnail' => wp_create_nonce( 'set-attachment-thumbnail' ),
37563757
),
37573758
'post' => array(
37583759
'id' => 0,

0 commit comments

Comments
 (0)