Skip to content

Commit 24c1bf2

Browse files
committed
Security: Backport the WordPress 7.1.4 security fixes to the 5.6 branch.
- Users: Escape user login - Privacy: Harden column_email() output escaping in request list tables - Editor: Align block-delimiter whitespace matching between the PHP and JavaScript parsers. - Customizer: Improve changeset handling. - Upgrade/Install: Improve the handling of the upgrade working directory. - Customize: Resolve selective refresh partial placements as selectors only - Block parser: Only accept HTML whitespace in block delimiters This also updates @wordpress/block-serialization-default-parser@3.8.1. Merges [64873], [64874], [64876], [64877], [64879] to the 5.6 branch. Props xknown, jeremyfelt, jorbin, rfaile313, westonruter, jonsurrell, dmsnell, lancewillett, umut3806, marcs0h, antonade. git-svn-id: https://develop.svn.wordpress.org/branches/5.6@64925 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 38da368 commit 24c1bf2

21 files changed

Lines changed: 90 additions & 45 deletions

‎package-lock.json‎

Lines changed: 3 additions & 3 deletions
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
@@ -87,7 +87,7 @@
8787
"@wordpress/block-directory": "1.17.11",
8888
"@wordpress/block-editor": "5.1.8",
8989
"@wordpress/block-library": "2.26.11",
90-
"@wordpress/block-serialization-default-parser": "3.8.0",
90+
"@wordpress/block-serialization-default-parser": "3.8.1",
9191
"@wordpress/blocks": "6.24.3",
9292
"@wordpress/components": "11.1.6",
9393
"@wordpress/compose": "3.22.0",

‎src/js/_enqueues/wp/customize/preview-widgets.js‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,18 +415,25 @@ wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function(
415415
* @return {wp.customize.selectiveRefresh.Partial} The widget instance partial.
416416
*/
417417
ensureWidgetPlacementContainers: function( widgetId ) {
418-
var sidebarPartial = this, widgetPartial, wasInserted = false, partialId = 'widget[' + widgetId + ']';
418+
var sidebarPartial = this, sidebarArgs, widgetPartial, wasInserted = false, partialId = 'widget[' + widgetId + ']';
419419
widgetPartial = api.selectiveRefresh.partial( partialId );
420420
if ( ! widgetPartial ) {
421421
widgetPartial = new self.WidgetPartial( partialId, {
422422
params: {}
423423
} );
424424
}
425425

426+
// Build containers from the registered sidebar, since partial params can be declared in post content.
427+
sidebarArgs = _.findWhere( self.registeredSidebars, { id: sidebarPartial.sidebarId } );
428+
426429
// Make sure that there is a container element for the widget in the sidebar, if at least a placeholder.
427430
_.each( sidebarPartial.placements(), function( sidebarPlacement ) {
428431
var foundWidgetPlacement, widgetContainerElement;
429432

433+
if ( ! sidebarArgs ) {
434+
return;
435+
}
436+
430437
foundWidgetPlacement = _.find( widgetPartial.placements(), function( widgetPlacement ) {
431438
return ( widgetPlacement.context.sidebar_instance_number === sidebarPlacement.context.instanceNumber );
432439
} );
@@ -435,8 +442,8 @@ wp.customize.widgetsPreview = wp.customize.WidgetCustomizerPreview = (function(
435442
}
436443

437444
widgetContainerElement = $(
438-
sidebarPartial.params.sidebarArgs.before_widget.replace( /%1\$s/g, widgetId ).replace( /%2\$s/g, 'widget' ) +
439-
sidebarPartial.params.sidebarArgs.after_widget
445+
sidebarArgs.before_widget.replace( /%1\$s/g, widgetId ).replace( /%2\$s/g, 'widget' ) +
446+
sidebarArgs.after_widget
440447
);
441448

442449
// Handle rare case where before_widget and after_widget are empty.

‎src/js/_enqueues/wp/customize/selective-refresh.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ wp.customize.selectiveRefresh = ( function( $, api ) {
262262
if ( selector ) {
263263
selector += ', ';
264264
}
265-
selector += '[data-customize-partial-id="' + partial.id + '"]'; // @todo Consider injecting customize-partial-id-${id} classnames instead.
265+
selector += '[data-customize-partial-id="' + $.escapeSelector( partial.id ) + '"]';
266266

267-
return $( selector ).map( function() {
267+
return $( document ).find( selector ).map( function() {
268268
var container = $( this ), context;
269269

270270
context = container.data( 'customize-partial-placement-context' );

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ function wp_ajax_add_user( $action ) {
17001700
'show-link' => sprintf(
17011701
/* translators: %s: The new user. */
17021702
__( 'User %s added' ),
1703-
'<a href="#user-' . $user_id . '">' . $user_object->user_login . '</a>'
1703+
'<a href="#user-' . $user_id . '">' . esc_html( $user_object->user_login ) . '</a>'
17041704
),
17051705
'role' => $role,
17061706
),

‎src/wp-admin/includes/class-wp-ms-users-list-table.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function column_cb( $user ) {
238238
<label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>">
239239
<?php
240240
/* translators: %s: User login. */
241-
printf( __( 'Select %s' ), $user->user_login );
241+
printf( __( 'Select %s' ), esc_html( $user->user_login ) );
242242
?>
243243
</label>
244244
<input type="checkbox" id="blog_<?php echo $user->ID; ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ); ?>" />
@@ -271,9 +271,9 @@ public function column_username( $user ) {
271271

272272
if ( current_user_can( 'edit_user', $user->ID ) ) {
273273
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
274-
$edit = "<a href=\"{$edit_link}\">{$user->user_login}</a>";
274+
$edit = "<a href=\"{$edit_link}\">" . esc_html( $user->user_login ) . '</a>';
275275
} else {
276-
$edit = $user->user_login;
276+
$edit = esc_html( $user->user_login );
277277
}
278278

279279
?>

‎src/wp-admin/includes/class-wp-privacy-data-export-requests-list-table.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function column_email( $item ) {
9898
$row_actions['complete-request'] = $complete_request_markup;
9999
}
100100

101-
return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) );
101+
return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), esc_html( $item->email ), $this->row_actions( $row_actions ) );
102102
}
103103

104104
/**

‎src/wp-admin/includes/class-wp-privacy-data-removal-requests-list-table.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function column_email( $item ) {
104104
$row_actions['complete-request'] = $complete_request_markup;
105105
}
106106

107-
return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) );
107+
return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), esc_html( $item->email ), $this->row_actions( $row_actions ) );
108108
}
109109

110110
/**

‎src/wp-admin/includes/class-wp-privacy-requests-table.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public function column_default( $item, $column_name ) {
508508
* @return string Email column markup.
509509
*/
510510
public function column_email( $item ) {
511-
return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( array() ) );
511+
return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), esc_html( $item->email ), $this->row_actions( array() ) );
512512
}
513513

514514
/**

‎src/wp-admin/includes/class-wp-upgrader.php‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,21 @@ public function download_package( $package, $check_signatures = false, $hook_ext
289289
return $download_file;
290290
}
291291

292+
/**
293+
* Builds an unpredictable name for the directory a package is unpacked into.
294+
*
295+
* @since 7.1.4
296+
*
297+
* @param string $package The full local path or URI of the package.
298+
* @return string The directory name, without a path.
299+
*/
300+
private function get_working_dir_name( $package ) {
301+
// Strip off any .tmp or .zip suffixes.
302+
$name = basename( basename( $package, '.tmp' ), '.zip' );
303+
304+
return $name . '-' . wp_generate_password( 16, false );
305+
}
306+
292307
/**
293308
* Unpack a compressed package file.
294309
*
@@ -308,16 +323,32 @@ public function unpack_package( $package, $delete_package = true ) {
308323

309324
$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
310325

311-
// Clean up contents of upgrade directory beforehand.
326+
// Clean up contents of upgrade directory beforehand, keeping its index.php.
312327
$upgrade_files = $wp_filesystem->dirlist( $upgrade_folder );
313328
if ( ! empty( $upgrade_files ) ) {
314329
foreach ( $upgrade_files as $file ) {
330+
if ( 'index.php' === $file['name'] ) {
331+
continue;
332+
}
333+
315334
$wp_filesystem->delete( $upgrade_folder . $file['name'], true );
316335
}
317336
}
318337

319-
// We need a working directory - strip off any .tmp or .zip suffixes.
320-
$working_dir = $upgrade_folder . basename( basename( $package, '.tmp' ), '.zip' );
338+
/*
339+
* The upgrade directory is web-served. Keep it from being listed, as core does
340+
* for wp-content and its plugins and themes directories, so the name of the
341+
* working directory created below cannot be discovered from a directory index.
342+
*/
343+
if ( ! $wp_filesystem->is_dir( $upgrade_folder ) ) {
344+
$wp_filesystem->mkdir( $upgrade_folder, FS_CHMOD_DIR );
345+
}
346+
if ( ! $wp_filesystem->exists( $upgrade_folder . 'index.php' ) ) {
347+
$wp_filesystem->put_contents( $upgrade_folder . 'index.php', "<?php\n// Silence is golden.\n", FS_CHMOD_FILE );
348+
}
349+
350+
// We need a working directory.
351+
$working_dir = $upgrade_folder . $this->get_working_dir_name( $package );
321352

322353
// Clean up working directory.
323354
if ( $wp_filesystem->is_dir( $working_dir ) ) {

0 commit comments

Comments
 (0)