Skip to content

Commit ea6e6d4

Browse files
committed
Security: Backport the WordPress 7.1.4 security fixes to the 5.9 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@6.0.33, @wordpress/block-serialization-default-parser@4.2.4. Merges [64873], [64874], [64876], [64877], [64879] to the 5.9 branch. Props xknown, jeremyfelt, jorbin, rfaile313, westonruter, jonsurrell, dmsnell, lancewillett, umut3806, marcs0h, antonade. git-svn-id: https://develop.svn.wordpress.org/branches/5.9@64922 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 66e2170 commit ea6e6d4

22 files changed

Lines changed: 98 additions & 53 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
@@ -84,8 +84,8 @@
8484
"@wordpress/blob": "3.2.2",
8585
"@wordpress/block-directory": "3.0.32",
8686
"@wordpress/block-editor": "8.0.18",
87-
"@wordpress/block-library": "6.0.32",
88-
"@wordpress/block-serialization-default-parser": "4.2.3",
87+
"@wordpress/block-library": "6.0.33",
88+
"@wordpress/block-serialization-default-parser": "4.2.4",
8989
"@wordpress/blocks": "11.1.5",
9090
"@wordpress/components": "19.2.3",
9191
"@wordpress/compose": "5.0.7",

‎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
@@ -1709,7 +1709,7 @@ function wp_ajax_add_user( $action ) {
17091709
'show-link' => sprintf(
17101710
/* translators: %s: The new user. */
17111711
__( 'User %s added' ),
1712-
'<a href="#user-' . $user_id . '">' . $user_object->user_login . '</a>'
1712+
'<a href="#user-' . $user_id . '">' . esc_html( $user_object->user_login ) . '</a>'
17131713
),
17141714
'role' => $role,
17151715
),

‎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
@@ -242,7 +242,7 @@ public function column_cb( $item ) {
242242
<label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>">
243243
<?php
244244
/* translators: %s: User login. */
245-
printf( __( 'Select %s' ), $user->user_login );
245+
printf( __( 'Select %s' ), esc_html( $user->user_login ) );
246246
?>
247247
</label>
248248
<input type="checkbox" id="blog_<?php echo $user->ID; ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ); ?>" />
@@ -275,9 +275,9 @@ public function column_username( $user ) {
275275

276276
if ( current_user_can( 'edit_user', $user->ID ) ) {
277277
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
278-
$edit = "<a href=\"{$edit_link}\">{$user->user_login}</a>";
278+
$edit = "<a href=\"{$edit_link}\">" . esc_html( $user->user_login ) . '</a>';
279279
} else {
280-
$edit = $user->user_login;
280+
$edit = esc_html( $user->user_login );
281281
}
282282

283283
?>

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

533533
/**

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)