Skip to content

Commit e1f5752

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

File tree

13 files changed

+218
-5
lines changed

13 files changed

+218
-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.7.8",
3+
"version": "5.7.9",
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@
6969
<div class="about__section changelog">
7070
<div class="column has-border has-subtle-background-color">
7171
<h2 class="is-smaller-heading"><?php _e( 'Maintenance and Security Releases' ); ?></h2>
72+
<p>
73+
<?php
74+
printf(
75+
/* translators: %s: WordPress version number. */
76+
__( '<strong>Version %s</strong> addressed some security issues.' ),
77+
'5.7.9'
78+
);
79+
?>
80+
<?php
81+
printf(
82+
/* translators: %s: HelpHub URL. */
83+
__( 'For more information, see <a href="%s">the release notes</a>.' ),
84+
sprintf(
85+
/* translators: %s: WordPress version. */
86+
esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
87+
sanitize_title( '5.7.9' )
88+
)
89+
);
90+
?>
91+
</p>
92+
7293
<p>
7394
<?php
7495
printf(

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

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

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

src/wp-includes/blocks.php

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

567+
if ( false !== strpos( $text, '<!--' ) && false !== strpos( $text, '--->' ) ) {
568+
$text = preg_replace_callback( '%<!--(.*?)--->%', '_filter_block_content_callback', $text );
569+
}
570+
567571
$blocks = parse_blocks( $text );
568572
foreach ( $blocks as $block ) {
569573
$block = filter_block_kses( $block, $allowed_html, $allowed_protocols );
@@ -573,6 +577,19 @@ function filter_block_content( $text, $allowed_html = 'post', $allowed_protocols
573577
return $result;
574578
}
575579

580+
/**
581+
* Callback used for regular expression replacement in filter_block_content().
582+
*
583+
* @private
584+
* @since 6.2.1
585+
*
586+
* @param array $matches Array of preg_replace_callback matches.
587+
* @return string Replacement string.
588+
*/
589+
function _filter_block_content_callback( $matches ) {
590+
return '<!--' . rtrim( $matches[1], '-' ) . '-->';
591+
}
592+
576593
/**
577594
* Filters and sanitizes a parsed block to remove non-allowable HTML from block
578595
* attribute values.

src/wp-includes/formatting.php

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

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

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
@@ -4308,7 +4308,8 @@ function wp_enqueue_media( $args = array() ) {
43084308
/** This filter is documented in wp-admin/includes/media.php */
43094309
'captions' => ! apply_filters( 'disable_captions', '' ),
43104310
'nonce' => array(
4311-
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
4311+
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
4312+
'setAttachmentThumbnail' => wp_create_nonce( 'set-attachment-thumbnail' ),
43124313
),
43134314
'post' => array(
43144315
'id' => 0,

0 commit comments

Comments
 (0)