Skip to content

Commit bd4ccab

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

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.0.18",
3+
"version": "5.0.19",
44
"description": "WordPress is web software you can use to create a beautiful website or blog.",
55
"repository": {
66
"type": "svn",

src/wp-admin/about.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@
6262

6363
<div class="changelog point-releases">
6464
<h3><?php _e( 'Maintenance and Security Releases' ); ?></h3>
65+
<p>
66+
<?php
67+
printf(
68+
/* translators: %s: WordPress version number */
69+
__( '<strong>Version %s</strong> addressed some security issues.' ),
70+
'5.0.19'
71+
);
72+
?>
73+
<?php
74+
printf(
75+
/* translators: %s: HelpHub URL */
76+
__( 'For more information, see <a href="%s">the release notes</a>.' ),
77+
sprintf(
78+
/* translators: %s: WordPress version */
79+
esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
80+
sanitize_title( '5.0.19' )
81+
)
82+
);
83+
?>
84+
</p>
6585
<p>
6686
<?php
6787
printf(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,10 @@ function wp_ajax_set_attachment_thumbnail() {
22572257
wp_send_json_error();
22582258
}
22592259

2260+
if ( false === check_ajax_referer( 'set-attachment-thumbnail', '_ajax_nonce', false ) ) {
2261+
wp_send_json_error();
2262+
}
2263+
22602264
$post_ids = array();
22612265
// For each URL, try to find its corresponding post ID.
22622266
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
@@ -2115,6 +2115,29 @@ function sanitize_html_class( $class, $fallback = '' ) {
21152115
return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback );
21162116
}
21172117

2118+
/**
2119+
* Strips out all characters not allowed in a locale name.
2120+
*
2121+
* @since 6.2.1
2122+
*
2123+
* @param string $locale_name The locale name to be sanitized.
2124+
* @return string The sanitized value.
2125+
*/
2126+
function sanitize_locale_name( $locale_name ) {
2127+
// Limit to A-Z, a-z, 0-9, '_', '-'.
2128+
$sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $locale_name );
2129+
2130+
/**
2131+
* Filters a sanitized locale name string.
2132+
*
2133+
* @since 6.2.1
2134+
*
2135+
* @param string $sanitized The sanitized locale name.
2136+
* @param string $locale_name The locale name before sanitization.
2137+
*/
2138+
return apply_filters( 'sanitize_locale_name', $sanitized, $locale_name );
2139+
}
2140+
21182141
/**
21192142
* Converts lone & characters into `&#038;` (a.k.a. `&amp;`)
21202143
*

src/wp-includes/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-includes/js/wp-embed.js

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

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

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

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

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
@@ -3442,7 +3442,8 @@ function wp_enqueue_media( $args = array() ) {
34423442
/** This filter is documented in wp-admin/includes/media.php */
34433443
'captions' => ! apply_filters( 'disable_captions', '' ),
34443444
'nonce' => array(
3445-
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
3445+
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
3446+
'setAttachmentThumbnail' => wp_create_nonce( 'set-attachment-thumbnail' ),
34463447
),
34473448
'post' => array(
34483449
'id' => 0,

0 commit comments

Comments
 (0)