Skip to content

Commit 65eaadf

Browse files
committed
Grouped backports to the 5.9 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. - Editor: Remove shortcode support from block templates. Merges [55760-55764] to the 5.9 branch. Props dd32, isabel_brison, martinkrcho, matveb, ocean90, paulkevan, peterwilsoncc, timothyblynjacobs, xknown, youknowriad. git-svn-id: https://develop.svn.wordpress.org/branches/5.9@55774 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1374e4b commit 65eaadf

File tree

14 files changed

+218
-8
lines changed

14 files changed

+218
-8
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.9.5",
3+
"version": "5.9.6",
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
@@ -49,6 +49,7 @@
4949

5050
var iframes = document.querySelectorAll( 'iframe[data-secret="' + data.secret + '"]' ),
5151
blockquotes = document.querySelectorAll( 'blockquote[data-secret="' + data.secret + '"]' ),
52+
allowedProtocols = new RegExp( '^https?:$', 'i' ),
5253
i, source, height, sourceURL, targetURL;
5354

5455
for ( i = 0; i < blockquotes.length; i++ ) {
@@ -84,6 +85,11 @@
8485
sourceURL.href = source.getAttribute( 'src' );
8586
targetURL.href = data.value;
8687

88+
/* Only follow link if the protocol is in the allow list. */
89+
if ( ! allowedProtocols.test( targetURL.protocol ) ) {
90+
continue;
91+
}
92+
8793
/* Only continue if link hostname matches iframe's hostname. */
8894
if ( targetURL.host === sourceURL.host ) {
8995
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
@@ -42,6 +42,26 @@
4242
<div class="about__section changelog">
4343
<div class="column">
4444
<h2><?php _e( 'Maintenance and Security Releases' ); ?></h2>
45+
<p>
46+
<?php
47+
printf(
48+
/* translators: %s: WordPress version number. */
49+
__( '<strong>Version %s</strong> addressed some security issues.' ),
50+
'5.9.6'
51+
);
52+
?>
53+
<?php
54+
printf(
55+
/* translators: %s: HelpHub URL. */
56+
__( 'For more information, see <a href="%s">the release notes</a>.' ),
57+
sprintf(
58+
/* translators: %s: WordPress version. */
59+
esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
60+
sanitize_title( '5.9.6' )
61+
)
62+
);
63+
?>
64+
</p>
4565
<p>
4666
<?php
4767
printf(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,6 +2732,10 @@ function wp_ajax_set_attachment_thumbnail() {
27322732
wp_send_json_error();
27332733
}
27342734

2735+
if ( false === check_ajax_referer( 'set-attachment-thumbnail', '_ajax_nonce', false ) ) {
2736+
wp_send_json_error();
2737+
}
2738+
27352739
$post_ids = array();
27362740
// For each URL, try to find its corresponding post ID.
27372741
foreach ( $_POST['urls'] as $url ) {

src/wp-includes/block-template.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,7 @@ function get_the_block_template_html() {
240240
$content = do_blocks( $content );
241241
$content = wptexturize( $content );
242242
$content = convert_smilies( $content );
243-
$content = shortcode_unautop( $content );
244243
$content = wp_filter_content_tags( $content );
245-
$content = do_shortcode( $content );
246244
$content = str_replace( ']]>', ']]&gt;', $content );
247245

248246
// Wrap block template in .wp-site-blocks to allow for specific descendant styles

src/wp-includes/blocks.php

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

631+
if ( false !== strpos( $text, '<!--' ) && false !== strpos( $text, '--->' ) ) {
632+
$text = preg_replace_callback( '%<!--(.*?)--->%', '_filter_block_content_callback', $text );
633+
}
634+
631635
$blocks = parse_blocks( $text );
632636
foreach ( $blocks as $block ) {
633637
$block = filter_block_kses( $block, $allowed_html, $allowed_protocols );
@@ -637,6 +641,19 @@ function filter_block_content( $text, $allowed_html = 'post', $allowed_protocols
637641
return $result;
638642
}
639643

644+
/**
645+
* Callback used for regular expression replacement in filter_block_content().
646+
*
647+
* @private
648+
* @since 6.2.1
649+
*
650+
* @param array $matches Array of preg_replace_callback matches.
651+
* @return string Replacement string.
652+
*/
653+
function _filter_block_content_callback( $matches ) {
654+
return '<!--' . rtrim( $matches[1], '-' ) . '-->';
655+
}
656+
640657
/**
641658
* Filters and sanitizes a parsed block to remove non-allowable HTML from block
642659
* attribute values.

src/wp-includes/formatting.php

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

2411+
/**
2412+
* Strips out all characters not allowed in a locale name.
2413+
*
2414+
* @since 6.2.1
2415+
*
2416+
* @param string $locale_name The locale name to be sanitized.
2417+
* @return string The sanitized value.
2418+
*/
2419+
function sanitize_locale_name( $locale_name ) {
2420+
// Limit to A-Z, a-z, 0-9, '_', '-'.
2421+
$sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $locale_name );
2422+
2423+
/**
2424+
* Filters a sanitized locale name string.
2425+
*
2426+
* @since 6.2.1
2427+
*
2428+
* @param string $sanitized The sanitized locale name.
2429+
* @param string $locale_name The locale name before sanitization.
2430+
*/
2431+
return apply_filters( 'sanitize_locale_name', $sanitized, $locale_name );
2432+
}
2433+
24112434
/**
24122435
* Converts lone & characters into `&#038;` (a.k.a. `&amp;`)
24132436
*

src/wp-includes/l10n.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ function determine_locale() {
147147
$wp_lang = '';
148148

149149
if ( ! empty( $_GET['wp_lang'] ) ) {
150-
$wp_lang = sanitize_text_field( $_GET['wp_lang'] );
150+
$wp_lang = sanitize_locale_name( wp_unslash( $_GET['wp_lang'] ) );
151151
} elseif ( ! empty( $_COOKIE['wp_lang'] ) ) {
152-
$wp_lang = sanitize_text_field( $_COOKIE['wp_lang'] );
152+
$wp_lang = sanitize_locale_name( wp_unslash( $_COOKIE['wp_lang'] ) );
153153
}
154154

155155
if ( ! empty( $wp_lang ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {

0 commit comments

Comments
 (0)