Skip to content

Commit 30625e1

Browse files
committed
Security: Backport the WordPress 7.1.4 security fixes to the 5.4 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.5.1. Merges [64873], [64874], [64876], [64877], [64879] to the 5.4 branch. Props xknown, jeremyfelt, jorbin, rfaile313, westonruter, jonsurrell, dmsnell, lancewillett, umut3806, marcs0h, antonade. git-svn-id: https://develop.svn.wordpress.org/branches/5.4@64927 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 47512c0 commit 30625e1

21 files changed

Lines changed: 96 additions & 49 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
@@ -80,7 +80,7 @@
8080
"@wordpress/block-directory": "1.5.9",
8181
"@wordpress/block-editor": "3.7.9",
8282
"@wordpress/block-library": "2.14.11",
83-
"@wordpress/block-serialization-default-parser": "3.5.0",
83+
"@wordpress/block-serialization-default-parser": "3.5.1",
8484
"@wordpress/blocks": "6.12.4",
8585
"@wordpress/components": "9.2.7",
8686
"@wordpress/compose": "3.11.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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,17 @@ wp.customize.selectiveRefresh = ( function( $, api ) {
256256
* @return {Array.<Placement>}
257257
*/
258258
placements: function() {
259-
var partial = this, selector;
259+
var partial = this, containers;
260260

261-
selector = partial.params.selector || '';
262-
if ( selector ) {
263-
selector += ', ';
261+
// Match the attribute value directly without requiring a selector escaper.
262+
containers = $( document ).find( '[data-customize-partial-id]' ).filter( function() {
263+
return this.getAttribute( 'data-customize-partial-id' ) === String( partial.id );
264+
} );
265+
if ( partial.params.selector ) {
266+
containers = containers.add( $( document ).find( partial.params.selector ) );
264267
}
265-
selector += '[data-customize-partial-id="' + partial.id + '"]'; // @todo Consider injecting customize-partial-id-${id} classnames instead.
266268

267-
return $( selector ).map( function() {
269+
return containers.map( function() {
268270
var container = $( this ), context;
269271

270272
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
@@ -1696,7 +1696,7 @@ function wp_ajax_add_user( $action ) {
16961696
'show-link' => sprintf(
16971697
/* translators: %s: The new user. */
16981698
__( 'User %s added' ),
1699-
'<a href="#user-' . $user_id . '">' . $user_object->user_login . '</a>'
1699+
'<a href="#user-' . $user_id . '">' . esc_html( $user_object->user_login ) . '</a>'
17001700
),
17011701
'role' => $role,
17021702
),

‎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
@@ -67,7 +67,7 @@ public function column_email( $item ) {
6767
'download-data' => $download_data_markup,
6868
);
6969

70-
return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) );
70+
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 ) );
7171
}
7272

7373
/**

‎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
@@ -73,7 +73,7 @@ public function column_email( $item ) {
7373
);
7474
}
7575

76-
return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) );
76+
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 ) );
7777
}
7878

7979
/**

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

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

421421
/**

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,21 @@ public function download_package( $package, $check_signatures = false ) {
286286
return $download_file;
287287
}
288288

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

306321
$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
307322

308-
// Clean up contents of upgrade directory beforehand.
323+
// Clean up contents of upgrade directory beforehand, keeping its index.php.
309324
$upgrade_files = $wp_filesystem->dirlist( $upgrade_folder );
310325
if ( ! empty( $upgrade_files ) ) {
311326
foreach ( $upgrade_files as $file ) {
327+
if ( 'index.php' === $file['name'] ) {
328+
continue;
329+
}
330+
312331
$wp_filesystem->delete( $upgrade_folder . $file['name'], true );
313332
}
314333
}
315334

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

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

0 commit comments

Comments
 (0)