Skip to content

Commit e9db099

Browse files
committed
Security: Backport the WordPress 7.1.4 security fixes to the 6.1 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 - Escape the labels of the post navigation and comments pagination links This also updates @wordpress/block-library@7.14.17, @wordpress/block-serialization-default-parser@4.17.2. Merges [64873], [64874], [64876], [64877], [64879] to the 6.1 branch. Props xknown, jeremyfelt, jorbin, rfaile313, westonruter, jonsurrell, dmsnell, lancewillett, umut3806, marcs0h, antonade. git-svn-id: https://develop.svn.wordpress.org/branches/6.1@64920 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 97299b4 commit e9db099

24 files changed

Lines changed: 102 additions & 52 deletions

‎package-lock.json‎

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
"@wordpress/blob": "3.17.1",
8484
"@wordpress/block-directory": "3.15.15",
8585
"@wordpress/block-editor": "10.0.10",
86-
"@wordpress/block-library": "7.14.16",
87-
"@wordpress/block-serialization-default-parser": "4.17.1",
86+
"@wordpress/block-library": "7.14.17",
87+
"@wordpress/block-serialization-default-parser": "4.17.2",
8888
"@wordpress/blocks": "11.16.4",
8989
"@wordpress/components": "21.0.7",
9090
"@wordpress/compose": "5.15.2",

‎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="' + CSS.escape( 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
@@ -1747,7 +1747,7 @@ function wp_ajax_add_user( $action ) {
17471747
'show-link' => sprintf(
17481748
/* translators: %s: The new user. */
17491749
__( 'User %s added' ),
1750-
'<a href="#user-' . $user_id . '">' . $user_object->user_login . '</a>'
1750+
'<a href="#user-' . $user_id . '">' . esc_html( $user_object->user_login ) . '</a>'
17511751
),
17521752
'role' => $role,
17531753
),

‎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( $item ) {
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
@@ -523,7 +523,7 @@ public function column_created_timestamp( $item ) {
523523
* @return string Email column markup.
524524
*/
525525
public function column_email( $item ) {
526-
return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( array() ) );
526+
return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), esc_html( $item->email ), $this->row_actions( array() ) );
527527
}
528528

529529
/**

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

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

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

311326
$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
312327

313-
// Clean up contents of upgrade directory beforehand.
328+
// Clean up contents of upgrade directory beforehand, keeping its index.php.
314329
$upgrade_files = $wp_filesystem->dirlist( $upgrade_folder );
315330
if ( ! empty( $upgrade_files ) ) {
316331
foreach ( $upgrade_files as $file ) {
332+
if ( 'index.php' === $file['name'] ) {
333+
continue;
334+
}
335+
317336
$wp_filesystem->delete( $upgrade_folder . $file['name'], true );
318337
}
319338
}
320339

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

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

0 commit comments

Comments
 (0)