Skip to content

Commit 96938e4

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

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.1.15",
3+
"version": "5.1.16",
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
@@ -36,6 +36,26 @@
3636

3737
<div class="changelog point-releases">
3838
<h3><?php _e( 'Maintenance and Security Releases' ); ?></h3>
39+
<p>
40+
<?php
41+
printf(
42+
/* translators: %s: WordPress version number */
43+
__( '<strong>Version %s</strong> addressed some security issues.' ),
44+
'5.1.16'
45+
);
46+
?>
47+
<?php
48+
printf(
49+
/* translators: %s: HelpHub URL */
50+
__( 'For more information, see <a href="%s">the release notes</a>.' ),
51+
sprintf(
52+
/* translators: %s: WordPress version */
53+
esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
54+
sanitize_title( '5.1.16' )
55+
)
56+
);
57+
?>
58+
</p>
3959
<p>
4060
<?php
4161
printf(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,6 +2507,10 @@ function wp_ajax_set_attachment_thumbnail() {
25072507
wp_send_json_error();
25082508
}
25092509

2510+
if ( false === check_ajax_referer( 'set-attachment-thumbnail', '_ajax_nonce', false ) ) {
2511+
wp_send_json_error();
2512+
}
2513+
25102514
$post_ids = array();
25112515
// For each URL, try to find its corresponding post ID.
25122516
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
@@ -2365,6 +2365,29 @@ function sanitize_html_class( $class, $fallback = '' ) {
23652365
return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback );
23662366
}
23672367

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

src/wp-includes/l10n.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function determine_locale() {
139139
}
140140

141141
if ( ! empty( $_GET['wp_lang'] ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
142-
$determined_locale = sanitize_text_field( $_GET['wp_lang'] );
142+
$determined_locale = sanitize_locale_name( wp_unslash( $_GET['wp_lang'] ) );
143143
}
144144

145145
/**

src/wp-includes/media.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3583,7 +3583,8 @@ function wp_enqueue_media( $args = array() ) {
35833583
/** This filter is documented in wp-admin/includes/media.php */
35843584
'captions' => ! apply_filters( 'disable_captions', '' ),
35853585
'nonce' => array(
3586-
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
3586+
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
3587+
'setAttachmentThumbnail' => wp_create_nonce( 'set-attachment-thumbnail' ),
35873588
),
35883589
'post' => array(
35893590
'id' => 0,

0 commit comments

Comments
 (0)