Skip to content

Commit 1032ca0

Browse files
committed
Grouped backports for the 5.5 branch.
- XML-RPC: Switch to `wp_safe_remote()` when fetching a pingback URL. - HTML API: Prevent `WP_HTML_Tag_Processor` instances being unserialized and add some extra logic for validating pattern and template file paths. - KSES: Optimize PCRE pattern detecting numeric character references. - Customize: Improve escaping approach used for nav menu attributes. - Media: Ensure the attachment parent is accessible to the user before showing a link to it in the media manager. - Administration: Ensure client-side templates are only detected when they're correctly associated with a script tag. - Filesystem API: Don't attempt to extract invalid files from a zip when using the PclZip library. Merges [61879-61885,61887,61890,61913] to the 5.5 branch. Props johnbillion, xknown, dmsnell, jorbin, peterwilson, desrosj, westonruter, jonsurrell, aurdasjb. git-svn-id: https://develop.svn.wordpress.org/branches/5.5@61955 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 30929f9 commit 1032ca0

12 files changed

Lines changed: 38 additions & 23 deletions

File tree

src/js/_enqueues/wp/util.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ window.wp = window.wp || {};
3636
};
3737

3838
return function ( data ) {
39-
compiled = compiled || _.template( $( '#tmpl-' + id ).html(), options );
39+
var el = document.querySelector( 'script#tmpl-' + id );
40+
if ( ! el ) {
41+
throw new Error( 'Template not found: ' + '#tmpl-' + id );
42+
}
43+
compiled = compiled || _.template( $( el ).html(), options );
4044
return compiled( data );
4145
};
4246
});

src/wp-admin/includes/class-walker-nav-menu-checklist.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) {
111111
$output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="' . esc_attr( $item->object ) . '" />';
112112
$output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="' . esc_attr( $item->menu_item_parent ) . '" />';
113113
$output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="' . esc_attr( $item->type ) . '" />';
114-
$output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="' . esc_attr( $item->title ) . '" />';
114+
$output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="' . htmlspecialchars( $item->title, ENT_QUOTES ) . '" />';
115115
$output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="' . esc_attr( $item->url ) . '" />';
116116
$output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="' . esc_attr( $item->target ) . '" />';
117-
$output .= '<input type="hidden" class="menu-item-attr-title" name="menu-item[' . $possible_object_id . '][menu-item-attr-title]" value="' . esc_attr( $item->attr_title ) . '" />';
118-
$output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="' . esc_attr( implode( ' ', $item->classes ) ) . '" />';
119-
$output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="' . esc_attr( $item->xfn ) . '" />';
117+
$output .= '<input type="hidden" class="menu-item-attr-title" name="menu-item[' . $possible_object_id . '][menu-item-attr-title]" value="' . htmlspecialchars( $item->attr_title, ENT_QUOTES ) . '" />';
118+
$output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="' . htmlspecialchars( implode( ' ', $item->classes ), ENT_QUOTES ) . '" />';
119+
$output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="' . htmlspecialchars( $item->xfn, ENT_QUOTES ) . '" />';
120120
}
121121

122122
}

src/wp-admin/includes/class-walker-nav-menu-edit.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) {
192192
<p class="description description-wide">
193193
<label for="edit-menu-item-title-<?php echo $item_id; ?>">
194194
<?php _e( 'Navigation Label' ); ?><br />
195-
<input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
195+
<input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo htmlspecialchars( $item->title, ENT_QUOTES ); ?>" />
196196
</label>
197197
</p>
198198
<p class="field-title-attribute field-attr-title description description-wide">
199199
<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
200200
<?php _e( 'Title Attribute' ); ?><br />
201-
<input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
201+
<input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo htmlspecialchars( $item->post_excerpt, ENT_QUOTES ); ?>" />
202202
</label>
203203
</p>
204204
<p class="field-link-target description">
@@ -210,13 +210,13 @@ public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) {
210210
<p class="field-css-classes description description-thin">
211211
<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
212212
<?php _e( 'CSS Classes (optional)' ); ?><br />
213-
<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode( ' ', $item->classes ) ); ?>" />
213+
<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo htmlspecialchars( implode( ' ', $item->classes ), ENT_QUOTES ); ?>" />
214214
</label>
215215
</p>
216216
<p class="field-xfn description description-thin">
217217
<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
218218
<?php _e( 'Link Relationship (XFN)' ); ?><br />
219-
<input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
219+
<input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo htmlspecialchars( $item->xfn, ENT_QUOTES ); ?>" />
220220
</label>
221221
</p>
222222
<p class="field-description description description-wide">

src/wp-admin/includes/file.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,11 @@ function _unzip_file_pclzip( $file, $to, $needed_dirs = array() ) {
16571657
continue;
16581658
}
16591659

1660+
// Don't extract invalid files:
1661+
if ( 0 !== validate_file( $file['filename'] ) ) {
1662+
continue;
1663+
}
1664+
16601665
$uncompressed_size += $file['size'];
16611666

16621667
$needed_dirs[] = $to . untrailingslashit( $file['folder'] ? $file['filename'] : dirname( $file['filename'] ) );

src/wp-includes/ID3/getid3.lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ public static function XML2array($XMLstring) {
723723
// http://websec.io/2012/08/27/Preventing-XEE-in-PHP.html
724724
// https://core.trac.wordpress.org/changeset/29378
725725
$loader = libxml_disable_entity_loader(true);
726-
$XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', LIBXML_NOENT);
726+
$XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', 0);
727727
$return = self::SimpleXMLelement2array($XMLobject);
728728
libxml_disable_entity_loader($loader);
729729
return $return;

src/wp-includes/class-wp-http-ixr-client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function query( ...$args ) {
8888
echo '<pre class="ixr_request">' . htmlspecialchars( $xml ) . "\n</pre>\n\n";
8989
}
9090

91-
$response = wp_remote_post( $url, $args );
91+
$response = wp_safe_remote_post( $url, $args );
9292

9393
if ( is_wp_error( $response ) ) {
9494
$errno = $response->get_error_code();

src/wp-includes/kses.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,8 +1800,8 @@ function wp_kses_normalize_entities( $string, $context = 'html' ) {
18001800
} else {
18011801
$string = preg_replace_callback( '/&amp;([A-Za-z]{2,8}[0-9]{0,2});/', 'wp_kses_named_entities', $string );
18021802
}
1803-
$string = preg_replace_callback( '/&amp;#(0*[0-9]{1,7});/', 'wp_kses_normalize_entities2', $string );
1804-
$string = preg_replace_callback( '/&amp;#[Xx](0*[0-9A-Fa-f]{1,6});/', 'wp_kses_normalize_entities3', $string );
1803+
$string = preg_replace_callback( '/&amp;#(0*[1-9][0-9]{0,6});/', 'wp_kses_normalize_entities2', $string );
1804+
$string = preg_replace_callback( '/&amp;#[Xx](0*[1-9A-Fa-f][0-9A-Fa-f]{0,5});/', 'wp_kses_normalize_entities3', $string );
18051805

18061806
return $string;
18071807
}

src/wp-includes/media.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3812,14 +3812,14 @@ function wp_prepare_attachment_for_js( $attachment ) {
38123812
$post_parent = false;
38133813
}
38143814

3815-
if ( $post_parent ) {
3815+
if ( $post_parent && current_user_can( 'read_post', $attachment->post_parent ) ) {
38163816
$parent_type = get_post_type_object( $post_parent->post_type );
38173817

38183818
if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $attachment->post_parent ) ) {
38193819
$response['uploadedToLink'] = get_edit_post_link( $attachment->post_parent, 'raw' );
38203820
}
38213821

3822-
if ( $parent_type && current_user_can( 'read_post', $attachment->post_parent ) ) {
3822+
if ( $parent_type ) {
38233823
$response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' );
38243824
}
38253825
}

src/wp-includes/nav-menu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item
492492
}
493493
}
494494

495-
if ( wp_unslash( $args['menu-item-title'] ) === wp_specialchars_decode( $original_title ) ) {
495+
if ( wp_unslash( $args['menu-item-title'] ) === $original_title ) {
496496
$args['menu-item-title'] = '';
497497
}
498498

src/wp-includes/template-loader.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,15 @@
101101
*
102102
* @param string $template The path of the template to include.
103103
*/
104-
$template = apply_filters( 'template_include', $template );
105-
if ( $template ) {
104+
$template = apply_filters( 'template_include', $template );
105+
$is_stringy = is_string( $template ) || ( is_object( $template ) && method_exists( $template, '__toString' ) );
106+
$template = $is_stringy ? realpath( (string) $template ) : null;
107+
if (
108+
is_string( $template ) &&
109+
( str_ends_with( $template, '.php' ) || str_ends_with( $template, '.html' ) ) &&
110+
is_file( $template ) &&
111+
is_readable( $template )
112+
) {
106113
include $template;
107114
} elseif ( current_user_can( 'switch_themes' ) ) {
108115
$theme = wp_get_theme();

0 commit comments

Comments
 (0)